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.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Redundancy in retrieved chunks is one of the under-discussed sources of context-engineering damage. Duplicate chunks burn token budget, displace genuinely useful content, and dilute the model's attention exactly the way unrelated distractors do. Detecting them before assembly is cheap when done right and expensive when done wrong.
This card walks through the two practical detection methods (hash and cosine), where each one belongs in the pipeline, how to tune them, and the edge cases that catch teams who only run one layer.
Two flavors of duplicate
Real corpora produce two distinct shapes of duplication, and the detection method has to match.
Verbatim duplicates. The same chunk text appearing in two different document IDs. Causes: syndicated content (the same article on multiple sites), version-controlled documentation (v2 and v3 of the same doc), copy-pasted FAQs, repeated boilerplate. After light normalization (lowercase, collapse whitespace, strip punctuation), these chunks hash to the same value.
Paraphrased duplicates. Two chunks that say the same thing in different words. Causes: different writers covering the same fact, the same source summarized at different granularities, translation back and forth in multilingual corpora. These chunks do not match by hash. They cluster in embedding space.
Why both layers matter
Hash alone misses paraphrases. Cosine alone is too expensive to run over wide retrieval sets and can be too aggressive on technical corpora where slight wording differences encode important distinctions. The layered approach catches both flavors at the right cost.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
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.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you tune the cosine threshold for a new corpus?
Curate a labeled set of duplicate and non-duplicate pairs; sweep threshold from 0.85 to 0.97; pick the value with best F1 on duplicate detection without dropping known-distinct pairs.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases 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.
60 second bullets to scan on the way to the call.
How do you distinguish verbatim duplicates from paraphrased duplicates?
What does hash-based detection catch and what does it miss?
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.