Skip to main content

Overview

Embeds the query and performs cosine similarity search against indexed code chunks, returning the most semantically relevant snippets with file paths and line numbers. If the codebase is not yet indexed, it will be indexed automatically first.

Parameters

ParameterTypeDefaultDescription
querystringrequiredNatural language description of what you’re looking for
pathstringrequiredAbsolute path to the codebase root directory
top_kinteger8Number of results to return (1–20)

Example

search_code("how does user authentication work", "/path/to/myproject")
Returns:
[1] src/auth.py:45-72 (score: 0.87)
def authenticate_user(token: str) -> User:
    ...

[2] src/middleware.py:12-28 (score: 0.81)
...

Notes

  • Queries are limited to 500 characters
  • Results include file path, line range, similarity score, and the code snippet
  • Auto-indexes on first call if no index exists for the given path