Back
advanced
Advanced RAG & Context

Context Compression and Long-Context RAG

Compress retrieved context so models see less noise and more useful evidence

22 min read· RAG· Context Compression· LongLLMLingua· Token Optimization

Context Compression and Long-Context RAG

Context compression means reducing text while preserving the information needed to answer.

The goal is not shorter text. The goal is higher signal.

Why compression helps

Long context can still fail when:

  • evidence is buried
  • chunks repeat each other
  • irrelevant text distracts the model
  • token cost is too high
  • latency is too slow

Compression strategies

StrategyUse when
extractive compressionkeep exact source sentences
abstractive summarycompress long background context
metadata filteringremove irrelevant documents early
rerankingkeep only strongest chunks
section selectioninclude headings around evidence
conversation summarycompress old chat history

Safety rule

For factual RAG, prefer extractive compression when possible. Summaries can accidentally change meaning.

Good compressed context

Good context keeps:

  • source ID
  • exact quote or close paraphrase
  • section title
  • date/version
  • enough surrounding context

Knowledge check

Q1: What is the risk of abstractive compression?

It can change or invent meaning.

Q2: What metadata should compressed evidence keep?

Source ID, section, date/version, and enough text to verify the claim.