Problem
Long conversations and large document retrievals exceed context window limits, causing truncation and loss of important context.
Solution
Apply compression strategies to reduce context size while preserving the most relevant information for the current query.
Compression strategies
- Conversation summarisation: After every N turns (e.g., 10), summarise the full conversation history into a concise summary and replace the old turns
- Selective retention: Score each historical turn for relevance to the current query (embedding similarity); discard low-scoring turns
- Document compression: For retrieved chunks, use an LLM to extract only the relevant sentences from each chunk before inserting into context
- LLMLingua (Microsoft): Token-level compression — removes redundant tokens from prompts using a small language model; the LLMLingua paper reports up to 20x compression with little performance loss
Trade-offs
- Pro: Lets conversations run longer than the context window would otherwise allow
- Pro: Reduces tokens → reduces cost per turn
- Con: Summarisation loses nuance; selective retention may discard information that later becomes relevant
- Con: Adds latency for compression LLM calls
When to use
Long multi-turn conversations, multi-document RAG, agent loops with many tool outputs.
When to avoid
Short, stateless API calls where context never grows.