Skip to main content
Looking for usage docs? See the Code Index guide for CLI walkthroughs 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 built-in CodeAgent.

Installation

FAISS and numpy live under the [rag] extras. If they’re missing the SDK raises:

CodeIndexConfig

FieldTypeDefaultDescription
repo_pathstrRepository root (required)
max_filesint5000Max files to scan
max_file_size_mbfloat1.0Skip files larger than this
chunk_overlapint50Token overlap between chunks
embedding_modelstr"nomic-embed-text-v2-moe-GGUF"Lemonade embedding model
cache_dirstr"~/.gaia/code_index"Cache directory
embedding_base_urlOptional[str]NoneCustom Lemonade base URL

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.

search(query, scope="all", top_k=10) -> List[SearchResult]

ParameterTypeDefaultDescription
querystrNatural language or code query
scopestr"all""all" or "code" (reserved for future filters)
top_kint10Number of results
L2 distance is converted to a similarity score in [0, 1] via 1 / (1 + dist).

get_status() -> Dict

clear_index()

Removes the FAISS index and metadata for this repo from the cache.

Data types

CodeChunk

FieldTypeDescription
contentstrSource text
file_pathstrPath relative to repo root
languagestrDetected language
start_lineintFirst line (1-indexed)
end_lineintLast line
symbol_nameOptional[str]Function / class name
symbol_typeOptional[str]"function", "class", …
docstringOptional[str]Extracted docstring
importsList[str]Imports parsed from the file

SearchResult

FieldTypeDescription
chunkCodeChunkThe matched chunk
scorefloatSimilarity score in [0, 1] (higher is better)
result_typestrCurrently always "code"

IndexResult

FieldTypeDescription
files_indexedintFiles newly parsed in this run
chunks_createdintTotal chunks in the resulting index (reused + new)
duration_secondsfloatWall-clock time for the run

Parsers

gaia.code_index.parsers provides language detection and symbol-aware chunking.

Agent integration: CodeIndexToolsMixin

The mixin lives at gaia.agents.tools.code_index_tools.CodeIndexToolsMixin. It exposes four @tool-decorated methods through register_code_index_tools():
ToolDescription
index_codebase(repo_path="")Build / refresh the FAISS index
search_code_index(query, scope="all", top_k=10)Semantic search
get_index_status()Report indexed state, chunk counts, embedding model, cache path
clear_code_index()Remove the cached index
CodeAgent already composes this mixin, so gaia-code index chat and any CodeAgent instance get the tools for free.

Composing onto a custom Python agent

State is initialised lazily — calling _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.PathValidator to keep file reads scoped to the configured repo_path, and the index_codebase tool refuses any repo_path that isn’t a sub-path of the agent’s original root.

Roadmap

  • #869 — MCP server wrapper exposing the index to external code assistants.
  • #870 — Multi-repo indexing in a single namespace.
  • #871 — Verilog / VHDL parsers.