Deduplicate copied passages by lineage and revision while preserving genuinely independent sources for corroboration.
Near-duplicate retrieval: collapse copies without hiding independent evidence
Separate copies from corroboration
A retrieval result can contain a policy paragraph copied into twelve team notes. Twelve hits are not twelve independent confirmations. Store document lineage, source owner, passage hash and revision so the system can group copies. Exact hashes catch byte-identical text; normalized hashes catch whitespace and formatting changes; semantic similarity can suggest near duplicates for review. A separate independent bulletin stating the same limit may be valuable corroboration and should not disappear merely because its wording is similar. Provenance decides which case applies.
Collapse at the right boundary
Group near duplicates after access filtering. A user who can see the public manual but not a private support note must not see the private note's title or existence in the collapsed result. Within an eligible group, choose an authoritative active revision and retain a list of permitted copies for audit. Do not pick a superseded revision only because it has a higher lexical score. Revision rules take precedence over ranking.
Protect the candidate window
Repeated template text can consume most of top-k, leaving no room for another document needed to answer the question. Collapse copies before context selection and reserve slots for distinct source lineages. Track both raw hit count and independent-lineage count in traces; a result of 20 hits from one copied memo is effectively one source. Evidence diversity should be measured at lineage level rather than URL count.
Choose a conservative similarity rule
A shared heading and two similar sentences do not prove two passages are duplicates. Numeric values, negations, dates and identifiers can differ while the rest of the text matches. Treat changes in those fields as blockers to automatic collapse. For uncertain pairs, keep both or flag them for review. False merging removes possible contradictions; false separation mostly wastes context. This asymmetry argues for conservative thresholds and explicit field checks.
Test both errors
Create copied passages, lightly reformatted copies, stale revisions and independently authored confirmations. Measure duplicate-group purity and answer-bearing passage recall after collapse. Include two near-identical policies whose refund windows differ and a copied note with a missing negation. The system should retain both contradictory policies for resolution, not merge them into a false consensus. Judged sets need lineage labels to make this visible.
Worked contract
import re
from dataclasses import dataclass
@dataclass(frozen=True)
class EvidenceCopy:
passage_id: str
tenant: str
lineage: str
revision: int
text: str
def normalize_copy(text: str) -> str:
return re.sub(r"\s+", " ", text.casefold()).strip()
def collapse_copies(passages: list[EvidenceCopy], tenant: str) -> list[EvidenceCopy]:
chosen: dict[tuple[str, str], EvidenceCopy] = {}
for passage in passages:
if passage.tenant != tenant:
continue
key = (passage.lineage, normalize_copy(passage.text))
if key not in chosen or passage.revision > chosen[key].revision:
chosen[key] = passage
return list(chosen.values())
copies = [EvidenceCopy("manual-r2", "north", "manual-47", 2, "Limit: 47 days"),
EvidenceCopy("manual-r3", "north", "manual-47", 3, "Limit: 47 days"),
EvidenceCopy("notice-r1", "north", "notice-83", 1, "Limit: 47 days"),
EvidenceCopy("private-r4", "south", "manual-47", 4, "Limit: 47 days")]
assert {hit.passage_id for hit in collapse_copies(copies, "north")} == {
"manual-r3", "notice-r1"}Performance and operating cost
The hash-based baseline scans N passages in O(NL) time for average passage length L and stores O(U) groups for U unique lineage-text pairs. Semantic near-duplicate detection adds candidate-pair and review cost; avoid an O(N squared) all-pairs scan on a large corpus by blocking on lineage, source type or approximate fingerprints first.
Common Mistakes
- Counting copied team notes as independent evidence.
- Grouping before access checks and exposing restricted source metadata.
- Merging passages that differ in a number, negation or effective date.
- Keeping the highest-ranked stale copy instead of the active revision.
Validation drill
Make 79 passages across 12 lineages with exact copies, formatting changes, copied notes and three contradictory revisions. Verify that collapse preserves all independent answer-bearing sources and no restricted metadata leaks.
