Context Compression
Context compression refers to techniques that retain as much effective information as possible within a limited window, reducing the number of input tokens by pruning, summarizing, rewriting or encoding. It is the key means by which long-context and multi-turn dialogue systems keep running without collapsing, and also the most direct means of controlling inference cost.
Core Principles
Model context windows keep expanding, but cost and effectiveness have not improved in step. Attention computation grows with length, and first-token latency rises markedly; more troublesome is the "lost in the middle" phenomenon, where information in the middle of a long context is easily ignored and the effective usable length is far smaller than the nominal limit. So stacking window size does not equal solving the problem.
Compression unfolds at three levels. At the token level, the LLMLingua family uses a small model to estimate the information entropy of each token, removing low-information words (function words, redundant modifiers, repeated phrasing), combined with context-aware iterative compression, achieving several-fold compression while preserving task performance. Its advantage is that no retraining of the target model is needed and there are no format requirements; its drawback is that high-entropy content such as code, numbers and tables is easily deleted by mistake.
At the passage level, abstractive compression hands a group of documents or dialogue history to a model to generate an outline-style summary, keeping conclusions, entities and constraints while discarding narrative buildup. In multi-turn dialogue, early turns are often rolled up into a summary, keeping only the original text of the most recent turns.
In engineering there is also a common lightweight practice: fold background information that repeatedly appears in the dialogue history into a single setting, for example condensing a user's repeatedly emphasized format preference into one global constraint that later turns reference directly. Such handcrafted rules combined with automatic summarization are often more stable than pure model summarization, because they are unaffected by sampling temperature.
At the structural level, selective retention picks passages by task relevance, for example keeping only the sentence window hitting the query sentence, or only the rows of a table relevant to the question, and discarding whole other passages. There is also compressing the dialogue history into a retrievable vector store and recalling it when needed, which belongs to the idea of external memory.
Key Points
Allocate compression rates by content type. Narrative text can be highly compressed, while code, formulas, numbers and proper nouns must be compressed little or kept verbatim, otherwise fine-grained correctness collapses immediately.
Compression needs a reversible design. Deleted content should at least keep an index so the original can be traced back when needed, avoiding the inability to answer as soon as a detail is asked.
Summary quality takes priority over compression rate. Generating poor summaries to fit more content is a negative return; summaries should preserve entities, times, values, negations and conditions.
Rolling compression must keep anchors. In multi-turn dialogue, the goals and constraints originally set by the user must always be kept, otherwise the model drifts from the requirements over a long conversation.
Check consistency before and after compression. Sampling and comparing whether answers to the same question agree before and after compression is the most practical way to assess whether compression is safe.
Common Misconceptions
Assuming compression is simple truncation, taking the first N characters or first K documents, and losing exactly the passage containing the answer. Another misconception is indiscriminate compression that also deletes numbers and codes, causing answer precision to plummet. Some compress only the input and ignore the output, while letting the model produce lengthy explanations also consumes the window. Some also ignore ordering, squeezing the most relevant information into the middle of a long context, which is worse than placing it at the beginning or end.
Application Scenarios
Long-document question answering, multi-turn customer service dialogue, meeting minutes organization, codebase understanding, retrieval-augmented generation pipelines, agent history management, cost-sensitive high-concurrency inference.