Conversation
Exact matcher could not report within-document duplicates. It grouped identical sentences, then discarded any group confined to a single document before pairing only across documents. On the sample corpus this under-reported by 85% (21 pairs against an actual 143). The "within-document" category label computed for exact pairs was unreachable by construction. Embedding matcher counted sentences as duplicates of themselves. The guard sliced off the top FAISS hit, which removes the self-match only when it ranks first; with byte-identical sentences the tied cosines are arbitrarily ordered, so the self-hit often landed at rank >= 1 and survived. 112 of 389 pairs (28.8%) were self-matches, which also inflated matched_sentences_pct in doc_metrics.csv. Verified after fix: exact 21 -> 143 (21 cross-document + 122 within-document), embeddings 389 -> 277 moderate and 374 -> 262 strict, self-match contamination 0.0%. SimHash unchanged at 186, confirming the change is isolated to the two intended paths. docs/FINDINGS.md records the full three-way comparison, per-phase timing, a Hamming threshold sweep, table-vs-prose attribution, and an explicit limitations section noting that no ground-truth labels exist, so all figures are yield/overlap/cost rather than precision/recall. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Measured all three duplicate-detection methods against each other on the sample corpus (5 docs, 1,590 sentences). The comparison surfaced two defects, both fixed here, plus a full writeup in
docs/FINDINGS.md.Before / after
Union across methods stays at 289 unique pairs — the fixes removed false positives and surfaced pairs already reachable via SimHash, rather than inventing new ones.
Defect 1 — exact matcher blind to within-document duplicates
It grouped identical sentences, then dropped any group confined to one document before pairing only across documents. 85% under-report: 21 against an actual 143.
The
"within-document"label computed for exact pairs was unreachable by construction — dead code indicating the capability was intended.Defect 2 — embeddings matched sentences to themselves
A self-match guard existed:
Slicing
I[i][0]removes the self-hit only when it ranks first. With byte-identical sentences the tied cosines of 1.0 come back in arbitrary order, so the self-hit often landed at rank ≥1 and survived. 112 of 389 pairs were a sentence paired with itself, which also inflatedmatched_sentences_pctindoc_metrics.csv.This is the harder class of bug: correct-looking code that degrades precisely on the input the tool exists to handle.
Fixed by excluding the self-index explicitly rather than positionally.
Other findings in
docs/FINDINGS.mdread_docx_textis 88% of runtime (7.16s of 8.14s). SimHash costs 902× more per sentence than exact and it still doesn't matter. The optimisation target is the parser.Algorithms.md.Limitations
No ground-truth labels exist, so every figure is yield, overlap, or cost — no precision or recall against human judgement is claimed. "Unique contribution" measures novelty, not correctness. Single corpus, n=5, one domain, heavily table-laden. Timing is single-run, no repeats.
The defect findings don't depend on any of that — they're properties of the code.
Verification
python corpus_dedup_runner.py --input_dir docs --out_dir out --use_embeddingsSimHash counts are unchanged at 186/175, confirming the diff is isolated to the two intended paths.
🤖 Generated with Claude Code