IT Vizag
← How LLMs Really Work

▶ Sign up free for the video, slides & prompts

The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.

Checking…

How LLMs Really Work · Lesson 8 of 15 · 2 min read · 6 min video

RAG: giving AI your own documents

Retrieval-augmented generation: chunk, embed, search, then answer with sources.

📄 Download slides (PDF)· free sign-up

A model only knows its training data. It doesn't know your college's syllabus, your company's leave policy or last week's price list. Retrieval-augmented generation (RAG) fixes that: find the relevant pieces of your documents, and hand them to the model along with the question.

The idea in one picture

Instead of a closed-book exam, RAG makes it an open-book exam: the model answers from pages you put in front of it.

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

  1. Load your documents: PDFs, web pages, policies, FAQs
  2. Chunk them into pieces of a few hundred tokens, often with a small overlap so ideas aren't cut in half
  3. Embed each chunk into a vector with an embedding model
  4. Store the vectors and the original text in a vector database

Part 2: Answering (every question)

  1. Embed the question with the same embedding model
  2. Retrieve the chunks whose vectors are closest, typically the top 3 to 8
  3. Build the prompt: instructions plus the retrieved chunks plus the question
  4. Generate an answer that uses only that context and cites which chunk it came from
🔒 Ready-to-copy prompt: sign up free (above) to unlock it.

Why RAG is so popular

  • Up to date: change a document and the answers change, with no retraining
  • Your private data stays in your own store and is sent only when relevant
  • Citations: users can check the source, which builds trust
  • Cheap: no training run needed

Where RAG goes wrong

Most failures are retrieval failures, not model failures:

  • Bad chunks: a table split across chunks, or chunks with no context ("It costs ₹500" — what does?)
  • Wrong matches: the question uses different words from the document
  • Too little or too much: missing the key chunk, or burying it among ten irrelevant ones
  • Stale index: documents changed but weren't re-embedded

Making it better

  • Add a heading or document title to each chunk
  • Hybrid search: combine meaning-based search with keyword search, which helps with codes, names and numbers
  • Re-ranking: retrieve 20, then let a re-ranker model pick the best 5
  • Rewrite vague questions before searching
  • Always log which chunks were used, so you can debug bad answers

In one line

RAG retrieves the most relevant chunks of your documents and puts them in the prompt, so the model answers from your data, with sources, without retraining.

Saved on this device. Sign in to keep progress everywhere.

Share with a friend