ANN (Approximate Nearest Neighbor)
Search algorithms that find approximately (not exactly) the nearest vectors, trading a small accuracy loss for massive speed improvements at scale.
Syntax
vector-databases
// Exact: O(n*d) — too slow at scale
// ANN: O(log n) — fast with ~95%+ recallExample
vector-databases
// Why ANN matters:
// Exact search over 1M vectors at 1536 dims:
// 1M * 1536 * float32 = 6GB, ~seconds per query
// HNSW index over same dataset:
// Query time: ~1ms, recall: 97%+
// Common ANN algorithms:
// HNSW (best overall) - pgvector, Qdrant, Weaviate
// IVFFlat (memory efficient) - pgvector, FAISS
// ScaNN (Google, very fast at scale)
// Annoy (Spotify, read-only workloads)