<!-- generated by build_articles.py — edit content/answers/semantic-code-search.md instead -->
---
title: "Semantic code search 2026: how it works for AI coding agents"
canonical: "https://xerj.org/answers/semantic-code-search"
updated: "2026-11-17"
source: "content/answers/semantic-code-search.md"
---

# Semantic code search for AI coding agents

**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](https://github.com/xerj-org/xerj/blob/main/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.

## Agent prompt

```text
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.
```

## Commands

### Command 1

Note: Install the release binary into ~/.local/bin.

```sh
curl -fsSL https://xerj.org/get | sh
```

### Command 2

Note: Start a local development node. Default embedding mode is lexical, not neural.

```sh
xerj --insecure --data-dir ./.xerj-data
```

### Command 3

Note: Index the repository, including definitions tree-sitter can parse.

```sh
xerj autoindex . --url http://127.0.0.1:9200 --progress plain
```

### Command 4

Note: Go to a definition by name, with file:line and a signature.

```sh
xerj def "BuiltinPager"
```

### Command 5

Note: Ranked passages when you can describe the behaviour but not the symbol.

```sh
xerj search "how is pagination implemented"
```

## Which code search fits your query?

*Figure: 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](/science/semantic-search).

*Figure: 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

| 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](/science/syntax-aware-search).

[Hybrid search](/science/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](/science/hybrid-vs-vector-vs-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](/compare/best-mcp-server-local-code-search-2026). For exact-match tools, see [grep and ripgrep alternatives for AI coding agents](/compare/best-grep-alternative-for-ai-coding-agents-2026).

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](https://hub.xerj.org).

## Read next

[Syntax-aware search](/science/syntax-aware-search), [semantic search](/science/semantic-search), [hybrid search](/science/hybrid-search), [the retrieval studies page](/answers/rag-vs-grep) and [a local AI search engine](/answers/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](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](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?](/science/semantic-search)
- [What is syntax-aware search?](/science/syntax-aware-search)
- [What is hybrid search?](/science/hybrid-search)
- [Hybrid search vs vector search vs semantic search](/science/hybrid-vs-vector-vs-semantic-search)
- [Best MCP servers for code search in 2026: 7 compared for Claude Code](/compare/best-mcp-server-local-code-search-2026)
- [Local AI search engine: private, offline search over your own files](/answers/local-ai-search-engine)
- [Grep and ripgrep alternatives for AI coding agents: 7 tools compared](/compare/best-grep-alternative-for-ai-coding-agents-2026) (same intent: code search for agents)
- [Is ripgrep enough for a coding agent, or do I need a code index?](/compare/xerj-vs-ripgrep-for-code-agents) (same intent: code search for agents)
- [RAG vs grep for AI coding agents](/answers/rag-vs-grep) (same intent: code search for agents)
