How can you detect redundancy across retrieved chunks before they hit the prompt?
Normalized text hash catches verbatim duplicates cheaply; pairwise cosine similarity over embeddings catches paraphrased duplicates; layer them so the expensive pass only sees the small set.
Imagine sorting a stack of leaflets a campaign just brought back. Some leaflets are obvious photocopies of each other, same words, same layout. You can flip through fast and toss those by eye in seconds. Others are reworded versions of the same message; you actually have to read them to notice. So you do the fast visual pass first across the whole stack and only do the careful reading on the much smaller pile that survives. Retrieval dedupe works the same way. A quick visual scan for the photocopies, a careful read for the reworded ones, in that order.
Detailed answer & concept explanation~5 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 minutes: the two duplicate flavors, hash dedupe shape and cost, cosine dedupe shape and cost, layered ordering, threshold tuning, edge cases.
Real products, models, and research that use this idea.
- LlamaIndex ships a SimilarityPostprocessor node that implements cosine dedupe at the top-k stage of its query pipeline.
- LangChain's EmbeddingsRedundantFilter operates the same way and pairs with the contextual-compression retriever.
- Cohere's 2026 production RAG guide explicitly recommends layered dedupe (hash before rerank, cosine after rerank).
- Anthropic's Claude Opus 4.7 RAG cookbook flags near-duplicate retrieval as a top source of irrelevance-penalty regressions.
- Vespa, Weaviate, and Qdrant ship native dedupe operators in 2026 that let the work happen at the index layer before chunks ever reach the prompt builder.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you tune the cosine threshold for a new corpus?
QWhat happens when two near-duplicates disagree on one important fact?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Running pairwise cosine similarity over the whole top-50 retrieval set. The cost scales with k squared. The right shape is hash-first over the wide set, then cosine over the small reranked set.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.