Approximate Nearest Neighbor Negative Contrastive Learning for Dense Text Retrieval

Lee Xiong, Chenyan Xiong, Ye Li, Kwok-Fung Tang, Jialin Liu, Paul N. Bennett, Junaid Ahmed, Arnold Overwijk

Abstract

Conducting text retrieval in a dense learned representation space has many intriguing advantages over sparse retrieval. Yet the effectiveness of dense retrieval (DR) often requires combination with sparse retrieval. In this paper, we identify that the main bottleneck is in the training mechanisms, where the negative instances used in training are not representative of the irrelevant documents in testing. This paper presents Approximate nearest neighbor Negative Contrastive Estimation (ANCE), a training mechanism that constructs negatives from an Approximate Nearest Neighbor (ANN) index of the corpus, which is parallelly updated with the learning process to select more realistic negative training instances. This fundamentally resolves the discrepancy between the data distribution used in the training and testing of DR. In our experiments, ANCE boosts the BERT-Siamese DR model to outperform all competitive dense and sparse retrieval baselines. It nearly matches the accuracy of sparse-retrieval-and-BERT-reranking using dot-product in the ANCE-learned representation space and provides almost 100x speed-up.

The "Easy Negative" Bottleneck

In information retrieval, the goal is to find relevant documents for a given query from a massive corpus. Traditional sparse retrieval (like BM25) relies on keyword matching, while modern Dense Retrieval (DR) uses neural embeddings to capture semantic meaning. However, DR models have historically struggled to surpass sparse methods without being paired with a heavy re-ranking stage.

The authors identify a theoretical bottleneck in how these models are trained: negative sampling. To learn effectively, a model needs to see "negatives" (irrelevant documents) to understand what not to retrieve. Most standard training regimes use "in-batch" negatives—random documents that happen to be in the same training batch.

Visualization of document embeddings. Random negatives (gray) are far from the query (red star), while dense retrieval negatives (blue) are much closer to the relevant documents (green), presenting a harder learning task.

As shown in the visualization above, random negatives are often so obviously irrelevant that the model learns very little from them. This leads to "diminishing gradients," where the model stops improving because the task has become too easy. To truly excel, a model needs to be challenged by "hard" negatives—documents that look deceptively relevant but are actually incorrect.

The ANCE Mechanism

To solve this, the researchers propose ANCE (Approximate nearest neighbor Negative Contrastive Estimation). Instead of relying on local, random negatives, ANCE selects global, hard negatives from the entire corpus.

Asynchronous Index Refresh

Finding the hardest negatives across millions or billions of documents during every training step is computationally prohibitive. ANCE overcomes this with a dual-process architecture:

  1. The Trainer: Continuously updates the model parameters using the current set of hard negatives.
  2. The Inferencer: Runs in parallel, periodically re-encoding the entire corpus using the latest model weights and updating an Approximate Nearest Neighbor (ANN) index.
The ANCE training workflow. An asynchronous Inferencer updates the ANN index used by the Trainer to sample globally hard negatives.

This asynchronous system allows the trainer to always have access to negatives that the current model finds difficult, effectively closing the gap between the training data distribution and the actual retrieval environment encountered during testing.

Experimental Results

The authors evaluated ANCE across several high-stakes benchmarks, including TREC Deep Learning, MS MARCO, and Open Domain Question Answering (OpenQA) datasets like Natural Questions (NQ).

  • Efficiency and Speed: ANCE matches the accuracy of complex BERT-based re-ranking pipelines while being 100x faster. It achieves this by performing high-quality retrieval in a single step using simple dot-products in the learned space.
  • State-of-the-Art Performance: On the TREC DL Document task, ANCE achieved an NDCG@10 of 0.628, significantly outperforming BM25 (0.519) and previous dense models like DPR (0.543).
  • OpenQA Gains: On the Natural Questions dataset, ANCE improved Top-20 retrieval accuracy to 81.9%, a significant jump from the 78.4% achieved by standard DPR models.
  • Scalability: When tested in a production environment with a corpus of 8 billion documents, ANCE provided a +15.5% relative gain in retrieval effectiveness over existing baselines.

Conclusion

ANCE demonstrates that the key to high-performance dense retrieval lies not just in the model architecture, but in the training dynamics. By moving from local random sampling to global approximate nearest neighbor sampling, ANCE forces the model to learn the fine-grained semantic distinctions necessary for top-tier retrieval. This approach effectively bridges the gap between efficient bi-encoders and accurate cross-encoders, making high-quality semantic search viable for real-time, large-scale applications.

Summary updated

BibTeX
@inproceedings{xiong2021approximate,
  author = {Lee Xiong and Chenyan Xiong and Ye Li and Kwok-Fung Tang and Jialin Liu and Paul N. Bennett and Junaid Ahmed and Arnold Overwijk},
  title = {{Approximate Nearest Neighbor Negative Contrastive Learning for Dense Text Retrieval}},
  booktitle = {International Conference on Learning Representations},
  year = {2021},
  url = {https://openreview.net/forum?id=zeFrfgyZln},
}
Figure