yahoojapan / NGT

Nearest Neighbor Search with Neighborhood Graph and Tree for High-dimensional Data
Apache License 2.0
1.24k stars 114 forks source link

Batch query from python #41

Closed scottgigante closed 4 years ago

scottgigante commented 4 years ago

Thanks for building NGT, this is excellent! I'm wondering what would be the most efficient way to compute the approximate k nearest neighbours for all data points in the index in python. I see you have a batch_insert function but I do not see an equivalent batch_query function. The equivalent code in e.g. scikit-learn would be

import sklearn.neighbors
distances, indices = sklearn.neighbors.NearestNeighbors(n_neighbors).fit(data).kneighbors(data)
masajiro commented 4 years ago

Thank you for your interest.

Although NGT does not have batch_query you mentioned, you only have to iterate search() with all of the registered objects after constructing an index.

scottgigante commented 4 years ago

Thanks. I was hoping to avoid a Python for loop, but this will be sufficient. Thank you!