6/35
Part 2 of 6 · Clean and map the pileLearn and do

Three passes catch copies, cheapest first

No single test catches every kind of copy.

PassCatchesMissesFor a billion
exact, SHA-256byte-identical filesany re-save32 GB
perceptual, PDQre-saves and resizescrops, big edits32 GB
semanticcrops, margins, filters1.5 TB

Exact. Take the SHA-256 of each file's bytes, a 32-byte digest. A sort or a hash join over a billion of them finds every byte-identical copy.

Perceptual. A perceptual hash summarizes what an image looks like, so a resized or recompressed copy gets a nearby hash. Meta's open-source PDQ is built for this job:

  • Each hash is 256 bits. Two hashes are compared by Hamming distance, the number of bits that differ.
  • PDQ's README treats two hashes as a match at a distance of 31 or less, 31 of the 256 bits.
  • Each hash comes with a quality score from 0 to 100 that measures detail, for spotting blurry or featureless images.

Semantic. The third pass needs a vector for each image, so it runs once the embeddings exist.

In the editor, write hamming(a, b) and same_photo(a, b). The stub builds three 256-bit PDQ hashes as Python ints: an original, a resaved copy 31 bits away and a cropped copy 40 bits away.