Local Wiki RAG: LightRAG Graph Stack
The wiki uses a two-retrieval-path architecture: qmd for fast lexical+vector search inside Claude Code sessions, and LightRAG for graph-aware synthesis in the TUI and MCP server. Both run locally at zero cost by default; LightRAG can optionally use Claude Haiku for higher-quality synthesis.Architecture
Why two paths
The agentic-search-vs-rag experiment validated the LightRAG path: graph search achieved 2× retrieval IoU with 99% fewer tokens vs flat RAG. See Agentic Search Vs Rag.
Tools
wiki-chat — interactive TUI
/mode local|global|hybrid|naive— switch mid-session/reindex— trigger wiki-index for new pages/status— show manifest stats
wiki-index — graph indexer
.env):
ANTHROPIC_API_KEYset → Claude Haiku (better entity/relation extraction)- unset → qwen2.5:3b via ollama (free — recommended for full rebuilds)
manifest.json tracks {path: mtime}. Only changed/new pages are re-extracted. The manifest is saved after each page so partial runs resume automatically.
The post-commit hook triggers wiki-index in the background after any commit touching wiki/. Progress: tail -f .lightrag/last-index.log.
wiki-mcp — MCP server
Zero-cost wiki queries from Claude Code or OpenCode. Exposes two tools:wiki_query(question, mode="hybrid")— graph-aware synthesiswiki_status()— show index stats
~/.config/opencode/opencode.json):
Setup
install.sh handles: copying binaries to ~/.local/bin, setting up the post-commit hook, pulling qwen2.5:3b and nomic-embed-text via ollama. uv handles Python deps via PEP 723 inline metadata — no pip or venv needed.
One-time graph build (required before wiki-chat or wiki-mcp):
Design choices
Graph over flat RAG
Per Agentic Search Vs Rag: graph search wins on cross-concept queries (99% fewer tokens, 2× IoU). Flat RAG only wins on explicit dependency recall. The wiki’s primary use case — “how do X and Y relate?”, “what patterns apply to problem Z?” — is exactly where graph search wins.One concept per page = natural graph nodes
The wiki rule “one thing per page” (CLAUDE.md) makes each page a clean entity for LightRAG to extract. Entities extracted fromconcepts/context-degradation naturally link to concepts/context-compression, concepts/ralph-loop, etc. Cross-links become graph edges.
qwen2.5:3b for local synthesis
Better structured output for entity extraction than phi4-mini. Fits comfortably in M1 Pro 16GB and RTX 2060 6GB. For higher-quality extraction at index time: useANTHROPIC_API_KEY — Haiku costs ~$0.001 per page at current pricing.
Manifest-based incremental indexing
Building the full graph from scratch takes ~30–60 min for 150 pages with a local LLM. The manifest approach means each new ingest only costs extraction time for the new pages (typically 1–3 pages). Post-commit automation makes this transparent.Performance
Related
- Agentic Search Vs Rag — experiment validating graph search for this wiki
- Local Rag Elasticsearch — stack comparison; retrieval latency benchmarks
- Contextual Retrieval — chunk context technique; wiki pages are pre-contextualized (one concept per page)
- BM25 — lexical retrieval used by qmd (wiki-context path)
- Reranking — post-retrieval filtering; not yet applied here
- qmd — BM25 + vector engine for the wiki-context skill path
- Wikilink Graph Extraction: Reducing LightRAG Indexing Cost — Obsidian wikilink hints injected at chunk time to reduce LightRAG extraction cost ~40–55%