Benchmarking nearest neighbors
Doing fast searching of nearest neighbors in high dimensional spaces is an increasingly important problem, but so far there has not been a lot of empirical attempts at comparing approaches in an objective way.
This project contains some tools to benchmark various implementations of approximate nearest neighbor (ANN) search for different metrics. We have pregenerated datasets (in HDF5) formats and we also have Docker containers for each algorithm. There's a test suite that makes sure every algorithm works.
- scikit-learn: LSHForest, KDTree, BallTree
- NMSLIB (Non-Metric Space Library): SWGraph, HNSW, BallTree, MPLSH
- hnswlib (a part of nmslib project)
- NGT: ONNG, PANNG, QG
- OpenSearch KNN
- DiskANN: Vamana, Vamana-PQ
- scipy: cKDTree
We have a number of precomputed data sets for this. All data sets are pre-split into train/test and come with ground truth data in the form of the top 100 neighbors. We store them in a HDF5 format:
|Dataset||Dimensions||Train size||Test size||Neighbors||Distance||Download|
Interactive plots can be found at http://ann-benchmarks.com. These are all as of December 2021, running all benchmarks on a r5.4xlarge machine on AWS with
The only prerequisite is Python (tested with 3.6) and Docker.
- Clone the repo.
pip install -r requirements.txt.
python install.pyto build all the libraries inside Docker containers (this can take a while, like 10-30 minutes).
python run.py(this can take an extremely long time, potentially days)
python create_website.pyto plot results.
python data_export.py --out res.csvto export all results into a csv file for additional post-processing.
You can customize the algorithms and datasets if you want to:
- Check that
algos.yamlcontains the parameter settings that you want to test
- To run experiments on SIFT, invoke
python run.py --dataset glove-100-angular. See
python run.py --helpfor more information on possible settings. Note that experiments can take a long time.
- To process the results, either use
python plot.py --dataset glove-100-angularor
python create_website.py. An example call:
python create_website.py --plottype recall/time --latex --scatter --outputdir website/.
Including your algorithm
- Add your algorithm into
ann_benchmarks/algorithmsby providing a small Python wrapper.
- Add a Dockerfile in
- Add it to
- Add it to
- Everyone is welcome to submit pull requests with tweaks and changes to how each library is being used.
- In particular: if you are the author of any of these libraries, and you think the benchmark can be improved, consider making the improvement and submitting a pull request.
- This is meant to be an ongoing project and represent the current state.
- Make everything easy to replicate, including installing and preparing the datasets.
- Try many different values of parameters for each library and ignore the points that are not on the precision-performance frontier.
- High-dimensional datasets with approximately 100-1000 dimensions. This is challenging but also realistic. Not more than 1000 dimensions because those problems should probably be solved by doing dimensionality reduction separately.
- Single queries are used by default. ANN-Benchmarks enforces that only one CPU is saturated during experimentation, i.e., no multi-threading. A batch mode is available that provides all queries to the implementations at once. Add the flag
plot.pyto enable batch mode.
- Avoid extremely costly index building (more than several hours).
- Focus on datasets that fit in RAM. For billion-scale benchmarks, see the related big-ann-benchmarks project.
- We mainly support CPU-based ANN algorithms. GPU support exists for FAISS, but it has to be compiled with GPU support locally and experiments must be run using the flags
- Do proper train/test set of index data and query points.
- Note that we consider that set similarity datasets are sparse and thus we pass a sorted array of integers to algorithms to represent the set of each user.
The following publication details design principles behind the benchmarking framework:
- M. Aumüller, E. Bernhardsson, A. Faithfull: ANN-Benchmarks: A Benchmarking Tool for Approximate Nearest Neighbor Algorithms. Information Systems 2019. DOI: 10.1016/j.is.2019.02.006