Context Embeddings for Efficient Answer Generation in RAG

David Rau, Shuai Wang, Hervé Déjean, Stéphane ClinchantarXiv 2024 · DOI

Introduction

Retrieval-Augmented Generation (RAG) is the gold standard for grounding Large Language Models (LLMs) in external facts. However, it introduces a significant "speed tax": as more retrieved documents are added to improve accuracy, the input sequence grows. Because the self-attention mechanism in Transformers scales poorly with length, this leads to massive KV caches, high memory usage, and slow inference times. Existing solutions like ICAE or xRAG attempt to compress context but often suffer from frozen decoder limitations and difficulties handling multiple documents.

The COCOM Framework

The authors introduce COCOM (COntext COmpression Model), which treats context compression as a first-class citizen in the LLM's training pipeline. COCOM uses a "Compressor" (either the same LLM or a lightweight BERT model) to transform retrieved passages into a small set of soft-prompt-like "Context Embeddings."

The COCOM architecture uses a compressor to turn contexts into embeddings, which are then concatenated with the question and processed by a fine-tuned decoder.

Key Methodological Innovations

  • Adaptable Compression ($\xi$): The system is flexible, allowing a 128-token passage to be compressed into 32 embeddings ($\xi=4$), 8 embeddings ($\xi=16$), or even a single embedding ($\xi=128$).
  • Decoder Fine-tuning: A central finding is that fine-tuning the decoder is non-negotiable. By training the entire system (using LoRA) on downstream QA tasks, the decoder learns to "read" the specific language of the compressed embeddings.
  • Two-Stage Training: The model is first pre-trained on auto-encoding and language modeling tasks using the Wikipedia-KILT corpus, then fine-tuned on a "multi-dataset" collection of ~493k examples across 10 popular QA benchmarks.
  • COCOM-light: For massive-scale applications, a BERT-base compressor can be used, making the initial compression step 89x faster than using a 7B parameter model.

Experimental Results

COCOM achieves a new state-of-the-art in the efficiency-effectiveness trade-off for RAG systems. By compressing each document independently, COCOM also enables offline indexing, where pre-computed embeddings can be stored to make the query-time pipeline incredibly lean.

COCOM establishes a superior Pareto frontier, providing significantly higher performance at much lower decoding latencies compared to previous compression methods.

Efficiency and Accuracy Gains

  • Speed & GFLOPs: COCOM achieves up to a 5.69x inference speedup and a 22x reduction in GFLOPs compared to standard RAG without compression.
  • Superior Accuracy: On the Natural Questions (NQ) dataset, COCOM ($\xi=4$) achieved an Exact Match (EM) score of 0.554, dwarfing previous methods like ICAE (0.210) and xRAG (0.184). Even at extreme compression ($\xi=128$), it significantly outperforms "Closed Book" models that use no context.
  • Storage Efficiency: At $\xi=128$, the index size for 24 million contexts drops from 6.06 TB to just 0.19 TB, making high-performance RAG feasible on consumer-grade hardware.

Limitations and Future Work

While highly effective, the current study focused on 7B parameter models and limited retrieval to 5 documents. Future work will explore whether these gains scale to 70B+ models and how the system handles larger document counts (20+). Additionally, the authors suggest testing COCOM on more diverse generative tasks like summarization and creative writing to see if compressed embeddings capture enough nuance for non-extractive tasks.

Summary updated

BibTeX
@misc{rau2024context,
  author = {David Rau and Shuai Wang and Hervé Déjean and Stéphane Clinchant},
  title = {{Context Embeddings for Efficient Answer Generation in RAG}},
  year = {2024},
  eprint = {2407.09252},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.09252},
}
Figure