semantic_search
Find code symbols by meaning using semantic embeddings. Describe a concept in natural language; retrieve matching functions and classes even when query words don't appear in their names.
Instructions
Semantic search using pre-computed libclang symbol embeddings. Finds
symbols by meaning, not by text — matches concepts even when query
words don't appear literally in the code. Uses cosine similarity over
variable-dimension embeddings generated during fw-context index.
Dimensions vary by model: mxbai-embed-large → 1024,
qwen3-embedding → 4096.
When to prefer over search_code: When you're describing a concept rather than searching for a known keyword. Examples:
"parcel locker state"finds door-state and shipment methods even though "parcel" and "locker" don't appear in their names."cell modem"finds_socket_tandModemMsg*classes."delivery box"findsset_shipmentandget_zrtdata."power consumption"findsget_load_powerand INA260 class.
When to prefer search_code instead: When you know the exact keyword
or symbol name ("fram_write", "cbor encode"). FTS5 is faster
and more precise for lexical matches.
Threshold guidance (mxbai-embed-large model):
0.50— exploratory: more results, lower precision0.55— balanced (~1000 results)0.60— precise: ~175 avg, high precision (default)0.65— strict: few results, may miss relevant symbols
Source-aware ranking: the similarity of a project symbol is
multiplied by 1.2, and the similarity of every other symbol by 0.85.
The index marks each file as project code or not, thus the two tiers
are all there are. _similarity in the result holds the multiplied
score, and not the raw cosine distance.
Requires an LLM with an embedding model.
Falls back to search_code with a warning if the LLM is unavailable.
This tool names no build. It takes neither variant nor
image, and it answers for the build that get_active_build
reports as the active one. On a project that holds several builds,
use search_code or search_bodies to ask about one named build.
Read-only: yes. The fallback to search_code may auto-reindex stale
files (non-blocking).
Args: query: Natural language description of what you're looking for. Be specific — 5–15 words works best. project_root: Project root. Auto-detected if omitted. project: Project name or project_id — call list_projects to get them. Use it to ask about a project that is not the project of the current directory. It is an alternative to project_root, which takes a root path. Give one of the two, not both. threshold: Minimum cosine similarity (0.0-1.0). Default 0.60. limit: Maximum number of results (default 20, max 100).
Returns:
list of dicts, each with: name, qualified_name, kind, file, line,
is_definition, signature, docstring, plus _similarity (cosine
similarity score) and _method ("embedding" or
"search_code_fallback").
When the best similarity is below the relevance floor (0.68), the
result is one dict with ``warning``, ``_best_similarity`` (float),
``_fallback_suggestion`` (``"search_code"``), and ``_results`` (the
low-similarity results). Treat those results as noise, and use
``search_code`` instead.
When the LLM is not running, or the embedding fails, this tool falls
back to ``search_code``. The results then carry
``_method: "search_code_fallback"``, and a leading dict holds a
``warning`` with the reason.
No match gives ``[]``. One dict with ``error`` means the query
failed — check that key first.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum results (default 20, max 100). | |
| query | Yes | Natural language description, 5-15 words. E.g. 'parcel locker state machine' or 'how does the modem connect?'. | |
| project | No | Project name or project_id — call list_projects to get them. Use it to ask about a project that is not the project of the current directory. It is an alternative to project_root, which takes a root path. Give one of the two, not both. | |
| threshold | No | Minimum cosine similarity (0.0-1.0). Default 0.60. Use 0.55 for exploratory, 0.50 for broad search. | |
| project_root | No | Project root. Auto-detected if omitted. This field also accepts a project name or a project_id, but project is the clear field for those. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |