All Guides
Intermediate • ~50min~50min reading timeFree Guide

RAG — Retrieval-Augmented Generation

Design an assistant anchored in your documents using Retrieval-Augmented Generation and guarantee verifiable responses.

The RAG Pipeline

How RAG Works: 5-Step Pipeline

From question to grounded answer

Step 1, Document Ingestion

Load your documents (PDFs, web pages, databases) and split them into chunks, typically 200-500 tokens each.

💡 Chunk at paragraph or section boundaries. Overlap by 50-100 tokens for continuity.

1/5
Loading diagram…

Chunking Strategies

Chunking Methods Compared

MethodHow It WorksProsCons
Fixed SizeSplit every N tokensSimple, predictableMay split mid-sentence
ParagraphSplit at paragraph boundariesPreserves meaningUneven chunk sizes
SemanticSplit when topic changesBest context preservationRequires embedding-based detection
RecursiveTry paragraph, then sentence, then characterBalances size and meaningMost common in LangChain/LlamaIndex

← Scroll horizontally →

Quick Check

Why is chunk overlap important in RAG?

The Context Engineering Challenge

Click to expand

Limitations

  1. →Retrieval quality bottleneck, If the wrong chunks are retrieved, the answer will be wrong or incomplete.
  2. →Embedding mismatch, Short queries may not embed close to long document passages. Use query expansion to improve recall.
  3. →Stale data, If documents change, you must re-embed. Set up automated re-indexing.
  4. →Multi-hop reasoning, Standard RAG retrieves chunks independently. Questions requiring information from multiple documents need advanced techniques (graph RAG, iterative retrieval).
  5. →Cost at scale, Embedding millions of documents and storing vectors has infrastructure costs.
Click to expand

Test Your Understanding

RAG Fundamentals Knowledge Check

0 / 5 answered

Q1.What does RAG stand for?

5 questions remaining

Next Steps

You now understand RAG fundamentals. In the next workshop, you will build a mini RAG system from scratch, loading documents, creating embeddings, searching, and generating grounded answers.


Continue to the workshop: Build a Mini RAG System to put theory into practice.


Workshop Overview

What We Are Building

A document Q and A system in 5 steps

Step 1, Load Documents

Load a set of documents (markdown files, PDFs, or plain text) and prepare them for processing.
code
// Pseudocode for the workshop
const docs = loadDocuments('./knowledge-base/')
console.log('Loaded', docs.length, 'documents')

💡 Start small: 5-10 documents. You can scale later.

1/5

Tuning Your RAG System

Embedding Models for RAG

ModelDimensionsSpeedQualityCost
text-embedding-3-small (OpenAI)1,536FastGood$0.02/1M tokens
text-embedding-3-large (OpenAI)3,072MediumExcellent$0.13/1M tokens
all-MiniLM-L6-v2 (Open Source)384Very FastGoodFree (self-hosted)
Cohere embed-v31,024FastExcellent$0.10/1M tokens

← Scroll horizontally →

Quick Check

Why does accuracy decrease when K (number of retrieved chunks) is too high?

Evaluation: How Good Is Your RAG?

Click to expand

Common Issues and Fixes

RAG Troubleshooting Guide

ProblemSymptomFix
Wrong chunks retrievedAnswer is about wrong topicImprove chunking strategy, add metadata filters
Answer includes hallucinationClaims not in source docsStrengthen "answer ONLY from context" instruction
Incomplete answersMissing key informationIncrease K, improve chunk overlap, check chunking boundaries
Slow retrievalQuery takes secondsAdd vector index (HNSW), reduce embedding dimensions
Stale answersDocument was updated but RAG gives old infoSet up automated re-embedding on document change

← Scroll horizontally →

Scaling Beyond the Workshop

Click to expand

Test Your Understanding

Mini RAG Workshop Check

0 / 5 answered

Q1.What are the 5 steps to build a RAG system?

5 questions remaining

Continue Learning

You have built your first RAG system. In the next module, you will learn about AI Agents, systems that can reason, use tools, and take actions autonomously using the ReAct framework.


Continue to ReAct Method: AI Agents Explained to understand autonomous AI systems.

Your progress

Progress is self-reported and stored in your browser. The final completion record is not a qualification or an independent assessment.

View progress and completion record

Learn AI, from prompts to agents

15 free guidesQuizzes, diagrams and workshopsNo account needed
GO DEEPER — FREE GUIDE

AI Agents & Autonomous Systems

Build agents with ReAct, function calling, and multi-agent patterns. Free interactive AI agents course.

One practical AI workflow in your inbox

Methods, resources and new exercises. Free, unsubscribe at any time.