RAG System Architecture
A RAG system is two pipelines sharing an index: offline ingestion turns sources into retrievable units; online query selects the right units for a model or agent.
The conceptual spectrum lives in Retrieval-Augmented Agents. This page describes the architecture.
The evaluation target lives in Retrieval Quality: answerability, citation coverage, freshness, context sufficiency, and faithful use of retrieved evidence. Keep the split clear. Architecture says how retrieval is assembled; quality says whether it found the right thing.
Offline Ingestion Pipeline
Steps:
- Load and parse: preserve structure, title, URL, source path, and timestamp.
- Normalize: strip boilerplate, keep headings, preserve code blocks when relevant.
- Chunk: split by semantic structure before fixed size. Overlap only where boundary loss matters.
- Embed: compute vectors for semantic recall.
- Index keywords: exact names, commands, file paths, identifiers.
- Store metadata: citations and freshness require it.
Most RAG quality problems are ingestion problems disguised as prompt problems.
Online Query Pipeline
Steps:
- Query transform: rewrite, expand, or split multi-hop tasks.
- Hybrid retrieve: combine semantic and exact search.
- Rerank: prioritize precision after cheap recall.
- Assemble context: pack citations and enough surrounding page context.
- Generate or act: answer, call tools, or continue agent loop.
- Write back: update memory when useful synthesis emerges.
Kevin Wiki Implementation
The wiki uses a document-first variant:
- Markdown pages are the source corpus.
build-index.tsproduces catalog/backlink/discovery artifacts.- qmd provides retrieval and embedding.
_index.mdgives a human-readable catalog.- Timelines and frontmatter preserve provenance.
qmd update && qmd embedrefreshes the retrieval layer after edits.
This is intentionally not a black-box vector DB. The corpus remains readable and editable.
Design Implications
- Keep ingestion and query concerns separate.
- Do not use embeddings alone; exact identifiers matter.
- Always store enough metadata to cite and refresh.
- Reranking is often cheaper than overhauling the whole embedding model.
- Evaluate retrieval recall before blaming the generator.
- Re-index after maintenance or large doc edits.
Failure Modes
- Stale embeddings after docs change.
- Chunks too small to preserve meaning.
- Chunks too large to match precise queries.
- Missing exact keyword index.
- No source metadata.
- Agent reads a retrieved snippet but not the page context.
Architecture Position
| Axis | Value |
|---|---|
| Family | Memory, context, and retrieval |
| Boundary owned | Ingestion/query split for retrieval augmented generation. |
| Read with | Vector Database and ANN Index Architecture, Retrieval Quality, Agent Memory System Architecture |
| Use this page when | designing source-backed answer systems |
Timeline
-
2026-07-01 | Architecture category refresh added this page to the Memory, context, and retrieval family, linked it to Architecture System Map, and kept it standalone because it owns this boundary: Ingestion/query split for retrieval augmented generation. Source: User request, 2026-07-01
-
2026-06-18 | Expanded with Kevin's qmd/wiki implementation, ingestion/query diagrams, and failure modes. Source: User request, 2026-06-18
-
2026-06-19 | Linked Retrieval Quality as the evaluation layer for this architecture. Source: whole-wiki concept review, 2026-06-19
-
2026-06-02 | Page created. Captured offline-ingestion / online-query split, chunking as central knob, hybrid retrieval, reranking, separate retrieval/generation evaluation, and mapping to qmd/context engine. Source: compiled from RAG system-design literature