Book a 30-min callBook a call

Vector search indexes explained: HNSW, IVF and product quantization

How approximate nearest neighbor indexes work: HNSW graphs, IVF clustering, product quantization, DiskANN, filtered search, and how to benchmark recall.

A field of dots in three circled clusters, and a query dot reached through a small layered graph of boxes.
Written by
BYD Tech
Published
Topic
Deep dives
Reading time
16 min read

Questions people ask

Is HNSW always better than IVF?

No. HNSW usually reaches a given recall at lower latency, and pgvector's README says it has the better speed and recall trade-off, but it uses more memory, builds more slowly and handles deletes poorly. IVF builds faster, uses less memory and deletes easily, at the cost of a training step and retraining when the data drifts.

What recall should a vector index target?

There is no universal number; it depends on what a missed neighbor costs. Measure recall@k against exact search at several settings of the search parameter, run your end-to-end evaluation at each, and keep the cheapest setting beyond which answer quality stops improving.

Why does my filtered vector query return fewer than k results?

The index probably searched first and filtered afterward. If only a small share of vectors match the filter, most of the candidates are thrown away. Use iterative scans or in-index filtering if your database supports them, oversample candidates, or use a regular index on the filter column with an exact scan when the filter is very selective.

When is exact search good enough?

When the collection is small, the query rate is low, or filters already narrow the search to a small set. A flat scan has perfect recall and no index to tune or rebuild, so measure its latency before adding an ANN index.

Building something like this?