Skip to content

fix(dedup): strip watermark and require 0.6 similarity for OCR duplicates - #380

Merged
ohld merged 1 commit into
productionfrom
fix/ocr-dedup-watermark-threshold
Oct 31, 2026
Merged

ohld merged 1 commit into
productionfrom
fix/ocr-dedup-watermark-threshold

Conversation

@ohld

@ohld ohld commented Oct 31, 2026

Copy link
Copy Markdown
Member

What

OCR duplicate matching (find_duplicate_by_ocr_text, used by Describe Memes, pending-meme dedup and upload moderation):

  • strips the @ffmemesbot watermark (and OCR misreads like @ffemesbot) and imgflip.com before the 12-char minimum and the match;
  • requires similarity(stripped, stripped) >= 0.6; the % operator (default 0.3) stays only as the trigram-index prefilter;
  • picks the most similar candidate first, then published, then oldest.

Why

We hand-labelled 152 OCR merges from the last 60 days. 43% were false merges, mostly unrelated short captions that shared only the watermark. Published-first ordering funnelled them into hub originals: one meme whose whole text is the watermark absorbed 655 dupes, another absorbed 760. Their reactions were moved onto the hub and the memes were removed from the feed. In the last 24h, 259 of 565 merges were below the new rule.

rule false merges recall of true merges
current (raw, 0.3) 43% 100% (by definition)
stripped ≥ 0.6 2.5% 93.5%

Tests

  • New regression test: a watermark-only match, a same-template different-punchline match, and a misread-watermark true duplicate.
  • tests/storage/test_deduplication.py and tests/tgbot/test_upload_moderation.py pass locally.
  • Query timed on prod: 1.0–1.6s per lookup, same index scan as before.

Restoring historical false merges is a separate change.

…ate matches

Audit of 152 recent OCR merges: 43% were false. Short captions sharing only the
@ffmemesbot watermark passed pg_trgm's default 0.3 threshold, and published-first
ordering funnelled hundreds of unrelated memes into a few hub originals.
Stripped similarity >= 0.6, ordered by similarity: ~2.5% false, ~93% recall.
@ohld
ohld merged commit 1eea42e into production Oct 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant