Back to website
Mayank Aggarwal Learning Center

Phase 05 · GenAI & LLM ApplicationsLesson 1 of 3

RAG (Retrieval-Augmented Generation) Explained

Ground an LLM's answers in your own documents.

  • 26:06 video
  • 2 min read
  • Intermediate
01

The problem

Ask a general chatbot about your company's leave policy and it will either admit it doesn't know or, worse, invent something plausible. LLMs only know what was in their training data. Retrieval-Augmented Generation (RAG) fixes this by fetching the relevant parts of your documents and handing them to the model along with the question.

02

The concept

The idea in one sentence#

Retrieve the most relevant information, augment the prompt with it, then let the model generate an answer grounded in that information.

Part 1: Indexing (done once, ahead of time)#

  1. Load your documents: PDFs, web pages, Notion pages, support tickets.
  2. Chunk them into smaller passages (for example, a few hundred words each).
  3. Embed each chunk: an embedding model turns text into a list of numbers (a vector) that captures its meaning.
  4. Store the vectors in a vector database such as Chroma, Pinecone, pgvector or Qdrant.

Part 2: Answering (every time a user asks)#

  1. Embed the question with the same embedding model.
  2. Search the vector database for the chunks whose vectors are closest in meaning.
  3. Build the prompt: the question plus the top few chunks as context.
  4. Generate: the LLM writes an answer using that context, ideally citing its sources.
Text
"How many leave days do new joiners get?"
        │ embed
        ▼
  vector search ──► 3 most similar chunks from HR-policy.pdf
        │
        ▼
  prompt = instructions + chunks + question ──► LLM ──► grounded answer + source

Why embeddings work#

Embeddings place text with similar meaning close together, even when the words differ. "Annual leave for freshers" and "vacation days for new employees" end up near each other, so the search finds the right chunk even without matching keywords.

A minimal prompt template#

Text
Answer the question using ONLY the context below.
If the answer is not in the context, say "I don't know".

Context:
{retrieved_chunks}

Question: {user_question}

RAG vs fine-tuning#

RAGFine-tuning
Teaches the modelNew knowledge (facts, documents)New behaviour (style, format, task skills)
Updating informationJust re-index the documentsRetrain the model
Can cite sourcesYesNo
Cost to startLowHigher

For "answer questions about our documents", RAG is almost always the right first choice.

03

Try it

Your task · about 10 minutes

Pick five pages of notes you own. Write down how you would chunk them and what questions a RAG bot over them should answer.

Use the interactive visual above to explore it step by step
04

Recap & next

Key takeaways

  1. LLMs don't know your private or latest data. RAG fetches relevant information and adds it to the prompt.
  2. Indexing: split documents into chunks → turn each into an embedding → store in a vector database.
  3. Answering: embed the question → retrieve the most similar chunks → the LLM writes an answer using them.
  4. RAG reduces hallucinations and lets answers cite sources, without retraining the model.

Quick check

2 questions · instant feedback

1What does the "R" in RAG stand for?
2What is stored in a vector database for RAG?

Want to train your team on this? Talk about corporate training

Finished this lesson?

Mark it complete to track your progress and keep your streak going.

Next