Privacy

Accept optional first-party analytics or decline. Functional journey and sound preferences stay on this device.

Read the privacy notice

Open to talks and workshops

TermOctober 10, 2026

HNSW index

Category
Retrieval & RAG
Also known as
  • Hierarchical Navigable Small World
  • ANN index
Related terms
  • Vector search
  • Embeddings
  • pgvector
01

A graph-based index that finds approximately nearest vectors quickly, without comparing the query to every row.

02

HNSW (Hierarchical Navigable Small World) builds layers of links between similar vectors. A search starts at the sparse top layer and walks down towards the closest matches. It trades a little accuracy for a lot of speed. In Postgres with pgvector, it only helps when the query is ORDER BY embedding <=> $1 LIMIT n directly on the indexed table.

03

My assistant's HNSW index was never used, because a DISTINCT ON above the search made Postgres sort by id first and compute the distance for every row.

04

If retrieval is slow, the first question is whether the index is being used at all.