Data Stores

Vector Index (ANN)

Also known as: approximate nearest neighbour, ANN index, HNSW

Definition

A vector index accelerates nearest-neighbour search over high-dimensional embeddings by trading exactness for speed. Structures such as HNSW and IVF return approximate results in logarithmic rather than linear time, with a recall/latency trade-off controlled by build and query parameters.

Last reviewed · Part of the Architecture Glossary

In practice

Exact search over a million 1,536-dimension vectors is a million dot products per query — hundreds of milliseconds. ANN indexes cut that to single-digit milliseconds by not looking everywhere.

IndexBuildQueryMemoryNotes
Flat (exact)noneO(n)vectors onlyCorrect baseline; fine below ~50k vectors
IVFfastfastlowClusters; recall depends on nprobe
HNSWslowvery fasthigh (graph)The usual production default
Product quantisationmediumfastvery lowCompresses vectors; recall cost

The parameters that matter for HNSW: M (graph degree, memory and recall), ef_construction (build quality), ef_search (query-time recall/latency dial — the one to tune per endpoint).

Filtering is the hard part. "Nearest neighbours where tenant_id = X" either pre-filters (correct, slow) or post-filters (fast, and may return nothing when the filter is selective). Check which one your store does before designing a multi-tenant retrieval path around it.

When it matters

RAG retrieval, semantic search, deduplication, recommendation.

Common mistake

Reporting latency without recall. An ANN index is only meaningful as a pair — 5 ms at 70% recall is a worse system than 12 ms at 95%, and only one of those numbers usually makes it into the benchmark slide.

See also

Go deeper