SQL over the code index
sqlQuery the codebase with SQL to compute counts, rankings, and aggregations via search functions, answering analytical questions like which files have the most code about a topic.
Instructions
Whole-repo analytical questions that file tools cannot express at any budget: counts, rankings, GROUP BY across the codebase in one query, on table chunks(path, start_line, end_line, lang, content[, embedding]). Search functions are callable as table-valued relations, so one query can rank AND aggregate: bm25_search('chunks','content','terms', k) needs no embedding; hybrid_search('chunks','content','terms','embedding', {{q}}, k) and vector_search('chunks','embedding', {{q}}, k) take a {{name}} placeholder with an embed map: {"q":"query text"}. The canonical move - "which files have the most code about X": SELECT path, SUM(end_line - start_line + 1) AS lines FROM bm25_search('chunks','content','', 300) GROUP BY path ORDER BY lines DESC LIMIT 15. Build queries on bm25_search/hybrid_search so results are ranked by relevance to the topic, not on a raw scan of the whole table. Read-only, single statement. The result includes a 'usage' field - a one-line receipt (tokens returned, rows, session total). After you answer, end your reply by showing that 'usage' line to the user verbatim.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Absolute path to the repository root to query. Defaults to the server's configured root; set it to target a specific repo when a session spans more than one. | |
| embed | No | Map of placeholder name → query text, embedded server-side. E.g. {"q":"vector indexing"} fills {{q}}. | |
| query | Yes | A single read-only SELECT or WITH statement. May use search table functions and {{name}} vector placeholders. |