Abstract
Maximum Inner Product Search (MIPS) is a fundamental component of modern recommendation systems and information retrieval. To handle massive datasets, quantization techniques compress vectors into short codes, but standard methods often optimize for reconstruction error rather than inner product accuracy. Recent state-of-the-art methods like ScaNN improve upon this by assuming a uniform query distribution. However, real-world queries are typically non-uniform. We introduce Query-Aware Quantization, a method that prioritizes quantization accuracy in directions where actual queries are most likely to appear, leading to significant improvements in search recall and precision.
The Challenge of MIPS Quantization
Maximum Inner Product Search (MIPS) involves finding the item vector $x$ that maximizes the inner product $\langle q, x \rangle$ for a given query $q$. In large-scale systems, calculating this for millions of items is computationally prohibitive. Quantization addresses this by mapping high-dimensional vectors to a discrete set of codebook entries.
Traditional Product Quantization (PQ) focuses on minimizing the Euclidean distance between the original and quantized vectors. For MIPS, however, we only care about the accuracy of the inner product. Recent "score-aware" methods like ScaNN introduce an anisotropic loss that penalizes errors in the direction of the data point itself. The limitation of ScaNN is its underlying assumption that queries are distributed uniformly across the unit sphere. In practice, queries often cluster in specific "hot" regions. Ignoring these clusters leads to a "precision budget" wasted on directions that are rarely or never queried.
Query-Aware Quantization Framework
The proposed method introduces a general framework that unifies existing quantization techniques (PQ, QUIP, ScaNN) using a positive definite weighting matrix $M_i$. The core innovation is the Query-Aware Matrix, which is derived from actual query samples rather than a theoretical uniform distribution.
Key Components:
- Query-Aware Weighting: The matrix $M_i$ is defined based on samples from the query distribution, specifically focusing on queries that yield high inner products using a sampled softmax approach.
- Local Shared Matrices: To maintain memory efficiency, data points are clustered, and each cluster shares a single Query-Aware Matrix.
- Iterative Optimization: The method employs an alternating optimization algorithm to update both the quantization indices and the codebooks, minimizing the query-aware loss.
Key Insights: Directional Importance
The fundamental insight is that quantization for MIPS is essentially an allocation of precision across different directions. If a query $q$ is likely to appear in a specific direction, the quantization error in that direction must be minimized to ensure accurate ranking.
As illustrated in the figure above, while ScaNN (b) focuses on the direction of the data point $x$, the Query-Aware approach (c) aligns the most accurate direction of the compressed vector $v_1$ with the actual distribution of high-scoring queries. This alignment makes the inner product calculation significantly more robust for the top-K results that matter most.
Experimental Results
The method was evaluated on three real-world datasets: LastFM (music recommendations), Glove (word embeddings), and Music100 (matrix factorization embeddings).
Performance Metrics
Query-Aware Quantization consistently achieved lower relative error in inner product estimation compared to PQ, QUIP, and ScaNN.
On the LastFM dataset, where the uniform query assumption of ScaNN fails, the improvement was particularly dramatic. The query-aware approach adapted to the non-uniform distribution, providing superior Recall@N across both normalized and unnormalized data.
Limitations and Future Work
While highly effective, the method introduces some computational overhead during the training phase due to the sampled softmax and clustering steps. Additionally, the performance is dependent on having a representative set of queries. If the query distribution shifts significantly—for instance, due to seasonal trends—the codebooks may require re-training. Future research could explore extending this framework to other quantization structures beyond Product Quantization.
Summary updated