Contextual Compression
Overview
Contextual Compression — a method for reducing the size of context passed to an LLM by removing irrelevant fragments and compressing relevant ones. It is applied in RAG systems to improve accuracy and reduce token costs.
Approaches
- Relevance Filtering: removal of chunks with low scores.
- Compression with LLM: generation of a brief summary of each chunk.
- Extraction of Key Sentences: highlighting the most informative parts.
- Combination with Re-ranking: compression after re-ranking.
Pipeline Diagram
graph LR
A[Query] --> B[Search]
B --> C[Reranking]
C --> D[Compression]
D --> E[LLM]