Retrieval meets Long Context Large Language Models

Peng Xu, Wei Ping, Xianchao Wu, Lawrence McAfee, Chen Zhu, Zihan Liu, Sandeep Subramanian, Evelina Bakhturina, Mohammad Shoeybi, Bryan Catanzaro

Introduction

This paper explores the tension between two popular methodologies for handling long documents in natural language processing: building models with massive context windows versus utilizing retrieval-augmentation (RAG). The authors demonstrate that a standard 4K-context model using simple retrieval can match the performance of a 16K-context model. More importantly, they reveal that adding retrieval to even the largest context models (up to 32K tokens) significantly boosts their accuracy while simultaneously improving inference speed.

The Problem: Context Windows vs. Retrieval

As Large Language Models (LLMs) evolve, the industry has entered a "context window arms race." Models like GPT-4 and Claude now support tens or hundreds of thousands of tokens. However, extending context windows is computationally expensive. Because self-attention scales quadratically with sequence length, processing massive contexts leads to high latency and substantial memory costs.

The primary alternative is Retrieval-Augmented Generation (RAG). In a RAG setup, a separate retriever system finds the most relevant "chunks" of text from a corpus and feeds only those high-signal snippets to the LLM. While this approach is much cheaper computationally, it risks missing crucial information if the retriever fails. The authors set out to answer two core questions: Is it better to build a bigger window, or is retrieval still the superior approach? Furthermore, can we combine both methods for a "best of both worlds" solution?

Methodology

The researchers conducted a comprehensive study using two state-of-the-art pretrained models: a proprietary 43B GPT and Llama2-70B.

  1. Context Extension: They employed Position Interpolation (PI) to extend the context windows of these models from their native 4K tokens up to 16K and 32K.
  2. Retrieval Integration: The study tested three different retrievers: Dragon, Contriever, and OpenAI embeddings. Source documents were segmented into 300-word chunks, and the top $N$ chunks were retrieved based on their similarity to the user's query.
  3. Instruction Tuning: Rather than relying solely on base models, the authors performed instruction fine-tuning on a blend of datasets (such as FLAN and Soda) to ensure the models were optimized to use retrieved context for question answering.
  4. The Hybrid Approach: They evaluated "retrieval-augmented long context" models. In this setup, a model with a 32K window is provided with the top-retrieved chunks, effectively using the expanded window to hold a large volume of highly relevant evidence rather than the raw, unedited document.

Datasets

The models were evaluated on nine long-context tasks across several established benchmarks:

  • Scrolls: QM (summarization), QASP (QA), NQA (NarrativeQA), and QLTY (multiple-choice QA).
  • LongBench: HotpotQA (multi-hop QA), MuSiQue (complex multi-hop), and MultiFieldQA (diverse domain QA).
  • Few-shot Learning: Trec and SAMSum.

These datasets are particularly challenging because the target answers are often buried deep within documents that far exceed a standard 4K context window.

Key Insights and Ideas

  • The 4K + RAG "Shortcut": One of the most surprising findings is that a 4K model equipped with simple retrieval performs roughly as well as a 16K model without retrieval. For practitioners, this implies that "long-context" performance can often be achieved without the massive compute overhead associated with long-context fine-tuning and inference.
  • RAG is a Universal Booster: Retrieval is not just a crutch for small-window models. Even when a model possesses a 32K window, adding retrieval improves its overall performance. RAG acts as an effective filter, removing noise and allowing the model to focus on high-signal information.
  • Solving the "Lost in the Middle" Problem: LLMs typically struggle to recall information located in the middle of a long prompt, a phenomenon clearly visible in performance metrics across different chunk positions.
EM scores showing the lost in the middle phenomenon

By using retrieval to grab the most relevant chunks and placing them strategically in the prompt, the authors effectively bypass this architectural weakness.

  • Model Size Matters for RAG: While retrieval significantly aided the 70B model, it was less effective for the smaller Llama2-7B model at long contexts. Larger models appear to possess a much stronger "zero-shot" ability to integrate and reason over disjointed, retrieved snippets.

Key Results

  • Performance: The retrieval-augmented Llama2-70B-32k emerged as the champion model. It outperformed both GPT-3.5-turbo-16k and Davinci003 on average across the nine evaluated tasks.
Main results comparing models with and without retrieval across different context lengths
  • Efficiency: On the NarrativeQA task, the retrieval-augmented model was 4x faster at generation than the non-retrieval baseline. By processing only the retrieved chunks, the model avoids passing the entire massive document through its transformer layers.
  • Consistency: The benefits of retrieval remained consistent regardless of which specific retriever (e.g., Dragon vs. Contriever) was utilized, suggesting the hybrid strategy is highly robust.

Limitations and Future Work

  • The "Distraction" Threshold: The authors noted that providing too many chunks (e.g., top-20 versus top-5) sometimes degraded performance. Models can still get "distracted" by irrelevant information, even if that information technically fits within the extended context window.
  • Retrieval Quality Bottleneck: The hybrid system remains fundamentally dependent on the retriever's ability to surface the correct chunks. If the retriever fails to find the relevant text, the LLM cannot answer correctly.
  • Future Directions: The researchers suggest exploring even longer windows (64K+) and investigating more advanced training objectives, such as the UL2 loss, to further enhance how models handle massive, noisy contexts. They also emphasize the need for better architectural or pre-training solutions to natively mitigate the "lost-in-the-middle" phenomenon.

Summary updated

BibTeX
@inproceedings{xu2024retrieval,
  author = {Peng Xu and Wei Ping and Xianchao Wu and Lawrence McAfee and Chen Zhu and Zihan Liu and Sandeep Subramanian and Evelina Bakhturina and Mohammad Shoeybi and Bryan Catanzaro},
  title = {{Retrieval meets Long Context Large Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=xw5nxFWMlo},
}
Figure