Pruning RAG context down to what the answer actually needs
TL;DR Highlight
A small LLM grades chunks and drops 68% of RAG context, keeping 96% recall and cutting query cost 34%.
Who Should Read
A backend or agent developer whose RAG pipeline sends every retrieved chunk to a large model and burns input tokens.
Core Mechanics
- Add a small LLM between reranker and generator
- A small, cheap LLM reads the question and all retrieved chunks together.
- It drops chunks the answer won't need before the expensive model sees them.
- It removes about 68% of context and keeps about 96% recall.
- Ignored chunks still cost money
- In kapa's assistants, retrieved chunks are about two-thirds of query cost.
- That is more than the answer, conversation history, and system prompt combined.
- Each chunk fewer cuts query cost by about 4%.
- Rerank-score cutoffs didn't work
- A rerank score is an ordering, not a measurement, so it isn't calibrated across queries.
- Pointwise cross-encoders score each query-chunk pair alone and miss chunks that only matter alongside others.
- In a production example, a chunk that never mentions audit logs scored as noise but was half the answer.
- Anchor documents failed too
- This plants synthetic chunks of known relevance in the ranking as reference points.
- The reranker still put partially or indirectly relevant chunks below clearly irrelevant ones.
- The lesson: what is judged is the set of chunks, not a single chunk.
- A listwise LLM call with a five-level scale
- Five levels from ESSENTIAL (5) to UNRELATED (1) are defined in words in the prompt.
- Level meanings stay the same across queries, so a fixed threshold finally works.
- Seeing all chunks together lets it judge partial and indirect relevance.
- Results beat simple top-N truncation by a lot
- At 98% recall, top-N truncation reaches only about 7% compression.
- Every LLM strategy reached 30% or more, and relevance scoring dropped close to half the chunks.
- The chosen configuration adds about 0.7 seconds per query.
- Three knobs matter
- Model: they picked the fastest, cheapest small model at low reasoning effort.
- Threshold: the main dial between compression and recall.
- keep-top-k: passes the top few reranked chunks regardless of grade to guard against grading mistakes.
Community Reactions
- Opinion that "RAG" is the wrong term here
- A commenter argues "Semantic Retrieval" is more accurate for this kind of post.
- RAG also covers tool use, and vector search is just one tool.
- Skepticism about trusting a small LLM
- One commenter says a small model could become an intellectual bottleneck on the hard-won information.
- Opinion that bad context hurts answers
- A commenter says bad or loosely related context can make the final answer worse than less context.
- Follow-up questions and a summary
- A commenter asked whether the pruner could completely replace the reranker.
- Another said using a rubric for Likert-scale grading is a good way to coax numbers out of an LLM.
How to Apply
- Measure chunk cost share from your RAG logs
- In 30 minutes today, compute what share of input tokens in recent queries are retrieved chunks.
- Run the prompt below on the same queries and see what share of chunks score 3 or less.
- Insert a pruning call between reranker and generator
- Use your cheapest small model at low reasoning effort.
- Pass the question and all top chunks in one call and get per-chunk grades as JSON.
- Send only chunks at or above the threshold to the generator.
- Protect top chunks with keep-top-k
- Always pass the top 2-3 reranked chunks regardless of grade.
- This prevents a grading mistake from removing a key chunk.
- Pick the threshold with labeled chunks
- Build a question set where the needed chunks are labeled.
- Sweep the threshold and plot compression against recall to choose your point.
- Start with agent search tools
- Turn it on first in the doc-search tool of agents with many tools and fast-filling context.
- Missing info can be searched again, and 0.7 seconds matters less there.
Try It
# Paste into Claude or ChatGPT. A simplified version of the small-model pruning call
You are a context pruner in a RAG pipeline.
Look at the question and all chunks together, and judge whether each chunk belongs to the set that produces the answer.
Grading scale:
5 ESSENTIAL: The answer cannot be produced without this chunk. It answers directly or is a definition or prerequisite another chunk depends on.
4 CONTRIBUTING: Does not answer alone, but supplies something a complete answer needs in combination with other chunks.
3 SUPPORTING: On topic and plausibly useful, but the answer is likely complete without it.
2 TANGENTIAL: Same domain or shared terminology, no concrete contribution.
1 UNRELATED: No meaningful connection.
Question: {{question}}
Chunks:
[1] {{chunk1}}
[2] {{chunk2}}
[3] {{chunk3}}
Output JSON only: [{"id":1,"grade":5,"reason":"one line"}, ...]
Then list the chunk ids that would be dropped with a threshold of 4 or higher.Terminology
Related Papers
FutureBench: A Renewable Framework for Evaluating Knowledge-Context Conflict in LLMs
Adding 'verify and prioritize the passage' to RAG prompts raised false-passage adoption; a knowledge-priority warning fixed it.
Faster Retrieval for Better, More Efficient RAG
Small neural nets learned query routing, hitting the same recall up to 8x faster in IVF search
Memorilla: Latent Semantic Memory for LLMs
Compressing documents into 16 memory tokens beat full-context accuracy on FactKG.
What the Author Wrote, What the Agent Reads: Silent Cue Loss in Enterprise Document Ingestion
Preserving red text and highlights in docx ingestion lifted marked-requirement F1 from 0.150 to 0.690.
Multimodal Reranking Is a System One Decision
One multiple-choice question to a VLM over 16 candidates reranks them, beating a dedicated 2B reranker.
You could have invented transformers from memory
Viewing linear, MLP and attention layers as memory stores: capacity goes ~64 to ~2,700 to over a million
Pointing AI at archives found a forgotten meteorite, lost rhinos, and more
Embedding search plus a cheap filter model surfaced unrecorded events in 400 years of archives
EmbeddingGemma 2: An open, lightweight multimodal embedding model
One open 740M model embeds text, images, audio and video into a single shared vector space