LearnThatStack Ace your next interview
AI Engineering

RAG (Retrieval-Augmented Generation).

Start free Change topic Change

Practise RAG (Retrieval-Augmented Generation) one question at a time. Answer out loud or in writing, get graded, and see exactly what you missed.

Try one question

What is Retrieval-Augmented Generation, and what problem does it solve?

The answer

Retrieval-Augmented Generation (RAG) fetches relevant text from an outside knowledge source at query time, then puts that text in the prompt. The model answers from the supplied evidence, not only from memory.

A trained model's knowledge is frozen at its cutoff, the date its training data stops. It has never seen your company's wiki, last week's ticket, or a private contract. Asking it anyway produces confident guesses.

RAG solves this without retraining. You update the documents, and the next answer changes. Because each answer traces back to a retrieved passage, you can show the source.

The tradeoff is that answer quality now depends on retrieval quality. If the search misses the right passage, the model is back to guessing.

Example · what grading looks like
What is an embedding, and why is it central to RAG?

“So an embedding is a list of numbers, a vector, that an embedding model turns a piece of text into, and texts that mean similar things end up close together. For RAG that's what lets search work on meaning instead of keywords. When you build the index you run every chunk through the model and store the vectors, and when a question comes in you embed it the same way and take the nearest chunks to put in the prompt. So if someone asks how to reset their login, it can still find the doc about recovering your account password, even though they barely share any words. And you need the same model for the questions and the chunks, otherwise the distances don't mean anything.”

Knew it

Nails the core idea: embeddings are vectors that cluster by meaning, letting retrieval match a query to chunks with no shared words. To go further, they could mention that rare names or IDs can still get missed since the model only knows what it learned.

Missed: Doesn't mention that embeddings only capture what the model learned, so rare product names or IDs can be missed


Get your own answers graded

Sign up free. Your account comes with 50 credits for grading, and it remembers what you missed.

What it covers

All 56 questions

Each on its own page

RAG fundamentals and tradeoffs

What RAG is, the stages of its pipeline, why it reduces but does not remove hallucinations, and when it beats fine-tuning or long-context prompting on quality and cost.

5 questions

  1. What is Retrieval-Augmented Generation, and what problem does it solve?
  2. Walk me through the canonical stages of a RAG pipeline.
  3. RAG is often said to reduce hallucinations. Why does it help, and why does it not eliminate them? Pro
  4. When should you use RAG versus fine-tuning versus just using a long context window? Pro
  5. Walk through the cost math: when does RAG lose to long-context stuffing or fine-tuning? Pro

Embeddings and vector indexes

How embeddings capture meaning, which similarity metric to use, how to choose an embedding model, and how vector databases and ANN indexes like HNSW and IVF work.

5 questions

  1. What is an embedding, and why is it central to RAG?
  2. What is a vector database, and why not just compare the query against every stored vector?
  3. Which similarity metric should you use for embeddings, and when does normalization matter? Pro
  4. What factors matter when choosing an embedding model for RAG? Pro
  5. Compare HNSW and IVF indexes, and explain where quantization fits in. Pro

Chunking and document preparation

Why and how documents are split, overlap and chunk size tradeoffs, parent-document and contextual retrieval, and handling tables and images.

7 questions

  1. Why do we chunk documents instead of embedding and retrieving whole documents?
  2. What is chunk overlap, and why is it commonly used?
  3. Compare fixed-size, recursive, semantic, and structural chunking. When would you pick each? Pro
  4. What are the tradeoffs between small chunks and large chunks? Pro
  5. What is parent-document (small-to-big) retrieval, and how does it differ from just using larger chunks? Pro
  6. What is contextual retrieval (contextual chunk enrichment), and what failure of naive chunking does it fix? Pro
  7. How do you handle tables, images, and other non-prose content in a RAG corpus? Pro

Retrieval and reranking

Dense versus keyword search, choosing top-k, hybrid retrieval with rank fusion, cross-encoder and LLM rerankers, diversity with MMR, and learned sparse or late-interaction models.

8 questions

  1. How does dense retrieval differ from keyword search like BM25? Pro
  2. What does top-k mean in retrieval, and how do you think about choosing k? Pro
  3. What is hybrid retrieval, and why does it usually outperform pure dense retrieval? Pro
  4. Explain Reciprocal Rank Fusion. Why is it preferred over combining raw scores? Pro
  5. What is a cross-encoder reranker, and why is it more accurate than the bi-encoder used for retrieval? Pro
  6. How do you balance relevance and diversity when retrieving chunks for RAG? Pro
  7. Compare cross-encoder rerankers with LLM-based rerankers. How would you choose? Pro
  8. When are SPLADE or ColBERT worth using instead of a dense plus BM25 hybrid? Pro

Context assembly and grounding

Building the final prompt, ordering and budgeting chunks, lost-in-the-middle, grounding and citations, verifying citations, and handling conflicting sources.

6 questions

  1. What does grounding mean in the context of RAG, and how do citations typically work? Pro
  2. How is the final prompt constructed in a RAG system, and what belongs in it? Pro
  3. What is the lost-in-the-middle problem, and how do you mitigate it in RAG? Pro
  4. How do you handle contradictory documents retrieved by a RAG system? Pro
  5. How do you detect and prevent hallucinated citations in RAG outputs? Pro
  6. How do you assemble the final context when many chunks survive reranking? Discuss ordering, deduplication, and token budgeting. Pro

Query rewriting and routing

Rewriting chat follow-ups, query expansion and decomposition, HyDE, and routing a query across sources or skipping retrieval entirely.

4 questions

  1. In a multi-turn chat, why can't you embed the user's latest message directly, and what do you do instead? Pro
  2. What are query expansion and query decomposition, and when does each help? Pro
  3. Explain HyDE. What problem does it address and what are its risks? Pro
  4. How do you route a query across knowledge sources, and when do you skip retrieval? Pro

Evaluation and debugging

Retrieval metrics, grading generated answers, building eval datasets and programs, common failure modes, and bisecting the pipeline to find where answers go wrong.

7 questions

  1. Define recall@k, MRR, and nDCG. When is each the right retrieval metric? Pro
  2. How do you evaluate the generation side of RAG, in the style of frameworks like RAGAS? Pro
  3. How would you build an evaluation dataset for a RAG system when none exists? Pro
  4. The assistant says it found nothing, but the document exists. How do you debug it? Pro
  5. What are the common failure modes of a RAG system in production? Pro
  6. Design a RAG evaluation program from prototype to production, and keep its metrics trustworthy. Pro
  7. Your dashboards show retrieval recall is high, yet users report wrong answers. Walk through your systematic diagnosis. Pro

Production operations and scale

Keeping the index fresh, migrating embedding models, latency budgets, caching and invalidation, and serving retrieval over 100M+ documents.

5 questions

  1. How do you keep a RAG index fresh as documents are created, edited, and deleted? Pro
  2. Walk through the latency budget of a production RAG query. Where does time go and how do you optimize? Pro
  3. What caching strategies apply to RAG, and what are the invalidation pitfalls? Pro
  4. Your embedding model is being deprecated. How do you migrate a large production index without downtime or quality regression? Pro
  5. Design retrieval for 100M+ documents under strict latency SLOs. What changes from a small stack? Pro

Access control, security and high-stakes use

Metadata filtering, multi-tenant access control, RAG-specific threats like indirect prompt injection, and designing for legal or medical liability.

4 questions

  1. How does metadata filtering work in vector search, and what is the difference between pre-filtering and post-filtering? Pro
  2. How do you implement multi-tenancy and document-level access control in RAG retrieval? Pro
  3. What security threats are specific to RAG systems, and how do you mitigate them? Pro
  4. How does a RAG design change when wrong answers carry legal or medical liability? Pro

Agentic, graph and structured RAG

Agentic control loops, multi-hop retrieval, Self-RAG and Corrective RAG, GraphRAG, and retrieving over SQL tables or APIs instead of documents.

5 questions

  1. What is GraphRAG, and when is it worth the added complexity? Pro
  2. What makes a RAG system "agentic," and what does that buy you over a fixed pipeline? Pro
  3. How do you handle multi-hop questions in RAG? Pro
  4. Explain Self-RAG and Corrective RAG. What production patterns did they inspire? Pro
  5. How do you do RAG over structured data such as SQL tables or APIs instead of documents? Pro
Practice · Questions

All questions

Showing of 56
Beginner 12
01

What is Retrieval-Augmented Generation, and what problem does it solve?

Visual

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
Visual

Retrieval-Augmented Generation (RAG) fetches relevant text from an outside knowledge source at query time, then puts that text in the prompt. The model answers from the supplied evidence, not only from memory.

A trained model's knowledge is frozen at its cutoff, the date its training data stops. It has never seen your company's wiki, last week's ticket, or a private contract. Asking it anyway produces confident guesses.

RAG solves this without retraining. You update the documents, and the next answer changes. Because each answer traces back to a retrieved passage, you can show the source.

The tradeoff is that answer quality now depends on retrieval quality. If the search misses the right passage, the model is back to guessing.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

Walk me through the canonical stages of a RAG pipeline.

Visual

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
Visual

A RAG pipeline has two halves. An offline indexing pass runs whenever documents change. An online query pass runs on every request.

The offline pass runs these stages in order:

  • Load and parse the documents.
  • Chunk them.
  • Embed each chunk.
  • Write the vectors, plus metadata, to the index.

The online pass runs these stages in order:

  • Rewrite the query.
  • Embed it.
  • Retrieve the top-k chunks.
  • Rerank them.
  • Build the prompt.
  • Generate the answer and return it with citations.

Two points beginners miss. The same embedding model must serve both halves, or the query vector and the stored vectors do not share one space. And the pipeline is a chain: if any stage before generation drops the right chunk, the model cannot recover it.

Reranking is optional. Retrieval is tuned for speed over a huge index, reranking for precision over a short list.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

What is an embedding, and why is it central to RAG?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

An embedding is a list of numbers, called a vector, that a model produces from a piece of text. Text with similar meaning gets vectors that sit close together in vector space.

RAG depends on embeddings because retrieval must match on meaning, not exact words. You embed each chunk at index time and the question at query time, then hand the nearest chunks to the LLM that writes the answer. A question about getting money back can reach the refund policy with no word in common.

q = embed("can I get my money back")      # one vector, e.g. 1536 floats
hits = index.search(q, k=5)               # chunks whose vectors are nearest

The query and the chunks must go through the same embedding model, or the numbers are not comparable. And the vector only carries what the model learned, so rare product names or IDs can be missed.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

What is a vector database, and why not just compare the query against every stored vector?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

A vector database stores each chunk's embedding next to its text and metadata, and returns the chunks nearest to a query vector. Its core trick is an approximate nearest neighbor (ANN) index, which finds close matches without scanning every vector. In RAG, the chunks it returns become the LLM's context.

Comparing the query against every stored vector is a brute-force or flat scan. It is exact, and it is fine for a few thousand vectors. But the cost grows linearly with the corpus. Five million vectors at 1536 dimensions is about 7.7 billion multiply-adds per query.

An ANN index keeps the cost per query nearly flat as the corpus grows. It usually finds 95 percent or more of the true nearest neighbors. The database also handles filters, updates and persistence, which an in-memory array leaves to you. So you trade a little recall for a large speed win.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

Why do we chunk documents instead of embedding and retrieving whole documents?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Chunking exists because an embedding is one fixed-size vector, no matter how long the input. A whole document collapses into a single point that averages all its topics, so the one relevant paragraph loses its signal.

Three forces make this concrete:

  • Dilution. A 40-page manual covering billing, refunds, and shipping matches a refund question only weakly. Most of its text is about something else.
  • Model limits. Embedding models cap input tokens. Text past the cap is truncated, so it never gets indexed at all.
  • Prompt budget. What you retrieve is what you paste into the prompt. Whole documents burn tokens and bury the answer among unrelated text.

So retrieve the smallest unit that still stands on its own.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

What is chunk overlap, and why is it commonly used?

Visual

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
Visual

Chunk overlap means neighboring chunks share some text at their edges. A 500-token chunk with 50-token overlap repeats the last 50 tokens of one chunk as the start of the next.

The reason is boundary loss. A hard cut can split a definition from its example, or leave a pronoun with nothing to point at. Overlap gives each idea a second chance to sit whole inside some chunk.

step = chunk_size - overlap
chunks = [tokens[i:i + chunk_size] for i in range(0, len(tokens), step)]

Typical overlap is 10 to 20 percent of chunk size. The cost is duplication: the index grows, and retrieval can return near-copies, so dedupe neighboring chunks before building the prompt.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

How does dense retrieval differ from keyword search like BM25?

Part of Pro
08

What does top-k mean in retrieval, and how do you think about choosing k?

Part of Pro
09

What does grounding mean in the context of RAG, and how do citations typically work?

Part of Pro Visual
10

RAG is often said to reduce hallucinations. Why does it help, and why does it not eliminate them?

Part of Pro
11

How is the final prompt constructed in a RAG system, and what belongs in it?

Part of Pro
12

Which similarity metric should you use for embeddings, and when does normalization matter?

Part of Pro Visual
Intermediate 23
13

Compare fixed-size, recursive, semantic, and structural chunking. When would you pick each?

Part of Pro Visual
14

What are the tradeoffs between small chunks and large chunks?

Part of Pro
15

What is hybrid retrieval, and why does it usually outperform pure dense retrieval?

Part of Pro Visual
16

Explain Reciprocal Rank Fusion. Why is it preferred over combining raw scores?

Part of Pro
17

What is a cross-encoder reranker, and why is it more accurate than the bi-encoder used for retrieval?

Part of Pro Visual
18

In a multi-turn chat, why can't you embed the user's latest message directly, and what do you do instead?

Part of Pro
19

What are query expansion and query decomposition, and when does each help?

Part of Pro
20

Explain HyDE. What problem does it address and what are its risks?

Part of Pro
21

Define recall@k, MRR, and nDCG. When is each the right retrieval metric?

Part of Pro
22

How do you evaluate the generation side of RAG, in the style of frameworks like RAGAS?

Part of Pro
23

How would you build an evaluation dataset for a RAG system when none exists?

Part of Pro
24

What is the lost-in-the-middle problem, and how do you mitigate it in RAG?

Part of Pro Visual
25

The assistant says it found nothing, but the document exists. How do you debug it?

Part of Pro
26

How does metadata filtering work in vector search, and what is the difference between pre-filtering and post-filtering?

Part of Pro
27

What factors matter when choosing an embedding model for RAG?

Part of Pro
28

Compare HNSW and IVF indexes, and explain where quantization fits in.

Part of Pro
29

When should you use RAG versus fine-tuning versus just using a long context window?

Part of Pro
30

How do you route a query across knowledge sources, and when do you skip retrieval?

Part of Pro
31

What is parent-document (small-to-big) retrieval, and how does it differ from just using larger chunks?

Part of Pro Visual
32

How do you handle contradictory documents retrieved by a RAG system?

Part of Pro
33

How do you balance relevance and diversity when retrieving chunks for RAG?

Part of Pro Visual
34

What are the common failure modes of a RAG system in production?

Part of Pro
35

What is contextual retrieval (contextual chunk enrichment), and what failure of naive chunking does it fix?

Part of Pro
Expert 21
36

What is GraphRAG, and when is it worth the added complexity?

Part of Pro
37

What makes a RAG system "agentic," and what does that buy you over a fixed pipeline?

Part of Pro
38

How do you handle multi-hop questions in RAG?

Part of Pro Visual
39

Explain Self-RAG and Corrective RAG. What production patterns did they inspire?

Part of Pro Visual
40

How do you detect and prevent hallucinated citations in RAG outputs?

Part of Pro
41

How do you keep a RAG index fresh as documents are created, edited, and deleted?

Part of Pro Visual
42

How do you implement multi-tenancy and document-level access control in RAG retrieval?

Part of Pro
43

Walk through the latency budget of a production RAG query. Where does time go and how do you optimize?

Part of Pro Visual
44

What caching strategies apply to RAG, and what are the invalidation pitfalls?

Part of Pro
45

How do you handle tables, images, and other non-prose content in a RAG corpus?

Part of Pro
46

Compare cross-encoder rerankers with LLM-based rerankers. How would you choose?

Part of Pro
47

Your embedding model is being deprecated. How do you migrate a large production index without downtime or quality regression?

Part of Pro
48

How do you assemble the final context when many chunks survive reranking? Discuss ordering, deduplication, and token budgeting.

Part of Pro Visual
49

Design a RAG evaluation program from prototype to production, and keep its metrics trustworthy.

Part of Pro
50

Your dashboards show retrieval recall is high, yet users report wrong answers. Walk through your systematic diagnosis.

Part of Pro
51

Design retrieval for 100M+ documents under strict latency SLOs. What changes from a small stack?

Part of Pro
52

What security threats are specific to RAG systems, and how do you mitigate them?

Part of Pro
53

Walk through the cost math: when does RAG lose to long-context stuffing or fine-tuning?

Part of Pro
54

How does a RAG design change when wrong answers carry legal or medical liability?

Part of Pro
55

How do you do RAG over structured data such as SQL tables or APIs instead of documents?

Part of Pro
56

When are SPLADE or ColBERT worth using instead of a dense plus BM25 hybrid?

Part of Pro

No matches

Try a different filter or search term.

Know someone prepping for RAG (Retrieval-Augmented Generation)? Send them this set.
Quick recap

RAG (Retrieval-Augmented Generation) in pictures.

A quick recap of RAG (Retrieval-Augmented Generation) in 40 short animated pictures, one idea at a time. About 10 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.

Pro The first chapter is free to play. The other 36 pictures come with Pro.

Get Pro · $10/mo
Pro · $10/mo

50 of 56 RAG (Retrieval-Augmented Generation) answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git