Skip to main content
Glama

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_t and ModemMsg* classes.

  • "delivery box" finds set_shipment and get_zrtdata.

  • "power consumption" finds get_load_power and 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 precision

  • 0.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

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum results (default 20, max 100).
queryYesNatural language description, 5-15 words. E.g. 'parcel locker state machine' or 'how does the modem connect?'.
projectNoProject 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.
thresholdNoMinimum cosine similarity (0.0-1.0). Default 0.60. Use 0.55 for exploratory, 0.50 for broad search.
project_rootNoProject 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

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv0.32.0
    • addedInput schema / properties / limit / minimum
      Added value: +1
    • addedInput schema / properties / query / minLength
      Added value: +1
    • addedInput schema / properties / threshold / maximum
      Added value: +1
    • addedInput schema / properties / threshold / minimum
      Added value: +0
  2. Changed3 schema fields changedv0.30.0
    • addedInput schema / additionalProperties
      Added value: +false
    • addedInput schema / properties / project
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "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.",
      +  "title": "Project"
      +}
    • changedInput schema / properties / project_root / description
      Previous value: -"Project root. Auto-detected if omitted."New value: +"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."
  3. Addedv0.5.0

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description must carry the full behavioral burden, and it does: it discloses read-only semantics, LLM dependency, the silent fallback to search_code with a warning, non-blocking auto-reindex of stale files, that _similarity holds the multiplied score and not raw cosine distance, and the 1.2/0.85 source-aware ranking tiers. Nothing behavioral is left to inference.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Long but well-organized with clear section headers, front-loaded purpose, and worked examples. Nearly every section earns its place. Minor redundancy exists — the fallback behavior is described both in the 'Requires an LLM' section and again in the Returns section — which is the only structural blemish in an otherwise disciplined layout.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex 5-parameter tool, the description is exhaustive: it covers the normal return shape, the warning-dict path when similarity is below the relevance floor, the LLM-unavailable fallback variant, empty results, and the error dict, instructing to check the error key first. Even with an output schema present, the description's coverage of edge cases and failure modes leaves nothing an agent needs to call it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3, but the description adds genuine value beyond the schema: per-threshold outcome guidance (0.50 exploratory vs 0.65 strict), query length recommendation (5-15 words), and clarification that project vs project_root are alternatives ('Give one of the two, not both'). This materially improves parameter understanding over the raw schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description names a specific verb+resource ('semantic search using pre-computed libclang symbol embeddings') and explicitly distinguishes itself from siblings by meaning ('Finds symbols by meaning, not by text'). Concrete worked examples ('parcel locker state', 'cell modem') make the intent unmistakable, and the contrast with search_code is drawn directly. An agent can tell exactly what this tool does without opening any schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It provides explicit when-to-prefer sections ('When to prefer over search_code') with concept-vs-keyword criteria and named alternatives (search_code, search_bodies) with reasons ('FTS5 is faster and more precise'). It even covers the multi-build case, steering to search_code/search_bodies when a specific build is targeted. This is exemplary usage guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.