LoRANN: Low-Rank Matrix Factorization for Approximate Nearest Neighbor Search

Elias Jääsaari, Ville Hyvönen, Teemu Roos

TL;DR

LoRANN is a new clustering-based library for Approximate Nearest Neighbor (ANN) search that replaces traditional Product Quantization (PQ) with a supervised method called Reduced-Rank Regression (RRR). By treating distance estimation as a multi-output regression problem, LoRANN achieves faster query times and lower memory usage than state-of-the-art methods, particularly on high-dimensional datasets.

What Problem Does This Paper Address?

In the era of Large Language Models (LLMs) and Retrieval-Augmented Generation (RAG), searching through millions of high-dimensional "embeddings" (vector representations of data) has become a critical bottleneck.

Current algorithms generally fall into two camps:

  1. Graph-based methods (like HNSW), which are lightning-fast but memory-hungry and slow to build.
  2. Clustering-based methods (like IVF-PQ), which are highly scalable and memory-efficient but suffer from slower query times.

Clustering-based methods usually rely on Product Quantization (PQ) to estimate distances. The authors argue that PQ is essentially an unsupervised way to approximate distances that fails to fully exploit the data's structure or the query distribution. This leads to sub-optimal performance on modern, high-dimensional embedding sets.

Methods

The core innovation of LoRANN is viewing distance estimation as a supervised learning problem.

  • Reduced-Rank Regression (RRR): Instead of using PQ's look-up tables, the authors observe that calculating the inner product between a query and all points in a cluster is a multivariate regression task. They use RRR to find a low-rank approximation of the cluster data, turning the "scoring" step into two fast matrix-vector multiplications.
  • 8-bit Quantization: To accelerate these multiplications, they quantize the regression matrices to 8-bit integers, leveraging modern CPU instructions (like AVX-512 VNNI) and GPU kernels.
  • Dimensionality Reduction: LoRANN further speeds up the process by projecting high-dimensional queries into a lower-dimensional space before performing the regression.
  • Supervised Training: Unlike unsupervised PQ, RRR can be "trained" on a sample of actual queries (or the corpus itself) to better adapt to the specific distribution of the data it will encounter in production.

Key Insights and Ideas

  • Regression is the "Exact" Solution: Ordinary Least Squares (OLS) regression provides the mathematically exact inner product. RRR is simply a computationally efficient way to get close to that exact answer.
  • Hardware Synergy: Matrix-vector multiplication is what modern hardware (CPUs and GPUs) is built to do best. By turning distance estimation into matrix math, LoRANN plays to the strengths of modern silicon much better than the "random access" patterns required by PQ look-up tables.
  • The "Aha" Moment on OOD: Because RRR is a supervised method, it can adapt to "Out-of-Distribution" (OOD) settings. If the queries look different from the corpus (e.g., searching images with text), training the RRR model on a sample of queries significantly boosts performance.
Performance comparison showing the benefit of training LoRANN on query distributions versus corpus distributions.
  • Memory vs. Accuracy Trade-off: RRR with a rank as low as $r=16$ or $r=32$ often outperforms PQ even when PQ is allowed to use much more memory.

Key Results

LoRANN was evaluated on a massive suite of 16 datasets, ranging from classic benchmarks (MNIST, SIFT) to modern high-dimensional embeddings (DistilBERT, OpenAI Ada, CLIP-ViT).

  • Superior to PQ: In direct comparisons, RRR consistently outperformed PQ in both query latency and memory usage across almost all high-dimensional datasets.
Queries per second vs. Recall on high-dimensional datasets, demonstrating RRR significantly outperforming PQ.
  • CPU Performance: LoRANN is highly competitive with top-tier graph algorithms like HNSW and GLASS. It often provides better "Queries Per Second" (QPS) at recall levels below 90%.
  • GPU Dominance: On high-dimensional data ($d > 300$), LoRANN outperformed state-of-the-art GPU methods like NVIDIA's RAFT-CAGRA.
  • Faster Indexing: LoRANN builds its search index significantly faster than graph-based methods, making it more practical for dynamic datasets that require frequent updates.

Limitations and Future Work

  • The 90% Recall Wall: Like most clustering-based methods, LoRANN's performance relative to graph methods tends to degrade when extremely high recall (e.g., >95%) is required, as it must search too many clusters.
  • Low-Dimensional Data: For datasets with very few dimensions ($d < 100$), the overhead of the low-rank approximation doesn't pay off as well as it does in high dimensions.
  • Distance Metrics: The current formulation is primarily optimized for inner product and Euclidean distance. While extendable, it hasn't been tested on more exotic distance metrics.
  • Future Directions: The authors suggest exploring more advanced SVD approximations for even faster indexing and adapting the library for "disk-based" search where data is stored on SSDs rather than RAM.

Summary updated

BibTeX
@inproceedings{jaasaari2024lorann,
  author = {Elias Jääsaari and Ville Hyvönen and Teemu Roos},
  title = {{LoRANN: Low-Rank Matrix Factorization for Approximate Nearest Neighbor Search}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=wyYsCI3K7U},
}
Figure