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
[rag] extras. If they’re missing the SDK raises:
CodeIndexConfig
| Field | Type | Default | Description |
|---|---|---|---|
repo_path | str | — | Repository root (required) |
max_files | int | 5000 | Max files to scan |
max_file_size_mb | float | 1.0 | Skip files larger than this |
chunk_overlap | int | 50 | Token overlap between chunks |
embedding_model | str | "nomic-embed-text-v2-moe-GGUF" | Lemonade embedding model |
cache_dir | str | "~/.gaia/code_index" | Cache directory |
embedding_base_url | Optional[str] | None | Custom 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]
| Parameter | Type | Default | Description |
|---|---|---|---|
query | str | — | Natural language or code query |
scope | str | "all" | "all" or "code" (reserved for future filters) |
top_k | int | 10 | Number of results |
[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
| Field | Type | Description |
|---|---|---|
content | str | Source text |
file_path | str | Path relative to repo root |
language | str | Detected language |
start_line | int | First line (1-indexed) |
end_line | int | Last line |
symbol_name | Optional[str] | Function / class name |
symbol_type | Optional[str] | "function", "class", … |
docstring | Optional[str] | Extracted docstring |
imports | List[str] | Imports parsed from the file |
SearchResult
| Field | Type | Description |
|---|---|---|
chunk | CodeChunk | The matched chunk |
score | float | Similarity score in [0, 1] (higher is better) |
result_type | str | Currently always "code" |
IndexResult
| Field | Type | Description |
|---|---|---|
files_indexed | int | Files newly parsed in this run |
chunks_created | int | Total chunks in the resulting index (reused + new) |
duration_seconds | float | Wall-clock time for the run |
Parsers
gaia.code_index.parsers provides language detection and symbol-aware chunking.
Agent integration: CodeIndexToolsMixin
The mixin lives atgaia.agents.tools.code_index_tools.CodeIndexToolsMixin. It exposes four @tool-decorated methods through register_code_index_tools():
| Tool | Description |
|---|---|
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
_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.