Benchmarking and Building Long-Context Retrieval Models with LoCo and M2-BERT

Jon Saad-Falcon, Daniel Y Fu, Simran Arora, Neel Guha, Christopher Re

Introduction

Retrieval pipelines are an integral component of many machine learning systems, but they often struggle in domains where documents are exceptionally long (e.g., 10K tokens or more). In these scenarios, identifying relevant information requires synthesizing context across the entire text. This paper introduces LoCoV1, a benchmark specifically designed to evaluate retrieval models on long documents where "cheating" via truncation or chunking is ineffective. To tackle this benchmark, the authors developed M2-BERT, an 80M parameter state-space model that significantly outperforms Transformer-based models 90x its size (such as E5-Mistral) while running up to 676x faster on long sequences.

Overview of the M2-BERT architecture, Orthogonal Projection Loss, and LoCoV1 performance.

The Challenge of Long-Context Retrieval

Most modern retrieval systems rely on the Transformer architecture, which suffers from two major flaws in the context of long documents. First, Transformers scale quadratically ($O(n^2)$) with sequence length, making it prohibitively expensive to process documents tens of thousands of tokens long. Second, existing benchmarks (like BEIR) are often "broken" for long-context evaluation. In many older datasets, the relevant information is contained in the first few hundred tokens. This creates a "truncation trap" where a model that simply truncates the text performs just as well as one that reads the whole document.

Methods: M2-BERT and Orthogonal Projection Loss

To build a system capable of synthesizing information across an entire 32K-token document efficiently, the researchers moved away from standard Attention-based Transformers and utilized the Monarch Mixer (M2) architecture. M2 is a subquadratic state-space model (SSM) that uses Monarch matrices to achieve linear or near-linear scaling.

Key methodological innovations include:

  • Pretraining Mixture: Training exclusively on long or short sequences proved insufficient. The authors utilized a data mixture of short, variable-length passages and long, concatenated sequences from C4, Wikipedia, and BookCorpus.
  • Warm-Starting: To help the 32K-context model converge, they "warm-started" it using weights from an 8K-context checkpoint, extending positional embeddings through replication.
  • Orthogonal Projection Loss (OPL): Standard retrieval finetuning requires large batch sizes to provide enough "negative" examples. However, long documents quickly exhaust GPU memory, forcing tiny batch sizes. OPL allows for effective finetuning even with a batch size of $B=1$ by encouraging positive pairs to align and negative pairs to be orthogonal in the embedding space. This decouples the quality of the learned embedding space from the physical memory limits of the hardware.

The LoCoV1 Benchmark

To rigorously evaluate long-context retrieval, the authors introduce LoCoV1, a 12-task benchmark spanning law, medicine, finance, and more.

Sample query-document pair and average document lengths for the LoCoV1 benchmark.

LoCoV1 includes datasets like CourtListener, QASPER, and LegalCaseReports. Crucially, these tasks require reasoning over the entire document, ensuring that relevant information is dispersed or located deep within the text. The researchers also utilized the standard BEIR benchmark to test for "negative transfer" (whether long-context optimization hurts short-context performance) and a synthetic "Needle-in-the-Haystack" task to test recall across the entire context window.

Key Results and Insights

  • Superior Accuracy: On the LoCoV1 benchmark, M2-BERT-32k achieved an average nDCG@10 of 95.2 (and a top aggregate LoCoV1 score of ~91 as shown in the performance chart), compared to 73.0 for E5-Mistral and 65.0 for BGE-Large.
  • David vs. Goliath: M2-BERT (80M parameters) beat E5-Mistral (7.11B parameters) by over 22 points, despite being roughly 90x smaller.
  • Unmatched Efficiency: For a 32K token document, M2-BERT is 676x faster at generating embeddings than E5-Mistral (7B).
  • Needle-in-the-Haystack: While Transformer models' performance plummeted as the "needle" moved further into the document due to their context limits, M2-BERT maintained high accuracy across the entire 32K range.

Limitations and Future Work

The authors noted a negative transfer effect: M2-BERT models finetuned specifically for long-context tasks performed slightly worse on short-context BEIR tasks compared to models trained only on short data. Balancing "generalist" retrieval performance remains an open challenge.

Additionally, while M2-BERT is an excellent encoder (dense retriever), it performed worse than traditional lexical search (BM25) when used as a reranker on certain datasets. Future work will likely explore hybrid approaches that combine M2-BERT's long-range synthesis with the precision of lexical matching.

Summary updated

BibTeX
@inproceedings{saadfalcon2024benchmarking,
  author = {Jon Saad-Falcon and Daniel Y Fu and Simran Arora and Neel Guha and Christopher Re},
  title = {{Benchmarking and Building Long-Context Retrieval Models with LoCo and M2-BERT}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=HkCRgoGtt6},
}
Figure