Skip to main content

Module index

Module index 

Source
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::EncodedVector not an f32 slice. Hooking that into a third-party crate requires either keeping a parallel Vec<f32> cache (doubles memory) or wrapping its Point trait in adapters (locks us into that crate’s API surface).
  • We need explicit delete semantics. instant-distance does 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 = 200
  • ef_search = 50
  • Layer assignment uses floor(-ln(rand()) * mL) with mL = 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§

HnswIndex
Hand-rolled HNSW index over f32 vectors.
HnswParams
Tuneable parameters.
SearchResult
Result entry from a search query.

Enums§

IndexError
Errors returned by the index.

Type Aliases§

NodeId
Stable identifier for the value an index node points back to.