AI Tools

What is RAG? Retrieval-augmented generation for beginners

RAG explained simply: how AI apps look up the right documents before answering, why companies use it, and what each step of the pipeline does.

On this page

RAG, short for retrieval-augmented generation, is one of the most common ways companies build AI features today: chatbots that answer from company documents, study assistants that answer from your notes, support bots that answer from a help centre. This post explains what RAG is and how it works, step by step, in simple words.

The problem RAG solves

An LLM only knows what was in its training data. That creates three problems:

  • It does not know your private information: your college's rules, your company's policies, your class notes.
  • It does not know recent information that appeared after it was trained.
  • When it does not know, it may make something up.

You could paste all your documents into every prompt, but they quickly overflow the context window, and you pay for every token.

The idea: an open-book exam

RAG turns a closed-book exam into an open-book exam. Before answering, the system looks up the few most relevant pages and hands them to the model along with the question. The model then answers from those pages.

questionretrieve relevant chunkschunks + questionLLMgrounded answer
RAG: look it up first, then answer.

The two halves of RAG

Part 1: prepare the library (done once, ahead of time)

  1. Collect the documents: PDFs, web pages, notes, FAQs.
  2. Split them into small chunks, such as a paragraph or a section each.
  3. Embed each chunk: turn it into numbers that capture its meaning. Our post on embeddings and vector search explains this.
  4. Store the chunks and their embeddings in a vector database.

Part 2: answer a question (done every time)

  1. Embed the question with the same embedding model.
  2. Retrieve the few chunks closest in meaning to the question.
  3. Build a prompt with instructions, the retrieved chunks and the question.
  4. Generate the answer with the LLM, ideally with citations pointing to the chunks it used.

A tiny example

Say a college puts its student handbook into a RAG assistant. A student asks: "How many days of leave can I take before I lose exam eligibility?"

  • Retrieval finds the paragraph about attendance rules.
  • The prompt says: "Answer using only the handbook text below. If the answer isn't there, say so."
  • The model answers from that paragraph and cites the section number.

The model never memorised the handbook. It just read the right page at the right moment.

Why companies like RAG

BenefitWhy it matters
Uses private dataNo need to retrain a model on your documents
Easy to updateChange a document and re-index it; answers change right away
Fewer made-up answersThe model answers from real text you control
CheckableCitations let people verify the source

What RAG does not fix

RAG is not magic. Most problems come from the retrieval step:

  • If the right chunk is not found, the model cannot use it.
  • Bad chunking, for example a table split in half, gives the model broken information.
  • Messy or outdated documents give messy or outdated answers.

That is why good RAG teams test their retrieval separately from the final answer.

Try it yourself

The best way to really understand RAG is to build a small one. Our tutorial on building a RAG chatbot with Ollama and pgvector runs completely on your laptop with free, open-source tools. It also makes an excellent portfolio project.

Quick recap

  • RAG = retrieve relevant text, then generate an answer from it.
  • It lets an LLM answer from private and recent information.
  • Prepare once (chunk, embed, store); then per question (embed, retrieve, prompt, generate).
  • Most RAG quality problems are retrieval problems.

Rahul Agarwal

Instructor, SkillByAI

Web developer for 15 years. Teaches developers and founders to build real products with open-source AI tools.

Get the next tutorial by email

One email when a new post lands, with the code ready to run. No spam.

By subscribing you agree to receive emails from SkillByAI. Unsubscribe anytime.