trelix-llama-index
LlamaIndex retriever for trelix — semantic code search using Tree-sitter AST parsing, hybrid BM25+vector search, call-graph expansion, and streaming synthesis support.
Install
pip install trelix-llama-index
Usage
from trelix_llama_index import TrelixIndexRetriever
# First index your repo (one-time)
# trelix index /path/to/repo
retriever = TrelixIndexRetriever(repo_path="/path/to/repo", k=10)
nodes = retriever.retrieve("how does authentication work?")
for node in nodes:
print(node.node.metadata["file"], node.score)
print(node.node.text[:200])
With LlamaIndex query engine
from llama_index.core import VectorStoreIndex
from llama_index.core.query_engine import RetrieverQueryEngine
from trelix_llama_index import TrelixIndexRetriever
retriever = TrelixIndexRetriever(repo_path="/path/to/repo", k=10)
query_engine = RetrieverQueryEngine.from_args(retriever)
response = query_engine.query("How does the authentication middleware work?")
print(response)
Streaming synthesis (v2.0.0+, enhanced v2.4.0)
from trelix_llama_index import TrelixIndexRetriever
from llama_index.core.query_engine import RetrieverQueryEngine
retriever = TrelixIndexRetriever(repo_path="/path/to/repo", k=10)
query_engine = RetrieverQueryEngine.from_args(retriever)
# Stream response token-by-token
response = query_engine.query_stream("Explain the payment flow")
for text_chunk in response:
print(text_chunk, end="", flush=True)
Beast-mode retrieval (v2.1.0+)
v2.1.0 activates enhanced retrieval features via environment variables. Enable HyDE synthetic snippet embedding and PageRank-based symbol boosting for architecturally central symbols:
from trelix_llama_index import TrelixIndexRetriever
from llama_index.core.query_engine import RetrieverQueryEngine
# v2.1.0: Beast-mode features active via env vars
# TRELIX_RETRIEVAL_HYDE_FALLBACK=true — HyDE synthetic snippet embedding
# TRELIX_RETRIEVAL_PAGERANK_BOOST=true — boost architecturally central symbols
retriever = TrelixIndexRetriever(
repo_path="/path/to/repo",
k=10,
)
nodes = retriever.retrieve("how does the payment processing work?")
v2.2.0 — What's New
trelix v2.2.0 adds four intelligence upgrades. The TrelixIndexRetriever interface is unchanged — activate features via env vars.
| Feature | Env var | Benefit for LlamaIndex users |
|---|---|---|
| Agentic loop | TRELIX_RETRIEVAL_AGENTIC=true |
Multi-hop retrieval for complex queries |
| SPLADE-Code | TRELIX_RETRIEVAL_SPARSE=true |
Better recall on identifier-heavy queries |
| Block indexing | TRELIX_CHUNKER_MULTI_GRANULARITY=true |
Precise sub-function retrieval |
| Taint analysis | trelix taint (CLI) |
Security flow detection in indexed repos |
Configuration
| Env var | Default | Description |
|---|---|---|
TRELIX_EMBEDDER_PROVIDER |
local |
Embedding provider: local | openai | azure | bedrock-cohere | bedrock-titan | huggingface | voyage |
OPENAI_API_KEY |
— | Required for openai provider |
AZURE_API_KEY |
— | Required for azure provider |
AWS_ACCESS_KEY_ID |
— | Required for Bedrock providers |
HUGGINGFACE_API_KEY |
— | Required for huggingface provider |
VOYAGE_API_KEY |
— | Required for voyage provider |
Provider switching (v2.0.0+)
# Use Bedrock Cohere embeddings (best retrieval, reuses AWS creds)
TRELIX_EMBEDDER_PROVIDER=bedrock-cohere trelix index /path/to/repo
# Use HuggingFace embeddings (open-source alternatives)
TRELIX_EMBEDDER_PROVIDER=huggingface HUGGINGFACE_API_KEY=hf_... trelix index /path/to/repo
# Use Voyage embeddings (specialized for code search)
TRELIX_EMBEDDER_PROVIDER=voyage VOYAGE_API_KEY=pa-... trelix index /path/to/repo
# Use local embeddings (no API key needed)
TRELIX_EMBEDDER_PROVIDER=local trelix index /path/to/repo
Graph-Enhanced Retrieval (v2.1.0+)
Enable the knowledge graph as a 4th retrieval leg for architecture-aware queries. v2.1.0 integrates beast-mode features for optimal performance:
from trelix_llama_index import TrelixIndexRetriever
# With graph-aware BFS (requires trelix[knowledge-graph])
# v2.1.0: HyDE + PageRank boost activate automatically in this mode
retriever = TrelixIndexRetriever(
repo_path="/path/to/repo",
k=10,
graph_search_enabled=True, # enables 4th BFS retrieval leg
graph_search_depth=2,
)
nodes = retriever.retrieve("how does the auth module interact with the DB layer?")
for node in nodes:
print(node.node.metadata.get("source")) # file path
print(node.score) # combined RRF + graph score
Install with graph support:
pip install trelix-llama-index 'trelix[knowledge-graph]'
How it works
When graph_search_enabled=True, trelix builds (or loads) a NetworkX MultiDiGraph over the
indexed repository and runs a BFS expansion from the highest-degree nodes relevant to the query.
Results from all four legs are fused via Reciprocal Rank Fusion (RRF):
| Retrieval leg | Technique |
|---|---|
| Vector | Semantic embedding similarity |
| BM25 | Keyword / TF-IDF |
| Call-graph expansion | Symbol → caller/callee traversal |
| Graph BFS (new) | Knowledge-graph breadth-first search |
Configuration
| Parameter | Default | Description |
|---|---|---|
graph_search_enabled |
False |
Enable the graph BFS retrieval leg (opt-in, zero impact when off) |
graph_search_depth |
2 |
BFS depth from seed nodes |
graph_search_max_results |
15 |
Maximum nodes returned from graph leg before RRF |
Environment variable alternative:
TRELIX_GRAPH_SEARCH_ENABLED=true trelix index /path/to/repo
Benchmarks (trelix repo, 4,599 nodes / 4,945 edges)
- Graph build time: 0.34 s
- Communities detected: 2,409 (Louvain algorithm)
graph_searchdepth=2: 10 results from top node (degree 438)- Full retrieval with graph enabled: 30 results (5 graph + 19 vector + 4 BM25 + 2 graph_expansion)
Breaking change (v2.0.0)
The old trelix graph <repo> <symbol> call-graph display command was renamed:
# Before (v1.x)
trelix graph ./repo MyClass
# After (v2.0.0+)
trelix call-graph ./repo MyClass
trelix graph now builds and queries the knowledge graph:
trelix graph ./repo # build graph, print summary
trelix graph ./repo --visualize # open Pyvis HTML in browser
trelix graph ./repo --concepts # run LLM concept extraction
trelix graph ./repo --json # emit graph stats as JSON
What's new in v2.4.0
⚠️ Breaking change — search_code MCP tool response envelope
search_code now returns a pagination envelope instead of a bare list:
{"results": [...], "next_cursor": 10, "total_available": 25}
Update any MCP client code that iterates search_code(...) directly:
# Before (v2.3.0)
for result in search_code(query="auth", repo_path="/repo"):
...
# After (v2.4.0)
response = search_code(query="auth", repo_path="/repo")
for result in response["results"]:
...
# Paginate: pass response["next_cursor"] as cursor= for the next page
FederatedRetriever TTL cache
from trelix_llama_index import TrelixIndexRetriever
# cache_ttl=120 (seconds) — SHA-256-keyed, thread-safe
retriever = TrelixIndexRetriever(repo_path="/path/to/repo", k=10, cache_ttl=120.0)
# Inspect cache stats
print(retriever.cache_stats()) # {"hits": 3, "misses": 1, "size": 1}
# Force eviction
retriever.clear_cache()
Set cache_ttl=0 to disable caching entirely. Expected ~90% hit rate for typical debugging-session query patterns.
Multi-Query Expansion observability
When multi_query_enabled=True (requires trelix>=2.3.0), each retrieval now records expansion metadata:
nodes = retriever.retrieve("how does auth work?")
# expansion_used, expansion_variants, expansion_elapsed_ms written to query_telemetry table
GitHub PR review integration
# Review a PR diff locally
trelix review --pr owner/repo#42
# Review and post findings back as a GitHub review comment
trelix review --pr owner/repo#42 --post-comments
Requires GITHUB_TOKEN env var. The TrelixIndexRetriever can be used as the retrieval backend inside DiffReviewer.
Multi-repo file watching
# Watch all indexed repos simultaneously; updates index on file changes
trelix watch-all
Deleted files are removed from the SQLite index and vector store automatically.
Config field rename
flare_max_retries replaces flare_max_iterations in RetrievalConfig. Both the new env var TRELIX_RETRIEVAL_FLARE_MAX_RETRIES and the old TRELIX_RETRIEVAL_FLARE_MAX_ITER are accepted (old name emits DeprecationWarning and will be removed in v3.0.0).
Links
- trelix on GitHub
- trelix on PyPI
- trelix-mcp — MCP server for Claude Code, Cursor, Windsurf
- trelix-langchain — LangChain retriever
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trelix_llama_index-2.4.0.tar.gz.
File metadata
- Download URL: trelix_llama_index-2.4.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48d8b36875275f0d0c4ad38f3ddd07bc735df8395bfd59334a2c8ba50c410dfe
|
|
| MD5 |
cefb6b86b58d16d2aec9b368b359ef9f
|
|
| BLAKE2b-256 |
2ab0d5de1ec62f14afefc541c90a54750df51d1929ae376a815ff64d59678a4f
|
Provenance
The following attestation bundles were made for trelix_llama_index-2.4.0.tar.gz:
Publisher:
release.yml on sairam0424/trelix
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trelix_llama_index-2.4.0.tar.gz -
Subject digest:
48d8b36875275f0d0c4ad38f3ddd07bc735df8395bfd59334a2c8ba50c410dfe - Sigstore transparency entry: 2072567801
- Sigstore integration time:
-
Permalink:
sairam0424/trelix@4b020c283f887fc7b2818d833d28b329e3121231 -
Branch / Tag:
refs/tags/v2.4.0 - Owner: https://github.com/sairam0424
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4b020c283f887fc7b2818d833d28b329e3121231 -
Trigger Event:
push
-
Statement type:
File details
Details for the file trelix_llama_index-2.4.0-py3-none-any.whl.
File metadata
- Download URL: trelix_llama_index-2.4.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0009938fac6ef821326a40af7f4ea686025bf82990d3eb0fdeccfd044a9a2a92
|
|
| MD5 |
c055cf482f91e9180811ed24fb04f574
|
|
| BLAKE2b-256 |
8f6abda12b9751065f7bb52c25b7acfdce848070e48b9ad27efa048ec2981fbb
|
Provenance
The following attestation bundles were made for trelix_llama_index-2.4.0-py3-none-any.whl:
Publisher:
release.yml on sairam0424/trelix
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trelix_llama_index-2.4.0-py3-none-any.whl -
Subject digest:
0009938fac6ef821326a40af7f4ea686025bf82990d3eb0fdeccfd044a9a2a92 - Sigstore transparency entry: 2072568082
- Sigstore integration time:
-
Permalink:
sairam0424/trelix@4b020c283f887fc7b2818d833d28b329e3121231 -
Branch / Tag:
refs/tags/v2.4.0 - Owner: https://github.com/sairam0424
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4b020c283f887fc7b2818d833d28b329e3121231 -
Trigger Event:
push
-
Statement type: