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

Jon Saad-Falcon, Daniel Y. Fu, Simran Arora, Neel Guha, Christopher Ré

TL;DR

This paper introduces LoCoV1, a new 12-task benchmark designed to evaluate long-context text retrieval where information must be synthesized across entire documents. To tackle this benchmark, the authors develop M2-BERT, an 80-million parameter state-space model that handles contexts up to 32K tokens, outperforming Transformer models 90× its size while running up to 676× faster at inference.

What Problem Does This Paper Address?

Most modern text retrieval systems rely on Transformer-based encoders that are fundamentally constrained to short sequences (typically 512 to 8,192 tokens) due to the quadratic memory and computational cost of attention mechanisms. In domains like law, medicine, and finance, documents routinely span tens of thousands of tokens.

Worse yet, existing retrieval benchmarks (like BEIR) don't adequately test long-context capabilities because the relevant information is often buried right at the beginning of the document, allowing naive truncation or chunking strategies to perform deceptively well.

Building an effective long-context retriever introduces three core challenges:

  1. Evaluation: The lack of benchmarks requiring holistic, long-text synthesis.
  2. Pretraining: Training a base model to effectively represent both short queries and long documents simultaneously.
  3. Fine-tuning: Standard contrastive loss functions (like Multiple Negatives Ranking Loss, or MNRL) require massive batch sizes to build a good embedding space, which immediately triggers out-of-memory errors on GPUs when processing long documents.

Methods

The authors address these challenges through three key innovations:

  • Monarch Mixer Architecture: Instead of standard Transformers, M2-BERT is built on the Monarch Mixer architecture, a subquadratic state-space model (SSM) that scales efficiently along both sequence length and model dimension.
  • Mixed-Length Pretraining: To ensure the model can handle both short queries and long documents, the authors pretrain M2-BERT on a carefully balanced mixture of short, variable-length passages and long concatenated sequences. For the 32K token variant, they utilize a warm-start strategy, initializing weights from an 8K checkpoint and replicating positional embeddings to guarantee convergence.
  • Orthogonal Projection Loss (OPL): To bypass the GPU memory bottleneck during fine-tuning, the authors replace MNRL with OPL. OPL operates on single-sample batches ($B=1$) by utilizing Mean Squared Error (MSE) to force positive query-document pairs to align (cosine similarity of 1.0) and negative pairs to be orthogonal (cosine similarity of 0.0). This allows long-context fine-tuning on standard hardware.
Figure 1: Left: The LoCoV1 long document retrieval benchmark and the average document length of its constituent datasets. Center Left: M2-BERT sequence mixer. Center Right: The orthogonal projection loss. Right: Performance of various retrieval models and M2-BERT at different sequence lengths on LoCoV1. Circles are open models, where circle area corresponds to model size. X marks are closed models.

Datasets

  • LoCoV1 (Long-Context Benchmark V1): A newly introduced 12-task benchmark spanning diverse real-world domains including law (CourtListener, Legal Case Reports), medicine (QASPER), screenwriting (SummScreenFD), government reports, and programming (StackOverflow). The average document length across these tasks ranges up to nearly 60K tokens.
  • BEIR / MTEB: Used to evaluate and ensure that M2-BERT's long-context adaptations do not degrade its performance on standard short-context retrieval and classification tasks.
  • Pretraining Corpora: A balanced mix of C4, Wikipedia, and BookCorpus.

Key Insights and Ideas

  • Chunking is a Suboptimal Band-Aid: On the LoCoV1 benchmark, traditional chunking and embedding-averaging strategies fail or even degrade performance. True long-context retrieval requires the model to reason across the entire document context holistically.
  • Contrastive Learning at Batch Size 1: The shift to Orthogonal Projection Loss (OPL) proves that effective dense retrieval spaces can be learned without massive batch sizes, offering a viable path forward for memory-constrained long-text training.
  • SSMs are Competitive Retrievers: While state-space models have gained massive traction for autoregressive generation (e.g., Mamba), this work demonstrates they are equally potent as bi-encoder dense retrievers.

Key Results

  • State-of-the-Art Performance: M2-BERT-32k achieves an average score of 94.7 on LoCoV1, outperforming the next-best open-source baseline approach (E5-Mistral-7B via truncation) by 23.3 points, and beating commercial APIs like OpenAI's text-embedding-ada-002 by 31.5 points.
  • Extreme Efficiency: Despite containing only 80M parameters (more than 90× fewer than the 7.11B parameter E5-Mistral), M2-BERT-32k generates embeddings 676× faster for a 32,768-token document on an A100 GPU.
  • No Short-Context Sacrifice: On the short-context BEIR benchmark, the 80M parameter M2-BERT-128 performs comparably to SentenceBERT (110M parameters), showing it retains robust short-text capabilities.

Limitations and Future Work

While OPL enabled successful training at a batch size of 1, the authors note that it is just one choice of batch-independent loss, and other mathematical formulations might yield even better embedding geometries. Additionally, the authors express interest in scaling the parameter size of M2-BERT further and exploring its utility in downstream applications like Retrieval-Augmented Generation (RAG) pipelines and zero-shot document clustering.

Summary updated

BibTeX
@inproceedings{saadfalcon2024benchmarking,
  author = {Jon Saad-Falcon and Daniel Y. Fu and Simran Arora and Neel Guha and Christopher Ré},
  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