mem1.wiki

Patterns

Pattern

Hierarchical Navigable Small World (HNSW)

Multi-layer graph index for approximate nearest neighbour search. De-facto default for vector databases when latency matters more than perfect recall.

Taxonomy
patterns.indexing
Category
indexing
Complexity
medium
When to use
Sub-10ms ANN queries on 100k-100M vectors, memory budget allows the index to stay in RAM.
When NOT to use
Workloads needing exact recall, frequent rebuilds on tiny datasets, or strict memory caps.

What it is

HNSW builds a layered proximity graph: upper layers are sparse and used for coarse navigation; lower layers are dense and used for refinement. A query starts at the top layer, greedy-walks toward the target, descends, and refines. Recall is tuned with ef_search; build cost is tuned with ef_construction and M.

Where you see it

Default ANN index in Qdrant, Milvus, Weaviate, pgvector (vector_hnsw_ops), Chroma.

Trade-offs

Common mistakes