Knowledge-graph-powered RAG sidecar for infrastructure querying
Project description
kt-rag
Knowledge-graph-powered RAG sidecar for infrastructure querying
Turn your infrastructure graph into a searchable knowledge base. kt-rag feeds discovered infrastructure data — services, databases, Kubernetes clusters, DNS zones, CI/CD pipelines — into a LightRAG knowledge graph, then lets you ask questions in plain English.
What you can do:
- "Which services depend on Postgres?" — get a structured answer with confidence scoring
- "What's the blast radius if us-east-1 goes down?" — trace dependencies across providers
- "Show me all EC2 instances tagged
productionin eu-west-1" — filter by metadata - "Generate a runbook for the auth service" — auto-document from live graph data
- "What changed in my infrastructure since last week?" — incremental sync awareness
How It Works
┌─────────────┐ ┌──────────┐ ┌──────────┐ ┌──────┐
│ Discovery │───▶│ kt-rag │───▶│ LightRAG │───▶│ LLM │
│ Plugins │ │ seed/sync│ │ KG Store │ │ │
└─────────────┘ └──────────┘ └──────────┘ └──────┘
│
┌────┴────┐ ┌─────┴──────┐
│ API │ │ Query CLI │
│ Server │ │ / Library │
└─────────┘ └─────────────┘
- Plugins discover your infrastructure (AWS, GitHub, K8s, etc.)
- kt-rag seeds entities and relationships into LightRAG's graph store
- LightRAG indexes everything for hybrid search (graph + vector)
- Your question triggers retrieval-augmented generation through an LLM
Quick Start
Install
pip install knowledgetree-rag
Or from source:
git clone https://github.com/knowledgetree-dev/kt-rag.git
cd kt-rag
pip install -e .
Configure
Copy the template and set your LLM API key:
cp .env.example .env
# Edit .env with your LLM provider and API key
Minimal .env:
LLM_BINDING_API_KEY=sk-...
Seed the graph
Populate LightRAG from your infrastructure data:
kt-rag-seed
Query
kt-rag-query "which services depend on postgres?"
Example output:
Response: The following services depend on Postgres:
- auth-service (production, us-east-1)
- user-api (staging, eu-west-1)
- analytics-backend (production, us-west-2)
- docs-service (production, us-east-1)
Confidence: 0.82
Start the API server
kt-rag-server
# Listening on http://0.0.0.0:8085
curl -s http://localhost:8085/api/v1/rag/health
CLI Commands
| Command | Description |
|---|---|
kt-rag-seed |
Full seed from Knowledge Tree into LightRAG |
kt-rag-query "..." |
Natural-language query (supports --filter, --min-score, --profile) |
kt-rag-server |
REST API on port 8085 |
API
Query
POST /api/v1/rag/query
{
"question": "which services depend on postgres?",
"mode": "hybrid",
"filter": {"provider": "aws", "region": "us-east-1"},
"profile_name": "claude"
}
Response:
{
"response": "The following services depend on Postgres...",
"confidence": 0.82,
"metadata": {
"mode": "hybrid",
"profile": "claude",
"tokens_used": 1247
}
}
Profile Management
# List profiles
GET /api/v1/rag/profiles
# Create profile
POST /api/v1/rag/profiles
{
"name": "claude",
"provider": "anthropic",
"api_key": "sk-ant-...",
"model": "claude-sonnet-4-20250514"
}
# Delete profile
DELETE /api/v1/rag/profiles/{name}
Multi-LLM Profiles
Switch between LLM providers at query time:
# Named profiles (persisted)
kt-rag-query "what's my blast radius?" --profile claude
# Ad-hoc via headers (server mode)
curl -H "X-KT-LLM-Provider: anthropic" \
-H "X-KT-LLM-Api-Key: sk-ant-..." \
-d '{"question": "..."}' \
http://localhost:8085/api/v1/rag/query
Configuration
All config via environment variables or .env:
| Variable | Default | Description |
|---|---|---|
LLM_BINDING |
openai |
LLM provider (openai, anthropic, ollama, azure) |
LLM_BINDING_API_KEY |
— | API key |
LLM_BINDING_MODEL |
gpt-4o |
Model name |
EMBEDDING_BINDING |
openai |
Embedding provider |
EMBEDDING_BINDING_MODEL |
text-embedding-3-small |
Embedding model |
LIGHTRAG_DIR |
./output |
LightRAG working directory |
LIGHTRAG_PORT |
8085 |
API server port |
KT_API_URL |
http://localhost:8080 |
Knowledge Tree API URL |
KT_API_TOKEN |
— | Knowledge Tree auth token |
PG_URI |
postgresql://localhost:5432/knowledgetree |
Database (read-only seed) |
SYNC_INTERVAL |
300 |
Sync interval in seconds |
Confidence Scoring
Every query response includes a 0.0–1.0 confidence score based on:
- Retrieval quality (30%) — how well the query matched stored entities
- Context coverage (30%) — how completely the retrieved data covers the question
- Factual support (40%) — whether the LLM's answer is grounded in retrieved facts
Set a minimum threshold:
kt-rag-query "what repos are production?" --min-score 0.6
Contributing
PRs are welcome. For feature requests or major changes, open an issue first.
# Dev setup
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
# Run tests
pytest tests/ -v --tb=short
# Type check
mypy .
Project Structure
├── seed.py # Full graph seed
├── sync.py # Incremental sync
├── query.py # CLI query entry point
├── server.py # FastAPI server
├── config.py # Environment config loader
├── profile_store.py # LLM provider profile persistence
├── scorer.py # Confidence scoring
├── kt_client.py # Knowledge Tree API client
├── tests/ # Test suite
└── .env.example # Config template
License
MIT
Project details
Release history Release notifications | RSS feed
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 knowledgetree_rag-0.1.0.tar.gz.
File metadata
- Download URL: knowledgetree_rag-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62d97a7d0c3012eb40c35ba09975f6dc2ec5700a4fc91a70f7e61cad0679eaff
|
|
| MD5 |
d4f650d20ee1b0dcb504e3e536ead6dd
|
|
| BLAKE2b-256 |
98cfa9bcc034952178fb995f9e9cacd0fd13d96f8e0a31c28cd5def0e48b49b1
|
Provenance
The following attestation bundles were made for knowledgetree_rag-0.1.0.tar.gz:
Publisher:
release.yml on knowledgetree-dev/kt-rag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
knowledgetree_rag-0.1.0.tar.gz -
Subject digest:
62d97a7d0c3012eb40c35ba09975f6dc2ec5700a4fc91a70f7e61cad0679eaff - Sigstore transparency entry: 1771175634
- Sigstore integration time:
-
Permalink:
knowledgetree-dev/kt-rag@3def4f7c636b4da5bd52c13671ede34407367e8f -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/knowledgetree-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3def4f7c636b4da5bd52c13671ede34407367e8f -
Trigger Event:
push
-
Statement type:
File details
Details for the file knowledgetree_rag-0.1.0-py3-none-any.whl.
File metadata
- Download URL: knowledgetree_rag-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.5 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 |
95ad310aeddf0fe63591eee8671e86f8f2ed3f702607a29243b5e4c560fd431d
|
|
| MD5 |
09e44c23459df88366cd1a0529982d74
|
|
| BLAKE2b-256 |
e5737ce5d634a30f5dfee61335d18a327b868cda1475a0e49a479eef20da898b
|
Provenance
The following attestation bundles were made for knowledgetree_rag-0.1.0-py3-none-any.whl:
Publisher:
release.yml on knowledgetree-dev/kt-rag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
knowledgetree_rag-0.1.0-py3-none-any.whl -
Subject digest:
95ad310aeddf0fe63591eee8671e86f8f2ed3f702607a29243b5e4c560fd431d - Sigstore transparency entry: 1771175974
- Sigstore integration time:
-
Permalink:
knowledgetree-dev/kt-rag@3def4f7c636b4da5bd52c13671ede34407367e8f -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/knowledgetree-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3def4f7c636b4da5bd52c13671ede34407367e8f -
Trigger Event:
push
-
Statement type: