Lesson 7 of 33 ยท 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

๐Ÿ“š๐ŸŒ๐Ÿ’ป
Learned in training
๐Ÿ“ฐ๐Ÿ“๐Ÿ“Š
Newer: never seen
TRAINING CUTOFF
"What was in yesterday's news?"โœ•
๐Ÿง 

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

~2,500 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

"What were Q3 sales?"
Q3 ReportSales DataRevenueHR PolicyProductDesignMeetingyour question

The 3 closest chunks are picked

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

1RAG = find documents, add them to the prompt, then answer
2Documents are cut into chunks and searched by meaning
3Real data in the prompt means less guessing
โ† Prev
1/0
Next: Agents & Tools โ†’