HNSW: graph-based, sub-linear latency, O(N log M) build memory, default-accurate. Use for most production middle-ground datasets (1M-100M). IVFFlat: cluster-based, must be trained on a sample, slightly less recall but uses less memory. Pre-2020 default. Pick HNSW unless RAM is the constraint.
HNSW: create index … m=16 ef_construction=64, query with ef_search=100.
IVFFlat: lists=sqrt(rows), probes=4-16, train on 100k representative vectors.
HNSW dominates on recall@K vs build cost until you hit billions of rows or memory pressure.
data size, latency target, recall@K target
HNSW for most mid-size prod
IVFFlat when memory pressure is the constraint
Flat (brute force) for < 100k rows ground truth
Default HNSW. Reach for IVFFlat only when memory bites.