Low-Precision Quantization for Efficient Nearest Neighbor Search

Anthony Ko, Iman Keivanloo, Vihan Lakshman, Eric SchkufzaarXiv 2021

Abstract

Fast k-Nearest Neighbor search over real-valued vector spaces (KNN) is an important algorithmic task for information retrieval and recommendation systems. We present a method for using reduced precision to represent vectors through quantized integer values, enabling both a reduction in the memory overhead of indexing these vectors and faster distance computations at query time. While most traditional quantization techniques focus on minimizing the reconstruction error between a point and its uncompressed counterpart, we focus instead on preserving the behavior of the underlying distance metric. Furthermore, our quantization approach is applied at the implementation level and can be combined with existing KNN algorithms. Our experiments on both open source and proprietary datasets across multiple popular KNN frameworks validate that quantized distance metrics can reduce memory by 60% and improve query throughput by 30%, while incurring only a 2% reduction in recall.

In modern information retrieval and recommendation systems, $k$-Nearest Neighbor (kNN) search is the engine under the hood. Whether searching for similar products, images, or songs, systems must compare a query vector against millions or billions of item vectors in high-dimensional space.

The primary challenge is scale. Storing 100 million 256-dimensional vectors in full 32-bit floating-point precision (fp32) requires massive amounts of RAM, which is expensive and limits the dataset size a single machine can handle. While techniques like Product Quantization (PQ) exist to compress these vectors, they often prioritize minimizing "reconstruction error" (how well the compressed vector matches the original) rather than "distance preservation" (ensuring the nearest neighbors stay the nearest neighbors).

A Data-Driven Quantization Strategy

Researchers have demonstrated that high-dimensional vector embeddings are often "over-provisioned" with unnecessary precision. We propose a feature-wise quantization method built on two key observations:

  1. Interdimensional Uniformity: In many large datasets, the distribution of values across different dimensions is remarkably consistent.
  2. Narrow Banding: Real-world embeddings often cluster in a very narrow range (e.g., between -0.125 and 0.125), meaning most of the representable range of a 32-bit float is wasted.
The distribution of floating-point values across embedding dimensions shows significant narrow banding, with most values clustered between -0.1 and 0.1.

Instead of complex codebooks, we utilize a clamped linear function. By analyzing the dataset to find the practical range of values, we map those values into the lowest-precision integer domain possible (typically int8). Values within the "normal" range are mapped linearly, while outliers are clamped to the minimum or maximum integer values. The goal is to ensure that if Vector A was closer to the Query than Vector B in the original space, that relationship is preserved in the new integer space.

Experimental Results

The study evaluated this method across three distinct datasets: PRODUCT60M (60 million product embeddings from Amazon), SIFT (1 million vectors), and Glove100 (1 million word embeddings). The quantization was tested across popular kNN frameworks including HNSWlib, FAISS, and NGT.

Moving to int8 provides massive efficiency gains with minimal "accuracy tax":

  • Memory Footprint: Reduced by approximately 60%. For the 60M dataset using HNSW, memory dropped from ~83GB to ~37GB.
  • Search Speed (Throughput): Improved by roughly 30% in terms of Queries Per Second (QPS).
  • Index Build Time: The time required to build the search index was nearly halved.
  • Search Quality: The "recall" (the percentage of true nearest neighbors found) only decreased by about 2% for the Amazon dataset.
Comparison of build time and memory usage between fp32 and int8 across various configurations, demonstrating significant resource savings.

Conclusion

The most striking insight is that we are using far more bits than necessary for effective retrieval. Precision is often less important than relative ordering. Because this method works at the implementation level—replacing float32 arrays with int8 arrays—it benefits from native hardware acceleration for integer operations and reduced cache misses due to the smaller data footprint. While future work will explore even lower bit-widths (like 4-bit integers), the current int8 approach offers a robust path for scaling high-performance search systems.

Summary updated

BibTeX
@misc{ko2021low,
  author = {Anthony Ko and Iman Keivanloo and Vihan Lakshman and Eric Schkufza},
  title = {{Low-Precision Quantization for Efficient Nearest Neighbor Search}},
  year = {2021},
  eprint = {2110.08919},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2110.08919},
}
Figure