Rewrite knn by using builtins.