What is context compression?

Context compression is the general name for methods that try to represent the prompt, retrieved documents or conversation history given to a language model with fewer tokens while keeping the information the task needs.

Unlike context extension, which enlarges the window a model can handle, context compression shrinks what goes into it. Unlike text summarisation, written for people, compressed context is designed as model input and need not read well to a human.

Topic
Prompts, context, reasoning and generation
Also known as
Prompt compression

How context compression works

  1. A small language model estimates how much information each token carries; low-information tokens or sentences are dropped.
  2. Retrieved documents are cut to question-relevant sentences or replaced by short summaries.
  3. In long conversation history, older turns are summarised while recent ones stay intact.
  4. Some methods compress the prompt into a few special tokens the model has learned, which requires training.

In more detail

KV cache compression and eviction methods

Beyond compressing input text (hard-prompt compression) or learning soft gist tokens, modern serving stacks also perform KV-cache compression directly in GPU memory. Techniques such as H2O (Heavy-Hitter Oracle), SnapKV, StreamingLLM and KV-cache quantisation evict or compress low-attention tokens inside the cache without altering the input text seen by the user.

Syntax and identifier damage and the interplay with prefix caching

Perplexity-based token pruning can accidentally remove syntax characters, identifiers, UUIDs, SQL keywords or negation words ("not", "except"), causing silent failures in code or structured workflows. It can also break KV prefix caching when static system instructions are altered per request, so production pipelines compress only dynamic retrieved chunks and protect structured spans.

Three approaches: hard, soft and query-aware compression

Context compression spans three distinct paradigms: hard prompt compression (pruning tokens/sentences so any off-the-shelf LLM can read the shortened text), soft prompt compression (encoding text into continuous embeddings or gist tokens, requiring model training and tying compressed representations to one model) and extractive/abstractive RAG compression (like LongLLMLingua or query-focused extractors).

Commonly confused terms

TermHow it differs
Retrieval and rerankingRetrieval/reranking selects which relevant chunks enter the pipeline before generation, whereas context compression reduces the token footprint of the already-selected chunks, prompt instructions or KV cache.

Why context compression matters for on-premises AI

Context compression can let the same in-house GPU capacity handle longer documents and more retrieved passages while cutting time to first token and memory use. Its risk is information loss: dropping an exception in a regulation or a figure makes the answer wrong. The compression rate is therefore chosen by task, critical fields are left uncompressed and results with compressed and full context are compared on the same test set. Original text is kept where citation is needed.

ON-PREMISES EXAMPLE

A capital markets body shrinks context in its internal regulation assistant by keeping only question-relevant sentences from retrieved documents; sentences with article numbers and dates are always kept, with answers citing the original articles.

Common questions

How does context compression differ from summarisation?

A summary is readable text for people. Compressed context is designed as model input and may not suit human reading.

What is the risk of context compression?

Dropping a needed detail. It is managed by protecting critical information types and comparing results with full context.

Sources

In the glossary: Glossary, A to C

What does this term mean for your infrastructure?

We can work out together in a technical assessment how it maps onto your data, hardware and security requirements.

Request a technical assessment →

This site sets no cookies. Visitor numbers are counted in aggregate using a cookieless method that does not identify anyone. See the Privacy Policy for details.