How HNSW graph and VectorStore work together
masterhnswlib-rs decouples the graph structure from the actual vector data:
Hnsw<K, M>: Owns the HNSW graph and maintains a mapping from your external keyKto an internalNodeId.VectorStore: A trait-based backend keyed byNodeIdthat provides the actual vector data on demand during search or insertion.
This separation allows you to keep vectors in any storage format (dense arrays, memory-mapped files, etc.) while the graph remains a compact, dense structure of u32 NodeIds.
To fetch a vector using an external key:
- Get the internal ID:
let id = hnsw.node_id(&key)?; - Retrieve the vector:
let v = vectors.vector(id).ok_or(Error::MissingVector)?;