Live data from Hacker News

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

github.com

21–30 of 61 posts

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

#21
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.

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

#22
Cool project, I've been meaning to do this myself at work for a codebase, and it's nice to see that this exists now.

Does the project you simply compute embeddings for every function unit and cluster them, or do we also mean-pool significant dependencies of a function? In other words, given the function

    def a():
      b()
      c()
      d()
Do we also embed b, c, and d as well and combine them somehow in the embedding of a?

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

#23
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.

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

#24
post #5

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…

Generally, I chunk by function/method (not by whole class), but different languages have specific concepts and features. Nested code units, anonymous functions, lambdas, closures are extracted as separate chunks.

The chunk size has allowed range and those outside are simply ignored.

- Upper limit is hardcoded with a body size of 10k chars

- Lower limit is configurable with a default of 10 AST nodes inside the body

The chunking strategy is something that can be improved in future versions.

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

#25

Cool project, I've been meaning to do this myself at work for a codebase, and it's nice to see that this exists now. Does the project you simply compute embeddings for every function unit and cluster them, or do we also mean-pool significant dependencies of a function? In other words, given the function def a(): b() c() d() Do we also embed b, c, and d as well and combine them somehow in the embedding of a?

It looks like it works only on function bodies[1]. I'm not sure I understand why you would want to look at invoked callables code, though. Calling the same set of helper functions is already flagged; repeated code in helpers is flagged as well when those helpers are analyzed. Do you have a specific example where you'd like a function flagged as a duplicate based on the code it calls out to?

[1] https://github.com/rafal-qa/slopo/blob/main/src/slopo/indexi...

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

#27

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]

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

#28

Cool project, I've been meaning to do this myself at work for a codebase, and it's nice to see that this exists now. Does the project you simply compute embeddings for every function unit and cluster them, or do we also mean-pool significant dependencies of a function? In other words, given the function def a(): b() c() d() Do we also embed b, c, and d as well and combine them somehow in the embedding of a?

Based on your example there is only a single function a() which is embedded. The rest is just a code and dependencies are not resolved. Did you think about adding this feature in your tool?

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

#30

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…

What a clever little tool. This is exactly the kind of pragmatic AI tools I want to see more of: linux-y single purpose tools!
Post reply on HN