Adaptive KG-RAG
Local-first knowledge graph repo memory for coding agents.
Adaptive KG-RAG indexes a workspace into a typed code knowledge graph, then
lets coding agents query compact repo context through MCP instead of reading
large parts of the repository into the prompt.
What It Does
- Indexes files, symbols, imports, calls, tests, docs, and repo-memory facts
across Python, JavaScript/TypeScript, Java, and C/C++ (functions,
structs/unions/enums, typedefs, macros,
#include edges).
- Shows graph status, node/edge counts, storage footprint, and export tokens in
a VS Code sidebar.
- Provides a graph explorer for inspecting files, symbols, and relationships.
- Configures MCP for Codex, Claude Code, Cursor, Antigravity, and Kimi.
- Lets agents query
adaptive_kg_status, adaptive_kg_query, and related MCP
tools before falling back to direct source reads. Graph retrieval is hybrid
(vector + lexical scoring, then graph expansion) and falls back to flat
vector chunk RAG when the graph is sparse.
- Uses offline Hash/KG mode by default (private, no API). Optional local
semantic embeddings (
sentence-transformers) or API providers are selectable
via the adaptiveKg.embeddingProvider setting.
Important Beta Note
This extension is currently a lightweight VS Code wrapper around the local
Adaptive KG Python package. For best results, install the Python package from
the project repository first:
git clone https://github.com/YijunSun/KG-RAG-CodeKG
cd KG-RAG-CodeKG
python -m pip install -e .[dev]
If you are developing from source, set adaptiveKg.sourceRoot to the repository
root when VS Code cannot discover src/adaptive_kg automatically.
Quick Use
- Open a repository in VS Code.
- Open the Adaptive KG activity bar icon.
- Run
Index Workspace or Rebuild Graph.
- Run
Configure Agent MCP and choose Codex, Claude Code, Cursor,
Antigravity, or Kimi.
- Restart the selected agent or open a fresh agent session.
MCP Targets
| Agent |
MCP Config |
Managed Instruction File |
| Codex |
~/.codex/config.toml |
AGENTS.md |
| Claude Code |
.mcp.json |
CLAUDE.md |
| Cursor |
~/.cursor/mcp.json |
.cursor/rules/adaptive-kg-rag.mdc |
| Antigravity |
~/.gemini/antigravity/mcp_config.json |
GEMINI.md |
| Kimi CLI |
~/.kimi/mcp.json |
— |
| Kimi Code |
~/.kimi-code/mcp.json |
— |
Use Adaptive KG: Uninstall Agent MCP to remove the managed MCP entry and
managed instruction block from one target or all configured targets.
Commands
Adaptive KG: Index Workspace
Adaptive KG: Rebuild Workspace Graph
Adaptive KG: Query Workspace Graph
Adaptive KG: Configure Agent MCP
Adaptive KG: Uninstall Agent MCP
Adaptive KG: Show Graph Status
Adaptive KG: Open Graph Explorer
Adaptive KG: Prepare LLM Graph Audit
Adaptive KG: Open Agent Protocol
Adaptive KG: Review Pending Updates
Adaptive KG: Start Local API Server
Adaptive KG: Evaluate Local Model
Embeddings
Set adaptiveKg.embeddingProvider:
hashing (default) — offline deterministic, zero dependencies, fully private.
sentence-transformers — local semantic embeddings (MiniLM); free and
private, needs the embed extra installed, and falls back to hashing if the
model isn't available.
openai / gemini / openrouter / custom — API embeddings. These send
code snippets to a third party and are subject to its rate limits.
For code retrieval the graph's edge structure (who-calls-whom, imports,
includes) does most of the work, so the local providers are recommended; API
embeddings mainly help fuzzy natural-language queries.
Privacy
Default indexing and querying are fully local — hashing and
sentence-transformers never send your code off the machine. Only the API
embedding providers transmit code, and only when you explicitly select one. MCP
mode does not ask Adaptive KG for your model API key; the host agent keeps using
its own account and model session.
Project
Source, documentation, benchmarks, and release notes:
https://github.com/YijunSun/KG-RAG-CodeKG