Index
code_context_agent.tools.search ¶
BM25Index ¶
BM25 full-text search index built from file contents.
Source code in packages/code-context-agent/src/code_context_agent/tools/search/bm25.py
from_files classmethod ¶
Build index from file paths relative to repo root.
Source code in packages/code-context-agent/src/code_context_agent/tools/search/bm25.py
search ¶
Search the index with a text query.
Source code in packages/code-context-agent/src/code_context_agent/tools/search/bm25.py
bm25_search ¶
Ranked text search using BM25 algorithm.
Unlike ripgrep (exact pattern matching), BM25 ranks results by relevance — terms appearing in fewer files score higher (TF-IDF-like).
Use for: finding code related to a concept (e.g., "authentication flow"), semantic-like search without embeddings, ranked results when ripgrep returns too many matches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query | str | Search query (natural language or code terms). | required |
repo_path | str | Absolute path to the repository. | required |
top_k | int | Maximum results to return. | 20 |
rebuild | bool | Force rebuild the index (default: reuse cached). | False |
Returns:
| Type | Description |
|---|---|
str | JSON with ranked results: [{path, score, matching_lines}] |