> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qodo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# /find-similar

> The `find-similar` endpoint is an intelligent code similarity analyzer that identifies patterns, implementations, and code snippets similar to your input across your codebase. Think of it as having a specialized code reviewer who can instantly find all instances of similar logic, patterns, or implementations throughout your repositories.

## What makes find similar unique

Unlike traditional search tools that look for exact matches, Find Similar:

* Analyzes semantic code patterns and logic flow, not just syntax

* Identifies similar implementations across different programming languages

* Finds functionally equivalent code even with different variable names or structure

* Understands architectural patterns and design similarities

* Traces similar business logic implementations across components

## API/MCP reference

### Request format

```json theme={null}
{
  "tool": "find_similar", 
  "parameters": {
    "input": "async function handleUserLogin(email, password) {\n  const user = await User.findByEmail(email);\n  if (!user || !await bcrypt.compare(password, user.passwordHash)) {\n    throw new Error('Invalid credentials');\n  }\n  return generateJWT(user);\n}",
    "repositories": ["backend/auth", "frontend/components"],
    "session_id": "similarity-analysis-456"
  }
}
```

### Parameters

| Parameter      | Type   | Required | Description                                                                                                     |
| :------------- | :----- | :------- | :-------------------------------------------------------------------------------------------------------------- |
| `input`        | string | Yes      | Code snippet, function, or textual description of the pattern/logic you want to find similar implementations of |
| `repositories` | array  | No       | List of repository identifiers to search within. Format: `org/repo`                                             |
| `session_id`   | string | No       | Unique identifier to maintain context across multiple similarity searches                                       |

### Response format

```json theme={null}
{
  "agent_summery": "Found 8 similar authentication patterns across your codebase...",
  "findings": [
    {
      "repo_name": "backend/auth",
      "file_path": "src/controllers/authController.js", 
      "similarity_score": 0.92,
      "code_snippet": "// Similar login implementation...",
      "reason": "Nearly identical authentication flow with email lookup and password comparison",
      "line_range": [15, 28]
    },
    {
      "repo_name": "mobile/app",
      "file_path": "lib/services/auth_service.dart",
      "similarity_score": 0.78, 
      "code_snippet": "// Dart equivalent authentication...",
      "reason": "Similar authentication logic implemented in Dart with same validation pattern",
      "line_range": [42, 58]
    }
  ]
}
```

## Recommended analysis strategies

* **Include complete code context** - Provide full functions or classes rather than isolated lines for better pattern matching

* **Specify target repositories** - Focus searches on relevant codebases to improve accuracy and performance

* **Use descriptive input** - Natural language descriptions work alongside code snippets for broader pattern discovery

* **Leverage session continuity** - Use session\_id when performing iterative similarity analysis across related components

* **Combine with architectural context** - Include surrounding code structure for finding architectural pattern similarities

<Accordion title="Usage examples">
  #### Finding similar API endpoints

  ```json theme={null}
  {
    "input": "GET endpoint that validates user permissions, fetches data from database, and returns JSON response with error handling",
    "repositories": ["api/v1", "api/v2", "microservices/user-svc"],
    "session_id": "api-pattern-search"
  }
  ```

  #### Locating similar algorithm implementations

  ```json theme={null}
  {
    "input": "function quickSort(array) {\n  if (array.length <= 1) return array;\n  const pivot = array[Math.floor(array.length / 2)];\n  const left = array.filter(x => x < pivot);\n  const right = array.filter(x => x > pivot);\n  return [...quickSort(left), pivot, ...quickSort(right)];\n}",
    "repositories": ["algorithms/sorting", "utils/array-helpers"]
  }
  ```

  #### Finding similar business logic

  ```json theme={null}
  {
    "input": "Calculate shipping cost based on weight, distance, and delivery speed with promotional discount application",
    "repositories": ["ecommerce/pricing", "logistics/shipping"],
    "session_id": "business-logic-review"
  }
  ```
</Accordion>
