Expand description
Approximate nearest-neighbour index.
Implements a minimal Hierarchical Navigable Small World (HNSW) graph following the algorithm of Malkov & Yashunin, “Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs” (TPAMI 2018, arXiv:1603.09320).
Why hand-rolled rather than instant-distance or hnsw_rs:
- The index needs to interleave with our codec layer so that
the on-disk representation is a
crate::encoding::EncodedVectornot anf32slice. Hooking that into a third-party crate requires either keeping a parallelVec<f32>cache (doubles memory) or wrapping itsPointtrait in adapters (locks us into that crate’s API surface). - We need explicit
deletesemantics.instant-distancedoes not expose deletion; we would have to maintain a tombstone set externally. Inverting that with a hand-rolled HNSW is a small amount of code and keeps the public API honest. - No new third-party dependency, no review burden.
Defaults:
M = 16(max bidirectional connections per layer)M0 = 32(max connections at layer 0)ef_construction = 200ef_search = 50- Layer assignment uses
floor(-ln(rand()) * mL)withmL = 1 / ln(M)per the original paper.
The index is single-threaded; coarser concurrency lives at
the crate::storage layer where a per-table Mutex is
held across an insert / search call.
Structs§
- Hnsw
Index - Hand-rolled HNSW index over
f32vectors. - Hnsw
Params - Tuneable parameters.
- Search
Result - Result entry from a search query.
Enums§
- Index
Error - Errors returned by the index.
Type Aliases§
- NodeId
- Stable identifier for the value an index node points back to.