RAG

What Is RAG (Retrieval-Augmented Generation)? A Beginner’s Guide

RAG is the technique behind most "chat with your documents" AI tools. Here's exactly how it works, with no assumed background.

← Back to Blog

RAG (Retrieval-Augmented Generation) is a technique where an AI model first retrieves relevant information from an external knowledge source — like a company's documents or a database — and then uses that retrieved information as context to generate its answer, rather than relying only on what it memorized during training.

Why Does RAG Exist? The Problem It Solves

Large language models are trained on a fixed snapshot of data up to some cutoff date, and they don't know anything about your company's internal documents, your product manuals, or anything published after training. Two common failure modes result:

  • The model doesn't know the answer — because the information was never in its training data
  • The model "hallucinates" — it confidently generates a plausible-sounding but incorrect answer instead of admitting it doesn't know

RAG addresses both by giving the model the actual relevant text to read before it answers — similar to giving someone an open-book exam instead of asking them to answer purely from memory.

How RAG Works, Step by Step

  1. Ingestion: Your documents (PDFs, web pages, database records) are broken into smaller chunks of text.
  2. Embedding: Each chunk is converted into a vector — a list of numbers that captures its meaning — using an embedding model.
  3. Storage: Those vectors are stored in a vector database, indexed for fast similarity search.
  4. Retrieval: When a user asks a question, the question is also converted into a vector, and the database returns the chunks whose vectors are most similar (this is cosine similarity in most implementations).
  5. Augmentation: Those retrieved chunks are inserted into the prompt sent to the language model, alongside the user's question.
  6. Generation: The model generates its answer using both its general knowledge and the specific retrieved context — and can cite where the answer came from.

RAG vs. Fine-Tuning: What's the Difference?

RAGFine-Tuning
What it changesWhat context the model sees at answer timeThe model's own weights/parameters
Good forAnswering from a specific, changeable knowledge baseTeaching a model a new style, format, or behavior
How current is the knowledgeAs current as your document source — update anytimeFrozen at the time of training; needs retraining to update
Cost & complexityLower — no model training requiredHigher — requires training infrastructure and data
Can cite sourcesYes, naturallyNo, the knowledge is baked in invisibly

In practice, most production AI applications use RAG rather than fine-tuning for knowledge questions, because it's cheaper, keeps information current, and lets you show exactly where an answer came from.

What Is a Vector Database?

A vector database is a database optimized to store and search embeddings (vectors) efficiently, rather than exact text matches. Popular options include Pinecone, Weaviate, Chroma, and pgvector (a Postgres extension). What makes them useful for RAG is semantic search — they can find chunks that are conceptually related to a query even if they don't share the exact same words.

Common RAG Applications

  • Document Q&A tools ("chat with your PDF")
  • Customer support bots that answer from a company's help docs
  • Internal knowledge assistants for onboarding and policy questions
  • Legal and research tools that cite specific source passages

Limitations of RAG

RAG isn't magic — if the retrieval step returns irrelevant or poor-quality chunks, the generated answer will still be wrong (a "garbage in, garbage out" problem). Getting RAG right in production involves tuning chunk size, retrieval count, and re-ranking — which is exactly the kind of hands-on skill that's hard to learn from a definition alone and needs practice building a real system.

Sources & Further Reading

  • Lewis et al., "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks," Facebook AI Research, 2020 (arXiv:2005.11401)
  • Pinecone, Weaviate, and Chroma vector database documentation

Build a Real RAG Application in Week 2

In the Generative AI Launchpad, you'll build a working Document Q&A Assistant from scratch — ingestion, embeddings, vector search, and all — not just read about how RAG works.

View Course & Enroll