Similar Code

The similar code tool retrieves the most similar code components from inside the organization's codebase, or from open-source code.

How to use the similar code tool

Manual usage

Comment on the PR:

/find_similar_component COMPONENT_NAME

Where COMPONENT_NAME is the name of a code component in the PR (class, method, function).

You can set a specific class or file where the component will be taken from:

/find_similar_component COMPONENT_NAME --pr_find_similar_component.file=FILE_NAME

Automatic usage

To run the tool automatically, use the analyze tool. On a PR, comment:

/analyze

For the components you want to find similar code, click the similar checkbox.

You can search for similar code within your organization’s codebase or globally, across open-source projects. Each result includes the matching code and its license information.

Search results

Each search result includes:

  • extracted keywords: Keywords identified in your code. Clicking the link to view the keywords and adjust the search if needed.

  • search context: The context in which the tool looks for similar code, either inside your organization’s repositories or across public open-source projects (Global).

  • similar code: Matching code snippets found in the selected search context. Click the link to open the code component in the relevant file.

  • relevant repositories: Open-source repos that contain code related to your component and its keywords.


Configuration options

Configure the similar code tool by setting configurations under the pr_find_similar_component part in your configuration file.

Possible configurations
Default value
What they do

search_from_org

false

if set to true, the tool will search for similar code in the organization's codebase

number_of_keywords

5

number of keywords to use for the search.

number_of_results

5

the maximum number of results to present


Example usage

Global Search for a method called chat_completion:

Search result link example:

Organization Search:

Last updated

Was this helpful?