Looking for usage docs? See the Code Index guide for the flagship-agent skill walkthrough and architecture overview.
CodeIndexSDK indexes repository files (no git history, no PRs) using Lemonade Server embeddings and FAISS for vector similarity search. The SDK is exposed to agents via CodeIndexToolsMixin, which is already composed into the flagship GaiaAgent.
Installation
[rag] extras. If they’re missing the SDK raises:
CodeIndexConfig
CodeIndexSDK
index_repository() -> IndexResult
Discover source files, parse them, embed via Lemonade, and persist a FAISS index. Re-runs are incremental — unchanged files (matched by SHA-256) reuse their existing embeddings.
A complete rebuild with no source chunks clears any previous index and disk
cache. Binary, out-of-scope, and vanished files are intentionally skipped. An
empty result after a read failure or scan limit raises an actionable error and
retains the previous index. Directory traversal and file metadata errors also
abort the rebuild, except missing files (including dangling symlinks), which are
skipped. A scan limit still permits indexing the nonempty results found so far.
search(query, scope="all", top_k=10) -> List[SearchResult]
L2 distance is converted to a similarity score in
[0, 1] via 1 / (1 + dist).
get_status() -> Dict
get_status() loads and checks the cache, so indexed: True means search() can use
it. When the index and its metadata don’t match (an interrupted write, or a file
copied in from another index), it returns indexed: False with an error naming the
cache path and the re-index step, and search() raises CodeIndexCacheError with the
same message.
clear_index()
Removes the FAISS index and metadata for this repo from the cache.
Data types
CodeChunk
SearchResult
IndexResult
Parsers
gaia.code_index.parsers provides language detection and symbol-aware chunking.
.v, .vh, .sv, .svh, .vhd, .vhdl) are chunked at
design units: Verilog/SystemVerilog module, interface, package, program, class,
function/task and always* blocks, including escaped names (\foo-bar) and a
same-line (* ... *) attribute prefix; VHDL entity, architecture, package,
configuration, context, process and function/procedure. VHDL keywords match
case-insensitively.
Agent integration: CodeIndexToolsMixin
The mixin lives atgaia.agents.tools.code_index_tools.CodeIndexToolsMixin. It exposes four @tool-decorated methods through register_code_index_tools():
GaiaAgent already composes this mixin, so the flagship agent’s coding skill gets the tools for free — see the Code Index guide.
Composing onto a custom Python agent
_init_code_index_state is optional but recommended so the agent honours the repo path you intended.
CodeIndexToolsMixin is also registered in KNOWN_TOOLS["code_index"] (src/gaia/agents/registry.py) for dynamic composition when scaffolding agents — see the custom-agent guide.
Privacy and safety
- All embeddings are generated locally by Lemonade Server.
- Sensitive filenames are skipped during discovery:
.env,.env.*, SSH private keys,*.pem,*.key,*.pfx,*.p12,*.jks,*.keystore. - The SDK uses
gaia.security.PathValidatorto keep file reads scoped to the configuredrepo_path, and theindex_codebasetool refuses anyrepo_paththat isn’t a sub-path of the agent’s original root.