Six copies of one policy paragraph filled all five retrieval slots. Measured: per-document caps do not help, shingle dedup partly does, MMR covered every fact.
The same paragraph, six times
Knowledge bases copy text. A returns policy is pasted into the shipping FAQ, the gift FAQ, the student FAQ and three more pages. Release notes repeat the previous release's caveats. Support macros are cloned and edited slightly. After chunking, each copy is a separate chunk with its own embedding, and because the copies say the same thing, they score almost identically against any query that matches one of them.
Retrieval then returns the top k chunks, and when the copies rank highest they arrive together. With k = 5, five slots can hold one fact five times. The generator sees no evidence about anything else, and answers confidently from what it has. The answer is not wrong, but it is incomplete in a way no relevance metric that scores chunks one by one will notice, because every retrieved chunk was relevant.
This guide measures the effect on a small synthetic corpus, then compares three remedies: a per-document cap, deduplication at ingestion, and diversification at query time with maximal marginal relevance (MMR). The companion example near_duplicate_topk runs everything with the standard library.
The setup
The corpus is twelve chunks from the Belgavi's Book Store help desk. Six are the same returns paragraph ("you can return a book within 30 days of delivery for a full refund...") on six FAQ pages. Five of the six copies differ only by a trailing sentence or not at all; one has a reworded clause ("You can start a return" instead of "Start a return"). The other six chunks cover distinct facts: damaged books can be returned within 90 days, refunds go to the original payment method, return shipping is free when the book arrived damaged, gift returns get store credit, plus two unrelated chunks about ebooks and loyalty points.
The query is the kind a customer such as Geetha actually asks: "Can I return a damaged book after 30 days and get a refund, and who pays the return shipping?" A complete answer needs four facts: the 30-day window, the 90-day damaged-book exception, the refund method and the free return shipping for damaged books.
Retrieval uses TF-IDF cosine similarity as a stand-in for an embedding model, so the run is deterministic and needs no downloads. The mechanism is the same with dense embeddings, since near-identical text produces near-identical vectors either way; the exact scores and ranks are not, and you should repeat the measurement with your own embedding model.
Measured on the synthetic corpus
| Method | Facts covered (of 4) | Top-5 slots spent on copies |
|---|---|---|
| Plain top-5 | 1 | 4 |
| Top-5 with at most one chunk per document | 1 | 4 |
| Shingle dedup at 0.8, then top-5 | 3 | 1 |
| Shingle dedup at 0.6, then top-5 | 3 | 0 |
| MMR, lambda 0.9 | 2 | 3 |
| MMR, lambda 0.5 | 4 | 0 |
Plain retrieval fills all five slots with the returns paragraph and covers one fact. The answer would explain the 30-day window and say nothing about damaged books, which is the part of the question that matters.
Why a per-document cap does not help
A per-document cap is the most common remedy, and it is aimed at a different problem: a single long document that produces many relevant chunks. Here the copies live in six different documents, so a cap of one chunk per document removes nothing. The measured result is identical to plain retrieval. Caps are still useful, but they do not address duplication across documents.
Deduplicating at ingestion
Near-duplicate detection with word shingles is an old and well-understood technique. Split each chunk into overlapping five-word sequences, compare the sets with Jaccard similarity, and keep one chunk per group above a threshold.
def shingles(text, n=5):
t = tokens(text)
return {tuple(t[i:i + n]) for i in range(max(1, len(t) - n + 1))}
def dedup(chunks, threshold=0.8):
kept, seen = [], []
for c in chunks:
s = shingles(c["text"])
if any(len(s & k) / len(s | k) >= threshold for k in seen):
continue
kept.append(c)
seen.append(s)
return keptTwo measured details matter. First, one reworded clause was enough to drop the Jaccard similarity between two copies to 0.75, below the 0.8 threshold, so the reworded copy survived and still took a slot. Lowering the threshold to 0.6 removed it; the number of chunks kept went from 11 at 0.9, to 8 at 0.8, to 7 at 0.6. Second, dedup only frees slots. It does not decide what fills them. The freed slots went to the next-ranked chunks: gift returns at both thresholds, and loyalty points at 0.6. The refund-method chunk still missed the top five. Dedup raised coverage from 1 to 3 facts, not to 4.
Dedup at ingestion has real advantages beyond retrieval quality: a smaller index, cheaper re-embedding and fewer copies to update when the policy changes. Keep a mapping from the kept chunk to every source page it represents, so citations can still point to the page the user was reading and so a later edit to one copy is noticed.
Diversifying at query time with MMR
MMR selects results one at a time, scoring each candidate by its relevance to the query minus its similarity to what has already been selected, weighted by lambda. At lambda 1 it is plain relevance ranking; at lower values it prefers candidates that add something new. Carbonell and Goldstein introduced it in 1998 for retrieval and summarisation, and many vector stores and RAG libraries offer it as a search option.
On this corpus, lambda 0.5 picked one copy of the returns paragraph and then the damaged-book exception, both refund chunks and the gift-returns chunk, covering all four facts with no slot spent on a copy. Lambda 0.9 was too close to plain relevance and still spent three slots on copies.
MMR has costs of its own. It needs a candidate pool larger than k, here four times k, and pairwise similarity among candidates, which adds latency at high k. Its lambda is a corpus-dependent tuning knob. And it can push out a second relevant chunk that happens to be similar to the first, which hurts when the question genuinely needs two closely related passages, such as two versions of a policy.
Which to use
- Use ingestion dedup when copies are a property of the corpus: pasted policies, mirrored pages, boilerplate. It fixes the index for every query and every retriever, and it saves cost. Tune the threshold on labelled pairs from your own corpus, because edit patterns vary.
- Use MMR when redundancy depends on the query, for example many help-desk cases describing the same incident in different words, which no reasonable shingle threshold will merge.
- Use both in large knowledge bases, with dedup removing exact and near-exact copies and MMR handling paraphrase.
- Keep a per-document cap for long documents that dominate results, but do not expect it to handle copies.
Failure modes
- Deduplicating across versions. Two policy versions can be near-identical but differ in the one sentence that matters. Exclude version-tagged documents from the same dedup group, or keep the newest and record the supersession.
- Losing provenance. If the kept chunk is from the student FAQ and the user is on the gift FAQ, the citation looks wrong. Store all source locations on the kept chunk.
- Measuring with chunk-level relevance only. Precision at k was 100 percent in the plain run. Measure fact or aspect coverage per query, which requires labelling which facts a query needs.
- Tuning lambda on one query. It overfits quickly. Use a set of multi-aspect queries.
Verification
The companion tests assert the table above, the 0.75 Jaccard of the reworded copy, the 11, 8 and 7 chunks kept at the three thresholds, and that the per-document cap leaves four copy slots. For your own system, build twenty or so queries whose answers need several distinct facts, label the facts, and track coverage and copy slots per method. Then sample your index for groups of chunks with high pairwise similarity; their size tells you how many top-k slots copies can take.