Live data from Hacker News

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

github.com

31–40 of 61 posts

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

#31

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. Exampl…

Correct me if I'm wrong, but looking at [1] it seems to be specifically using function definitions (I'm guessing this works with functions, methods, and lambdas (the " " part)?) as units of repetition. If yes, that's fine, but I would seriously consider adding some settings to allow the user to control that granularity. Sometimes, the repeated code is a conditional branch within larger functions (i.e., "every else:"…

Currently, only whole functions (including function-like constructs depending on language) are considered as unit.

Skipping the extraction of conditional branches was my decision to not overcomplicate the first versions, which was intended to validate the idea. I will add this in future versions because I agree it's needed for large functions.

I don't think it needs configurable granularity. In the current version, there is an analogous mechanism: when functions are nested, both outer and inner are embedded separately. When both are similar to each other, this pair is excluded. Inner or outer functions can appear in results depending on similarity to other units.

Regarding comments, they are removed and I will think about handling them. The challenge is not with extraction, but with how to present this in a report. This may be a nice addition because coding agents often add comments.

Thanks for the feedback.

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

#32

Did you benchmark it against simpler methods like BM25?

I just focused on embeddings without comparing them to deterministic solutions.

But I plan to do my own analysis of different embedding models in the context of code similarity detection. Including BM25 in the comparison is a very good idea.

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

#34

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. Exampl…

[flagged]

My solution for false positives is simpler:

1. The tool uses only cosine similarity plus boost depending on distance in the codebase.

2. Classification with LLM. This can be done by coding agent used with project giving better results than integrating this pass in the tool. LLMs used for coding are pretty good.

I assumed that this is not a problem I need to solve inside the tool. I'm aware this is not deterministic, but this is by design.

Regarding information about raw similarity: currently, the score (raw similarity + boost) is visible in the report, so this value can be configured based on data. The raw similarity threshold can also be configured, but it's not displayed. I will think about how to handle this.

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

#35
post #18

have you considered a deterministic tier before the embedding pass? I feel that approach can be more efficient.

We did this by using the ASTs you can go quite far without embeddings and the result is easier to debug and follow what's going on.

[deleted]

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

#36
post #18

have you considered a deterministic tier before the embedding pass? I feel that approach can be more efficient.

There are good mature tools for deterministic duplication detection and I intentionally focused on embedding-based to fill this gap (I didn't find other tools using this approach). If by "more efficient" you mean to avoid embedding of the same code multiple times, this optimization is already implemented internally.

[dead]
Post reply on HN