Approximate Nearest Neighbor Search (ANN)

Approximate Nearest Neighbor (ANN) search finds vectors close to a query vector without comparing against every vector in the dataset. Exact nearest-neighbor search is O(n × d) — an exhaustive scan that becomes infeasible at millions or billions of vectors and real-time query rates. ANN methods trade a small, tunable loss of recall for orders-of-magnitude gains in speed and (often) memory.

The Core Trade-off

Every ANN index sits on a curve of search quality vs. speed, with index size / memory as a third axis. Exact (Flat) search is 100% recall but slowest; each approximate index gives up a little recall to prune the search space. The practical skill is tuning each index’s knobs to land where the application needs on that curve.

Index Families

FamilyApproachNote
FlatExhaustive brute forceExact baseline, not an approximation
LSHHash similar vectors into shared bucketsBest at low dimensionality
HNSWMulti-layer proximity graph traversalDominant for high-recall, low-latency
IVFCluster into Voronoi cells, probe nearestScales to very large corpora
Vector QuantizationCompress vectors (PQ/SQ/BQ)Combined with IVF or HNSW

Evaluation

ANN quality is measured by Recall@k — the fraction of the true top-k neighbors an approximate search returns — reported alongside query latency and index size. See Vector Search Evaluation.

The same quantity is often called overlap@k: run the exact search, run the approximate search, and compute the overlap between the two result sets. The vocabularies are interchangeable, and both are measured against a brute-force baseline, which is why an exact scan remains useful even in systems that never serve one.

How Much Recall Loss Is Acceptable

Tolerance is a property of the use case, not of the index. Jo Kristian Bergum frames the extremes: a billion-photo image search does not need perfect recall — “there are many equally great cat photos” — while a retina scan deciding building access needs excellent overlap@1. Academic ANN work separates these as high-recall and low-recall settings.

The three axes to price before adopting ANN at all are the latency SLA, the anticipated peak throughput, and the accuracy loss the application can absorb — which together decide how many servers are needed, or whether servers are needed. See Three mistakes when introducing embeddings and vector search.

Tools

  • FAISS — reference library implementing all major ANN index families
  • ann-benchmarks — the standard recall-vs-QPS comparison across implementations

Datasets

  • SIFT1M — the conventional benchmark workload for these comparisons

Articles