Skip to main content

vai code-search

Index a codebase into MongoDB Atlas and run semantic (embedding-based) search over source chunks. This is not grep or regex: results are ranked by meaning, using a code-oriented embedding model by default.

vai pixel robot thinking

Meaning, not grep

Semantic code search answers “where is this discussed?” not “symbol X”

Pair init, refresh, and incremental hashes with the right MCP tools for agents. Workspace tools ( vai_search_code) and the code index family ( vai_code_search) assume different collections, so match the tool to how you indexed.

MCP code-search tools

Use the CLI for local workflows; use MCP tools vai_code_index, vai_code_search, and related tools when an agent should drive indexing and search.

Synopsis

vai code-search [options] <query>
vai code-search init [path] [options]
vai code-search status [options]
vai code-search refresh [path] [options]

Subcommands

Query (default)

With a positional query, vai embeds the question, runs vector search on the indexed collection, and returns ranked code chunks (with optional reranking).

FlagDescriptionDefault
querySearch text (positional)
-l, --limit <n>Max results10
--no-rerankSkip rerankingrerank on
--rerank-model <model>Reranking modelrerank-2.5
-m, --model <model>Embedding modelFrom config / code default
--db <name>MongoDB databaseProject / env
--collection <name>CollectionFrom project naming
--jsonJSON output
-q, --quietLess noise

init

Full index of a directory: discover files, chunk, embed, upsert into Atlas, and ensure a vector search index.

FlagDescriptionDefault
[path]Workspace rootCurrent directory
-m, --model <model>Embedding modelCode-optimized default
--db <name>DatabaseResolved from config
--collection <name>CollectionDerived from project
--chunk-size <n>Chunk size (characters)512
--chunk-overlap <n>Overlap50
--max-files <n>Cap files scanned5000
--max-file-size <bytes>Skip larger files100000
--batch-size <n>Embedding batch size20
--json / -qOutput modes

status

Summary stats: chunk count, files indexed, languages, last indexed time, vector index state. Counts exclude index_meta control documents.

refresh

Re-index changed files using content hash and mtime (and optional git hints when metadata is present). Use --full to re-embed everything regardless of incremental skip.

FlagDescription
[path]Workspace root (default: cwd)
--fullIgnore incremental optimization; rebuild all scanned files
-m, --model, --db, --collection, --chunk-size, --chunk-overlap, --batch-size, --json, -qSame roles as init / query
MCP toolRole
vai_code_indexIndex or refresh a codebase (path or GitHub URL) into a code-search collection
vai_code_searchSemantic search over that collection
vai_code_queryRAG-style: retrieve + rerank for “how does X work” questions
vai_code_find_similarEmbed a snippet; nearest neighbors in the index
vai_code_statusSame class of stats as vai code-search status

Not the same as vai_search_code: that tool searches a collection built by vai_index_workspace (general workspace indexing). Prefer vai_code_* when you are using the dedicated code-index pipeline and voyage-code-3-style chunks.

Further reading