AI

What is RAG? Retrieval-augmented generation explained

How RAG works: retrieve the right documents, add them to the prompt and generate a grounded answer, with a worked Python example and the mistakes to avoid.

  • 5 min read
  • 5 questions
  • +35 XP
Transcript

RAG, explained by cats. Kitty asks the AI, “What’s our vacation policy? And how do I reset the build server?” The model blinks with big confident cat eyes. But if it only knows training data, it might guess. And guessing is how you get chaos.

So Kitty uses RAG. RAG stands for Retrieval-Augmented Generation. Which is a fancy way of saying: don’t just answer. Go look it up first. Step one: retrieval. Kitty asks a question, and the system searches the right documents. HR policies.

Support tickets. Manuals. Legal files. The sacred folder of PDFs. Step two: augmentation. The system takes the user’s question and the useful document snippets and stuffs them into the prompt. Now the model has context. Step three: generation. The LLM writes an answer grounded in that retrieved info.

So the model is still the writer cat. But the documents are the notes on the desk. Why does Kitty use RAG? Because it helps the AI be specific, more up to date, and less likely to hallucinate tuna regulations.

That’s why companies use it for internal chatbots, customer support, and document-heavy work. Without RAG, the AI guesses. With RAG, the AI checks the receipts.