What Is RAG (Retrieval-Augmented Generation)? A Clear Guide
8 min readUpdated October 29, 2026
Retrieval-augmented generation (RAG) gives a language model relevant documents at question time, so it answers from your data instead of from memory. The term comes from a 2020 paper by Lewis et al., and today RAG powers most "chat with your docs" products, support bots and internal assistants.
Why RAG exists
LLMs only know what was in their training data, which stops at a knowledge cutoff and doesn't include your private documents. Ask about your refund policy and the model will guess, fluently and confidently. RAG fixes that by retrieving the actual policy and putting it in the prompt, ideally with citations the user can check.
How a RAG pipeline works
Indexing (ahead of time):
- Load documents and clean them.
- Split them into chunks (for example ~500 tokens with some overlap).
- Turn each chunk into an embedding vector.
- Store vectors plus metadata in a vector database.
At question time:
- Embed the question with the same embedding model.
- Retrieve the top-k most similar chunks (often with hybrid keyword + vector search and a reranker).
- Build a prompt: instructions, numbered sources, the question.
- Generate an answer that cites the sources, or says "I don't know".
Common mistakes
- Embedding queries with a different model than the documents.
- Chunks that are too big (noisy) or too small (no context).
- No metadata, so you can't filter or cite.
- Pure vector search missing exact terms like error codes or SKUs. Use hybrid search.
- Never measuring retrieval, so you can't tell whether bad answers come from search or from generation.
How to evaluate RAG
Measure the two halves separately. For retrieval, label which chunk answers each test question and track recall@k and MRR. For generation, grade faithfulness (is every claim supported by the sources?) and answer relevance, usually with an LLM judge spot-checked by humans.
RAG vs fine-tuning
Use RAG for knowledge: facts that change, private data, anything that needs citations. Use fine-tuning for behavior: consistent format, tone or a narrow task at lower cost. Fine-tuning is a poor way to add facts: they go stale and can't be cited.
Practice what you just read
▶Practice it hands-onEmbeddings & Similarity▶Practice it hands-onChunking Documents▶Practice it hands-onBuilding a RAG Pipeline▶Practice it hands-onHybrid Search & Reranking▶Practice it hands-onEvaluating RAG: Recall, MRR & FaithfulnessFrequently asked questions
Does RAG eliminate hallucinations?
No, but it reduces them a lot when retrieval finds the right text and the prompt requires citations and allows "I don't know".
What database do I need for RAG?
Any store that supports vector similarity search: Postgres with pgvector (including Supabase), or dedicated vector databases like Pinecone, Qdrant, Weaviate or Chroma.