zvec-grep: Search Code and Documents by Meaning
zvec-grep, or zg, is a local-first search tool for source code, documents, and structured data. It brings together exact or regular-expression search through ripgrep, ranked keyword search with BM25, and vector search for similarity in meaning. It is useful when you know what a piece of code does but not its name, or want to find an existing document about a topic.
For a known identifier, exact search is often the simplest starting point. For “where are execution fees allocated?”, semantic search can suggest relevant code even if the implementation uses different words. The example here is the backtest from the fee-allocation fix in Agent Memory.
What an index adds
Indexing breaks files into searchable pieces while preserving useful structure and source locations. Code results can include symbols and signatures; prose results can point to sections and passages. This helps you decide which source to open next without first reading every file.
Results are not restricted to file paths and line numbers. The default output is compact Markdown for agents; --human provides terminal-oriented output with full previews by default. Output length depends on the query, result count, and preview settings. A returned range is a starting point: read callers, tests, surrounding definitions, or the whole file when the task requires them.
Vector Indexes: Exact Search, HNSW, and IVF explains how approximate search reduces comparisons.
Build and query a workspace index
These examples require Node.js 22 or newer and the official npm package. npx can download the package if it is not installed. Run commands from the directory you intend to index. Choose one initial model for that workspace:
# Code repository
npx @zvec/zvec-grep index --embedding local/potion-code-16m-v2
For a multilingual document collection, use this alternative instead:
npx @zvec/zvec-grep index --embedding local/potion-multilingual-128m
The model guide lists 11 local models: local/potion-retrieval-32m for English documents, for example, or local/qwen3-embedding-0.6b for higher-capacity multilingual retrieval. The only remote embeddings today are Qwen's, which need explicit authorisation with --allow-remote or zg auth grant. The index is stored in .zvec-grep/ beneath the project root. Keep this generated index out of version control.
In an indexed Python repository, search for fee-related logic:
npx @zvec/zvec-grep query "order execution slippage commission fee" -g '*.py' --limit 3 --human
In a demo repository of three Python files (one each for fees, market-data loading, and the returns report; zvec-grep 0.2.2 with local/potion-code-16m-v2), the top result is apply_slippage(), which handles slippage. The same search with the Chinese query “订单执行 滑点 佣金 手续费” also puts it first, although the code's names and comments contain no Chinese at all. The block below comes from that Chinese run: besides the path and line numbers, the result carries the function name, signature, and source:
File: backtest/fees.py
Hits: 1
#1 function apply_slippage matchedBy=fts+vector score=0.0328
Range: 10-13 Status: fresh
Kind: code/function
Symbol: apply_slippage
Signature: def apply_slippage(price, side, bps):
Source:
10 def apply_slippage(price, side, bps):
11 """Move the fill price against the trader by a number of basis points."""
12 sign = 1 if side == "buy" else -1
13 return price * (1 + sign * bps / 10_000)
In an indexed documentation repository with a docs/ directory, search for existing coverage:
npx @zvec/zvec-grep query "personal knowledge system" -g 'docs/**' --limit 3
Here -g filters paths and --limit caps results per query group. One command can carry several queries (for example an exact query with --fts and a semantic one with --vector); each query forms its own group with its own ranking, and the command above, with a single query, has a single group. The full option list is in zg query --help. If a page covers the same subject, consider updating it or linking to it.
Check the source before changing it
Open promising results in the current working tree and confirm the behavior against tests or supporting documents. If results are missing or stale, check the indexed scope and status, then refresh the index as needed:
npx @zvec/zvec-grep status
npx @zvec/zvec-grep index
These commands assume an existing workspace index and reuse its model configuration.
Connect an AI assistant
zg server runs a shared MCP server and zg install connects it to an agent, for example zg install --target opencode --yes. For how zvec-grep compares with QMD and Basic Memory, and the limits the three share, see Agent Memory.