knn graph constructor