Your company hires a brilliant new employee. IIT topper, knows everything about everything — except your company. Day one, a customer asks about the refund policy. What do you do? You don't send them back to college for retraining. You hand them the policy document and say "answer from this." That exact move — smart generalist + the right document at the right moment — is RAG, the most-used GenAI architecture in industry and the most-asked applied topic in GenAI interviews. This is the lesson to know cold.
The problem: the model has never read your documents
An LLM knows what its training data contained — public internet, frozen at a cutoff date. Your leave policy, your product manuals, your client contracts? Never seen them. Ask anyway and you get the worst case from lesson 7: a fluent, plausible, invented answer. So how do you make a model answer from your knowledge? The naive options both fail: retrain/fine-tune on the documents? Slow, costly, unreliable for facts, and repeats every time a document changes (lesson 10 has the full autopsy). Paste everything into every prompt? Ten thousand pages don't fit any context window — and even when they fit, you'd pay for all of them on every question.
The idea: make it an open-book exam
In a closed-book exam you answer from memory — you hallucinate under pressure (every student knows this feeling). In an open-book exam, you first find the right page, then answer from it. RAG is exactly the open-book exam: Retrieve the few passages relevant to the question, Augment the prompt with them, Generate the answer from that context. Don't teach the model your knowledge — hand it the right page at the right moment.
The full pipeline — one diagram to memorize
Phase 1 — Indexing (done once, and on every document update): collect the documents, split them into chunks, turn each chunk into an embedding vector, store vectors + text in a vector database. Phase 2 — Query time (every question, live): embed the user's question with the same embedding model, run a similarity search for the nearest chunk-vectors, take the top few chunks, build a prompt of instructions + chunks + question, and let the LLM generate a grounded answer — ideally citing which chunk it used. If you can draw this from memory and narrate each arrow, you can answer 80% of RAG interview questions. Let's zoom into the three steps that carry the design decisions.
Chunking — why and how to split
Why not embed each document whole? Because a 50-page PDF is about fifty topics — one vector for all of it is a blurry average that matches nothing well. And retrieval-wise, you want to hand the model the relevant paragraph, not 50 pages of mostly-noise. Chunking = splitting documents into focused pieces, typically a few hundred tokens each.
The trade-off interviewers probe: too big → blurry vectors, wasted context, diluted relevance; too small → fragments lose their meaning ("the notice period is 30 days" — notice period of what?). Sensible defaults: 200–500 tokens, split along natural boundaries (headings, paragraphs) rather than mid-sentence, with a little overlap between neighbours so a fact sitting on a boundary survives in at least one chunk. Smarter variants (semantic chunking, heading-aware splitting) exist, but defaults-plus-reasoning is the placement-level answer.
Embeddings and vector search — lesson 2 pays off
Remember embeddings: text → vector, where distance ≈ difference in meaning. That geometry is the whole search engine. The question "how many casual leaves do I get?" lands near the chunk "employees get 12 casual leaves per calendar year" — even though they share almost no words. That's the upgrade over keyword search: semantic search matches meaning, not spelling. "Sick leave" finds "medical leave". The vector database's job is doing this nearest-neighbour lookup fast over millions of chunks (names to drop: Pinecone, Chroma, FAISS, pgvector, Weaviate, Milvus).
💡 The silent killer: index with one embedding model, query with another, and nothing errors — the similarity scores are just meaningless, because each model defines its own coordinate system. Everything runs; results are garbage. Same embedding model on both sides, always.
Assembling the answer — the final prompt
The last step is just disciplined prompting (lesson 6). The retrieved chunks and the question become one grounded prompt:
prompt = f"""You are the HR assistant. Answer ONLY from the
context below. If the context doesn't contain the answer, say
"I don't have that information" - do not guess.
Cite the source document of your answer.
Context:
{retrieved_chunks} # top 3-5 chunks from the vector DB
Question: {user_question}
"""Result
You are entitled to 12 casual leaves per calendar year, with requests needing one day's notice. (Source: Leave_Policy.pdf)
All three hallucination defences from lesson 7 are visible right there: grounding ("only from the context"), the escape hatch ("say you don't have it"), and citations. RAG isn't a separate magic — it's lessons 2, 6 and 7 assembled into a system.
Wait — context windows are huge now. Why not paste everything?
The modern version of the question, and interviewers love it. Three answers. Economics: tokens cost money on every call — pasting 300 pages per question, thousands of questions a day, is a bonfire of budget; retrieval sends 3 relevant chunks instead. Quality: models attend less sharply when the one relevant needle sits in a giant haystack (the "lost in the middle" effect) — focused context beats bulk context. Scale: real corpora are gigabytes; no window fits them. Long context and RAG are teammates, not rivals: retrieve first, then be generous with what you retrieved.
And beyond the window debate, RAG's structural wins: freshness (update a document → re-index one file — no retraining), citability (answers point to sources), and access control (retrieval can respect per-user permissions — the intern's query never retrieves the salary sheet).
Beyond basic RAG — the terms you'll hear
Production systems layer upgrades onto this skeleton: hybrid search (combine vector similarity with keyword search — jargon and exact codes like "HRA-104" need keywords), reranking (retrieve 20 candidates cheaply, then a smarter model re-orders and keeps the best 3), metadata filtering (only chunks where department = "HR"), and agentic RAG (an agent decides whether, where and how often to retrieve — lesson 11 energy). At placement level you need the names and one-liners, not implementations — and the honest signal that basic RAG's failures are usually retrieval failures, which is exactly what the Practice Zone's debugging task drills.
Selection-round radar: "Explain RAG" / "design a chatbot over company documents" is reported from TCS, Infosys, Accenture, Cognizant AND product companies — it's the closest thing GenAI interviews have to "reverse a linked list." Practice narrating the two-phase pipeline in 90 seconds, with chunk-size reasoning and the same-embedding-model rule included.
Common mistakes
- Different embedding models for indexing and querying — runs fine, retrieves garbage.
- Chunking blindly at fixed character counts through mid-sentence — split on natural boundaries with overlap.
- No escape hatch in the generation prompt — the model answers from memory when retrieval comes back empty, and you're back to hallucinating.
- Forgetting to re-index when documents change — the bot confidently serves last year's policy.
- Blaming the LLM when answers are wrong — in RAG, the bug is usually in retrieval (wrong/missing chunks), so debug there first.
- Ignoring permissions — retrieval that can surface any document to any user is a data leak with extra steps.
Quick recap
| Concept | One-liner |
|---|---|
| RAG | retrieve relevant chunks → augment the prompt → generate grounded answer |
| Two phases | index once (chunk → embed → store); retrieve + generate per question |
| Chunking | a few hundred tokens, natural boundaries, slight overlap |
| Vector DB | fast nearest-neighbour search over chunk embeddings |
| Golden rule | same embedding model for documents and queries |
| vs long context | cost, focus, scale — retrieve first, then be generous |
| Debugging | when RAG fails, suspect retrieval before the LLM |
Practice Zone — PYQs from real selection rounds
Six MCQs and three serious tasks: build a toy retriever in numpy, design the HR-bot pipeline out loud, and debug a failing RAG system — the three shapes RAG questions actually take.
RAG (Retrieval-Augmented Generation) primarily solves the problem of:
Asked in

The correct order of a basic RAG pipeline is:
Asked in

Documents are split into chunks before embedding because:
Asked in

The vector database in a RAG system stores:
Asked in

Why must the query be embedded with the same embedding model used for the documents?
Asked in

Context windows now fit hundreds of pages. Why still use RAG instead of pasting all documents into every prompt?
Asked in

Hands-on tasks:
Four chunks from a company handbook are already embedded (toy 3-D vectors below). Write the retrieval step: embed the query (given), find the most similar chunk by cosine similarity, and predict which chunk wins for the query "how many casual leaves do I get?"
Asked in

import numpy as np
chunks = {
"Employees get 12 casual leaves per calendar year.": np.array([0.9, 0.1, 0.1]),
"The office cafeteria serves lunch from 12 to 2 pm.": np.array([0.1, 0.9, 0.2]),
"Laptops must be returned on the last working day.": np.array([0.2, 0.3, 0.9]),
"Casual leave requests need one day's notice.": np.array([0.8, 0.2, 0.2]),
}
query_vec = np.array([0.85, 0.15, 0.12]) # "how many casual leaves do I get?"Interview scenario: "Design a chatbot that answers employee questions from our 200 HR policy PDFs. Walk me through your pipeline." Give the end-to-end answer, including one design decision per stage.
Asked in

Your RAG bot says "I don't have that information" for a question whose answer definitely exists in the indexed documents. List the four most likely causes, ordered by how commonly they occur, with the check for each.
Asked in

FAQ
Does RAG completely stop hallucinations?
No — it's the strongest single reducer, but the model can still misread chunks or blend them wrongly, and retrieval can fetch the wrong text. That's why serious systems also measure groundedness (is every claim supported by the retrieved context?) — lesson 12.
RAG vs fine-tuning — which should I choose?
The single most-asked GenAI interview question — it gets all of lesson 10. Short version: knowledge (especially changing knowledge) → RAG; behaviour/style/format → fine-tuning; many real systems → both.
Which vector database should I learn first?
For learning: Chroma or FAISS — free, local, five lines to start. For interviews, the concept matters far more than the brand; be ready to say why a vector DB exists (fast approximate nearest-neighbour search at scale) rather than recite product names.
How many chunks should I retrieve (top-k)?
Common starting point: 3–5. Too few risks missing the answer; too many dilutes the context and cost. Tune with an evaluation set — and if you need many candidates, retrieve wide (say 20) and rerank down to the best few.
Next lesson: the question every interviewer eventually asks — Lesson 10: Fine-tuning vs RAG vs Prompting →


