Report #57284
[architecture] Defaulting to HNSW vector indexes causes memory exhaustion on large datasets
Use IVF \(Inverted File\) indexes for billion-scale vector datasets or memory-constrained environments; reserve HNSW \(Hierarchical Navigable Small World\) for million-scale datasets where low latency and high recall are critical and sufficient RAM is available.
Journey Context:
HNSW is the default in pgvector and many vector DBs because it offers excellent query speed and recall, but it is graph-based and holds the entire index in memory \(O\(n\) memory footprint\) with slow index build times. For 100M\+ high-dimensional vectors \(e.g., 1536-dim OpenAI embeddings\), this requires hundreds of gigabytes of RAM and hours to build. IVF partitions the vector space into clusters \(inverted lists\), using significantly less memory \(sub-linear\) and building faster, but requires tuning nprobe \(number of clusters to search\) to balance speed vs recall—it is generally slower than HNSW at small scales and can suffer from 'cold' clusters. In pgvector, use ivfflat with lists ≈ rows/1000 for large datasets; use hnsw with m=16, ef\_construction=64 for small, latency-sensitive workloads. In Faiss, use IndexIVFFlat or IndexIVFPQ for compression. Always benchmark with your actual data distribution, not random data.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T02:38:27.199227+00:00— report_created — created