Wikilink Graph Extraction: Reducing LightRAG Indexing Cost
LightRAG’s entity/relation extraction is expensive because it pays the LLM to discover graph structure from raw text. In an Obsidian-style wiki, this structure is already explicit:[[wikilinks]] are a manually curated knowledge graph, and frontmatter declares entity metadata (title, type, tags).
Injecting this pre-parsed structure as extraction hints reduces redundant LLM work and focuses extraction on implicit relations not captured by explicit links.
The Problem
LightRAG runs three extraction phases per page during indexing:- Entity extraction — LLM identifies named concepts, tools, people
- Relation extraction — LLM finds connections between entities
- Community summarization — LLM summarizes entity clusters
[[wikilinks]], phases 1–2 largely re-discover what’s already known. At ~150 pages with Haiku, this costs $10–30 (claimed, unverified).
Example — what the LLM re-discovers unnecessarily:
The Optimization: Extraction Hint Injection via chunking_func
LightRAG accepts a custom chunking_func that controls how each document is split before the extraction LLM sees it. By wrapping the default chunker, we can prepend a structured header:
Implementation
Expected Savings
The header adds ~50-100 tokens per chunk but saves the LLM from outputting confirmed relations it would have generated anyway. Net reduction depends on link density and how explicit the prose is.
These are estimates — actual savings depend on LightRAG’s internal prompting and how much the model weighs the hint header.
Limitations
- Header increases input tokens slightly per chunk (offset by output savings, since confirmed relations don’t need to appear in the LLM’s extraction output)
- Link quality matters — circular or stale wikilinks in the hints could mislead extraction; keep
[[links]]accurate - Community summarization phase unchanged — this optimization targets phases 1-2; community summaries still require full LLM passes
- Not a full bypass — the LLM still runs; this optimizes what it’s asked to discover, not whether it runs
Future Work: Direct Graph Injection
A more aggressive optimization would bypass LightRAG’s LLM extraction entirely for well-linked pages and write entities/relations directly into LightRAG’s graph store from the wikilink structure. This would reduce full-build cost from $10–30 → near-zero. Requires: understanding LightRAG’s internal storage format (graph_chunk_entity_relation.graphml, entity/relation KV stores) and injecting programmatically. LightRAG doesn’t expose a public API for this — it would require either internal API use or a PR to LightRAG upstream.
Related
- Local Wiki RAG: LightRAG Graph Stack — full RAG stack architecture; cost estimates
- Contextual Retrieval — related technique: prepending context to chunks before retrieval (vs extraction); same principle applied differently
- qmd — the BM25+vector alternative retrieval path that has no extraction cost