What is prompt compression?

Prompt compression is the general name for methods that express the prompt sent to a language model in fewer tokens while keeping the information the task needs. The aim is faster, cheaper inference and fitting long content into the context window.

Unlike context compression, a wider family that also covers conversation history and internal caches, it shortens the prompt text itself; methods that trim internal caches cannot easily serve black-box models reached through an API.

Topic
Prompts, context, reasoning and generation
Also known as
Prompt shortening
Origin
2023, Selective Context, gist tokens and LLMLingua

How prompt compression works

  1. Hard methods delete less informative tokens or sentences; the result is still text.
  2. Selective Context and LLMLingua decide what to drop using self-information or perplexity computed by a small language model.
  3. LLMLingua-2 decides to keep or drop each token with a Transformer encoder that sees bidirectional context.
  4. Soft methods such as gist tokens compress the prompt into a few learnt vectors and require training the model.

In more detail

Hard and soft prompt compression

A survey groups prompt compression techniques into hard prompt methods and soft prompt methods. Hard methods select or delete natural language tokens; soft methods compress the prompt into special tokens or vectors learnt by the model. The survey names combining the two approaches as a future research direction.

Commonly confused terms

TermHow it differs
Prompt cachingPrompt caching stores the computation for a repeated prompt prefix and reuses it on later calls; the prompt content does not change. Prompt compression shortens the content itself, cutting tokens on every call but risking information loss.

Why prompt compression matters for on-premises AI

Chain-of-thought prompting and in-context learning can push prompts past tens of thousands of tokens. LLMLingua reported up to 20x compression with little performance loss. At 2x to 5x compression LLMLingua-2 cut end-to-end latency by 1.6 to 2.9 times. Gist tokens achieved up to 26x compression and up to 40% fewer FLOPs.

ON-PREMISES EXAMPLE

An insurer's Retrieval-Augmented Generation-based assistant compresses long passages retrieved from policy documents before sending them to the model. Rules check that fields such as policy number and date survive; the compression ratio is chosen by comparing answers from compressed and full prompts on a fixed evaluation set.

Common questions

Does prompt compression reduce answer quality?

It can. Published methods report small losses at high ratios, but results depend on the task and data. The compression ratio is therefore chosen on the organisation's own evaluation set.

Can prompt compression be used with a model reached only through an API?

Yes. Hard methods that delete tokens still produce text, so they work with black-box models. Soft methods such as gist tokens require training the model.

Sources

In the glossary: Glossary, M to Q

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.