Show HN: CLI tool for detecting non-exact code duplication with embedding models

45 points - today at 2:19 PM

Source

Comments

vander_elst today at 6:09 PM
I implemented this for a large monorepo last year, it runs as an analysis during code review and it shows what are possible similar snippets wrt the code under review. It was a very nice project. It also allows to see across the repo what are the most common constructs for the different languages. This could also be helpful to see if some code has been copied e.g. from open source projects.
rkochanowski today at 2:19 PM
I built Slopo to solve one specific problem: finding similar code that is hardest to detect by other tools, coding AI agents, and humans.

It finds similar-looking code with embeddings. This detects more than just copy-paste clones or even clones with minor changes. Similar code is often not a clone to refactor, and this is a trade-off. Initial results need to be verified, but coding agents can do this quickly. Example prompts are available on https://slopo.dev

Additionally, similar code distant in the codebase is ranked higher to focus on less obvious duplication.

The results differ a lot depending on the codebase. I noticed that sometimes most of the detected duplicates are false positives, but the remaining ones are strong candidates to refactor or even bugs. Sometimes it reveals much more real duplication.

rohanat today at 6:06 PM
have you considered a deterministic tier before the embedding pass? I feel that approach can be more efficient.
murats today at 3:28 PM
Nice idea. I can see this being useful before refactors, especially when the duplication is semantic rather than copy paste.
philajan today at 4:40 PM
This is neat. Have you noticed any difference in duplicate detection between strongly typed and loosely typed languages / code bases?
BrandiATMuhkuh today at 4:59 PM
What a simple and smart idea. Wonderful
forhadahmed today at 5:13 PM
self plug (for similar tool): https://github.com/forhadahmed/refactor
hdz today at 4:36 PM
Very nice. I can imagine putting this into a pre push hook to keep things clean after an initial sweep.
NYCHMPAI today at 3:26 PM
This is a great use case for embeddings. Code deduplication across distant modules is notoriously hard for traditional AST-based tools.

How do you handle chunking and parsing for different languages to make sure the embeddings capture semantic meaning effectively? For instance, do you chunk by functions/classes, or use a fixed token window? If a function is too long or too short, it can drastically skew the embedding similarity.

SpyCoder77 today at 4:46 PM
I think that this is pretty cool, but is there any reason why we would want to remove similar/possible duplicate code?