hsnw
Hierarchical Navigable Small World Graph for fast ANN search
Enable the serde1
feature to serialize and deserialize Hamming
and Euclidean
types.
Example
Binary feature search using hamming distance
use ;
use ;
Please refer to the space
documentation for the trait and types regarding distance. It also contains special Bits128
- Bits4096
tuple structs that wrap an array of bytes and enable SIMD capability. Benchmarks provided use these SIMD impls.
Floating-point search using euclidean distance
An implementation is currently not provided for euclidean distance after a recent refactor. Hamming distance was more relevant at the time, and so that was prioritized. To implement euclidean distance, do something roughly like the following:
;
Note that the above implementation may have some numerical error on high dimensionality. In that case use a Kahan sum instead.
Benchmarks
Here is a recall graph that you can compare to its alternatives:
For more benchmarks and how to benchmark, see benchmarks.md
.
Implementation
This is based on the paper "Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs" by Yu. A. Malkov and D. A. Yashunin. This paper builds on the original paper for NSW. There are multiple papers written by the authors on NSW, which proceeded HNSW.
For more details about parameters and details of the implementation, see implementation.md
.
Credit
This is in no way a direct copy or reimplementation of the original implementation. This was made purely based on the paper without reference to the original headers. The paper is very well written and easy to understand, with some minor exceptions. Thank you to the authors for your valuble contribution.
Questions? Contributions? Excited?
Please visit the Rust CV Discord.