Abstract
Retrieval-Augmented Generation (RAG) is essential for grounding Large Language Models (LLMs) in factual data, yet it introduces significant computational overhead as retrieved context grows. We present OSCAR (Online Soft Compression And Reranking), a framework that reduces RAG inference costs by 2–5× while maintaining high accuracy. OSCAR utilizes a lightweight, query-aware compressor to map long documents into a small set of dense "memory tokens" during inference. This approach bridges the gap between inefficient hard compression and query-agnostic offline soft compression. Our evaluations across multiple benchmarks demonstrate that OSCAR achieves substantial speedups and competitive accuracy, often outperforming traditional RAG baselines.
Introduction
The effectiveness of RAG is often limited by the "long context" problem: as more documents are retrieved to ensure factual coverage, the input prompt length increases, leading to quadratic growth in self-attention computation. Current mitigation strategies typically involve "hard compression" (text summarization or pruning) or "offline soft compression" (pre-computing embeddings). Hard compression often yields modest gains and can be slow, while offline soft compression fails to capture query-specific nuances, often missing critical "needles in the haystack."
OSCAR addresses these challenges through Online Soft Compression. By running a lightweight compressor model during the inference pass, OSCAR generates query-specific document representations that are both highly compressed and contextually relevant.
Methodology
The core of OSCAR is a dual-purpose compressor that performs both document compression and reranking in a single forward pass.
Online Soft Compression
Unlike previous methods that pre-calculate document embeddings, OSCAR's compressor takes both the user query and the retrieved document as input. It produces a fixed number of "memory tokens" (e.g., 8 tokens for a 128-token document, a 16× compression ratio). These tokens represent the document's information relative to the specific query, ensuring that the most relevant details are preserved for the generator LLM.
Architecture and Training
The authors explore two compressor variants:
- OSCAR-N-Layers: Uses the initial layers of the generator LLM itself.
- OSCAR-llama: Employs a smaller standalone model (e.g., Llama-3.2-1B).
Training is conducted via sequence-level distillation. A large "Teacher" model (e.g., Mistral-7B) generates answers using full-text contexts, and the OSCAR "Student" learns to replicate these outputs using only the compressed memory tokens.
Simultaneous Reranking
OSCAR integrates a reranking head into the compressor. By adding a special [RR] token, the model predicts a relevance score during the compression pass. This allows the system to rerank documents "for free," optimizing the context quality without additional computational stages.
Experimental Results
OSCAR was evaluated on a wide range of benchmarks, including Natural Questions (NQ), TriviaQA, ASQA, and HotpotQA, using backbones ranging from 1B to 24B parameters.
Efficiency and Accuracy
OSCAR consistently achieved inference speedups between 2.2× and 4.8×. Notably, efficiency gains scaled with the size of the generator model; for a Mistral-24B backbone, OSCAR reduced computational complexity by 5×. Despite the high compression rates (up to 128×), accuracy remained stable, and in some instances, OSCAR-llama exceeded the "no compression" baseline by filtering out irrelevant noise.
Reranking Performance
The "free" reranker within OSCAR performed competitively with dedicated cross-encoders like DeBERTa-v3, significantly improving the quality of the top-k documents fed to the generator.
Conclusion
OSCAR represents a significant step forward in making RAG systems more efficient and scalable. By moving compression "online" and making it query-aware, it overcomes the primary limitations of existing context reduction techniques. Future work will focus on making the compressor backbone-agnostic and exploring dynamic token allocation to further optimize the balance between relevance and compute.
Summary updated