IVF and Product Quantization
You'll learn how inverted file indexes and product quantization dramatically reduce memory usage in vector databases while maintaining reasonable search accuracy.
The Memory Challenge
After learning HNSW's graph-based approach, you now face a critical problem: storing millions of high-dimensional vectors (often 768 or 1536 dimensions) consumes enormous memory. For large-scale RAG systems, this becomes prohibitively expensive.
Inverted File Index (IVF)
Think of IVF like organizing a massive library by subject sections before searching.
How it works:
- Cluster training vectors into k centroids (like subject categories)
- Assign each vector to its nearest centroid
- At search time, find the nearest centroid(s) to your query, then search only those "buckets"
Instead of comparing your query against 10 million vectors, you compare against 1000 centroids, then search maybe 10,000 vectors in the top-5 nearest clusters. This is IVF — you've created an inverted index mapping centroids to their member vectors.
Product Quantization (PQ)
PQ compresses vectors by splitting and encoding them cleverly.
How it works:
- Split each vector into m subvectors (e.g., 768 dims → 8 subvectors of 96 dims)
- Cluster each subspace independently into 256 centroids
- Replace each subvector with its centroid ID (1 byte)
- Original 768 floats (3072 bytes) → 8 bytes (384× compression!)
Distance calculations use lookup tables computed once per query, making searches extremely fast.
Why Combine Them
IVF+PQ uses IVF for coarse filtering, then PQ-compressed vectors for fine-grained comparison. This balances speed, memory, and accuracy — the foundation of scalable vector databases like Faiss.
Key Takeaway: IVF partitions the search space into clusters for faster lookups, while Product Quantization compresses vectors into tiny codes, enabling billion-scale vector search in memory-constrained environments.