ANSWERS · ANSWERS FOR CODING AGENTS

Semantic code search for AI coding agents

AUTHOR · XERJ documentation team · REVIEWED BY · XERJ engineering team · PUBLISHED · 2026-11-13 · UPDATED · 2026-11-17
SHORT ANSWER · UPDATED 2026-11-17

Semantic code search finds code by what it does, not only by the words in it. You describe the behaviour, such as how pagination works, and it ranks the passages that match the meaning. Use it when you do not know the symbol name; use a definition lookup when you do, and hybrid search when the query mixes both.

Key number: XERJ covers 36 languages via tree-sitter, pinned by a unit test. A file over 2 MiB is skipped, at most 5,000 symbols per file, and names over 200 bytes are dropped. There is no call graph. (as of 2026-11-13 · source: landing/science/syntax-aware-search.html)

TL;DR Semantic code search finds code by what it does, not only by the words in it. Describe the behaviour, and it ranks the passages that match the meaning. When you already know the name, a definition lookup is faster. When the query mixes a name and a description, hybrid search ranks by both. XERJ gives an agent all three over one local index.

PASTE THIS TO YOUR AI AGENT. IT DOES THE REST Act as a coding agent. Read https://xerj.org/llms.txt, start a node with `xerj --insecure --data-dir ./.xerj-data`, index the repository with `xerj autoindex . --url http://127.0.0.1:9200 --progress plain`, then use `xerj def` when you know the symbol name and `xerj search` when you only have a description. Cite file:line. If the node was not started with --embed-mode neural, say that the default embedding mode is lexical.
RUN THIS XERJ COMMAND curl -fsSL https://xerj.org/get | sh Install the release binary into ~/.local/bin.
RUN THIS XERJ COMMAND xerj --insecure --data-dir ./.xerj-data Start a local development node. Default embedding mode is lexical, not neural.
RUN THIS XERJ COMMAND xerj autoindex . --url http://127.0.0.1:9200 --progress plain Index the repository, including definitions tree-sitter can parse.
RUN THIS XERJ COMMAND xerj def "BuiltinPager" Go to a definition by name, with file:line and a signature.
RUN THIS XERJ COMMAND xerj search "how is pagination implemented" Ranked passages when you can describe the behaviour but not the symbol.

Which code search fits your query?

Try it: which code search fits your query?

Answer three questions about what you are looking for

What do you know about the code?
What should come back?
Who runs the search?

xerj def

Syntax-aware lookup

Go straight to the definition. Tree-sitter parsing in 36 languages.

xerj search

Search by description

Describe the behaviour and get passages ranked by meaning. Lexical embedder by default, neural with --embed-mode neural.

hybrid query

Hybrid search

Fuse a BM25 ranking with a semantic ranking, so names and meaning both count.

Runs in your browser and sends nothing. Each answer adds a point to the option it matches. A rule of thumb, not a benchmark. On a XERJ node the embedder is lexical by default; start the node with --embed-mode neural for the built-in neural embedder.

How semantic code search works

A semantic search engine turns each code passage and each query into a vector, a list of numbers that stands for meaning. Passages whose vectors sit close to the query vector rank first. That is how a question like "how is pagination implemented" can surface a function whose name you never typed. On a XERJ node this runs with the lexical embedder by default, and with the built-in neural embedder when you start the node with --embed-mode neural.

This matters most for AI coding agents. An agent dropped into an unfamiliar repo rarely knows the symbol names yet. Without a ranked search over the repo it guesses names and greps, then reads whole files. With it, the first search returns a few ranked passages and their file paths, and the agent reads only those.

On a XERJ node the default embedding mode is lexical: semantic queries run on word and sub-word overlap plus BM25. Start the node with --embed-mode neural to turn on the built-in neural embedder. The concept outside of code is what semantic search is.

Try it: three ways to search code

Meaning, names, or both

Rank passages by meaning

This mode ranks passages that share meaning with the query, not only the same words. On a XERJ node the default embedding mode is lexical, not neural. Start the node with --embed-mode neural when you want the built-in neural embedder.

Language count and caps are the published syntax-aware figures. On a XERJ node the default embedding mode is lexical, not neural. Start the node with --embed-mode neural when you want the built-in neural embedder.

Semantic search, grep and hybrid side by side

ApproachYou give itYou get backBest for
Exact match (grep, ripgrep)A string or regexEvery line that matchesError messages, renames, audits
Syntax-aware lookup (xerj def)A symbol nameThe definition with file:line and signatureJumping to code you can name
Semantic search (xerj search)A description of behaviourPassages ranked by meaning (lexical embedder by default, neural with --embed-mode neural)Exploring a repo you do not know
Hybrid searchA name plus a descriptionOne list ranked by words and meaningBug fixes that start from a log line

Syntax-aware lookup uses tree-sitter in 36 languages. A file over 2 MiB is skipped, at most 5,000 symbols per file are kept, and names over 200 bytes are dropped. There is no call graph. Details are on syntax-aware search.

Hybrid search fuses a BM25 ranking with a semantic ranking, often with reciprocal rank fusion. It is the safest default when you are not sure which words the source uses. How the three modes relate is on hybrid, vector or semantic search.

When to choose grep or ripgrep instead

Choose grep or ripgrep when you know the exact string. They print every matching line. That is what you want for a rename, an audit or an error message. By default, ripgrep searches folders recursively and skips files listed in .gitignore. A ranked search does not replace that job. It finds the right area first.

Run it on your repo

  1. Install: curl -fsSL https://xerj.org/get | sh
  2. Start a local node: xerj --insecure --data-dir ./.xerj-data
  3. Index the repo: xerj autoindex . --url http://127.0.0.1:9200 --progress plain
  4. Search by description (lexical by default, neural with --embed-mode neural): xerj search "how is pagination implemented"
  5. Jump to a name: xerj def "BuiltinPager"

Every command is on this page with a copy button. To hand the work to an agent, use Copy the prompt. Paste it into Claude Code, Cursor or Codex.

Semantic code search for agents over MCP

An agent calls the same index through xerj mcp. On main it registers 24 tools, or 21 when the binary has no Corpus Hub key. The agent searches, reads the cited passages and writes code from them, so it spends fewer tokens reading whole files.

For a comparison of local code search MCP tools, see the 2026 comparison of code search MCP tools. For exact-match tools, see grep and ripgrep alternatives for AI coding agents.

To search a GitHub project, clone it and run xerj autoindex. For selected public projects, xerj ask answers from a signed Corpus Hub pack with no clone. Browse those packs at hub.xerj.org.

Read next

Syntax-aware search, semantic search, hybrid search, the retrieval studies page and a local AI search engine.

FAQ

Is semantic code search better than grep?

They answer different questions. Grep and ripgrep are best for an exact string, an error message or a rename across the repo. Semantic search is best when you can describe the behaviour but not the words. Many agents use both: semantic or hybrid search to find the area, then an exact match to confirm.

Do I need a vector database for semantic code search?

Not with XERJ. Indexing, the embedder and search ship in one binary. Some other code search MCP servers pair an external vector store with a hosted embedding API, so check the setup each one needs.

What is semantic code search?

It ranks source passages by meaning, not only by the exact words in the query. Use it when you can describe the behaviour but do not know the symbol name.

How is that different from syntax-aware search?

Syntax-aware search finds definitions and other syntactic forms, using a parser such as tree-sitter. It is the right tool when you already know the name. Semantic search is the right tool when you only have a description.

Does XERJ do semantic code search by default?

The default embedding mode is lexical, not neural. Semantic queries still run, but they use word and sub-word overlap plus BM25 unless you start the node with --embed-mode neural.

Can I search a GitHub repo this way?

Clone the repo, or index a local checkout, then run xerj autoindex. For selected public corpora, xerj ask answers from a signed pack without a clone. That is a different path, limited to the Corpus Hub catalogue.

How do I call this from an agent?

Use xerj mcp. On main it registers 24 tools, or 21 with no Corpus Hub key. A comparison of local code search MCP servers is on Best MCP servers for code search in 2026.

Evidence

Related