HNSW Vector Index

The backbone vector indexing algorithm powering all Zenpower retrieval. Hierarchical Navigable Small World (HNSW) builds a hierarchical graph structure that enables fast approximate nearest neighbor (ANN) search across millions of vectors — combining speed and accuracy that exhaustive search cannot match at scale.

The Graph Structure

Layer 0

The base layer contains all vectors, each connected to its nearest neighbors in a dense local graph. Every vector in the index lives here — this is where final candidate evaluation happens.

Higher Layers

Progressively sparser layers hold a random subset of vectors with long-range connections. These upper layers act as a highway network — enabling fast coarse navigation across the index before descending into dense regions.

Search

Queries enter at the top layer and greedily descend through layers, following edges toward the nearest neighbor at each step. The result is a beam-guided traversal that finds approximate neighbors in logarithmic time.

Performance

Recall

99.1% at ef=200. Near-exact accuracy with a fraction of the compute cost of exhaustive search.

Latency

<5ms P95 for 1M vectors. Sub-millisecond on smaller indexes — fast enough for real-time agent context injection.

Throughput

10K queries/second per index. Concurrent search requests are handled without degradation under load.

Scalability

Millions of vectors per index. Graph construction is incremental — new vectors are inserted online without rebuilding the full index.

Configuration

M

Number of bidirectional connections per node. Higher values improve recall and reduce graph fragmentation at the cost of more memory and slower construction. Typical range: 1664.

ef_construction

Build-time beam width controlling graph quality during index construction. Higher values produce a better-connected graph and higher recall, but increase build time. Typical range: 100500.

ef_search

Query-time beam width controlling the candidate set explored during search. Higher values increase recall at the cost of latency. Can be tuned per query without rebuilding the index.

Access

API Documentation

HNSW powers all vector search across RAG, BRAIN, and agent memory systems.