Skip to content

Prompt Compression

Definition

Prompt Compression — a collection of techniques aimed at reducing the number of tokens in a prompt before sending it to an LLM. Compression can be performed at the source text level, at the embedding level, or through training specialized compressor models. The goal is to retain relevant information by removing redundant or low-information parts.

Compression Methods

Method Description Application
Key Phrase Extraction Highlighting the most significant sentences Long documents
Summarization Generating a brief summary News, reports
Embedding Compression Projecting into a lower-dimensional space Context caching
Training a Compressor Specialized model that compresses the prompt High-load systems

Example

# Pseudocode for prompt compression
compressed_prompt = compress(
    original_prompt,
    ratio=0.3,  # target compression to 30%
    method="extractive"
)

See also