My library is over 50k as well. One of the problems I've experienced, other tools have created thumbnails of my photos. Eventually I lost control of which is the original. Now I have over 300k photos :( I fear deleting the "wrong" file.
I've been working on the same thing for the past month. You have a lot of similar ideas. I haven't yet implement any automated decision making yet.
I create a json registry of all my photos, then use that for comparison for new imports (to catch early duplication, or multiple streams filling library), and for in-library analysis later.
You can see similarities just based on the json containing these important fields:
Totally relate to the ‘lost control of originals’ fear. That’s exactly why I designed this to be non-destructive by default. A few clarifications on my side:
No thumbnails are written to disk. Thumbs are created in-memory only for hashing and then discarded. The script never replaces files with generated thumbs.
No deletions by default. It runs dry-run + produces a CSV audit, and the “delete” step is an explicit opt-in (I prefer quarantine / send-to-trash over hard delete).
Deterministic keeper policy. Within a duplicate cluster it picks a “keeper” based on resolution → sharpness → preferred format → compression proxy. The idea is: even if you do remove duplicates, you keep the best source material.
Your JSON registry approach is solid. I do something similar conceptually (feature table), and then. Similarity search: BK-tree vs bucketing. BK-tree works nicely for Hamming distance (esp. for perceptual hashes). The tradeoff is it can get slow on very large N depending on query radius and distribution. I went with bucketing on hash prefixes + union-find clustering. It’s essentially “generate candidates cheaply” (reduce comparisons) and then merge via DSU so you get families/clusters instead of just nearest-neighbor pairs.
If you stick with BK-tree, one practical speed win is to use a coarse pre-filter first (e.g. first K bits bucket or aspect ratio bucket), then BK-tree inside the bucket. That keeps tree sizes smaller.
On ‘original control’. If you’re anxious about losing originals, two patterns help a lot. Quarantine instead of delete (move drops into a quarantine folder retaining paths/IDs). Persistent manifest/log (you already have JSON; add a reversible rename/move log so you can undo).
Also: +1 on comparing new imports against the registry — catching duplicates at ingest prevents the “300k spiral”.
And yeah, definitely share your GitHub when it’s up — I’d be interested to compare BK-tree behavior vs my bucket+DSU thresholds, especially on borderline cases (cropped/blurred/HEIC→JPG exports). Happy to link your repo in an update if you want.
View all comments
2
u/daguz Feb 17 '26
My library is over 50k as well. One of the problems I've experienced, other tools have created thumbnails of my photos. Eventually I lost control of which is the original. Now I have over 300k photos :( I fear deleting the "wrong" file.
I've been working on the same thing for the past month. You have a lot of similar ideas. I haven't yet implement any automated decision making yet.
I create a json registry of all my photos, then use that for comparison for new imports (to catch early duplication, or multiple streams filling library), and for in-library analysis later.
You can see similarities just based on the json containing these important fields:
"file_name": "absolute_path": "hash_size": "dhash_int": "ahash_int": "dhash_hex": "ahash_hex": "dhash_bits": "ahash_bits": "sha384":
After creating my library I run that though a BK-tree to find nearest neighbors. I'm able to create trees based on existing library and import list.
My performance is slow, but I don't care. I'll be publishing this soon on github. I'll try to remember to call you out if you're interested.