Efficient Nearest Neighbor Search for Cross-Encoder Models using Matrix Factorization

Nishant Yadav, Nicholas Monath, Rico Angell, Manzil Zaheer, Andrew McCallum

Introduction

In modern Information Retrieval (IR) and Natural Language Processing (NLP), a fundamental trade-off exists between retrieval speed and ranking accuracy. Dual-Encoder (DE) models are the industry standard for efficiency; they embed queries and documents into a shared vector space independently, allowing for sub-linear search times using Maximum Inner Product Search (MIPS). However, DE models often fail to capture complex, fine-grained interactions between query and document terms.

Cross-Encoder (CE) models, by contrast, process the query and document pair simultaneously through all layers of a Transformer, yielding significantly higher accuracy. The computational cost of CEs is prohibitive for large-scale retrieval, as it requires a full forward pass for every query-document pair in the corpus. To mitigate this, practitioners typically employ a two-stage pipeline: a cheap DE retrieves a small candidate set (e.g., top 100), which a CE then re-ranks. This approach suffers from a "recall bottleneck"—if the DE fails to include the relevant document in its initial candidate set, the CE never has the opportunity to rank it. This paper introduces ANNCUR, a method designed to perform efficient nearest neighbor search directly on Cross-Encoder models across the entire corpus.

The ANNCUR Framework

ANNCUR (Approximate Nearest Neighbor search using CUR decomposition) treats the query-item similarity matrix as a structure that can be approximated through matrix factorization. Rather than computing every entry in the similarity matrix, the method leverages CUR decomposition to reconstruct the matrix using a small subset of "anchor" rows and columns.

CUR Decomposition for Retrieval

The core mathematical intuition is that the similarity matrix $A$ can be approximated as $A \approx C U R$, where $C$ consists of actual columns (anchor items) from the matrix, $R$ consists of actual rows (anchor queries), and $U$ is a small linking matrix. At inference time, the system only needs to score a new query against the anchor items. These scores are then used to derive a latent embedding for the query, which can be searched against the pre-computed latent embeddings of all items using standard MIPS libraries.

The [EMB]-CE Architecture

A significant contribution of this work is the realization that standard Cross-Encoder architectures are inherently difficult to approximate. Traditional CEs use a [CLS] token followed by a linear layer to produce a scalar score, resulting in a high-rank similarity matrix. To address this, the authors propose the [EMB]-CE architecture. In this model, the Cross-Encoder outputs contextualized embeddings for both the query and the item, and the final score is defined as their dot product. This architectural shift forces the model to produce a lower-rank score matrix, making the CUR approximation significantly more accurate without sacrificing the performance benefits of cross-attention.

Experimental Evaluation

The researchers evaluated ANNCUR on the ZESHEL (Zero-Shot Entity Linking) dataset. This task requires linking entity mentions in text to descriptions within a library across 16 diverse domains (e.g., Star Trek, Military history). The "zero-shot" nature of the task ensures that the model must rely on its ability to generalize to unseen entities based purely on textual descriptions.

Key Findings

  • Rank Reduction: The [EMB]-CE architecture successfully reduced the rank of the score matrix. On the YuGiOh domain (~10k items), the rank dropped from 315 in the standard model to 45 in the [EMB]-CE model, facilitating much more efficient factorization.
  • Superior Trade-offs: For $k > 10$ (retrieving the top 10 or more neighbors), ANNCUR consistently outperformed distilled Dual-Encoders and TF-IDF baselines in terms of the recall-vs-computational cost trade-off.
  • Accuracy Preservation: The [EMB]-CE model achieved parity with the standard [CLS]-CE model on downstream tasks, proving that the low-rank constraint does not inherently degrade the quality of the Cross-Encoder's representations.
  • No Distillation Required: Unlike many efficient retrieval methods that require training a "student" model to mimic a "teacher," ANNCUR relies on linear algebra and matrix decomposition, avoiding the need for additional intensive gradient-based training.

Limitations and Future Work

While ANNCUR represents a significant step forward, it faces challenges at very low values of $k$ (e.g., $k=1$), where highly optimized Dual-Encoders trained on massive datasets still maintain an advantage. Additionally, while the method avoids distillation, the initial indexing step requires computing a "skeleton" of the matrix (scores between anchor queries and all items), which remains computationally intensive for extremely large corpora. Future research may explore combining ANNCUR with graph-based or tree-based indices to further accelerate the search process.

Conclusion

ANNCUR demonstrates that the high accuracy of Cross-Encoders can be brought to large-scale retrieval by rethinking model architecture through the lens of matrix rank. By making the similarity matrix "factorization-friendly," ANNCUR bypasses the recall bottleneck of two-stage systems, offering a new path for efficient and accurate information retrieval.

Summary updated

BibTeX
@inproceedings{yadav2022efficient,
  author = {Nishant Yadav and Nicholas Monath and Rico Angell and Manzil Zaheer and Andrew McCallum},
  title = {{Efficient Nearest Neighbor Search for Cross-Encoder Models using Matrix Factorization}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.emnlp-main.140},
}
Figure