Approximate Nearest Neighbor Search

Compare hierarchical graph navigation, inverted-file filtering, and product quantization using explicit recall and distance objectives.

Source
Anbloq
Language
English
Created
Updated
Chapters
3
Reading time
2 min
In this article3 chapters
  1. A graph index navigates local neighborhoods
  2. Inverted files and compressed distances restrict different costs
  3. Report recall against an exact baseline

A graph index navigates local neighborhoods

HNSW builds layers of proximity graphs with progressively fewer points at upper layers. Search starts at a high layer and descends from an improving candidate. A search on the dense base layer keeps a candidate frontier, with its exploration budget influencing recall and latency. Connectivity can deteriorate around clusters or segment boundaries. A configuration tuned to one query distribution can therefore perform differently when the query mix changes.

Cosine and Euclidean ranking agree for unit vectors under a common tie convention. Locality-sensitive hashing gives another retrieval design whose candidate probability can be calculated from its similarity assumptions.

Inverted files and compressed distances restrict different costs

An inverted-file index assigns database vectors to coarse clusters. It probes the lists of several nearby clusters, trading fewer examined points against the chance that a true neighbor was assigned elsewhere. Product quantization splits each vector into \(m\) subvectors and stores a codeword index \(c_j\) per block. For a query \(q\) and reconstructed block \(u_{j,c_j}\), the asymmetric squared distance is

\[ \|q-\widehat x\|_2^2=\sum_{j=1}^{m}\|q_j-u_{j,c_j}\|_2^2. \]

The index can precompute the distances from each query block to each codeword and sum table entries during scanning. Quantization can reverse nearly tied distances. Exact reranking of a shortlist can restore their ordering when both vectors are still present.

Report recall against an exact baseline

If \(A_k(q)\) returns \(k\) nearest candidates and \(E_k(q)\) is the exact answer under the same metric and tie rule, recall at \(k\) is \(|A_k(q)\cap E_k(q)|/k\). Compare latency percentiles and memory at matched recall on held-out queries. Structured attributes, updates and deletions change that tradeoff. See learned indexes for ordered exact lookup and multimodal foundation models for one source of embedding spaces whose geometry retrieval depends on.[1][2]

References

  1. Yury A. Malkov and Dmitry A. Yashunin, Efficient and Robust Approximate Nearest Neighbor Search Using Hierarchical Navigable Small World Graphs ↩
  2. Hervé Jégou, Matthijs Douze and Cordelia Schmid, Product Quantization for Nearest Neighbor Search ↩