Rowles.LeanLucene.Codecs.Hnsw
Classes
HnswBuildConfig
Build-time configuration for HNSW vector graphs.
HnswGraph
In-memory hierarchical navigable small world graph. Vectors are expected to be L2-normalised so that dot product equals cosine similarity; the graph itself works in distance space (lower is better) with distance defined as negative dot product.
HnswGraphBuilder
Bulk constructor for HnswGraph. Performs a deterministic shuffle of insertion order when a seed is supplied so that builds are reproducible.
HnswReader
Reads a HnswGraph previously written by HnswWriter. The graph is materialised into the frozen, read-only state ready for concurrent search.
HnswSearchScratch
Reusable scratch buffers for one HNSW
SearchLayertraversal. Borrow via Borrow(), dispose to return. A single instance per thread is held in System.ThreadStaticAttribute storage so steady-state queries avoid repeated System.Collections.Generic.HashSet`1 and System.Collections.Generic.PriorityQueue`2 allocations. Concurrent searches on the same thread (e.g. nested calls) fall back to a fresh allocation; only the outermost borrow uses the cached instance.
HnswWriter
Writes a frozen HnswGraph to disc. File format (version 1):
[magic:int32][version:byte=1] [dimension:int32][normalised:byte][M:int32][M0:int32][efConstruction:int32] [seed:int64][entryPoint:int32][maxLevel:int32][nodeCount:int32] [levelCount:int32] for each level (descending from max to 0): [nodeCount:int32] for each node: [docId:int32][neighbourCount:int32][neighbours:int32[]]
Structs
HnswSearchResult
Result entry returned from HNSW search.
HnswSearchStats
Per-call HNSW search statistics. NodesVisited is the primary recall-vs-cost signal: it counts distinct nodes visited during the layer-zero traversal.