Skip to main content
Looking for the API? See the Code Index SDK Reference for CodeIndexSDK, CodeIndexConfig, and CodeIndexToolsMixin.
GAIA’s Code Index gives you fast semantic search over a repository without sending source to the cloud. It parses files into symbol-level chunks, embeds them via Lemonade Server on AMD NPU/GPU hardware, and stores them in a local FAISS index for sub-second queries. The index is exposed two ways:
  • Tool mixin — CodeIndexToolsMixin powers the flagship GAIA agent’s coding skill and is available to any custom agent that opts in via KNOWN_TOOLS["code_index"].
  • Python SDK — CodeIndexSDK for direct programmatic use.
gh is not required — the index covers source files only.

Overview

Setup

Install the [rag] extras (FAISS + numpy live there):
Embeddings are generated locally by Lemonade. If you haven’t installed it yet, gaia init installs the server and pulls the model — gaia daemon starts and supervises it from there.
The embedder is user.embeddinggemma-300m-GGUF (EmbeddingGemma 300M). A cached index (under ~/.gaia/code_index/) records the model it was built with, so an index built before v0.22.0 with nomic-embed-text-v2-moe-GGUF fails loudly with a model-mismatch error naming both models. Re-index to rebuild it with EmbeddingGemma.
If FAISS or numpy are missing at runtime you’ll see exactly:

Using it from the flagship agent

The coding skill is what puts the code index in front of the flagship GAIA agent — it lists search_code_index among the tools a coding task needs, and directs the agent to run index_codebase once per repo before relying on semantic search. Ask the agent to work on a codebase and it calls these tools autonomously: You don’t have to call index_codebase first: the first search_code_index in a repository with no index builds it, then searches. That first search is slow on a large repository; a task that never searches never pays for the embedding pass. Set GAIA_PROJECT_MAP_AUTO_INDEX=1 to build it in the background at task start instead.

Example interaction

Custom agents compose CodeIndexToolsMixin directly in their class declaration; it’s also registered in KNOWN_TOOLS["code_index"] (src/gaia/agents/registry.py) for dynamic resolution. For SDK-level composition see the SDK reference.

Using it from Python

For direct programmatic use (no agent), call CodeIndexSDK yourself:
See the Code Index SDK Reference for the full CodeIndexConfig, CodeIndexSDK, and data-type reference.

Cache layout

Both files are written atomically (temp file + rename). The cache is keyed by the resolved repo path. If you switch embedding models the metadata mismatch is detected and search returns empty until you re-index.

Privacy

All processing is local. No source code is sent to external services. Sensitive filenames are skipped automatically: .env, .env.*, .htpasswd, SSH private keys (id_rsa, id_ed25519, …), and any *.pem, *.key, *.pfx, *.p12, *.jks, *.keystore.

Testing

The code-index stack has unit-test coverage in tests/unit/test_code_index*.py — 64 tests spanning the SDK (cache layout, incremental re-index, atomic writes), the parsers (Python AST + the regex backends for JS/TS/Go/Rust/Java/C/C++), and the CodeIndexToolsMixin tool surface. Run them with:
Retrieval-quality benchmarks (precision/recall against curated queries) are tracked under #868.

Real-world benchmark

Indexing the gaia repo itself against Lemonade Server’s user.embeddinggemma-300m-GGUF embedding model:
The 51-minute figure is network-bound (embeddings sent to a remote Lemonade Server over an ngrok tunnel). On a local Ryzen AI setup the embedding step runs on the NPU and is substantially faster. For retrieval-quality metrics see #868.

Roadmap

  • #869 — MCP server wrapper, so external code assistants can drive the index.
  • #870 — Multi-repo indexing in a single namespace.
  • #871 — Verilog / VHDL parsers for hardware-design codebases.