Layered RAG (llmwiki pointer layer over a rawrag kernel)
Generated from
mcp/patterns.registry.json— do not edit by hand; change the registry and runbun run patterns:build.
Category: AI · Tier: deep · Risk: medium — external embedding/LLM providers with quota limits
A shared rawrag retrieve() kernel (embed → tiers → RRF fusion → drill) feeds two layers: llmwiki TLDR pointer pages as the answer surface over immutable rawrag chunks as the audit trail.
When to use: Use when a project needs grounded answers over a corpus: start with read-only search plus citation/provenance before adding any mutating tools.
Docs
- docs/blueprint/ai/layered-rag.md — The two-layer architecture (GitHub · GitLab)
- docs/blueprint/ai/knowledge-base.md — Corpus and ingest door (GitHub · GitLab)
- docs/blueprint/ai/graph-rag.md — Graph tier (GitHub · GitLab)
Code
src/lib/server/rawrag/index.ts— retrieve() — the single shared kernel (GitHub · GitLab)src/lib/server/rawrag/plan.ts— Retrieval planning (GitHub · GitLab)src/lib/server/rawrag/tiers/— Tier implementations (GitHub · GitLab)src/lib/server/llmwiki/search.ts— Pointer-layer search (GitHub · GitLab)src/lib/server/llmwiki/overview.ts— Deterministic system-overview anchor (GitHub · GitLab)
Tests
src/lib/server/rawrag/index.test.ts(GitHub · GitLab)src/lib/server/rawrag/plan.test.ts(GitHub · GitLab)src/lib/server/rawrag/rank.test.ts(GitHub · GitLab)src/lib/server/llmwiki/rrf.test.ts(GitHub · GitLab)src/lib/server/llmwiki/overview.test.ts(GitHub · GitLab)
Proof
Invariants
- The kernel is never forked — a single user_id tenant filter at the chunk level is the corpus boundary; a duplicated filter would be a cross-tenant leak.
- Retrieval tools close over userId via buildRetrievalTools({ userId }) — the model cannot forge identity.
- Raw chunks are source truth; llmwiki is the compressed pointer layer — the model answers from wiki TLDRs by default and drills into raw chunks only when the user asks for exact wording or challenges a claim.
Emulation notes
- 'nRAG' in docs is a concept name only — the code identifier is rawrag/retrieve(); do not search for an nrag module.
- Build the raw layer first; the pointer layer compiles from it and can start empty.
Depends on
Machine-readable record: layered-rag in mcp/patterns.registry.json.