Menu

Finding near-duplicate documents with MinHash and LSH before you index them for RAG
📰

Finding near-duplicate documents with MinHash and LSH before you index them for RAG

DEV Community: python·Ali Ahmed·11 days ago
#gRkrextc
#devtopython#devto#dev#documents#minhash
Long article (869 words) — no AI summary yet.
Reading 0:00
15s threshold

Document collections are full of near-duplicates : the same policy exported twice, a page with a new footer, version 1 and version 2 of a contract. Indexed for RAG, they fill the top-k results with copies of one passage and crowd out everything else. MinHash finds them efficiently: split each document into overlapping word shingles , and compare documents by Jaccard similarity (shared shingles ÷ all shingles). MinHash compresses each document into a short signature whose matching positions estimate Jaccard, and LSH banding finds candidate pairs without comparing every document to every other. One warning from my test: two versions of a policy with different numbers are 66% similar . Deduplicate copies; never deduplicate versions.

Shingles and Jaccard similarity

A shingle is a run of k consecutive words.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.