Practical and Asymptotically Optimal Quantization of High-Dimensional Vectors in Euclidean Space for Approximate Nearest Neighbor Search

Jianyang Gao, Yutong Gou, Yuexuan Xu, Yongyi Yang, Cheng Long, Raymond Chi-Wing Wong

TL;DR

This paper introduces an extension to the RaBitQ quantization method, allowing for flexible, moderate compression rates (like 4x or 8x) while maintaining "asymptotic optimality"—the best possible theoretical trade-off between memory usage and error. By combining a novel grid-based codebook with a two-stage SIMD-accelerated search, the authors achieve 95-99% recall on massive datasets without needing to store original vectors for re-ranking.

What Problem Does This Paper Address?

In the era of Large Language Models (LLMs) and Retrieval-Augmented Generation (RAG), we are drowning in high-dimensional "embeddings"—vectors that represent the meaning of text, images, or audio. To find the "nearest neighbor" to a query vector in a database of millions, we usually turn to Approximate Nearest Neighbor (ANN) search.

The bottleneck is memory. Storing these vectors in RAM is incredibly expensive. Standard techniques like Product Quantization (PQ) or Scalar Quantization (SQ) help by compressing vectors, but they face a dilemma:

  1. High Compression: Save lots of space, but accuracy drops so much that you must keep the original "raw" vectors on hand to double-check (re-rank) the results, which negates the memory savings.
  2. Moderate Compression: Better accuracy, but existing methods often lack theoretical guarantees and struggle to remain efficient.

A recent method called RaBitQ offered a breakthrough with unbiased distance estimation and optimal error bounds, but it was a "one-trick pony" limited to a fixed 32x compression rate. This paper seeks to make RaBitQ practical for a wider range of accuracy-memory trade-offs.

Methods

The authors propose Extended RaBitQ, which introduces several key innovations:

  • Grid-Based Codebook: Instead of the simple binary codes used in the original RaBitQ, the authors construct a codebook by taking a uniform grid of $B$-bit integers, normalizing them onto a unit sphere, and applying a random rotation. This allows the user to choose $B$ (e.g., 4, 5, or 8 bits) to tune the compression rate.
  • Efficient Quantization Algorithm: Finding the "closest" point in this new, complex codebook during the indexing phase is computationally expensive. The authors developed an $O(2^B \cdot D \log D)$ algorithm that enumerates "critical values" to find the optimal quantized vector quickly.
  • Two-Stage Distance Estimation: This is the "secret sauce" for speed. The first bit of their $B$-bit code is actually equivalent to the original RaBitQ code.
  • Pruning: They use the first bit (the Most Significant Bit) to perform a lightning-fast initial distance estimate using SIMD instructions (FastScan).
  • Refinement: If a vector looks like a likely candidate, they access the remaining bits to calculate a high-precision distance. This "look-ahead" strategy avoids heavy computation on obviously poor matches.

Datasets

The researchers evaluated their method against six diverse, real-world datasets:

  • MSong: Audio features (420 dimensions).
  • Youtube: Video features (1,024 dimensions).
  • Word2Vec: Text embeddings (300 dimensions).
  • GIST: Image descriptors (960 dimensions).
  • OpenAI-1536 & OpenAI-3072: Modern, high-dimensional text embeddings generated by OpenAI’s text-embedding-3-large model.
  • MSMARCO: A massive scale dataset with over 100 million vectors.

Key Insights and Ideas

  • Unbiasedness is King: Unlike many quantization methods that introduce systematic bias, Extended RaBitQ provides an unbiased estimator of squared Euclidean distances. This means that on average, the estimated distance is exactly the true distance, which is critical for stable ANN performance.
  • The Power of Random Rotation: By randomly rotating the quantization grid, the authors ensure that the error is "spread out" across dimensions, allowing them to inherit the strong theoretical error bounds of the original RaBitQ.
  • MSB Pruning: The realization that the most significant bit of a multi-bit quantization can be treated as a standalone coarse filter is a brilliant bridge between high-speed binary search and high-accuracy multi-bit search.

Key Results

  • Superior Accuracy: At the same memory budget, Extended RaBitQ consistently showed lower average and maximum relative error compared to Scalar Quantization (SQ) and Learned Vector Quantization (LVQ).
  • No Re-ranking Needed: The method stably produces >95% recall at 6.4x compression and >99% recall at 4.5x compression without ever touching the original raw vectors during the search.
  • Efficiency: On the 100-million vector MSMARCO dataset, the method outperformed competitive baselines in the "Queries Per Second (QPS) vs. Recall" trade-off, proving it scales to production-level workloads.
  • Fast Indexing: Quantizing a million vectors with 3,072 dimensions takes only a few minutes, making it practical for real-world pipelines.

Limitations and Future Work

  • Index Integration: This paper primarily focuses on combining quantization with Inverted File (IVF) indices. While IVF is popular, many modern systems use Graph-based indices (like HNSW). The authors acknowledge that integrating their method with graph indices requires further engineering to handle random memory access patterns efficiently.
  • Extreme Compression: While this work excels at moderate compression (4x-16x), for extreme compression (>32x), the authors suggest first applying dimensionality reduction (random projection) before using the original RaBitQ, a direction they leave for future study.

Summary updated

BibTeX
@article{gao2025practical,
  author = {Jianyang Gao and Yutong Gou and Yuexuan Xu and Yongyi Yang and Cheng Long and Raymond Chi-Wing Wong},
  title = {{Practical and Asymptotically Optimal Quantization of High-Dimensional Vectors in Euclidean Space for Approximate Nearest Neighbor Search}},
  journal = {Proc. ACM Manag. Data},
  year = {2025},
  doi = {10.1145/3725413},
}

Loading related content...

Figure