Interactive guide

Retrieval-Augmented
Generation (RAG)

LLMs are powerful but blind to your private docs and yesterday's deploy. RAG retrieves relevant passages at query time, stuffs them into the prompt, and grounds the answer — without retraining weights.

Demo corpus: fictional Acme Analytics internal docs (HR, API, ops, FAQ). You'll query them like a real enterprise search + chat stack.

Three parts: The gapThe pipeline Ship it. Step 04 is the full retrieve → generate playground.

Part 1 · Step 01

The gap RAG fills

Start with how LLM chat works today, name what's missing, then walk the full RAG data flow — indexing offline, retrieval and generation at query time.

Query time only — no document path

UserAsks a question
Your appBuilds a prompt
LLMFrozen weights only
AnswerGeneric / guessed
Company docsPDFs, wikis, tickets

This is the default "chat with GPT" architecture — powerful language skill, but no live wire into your knowledge base.

Same question, two architectures — toggle a sample query below:

User: How many PTO days do employees get?

Without RAG

Most companies offer around 10-15 vacation days, but policies vary widely.

Weights only — docs never consulted

With RAG

Employees receive 20 days of PTO per year, with up to 5 days rollover. New hires accrue from day one.

Retrieved from HR Policy

Part 2 · Step 02

The RAG pipeline

Two phases: indexing (offline) builds a searchable memory; query time retrieves, augments, and generates.

Click each stage — this is the query-time half of the RAG data flow you saw in Step 01. Indexing (offline) happens separately.

Offline
Index
Online
Retrieve
Augment
Generate

Documents are chunked, embedded, and stored before any user asks a question.

RAG = Retrieve(context) + Augment(prompt) + Generate(LLM)

Part 2 · Step 03

Indexing: chunk, embed, store

Documents are split into chunks, converted to vectors, and stored in a vector database. This is the knowledge base your app queries — not the LLM weights.

4 documents15 chunks indexed768-dim vectors (illustrative)

chunk 0 · internal/hr-policy.pdf

Acme Analytics employees receive 20 days of PTO per year.

→ vector[i]

chunk 1 · internal/hr-policy.pdf

Unused PTO rolls over up to 5 days.

→ vector[i]

chunk 2 · internal/hr-policy.pdf

Remote work is allowed up to 3 days per week with manager approval.

→ vector[i]

chunk 3 · internal/hr-policy.pdf

New hires accrue PTO starting day one.

→ vector[i]

Indexing runs offline: split text, embed each chunk, upsert into a vector database (Pinecone, pgvector, OpenSearch, etc.).

Part 2 · Step 04 — interactive

Retrieve, augment, generate

Watch similarity scores pick chunks, see the augmented prompt, and read the grounded answer. This is what most "chat with your docs" products implement under the hood.

Query: How many PTO days do employees get?

95%
#1 · HR Policy

Acme Analytics employees receive 20 days of PTO per year.

75%
#2 · HR Policy

Unused PTO rolls over up to 5 days.

System: Answer using ONLY the context below. If the answer is not in the context, say you don't know.

Context:
[1] (HR Policy)
Acme Analytics employees receive 20 days of PTO per year.

[2] (HR Policy)
Unused PTO rolls over up to 5 days.

User: How many PTO days do employees get?

Assistant:

Generated answer

Employees receive 20 days of PTO per year, with up to 5 days rollover. New hires accrue from day one.

Part 3 · Step 05

Chunking tradeoffs

Chunk size shapes retrieval quality. Too large adds noise; too small loses context. Production systems often use 256–512 tokens with overlap.

Query: What is the API rate limit per minute?

15 chunks in index · top match scores below

API Guide · score 98%

The rate limit is 1000 requests per minute per API key.

Incident Runbook · score 55%

Escalate to the platform team if error rate exceeds 2%.

Small chunks improve precision — the rate-limit sentence ranks high without extra noise.

Part 3 · Step 06

Pitfalls & architecture choices

RAG shifts the problem from "can the model answer?" to "did we fetch the right evidence?" — plus classic LLM security and freshness concerns.

Bad retrieval = bad answers

If the right chunk isn't retrieved, the LLM cannot magically know your policy. Monitor recall@k and human eval on retrieval.

Mitigation: Better chunking, hybrid search (BM25 + vectors), rerankers

Engineering checklist: chunk strategy, embedding model, top-k, prompt template, access control on the vector store, logging of retrieved chunks for debugging, and eval sets with real internal questions.

Pair with Introduction to LLMs for the model layer and Transformer walkthrough for embeddings and attention underneath vector search.