RAG Architecture Diagram

A RAG architecture diagram shows how a retrieval-augmented generation system answers questions from your own documents. This sample draws a typical internal knowledge assistant in two lanes: an offline ingestion path that turns documents into a searchable vector index, and an online query path that retrieves, reranks and hands the best chunks to an LLM. It is an architecture data-flow diagram, not UML, because the interesting part is where data moves and where it is stored.


1. The Diagram

RAG System: Ingestion and Query Paths OFFLINE INGESTION (batch, on document change) Documents PDF, HTML, wiki Parse and clean text + metadata Chunk 512 tok, 64 overlap Embed bi-encoder, 1024-d Vector index HNSW + metadata each chunk stored as (id, vector, text, source, page) ONLINE QUERY (per request, ~1-3 s) User question natural language Embed query same model Retrieve top-50 vector + BM25 Rerank top-5 cross-encoder k-NN search Build prompt context + question LLM generate grounded answer Answer with citations shown to user guardrails: cite or refuse if context is empty

Read the top lane once per document change and the bottom lane once per question. The only link between them is the yellow k-NN search into the index.

  1. Documents (PDFs, HTML, wiki pages) are pulled in whenever they change.
  2. Parse and clean extracts text plus metadata such as title, source URL and page number, which later become citations.
  3. Chunk splits text into roughly 512-token pieces with a 64-token overlap so a sentence is never cut away from its context.
  4. Embed turns each chunk into a dense vector with a bi-encoder model, and the vector index (HNSW) stores it alongside the text.
  5. At query time the user question is embedded with the same model; a different model would put it in a different vector space.
  6. Retrieve top-50 runs hybrid search: k-nearest-neighbour on vectors plus BM25 keyword match, merged with reciprocal rank fusion.
  7. Rerank top-5 scores each (question, chunk) pair with a slower but more accurate cross-encoder.
  8. Build prompt places the five chunks and their sources in front of the question, with an instruction to cite or refuse.
  9. LLM generate writes the grounded answer, returned to the user with citations.

2. How to Read It

Notation Used Step transforms data process step Store persistent data data flow read from store Output result to user lane runtime boundary Yellow = the input and the retrieval hop that joins the two lanes.

Boxes are processing steps, the cylinder is persistent storage and dashed rectangles are lanes that run on different schedules. Sub-labels carry the one design parameter that matters most for that step (chunk size, k, model type), which is where most RAG quality problems are found.

3. Variant: Corrective RAG

Variant: Corrective RAG with a Relevance Check Question Retrieve top-k chunks relevant? LLM grader Generate cited answer Rewrite query HyDE / expand Say I don't know + log gap [yes] [no] retry retrieval [attempts < 2] [attempts = 2] Answer to user

The basic pipeline always answers, even when retrieval found nothing useful. This variant adds a decision diamond: a small LLM grader checks whether the chunks are relevant. If not, the query is rewritten (for example with HyDE, which embeds a hypothetical answer) and retrieval runs again. After two failed attempts the system says it does not know and logs the gap so the content team can add a document. Red marks the error path.

4. Pros, Cons, and When to Use

Pros

Cons

When to use

When not to use

5. As Diagrams-as-Code

The same diagram as a Mermaid flowchart with two subgraphs:

flowchart LR
  subgraph Ingest[Offline ingestion]
    D[Documents] --> P[Parse and clean] --> C[Chunk 512/64] --> E[Embed bi-encoder]
    E --> I[(Vector index HNSW)]
  end
  subgraph Query[Online query]
    Q[User question] --> QE[Embed query] --> R[Retrieve top-50 vector+BM25]
    R --> RR[Rerank top-5 cross-encoder] --> B[Build prompt] --> G[LLM generate]
    G --> A[Answer with citations]
  end
  I -. k-NN search .-> R