Home
ArenaGraphSignalTopics
/Large Language Model Infrastructure: Building and Deploying Production AI Systems
Chapter 7 • Module 4 9 min breakdown +15 XP Module

IVF-PQ Vector Indexing: Scaling Vector Databases to Billions of Vectors

While Hierarchical Navigable Small World (HNSW) graphs offer unmatched search latency and recall, they suffer from a severe operational bottleneck: extreme RAM consumption.

To index 100 million 1536-dimensional vectors using HNSW:

  • Raw vector storage:
  • Graph edges and pointer metadata:
  • Total Server RAM required: of expensive host memory!

To scale vector search to hundreds of millions or billions of items without paying hundreds of thousands of dollars in cloud RAM instances, infrastructure teams rely on Inverted File with Product Quantization (IVF-PQ) (FAISS).

IVF-PQ compresses raw high-dimensional floating-point vectors by up to 95% while enabling ultra-fast Asymmetric Distance Computation (ADC) directly in compressed byte space.

Interactive Blueprint
Rendering diagram...

1. Stage 1: Inverted File (IVF) Coarse Partitioning

The purpose of the Inverted File (IVF) layer is Non-Exhaustive Search: avoiding scanning the entire database by partitioning vector space into discrete Voronoi Cells.

Interactive Blueprint
Rendering diagram...

Ingestion & Search Workflow:

  1. Clustering: During index training, K-Means clusters the dataset into coarse centroids ().
  2. Posting Lists: Each document vector is mapped to its closest centroid and appended to that centroid's inverted posting list.
  3. Query Probing (nprobe): When a query arrives, the engine computes distances to all centroids, selects the nprobe closest centroids (e.g. nprobe = 16 out of ), and searches only the posting lists attached to those 16 centroids.
  • Pruning: 99.6% of the database is pruned from the search space instantly!

2. Stage 2: Product Quantization (PQ) Compression

Once a vector is assigned to a Voronoi cell, storing the raw 1536-dimensional floating-point vector still consumes 6,144 bytes of RAM. Product Quantization (PQ) compresses this vector into a compact array of 1-byte integers.

Interactive Blueprint
Rendering diagram...

The PQ Algorithm:

  1. Split the -dimensional vector space into orthogonal sub-spaces of dimension .
  2. Run K-Means independently within each sub-space to learn sub-centroids (requiring exactly 8 bits = 1 byte to address each centroid).
  3. Replace each sub-vector with the 1-byte integer ID of its nearest sub-centroid.
  • A 1536-dimensional vector () split into sub-vectors is stored as exactly 64 bytes in RAM ( memory reduction!).

3. Asymmetric Distance Computation (ADC)

How does the search engine compute distances between an unquantized query and millions of 64-byte compressed PQ codes without decompressing them?

Asymmetric Distance Computation (ADC) computes the exact distances between the query sub-vectors and the 256 codebook centroids once upfront, storing them in a small lookup table:

When scanning a compressed vector code :

The search reduces to 64 array lookups and additions in CPU L1 cache using SIMD vector instructions—executing tens of millions of distance calculations per second!


4. HNSW vs IVF-PQ Architecture Trade-Off Matrix

Metric / DimensionFlat (Brute Force)HNSW (Graph Index)IVF-PQ (Quantized Inverted Index)
Search Time Complexity (Linear) (Logarithmic) (Sub-linear)
10M Vector Search Latency
Search Recall @ 10 (Exact Ground Truth)
100M Vector RAM Footprint (98% Savings!)
Build / Training TimeZeroModerate ( hours)Fast ( mins)
Ideal Production Use CaseSmall datasets ()Real-time low-latency RAG ()Billion-scale search on budget hardware

5. Summary & Key Takeaways

  1. HNSW is Fast but Memory-Heavy: Indexing hundreds of millions of vectors in HNSW requires terabytes of expensive RAM.
  2. IVF Prunes Vector Space: Inverted File clustering into Voronoi cells prunes over 98% of the database during candidate lookup.
  3. PQ Compresses Vectors to Bytes: Product Quantization splits high-dimensional vectors into sub-vectors, compressing 6,144-byte vectors into 64 bytes.
  4. ADC Enables Instant SIMD Lookups: Asymmetric Distance Computation evaluates compressed vectors using CPU cache lookup tables, scanning millions of vectors in milliseconds.
Milestone Verification

Ready for the next lesson?

Mark this module complete to record verified progress and earn +15 XP toward your architect profile.