Lesson 6 of 23 ยท Part 0: Foundations

RAG (Retrieval-Augmented Generation)

Give your LLM access to private data by injecting documents into the prompt.

Last time: AI can be confidently wrong, and giving it real documents is one strong way to fight it.
Today: RAG lets the AI answer from YOUR documents: find them, add them to the prompt, then answer.

The Knowledge Cutoff

๐Ÿ“š๐ŸŒ๐Ÿ’ป
Training Data (up to 2023)
TRAINING CUTOFF
๐Ÿ“ฐ๐Ÿ“๐Ÿ“Š
After Cutoff (unknown)
"What happened at CES 2025?"โœ•
๐Ÿง 

LLM

Generic knowledge only

โœ•
๐Ÿ”’

Your Company Data

Private, internal docs

The LLM has never seen your private documents.

"What were Q3 sales?" โ†’ "I don't have access to your company data..."

Retrieval-Augmented Generation

๐Ÿ”RRetrieve

Find relevant documents from your data store

โž•AAugment

Inject retrieved context into the prompt

โœจGGenerate

LLM produces a grounded, sourced answer

Step 1: Retrieve

Search your document store for relevant matches

"What were Q3 sales?"
๐Ÿ“„

Q3 Report.pdf

MATCH
๐Ÿ“Š

Sales Data.csv

MATCH
๐Ÿ“„

Q1 Report.pdf

๐Ÿ“„

HR Policy.pdf

๐Ÿ“

Meeting Notes

MATCH
๐Ÿ“

Product Spec

๐Ÿ”
Try another question:
๐Ÿ“„

Full Document

~4000 tokens

โœ‚๏ธโ†’Split
Chunk 1~500 tokens
Chunk 2~500 tokens
Chunk 3~500 tokens
Chunk 4~500 tokens
Chunk 5~500 tokens
โ†’๐Ÿ—„๏ธStore

Split documents into manageable chunks so retrieval is precise

Vector Search

Convert question to a vector, find nearest document chunks

"What were Q3 sales?"
โ†“ embed โ†’
dim 1dim 2
Q
query
Q3 Report
Sales Data
Revenue
HR Policy
Product
Design
Meeting

Nearest chunks are the most relevant matches

Without Context

system: "You are helpful"
user: "Q3 sales?"
โ†’injectcontext

With Context (Augmented)

system: "You are helpful"
context: "Q3 revenue was $4.2M, up 18% YoY, driven by enterprise..."
user: "Q3 sales?"
Try another question:

Token Budget Problem

8K context window โ€” everything must fit

Balanced Budget

System
Q
Retrieved Docs (3K)
Response Space (4K)
๐Ÿง 

LLM generates a grounded answer from the augmented prompt

"Your Q3 revenue was $4.2M, up 18% YoY, primarily driven by enterprise contracts."

[Source: Q3 Report]
โœ“
Question: "What were Q3 sales?"
โœ•Without RAG

"Revenue was approximately $3M based on typical industry averages..."

โœ•Hallucinated, no source
โœ“With RAG

"$4.2M, up 18% YoY, driven by enterprise contracts."

[Source: Q3 Report]

โœ“Grounded, sourced, accurate
Try another question:

The Full RAG Pipeline

๐Ÿ“„
Documentsโ†’
โœ‚๏ธ
Chunkโ†’
๐Ÿ“
Embedโ†’
๐Ÿ—„๏ธ
Storeโ†’
โ“
Queryโ†’
๐Ÿ”
Retrieveโ†’
๐Ÿ’‰
Augmentโ†’
๐Ÿง 
Generateโ†’
โœ…
Answer

Data flows left โ†’ right through the pipeline

When RAG Isn't Enough

RAG Can Answer

โœ“What were Q3 sales?
โœ“Summarize the contract
โœ“Find the relevant policy

RAG Cannot Act

โœˆ๏ธBook a flightโœ•
๐Ÿ“งSend an emailโœ•
๐Ÿ’ปRun codeโœ•
For actions, you need...โš™๏ธAgentsโ†’

Key Takeaways

1LLMs have a knowledge cutoff โ€” they cannot see your private data
2RAG = Retrieve relevant docs, Augment the prompt, Generate a grounded answer
3Chunking and vector search are the backbone of retrieval
4Watch your token budget โ€” too many docs starve the response
5When you need actions (not just answers), you need Agents
โ† Prev
1/0
Next: Agents & Tools โ†’