Skip to main content
Interactive 3D/Approximate Nearest Neighbor (ANN) Algorithm Comparison
Recall@10
99.4%
Query Time
2.0ms
Build Time
32.0s
Memory
61MB
QPS
500
HNSW: Hierarchical graph. Best recall/speed tradeoff. Higher M = better recall, more memory.Complexity: O(log n)
AlgorithmRecall@10Query TimeMemoryComplexity
FLAT100.0%50ms49MBO(n)
IVF97.5%7.8ms49MBO(n/k + k)
HNSW99.4%2.0ms61MBO(log n)
LSH78.8%1.0ms24MBO(1) amortized
2D Search Visualization - HNSW
QueryFound by HNSWMissed (recall gap)
Controls
Algorithm
Dataset Size100K
10K1M
Recall Target95%
HNSW M parameter16
M = edges per node. Higher M = better recall, more memory/build time.
ANN benchmarks: ann-benchmarks.com tracks all algorithms. HNSW consistently wins on recall/QPS tradeoff.

FAISS: Facebook's ANN library implements IVF, HNSW, PQ, and combinations. Most production deployments use FAISS.

nprobe (IVF): how many cells to search. Higher = better recall, slower query.

Approximate Nearest Neighbor (ANN) Algorithm Comparison - Interactive Visualization

Exact nearest neighbor search scans every vector in the database - O(n) per query, completely infeasible at billion-vector scale. Approximate Nearest Neighbor algorithms trade a small recall penalty for orders-of-magnitude speedup. Flat (brute force) is the baseline with 100% recall. IVF (Inverted File Index) partitions vectors into k-means clusters and searches only the nearest nprobe clusters. HNSW (Hierarchical Navigable Small World) builds a multi-layer graph with logarithmic search time and the best recall-speed tradeoff in practice. LSH (Locality Sensitive Hashing) uses random projections to hash similar vectors into the same bucket - fastest build time, lowest recall. FAISS (Facebook AI Similarity Search) implements all of these and is the de-facto production library.

  • HNSW: hierarchical graph, O(log n) query, best recall/QPS tradeoff, high memory (graph edges overhead)
  • IVF: k-means cells, recall controlled by nprobe - higher nprobe = better recall, slower query
  • LSH: random projections to hash buckets, O(1) amortized query, lowest recall, simplest implementation
  • Flat: exact brute-force, 100% recall, O(n) per query - only viable for <1M vectors
  • Recall@10: HNSW achieves 99%+ recall at 2ms query time; IVF achieves 90%+ recall at similar speed with less memory
  • ann-benchmarks.com: standardized recall vs QPS comparisons across all major algorithms and libraries

Part of the EngineersOfAI Interactive 3D - free interactive visualizations covering every major concept in machine learning and AI engineering. Hover any element for a plain-English explanation. No code required.