Semantic code search for AI coding agents
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.
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.
curl -fsSL https://xerj.org/get | sh
Install the release binary into ~/.local/bin.
xerj --insecure --data-dir ./.xerj-data
Start a local development node. Default embedding mode is lexical, not neural.
xerj autoindex . --url http://127.0.0.1:9200 --progress plain
Index the repository, including definitions tree-sitter can parse.
xerj def "BuiltinPager"
Go to a definition by name, with file:line and a signature.
xerj search "how is pagination implemented"
Ranked passages when you can describe the behaviour but not the symbol.
Which code search fits your query?
Answer three questions about what you are looking for
Syntax-aware lookup
Go straight to the definition. Tree-sitter parsing in 36 languages.
Search by description
Describe the behaviour and get passages ranked by meaning. Lexical embedder by default, neural with --embed-mode neural.
Hybrid search
Fuse a BM25 ranking with a semantic ranking, so names and meaning both count.
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.
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.
Find the definition
Syntax-aware search uses tree-sitter to pull definitions. XERJ covers 36 languages this way, 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.
Blend the rankings
Hybrid search fuses a full-text ranking such as BM25 with a vector or semantic ranking, often with reciprocal rank fusion. Use it when a query has both identifiers and a description of the behaviour you want.
Semantic search, grep and hybrid side by side
| Approach | You give it | You get back | Best for |
|---|---|---|---|
| Exact match (grep, ripgrep) | A string or regex | Every line that matches | Error messages, renames, audits |
Syntax-aware lookup (xerj def) | A symbol name | The definition with file:line and signature | Jumping to code you can name |
Semantic search (xerj search) | A description of behaviour | Passages ranked by meaning (lexical embedder by default, neural with --embed-mode neural) | Exploring a repo you do not know |
| Hybrid search | A name plus a description | One list ranked by words and meaning | Bug 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
- Install:
curl -fsSL https://xerj.org/get | sh - Start a local node:
xerj --insecure --data-dir ./.xerj-data - Index the repo:
xerj autoindex . --url http://127.0.0.1:9200 --progress plain - Search by description (lexical by default, neural with
--embed-mode neural):xerj search "how is pagination implemented" - 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
- grep searches input files for lines that match a pattern and prints each matching line. Source: https://www.gnu.org/software/grep/manual/grep.html
- ripgrep searches a directory recursively and respects gitignore rules by default. Source: https://github.com/BurntSushi/ripgrep
- 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. Source:
landing/science/syntax-aware-search.html - On main, xerj mcp registers 24 MCP tools, or 21 when the binary has no Corpus Hub key. Source:
landing/docs/agents/schemas/mcp-tools.json
Related
- What is semantic search?
- What is syntax-aware search?
- What is hybrid search?
- Hybrid search vs vector search vs semantic search
- Best MCP servers for code search in 2026: 7 compared for Claude Code
- Local AI search engine: private, offline search over your own files
- Grep and ripgrep alternatives for AI coding agents: 7 tools compared · same intent: code search for agents
- Is ripgrep enough for a coding agent, or do I need a code index? · same intent: code search for agents
- RAG vs grep for AI coding agents · same intent: code search for agents