Table of Contents

Public namespace Rowles.LeanLucene.Codecs.Hnsw

Classes

Public class HnswBuildConfig

Build-time configuration for HNSW vector graphs.

Internal classInternal 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.

Internal classInternal HnswGraphBuilder

Bulk constructor for HnswGraph. Performs a deterministic shuffle of insertion order when a seed is supplied so that builds are reproducible.

Internal classInternal HnswReader

Reads a HnswGraph previously written by HnswWriter. The graph is materialised into the frozen, read-only state ready for concurrent search.

Internal classInternal HnswSearchScratch

Reusable scratch buffers for one HNSW SearchLayer traversal. 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.

Internal classInternal 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

Internal structInternal HnswSearchResult

Result entry returned from HNSW search.

Internal structInternal HnswSearchStats

Per-call HNSW search statistics. NodesVisited is the primary recall-vs-cost signal: it counts distinct nodes visited during the layer-zero traversal.