Skip to content
mentoor

Topic 3 of 4 · 4 min read

Deduplicating copies and tracking versions

Goal: Configure deduplication and version tagging so a query returns one current copy instead of five stale ones.

Retrieval returns the best matches by similarity, so five copies of the same text, or five versions of the same policy, take five slots; the fix is to detect copies at ingestion and to tag versions so only the current one is searchable.

Check yourself · 1 of 3

Why do duplicate chunks hurt answer quality?

Choose one answer

Why it matters

The model sees the top few chunks, often five to ten. If four of them are the same paragraph from a wiki page, a PDF export and two email attachments, the context holds one fact and wastes the rest. Worse, if an old and a new version of a refund policy both score high, the model may quote the stale one, or blend them into an answer that matches neither.

How to do it

  1. Exact duplicates: hash. Hash the normalised chunk text (lower-case, whitespace collapsed). Same hash means the same chunk. Keep one and record the other source paths in a also_in list, so citations still work.
  2. Near duplicates: fuzzy match. Pages that differ by a date or a nav bar will not hash equal. Compare with MinHash or SimHash, or an embedding similarity above a high threshold such as 0.97, and review a sample before trusting the threshold. Research on large text corpora shows near-duplicates are common and need fuzzy matching, not only exact.
  3. Tag versions. Give each chunk doc_id, version, effective_from and status (current or superseded). When version 4 arrives, mark version 3 superseded in the same sync.
  4. Filter at query time. Default every search to status = current. Allow as_of queries for questions such as "what was the policy in March?", where the older version is the right answer.
  5. Choose the survivor by rule. Prefer the canonical source, then the newest, then the one with the most complete metadata.

Before and after

# Before: top-5 returns the same paragraph from five files
hits = index.search(query, top_k=5)
# After: current versions only, one hit per content hash
hits = index.search(query, top_k=20, filter={"status": "current"})
seen, out = set(), []
for h in hits:
    if h.meta["text_hash"] in seen:
        continue
    seen.add(h.meta["text_hash"])
    out.append(h)
out = out[:5]

What goes wrong

  • Over-aggressive thresholds. Two different clauses that share boilerplate get merged, and a real answer disappears. Sample the merged pairs.
  • Deleting old versions outright. Audits and "as of" questions need history. Mark them superseded; do not erase them unless required.
  • Dedupe after top-k. If you remove duplicates after fetching only five, you are left with two. Fetch more, then dedupe, then cut.
  • Ignoring copies with different access rights. Merging a public copy with a restricted copy can leak or hide content. Dedupe within the same access label.

Examples

Five copies of one handbook paragraph

A query about notice periods returned five hits with the same sentence: the wiki, a PDF export, two email attachments and an archived copy. After hashing normalised text, one chunk remained with also_in listing the four other paths, and the other four slots went to the related clauses on probation and resignation.

Version metadata on a chunk

{
  "doc_id": "refund-policy",
  "version": 4,
  "effective_from": "2026-09-01",
  "status": "current",
  "text_hash": "9f2c...e1"
}

Version 3 of the same document is rewritten to "status": "superseded" when version 4 is indexed.

Key points

  • Duplicates waste the few retrieval slots the model sees, and stale versions can win and produce wrong answers.
  • Hash normalised text for exact copies and use MinHash, SimHash or a high similarity threshold for near copies.
  • Tag chunks with doc_id, version, effective date and status, and mark old versions superseded in the same sync.
  • Filter on status current by default and allow an as-of filter for historical questions.
  • Fetch more than you need, dedupe, then cut to the final count.

Common mistakes

  • Deduplicating only exact copies and ignoring pages that differ by a date or banner.
  • Deleting superseded versions when audits or as-of questions need them.
  • Removing duplicates after cutting to top-k, leaving too few results.
  • Merging copies that carry different access labels.

Check yourself · 2 of 3

Two pages differ only by a footer date, so their hashes differ. Which method still finds them as copies?

Choose one answer

Check yourself · 3 of 3

Version 4 of a policy is indexed. What should happen to version 3 chunks by default?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic