Skip to content
RAG13 MIN READ · UPDATED JAN 2026

What is RAG? The complete guide to Retrieval-Augmented Generation

The complete guide to Retrieval-Augmented Generation — chunking, embeddings, vector search, reranking, and how it compares to fine-tuning.

By AI-DE AI Platform Team·Reviewed JAN 2026
Quick answer

RAG (Retrieval-Augmented Generation) is a technique that combines semantic search with a language model. When a user asks a question, RAG retrieves the most relevant document chunks from a vector database, then passes them as context to the LLM to generate a grounded, citation-backed answer. It solves hallucination by giving the model real evidence at inference time — no retraining required. Learn RAG hands-on at /learn/rag or build a real system with /projects/enterprise-rag.

What is RAG?

RAG was introduced by Meta AI in 2020 as a way to combine parametric knowledge (what the LLM learned during training) with non-parametric knowledge (live documents in an external store). The key insight: instead of baking all knowledge into model weights, you retrieve it on demand.

In a naive setup, an LLM answers from training data alone — stale, unverifiable, and prone to hallucination. With RAG, every prompt is augmented with the top-K most relevant document chunks pulled from a vector store. The model now has actual evidence to ground its answer.

Two patterns dominate in practice. Naive RAG chunks documents at a fixed size, runs a single vector search, and hands results to the LLM — quick to build, fine for prototypes. Advanced RAG layers hybrid search (BM25 + vector), cross-encoder reranking, query rewriting, and retrieval monitoring — required for enterprise-grade accuracy and trust.

RAG is a data pipeline, not a chat feature. Chunking, embedding, indexing, and reranking all need the same care as any production pipeline: versioning, monitoring, and regression tests on retrieval quality.

SKILL · RAG

Master RAG in 5 hours, hands-on.

From chunking strategies to hybrid search and cross-encoder reranking. Builds a working RAG system end-to-end with evaluation metrics that catch retrieval regressions.

Why does RAG matter?

  • Answers are grounded in your actual documents — not the model's training cutoff
  • Citations include page numbers and similarity scores so users can verify
  • Knowledge updates require re-indexing, not retraining — minutes vs days
  • Context window is used efficiently: only the top relevant chunks, not the whole corpus
  • Retrieval explainability — you can show exactly why each chunk was chosen
  • Compliance is tractable — sensitive documents stay in your control plane

How does RAG work?

RAG is a four-stage pipeline. Documents flow in at ingest time; queries flow through at inference time.

  1. Ingest — parse documents, split into chunks, embed each chunk with an embedding model (OpenAI text-embedding-3-small, Cohere embed-v3, or open-source bge-large), store vectors + metadata in a vector DB (Pinecone, Weaviate, Chroma, pgvector)
  2. Retrieve — embed the user query with the same model, run vector similarity search for the top-K chunks (typically K=20), optionally add BM25 keyword search and merge the two ranked lists
  3. Rerank — pass the top-20 retrieved chunks through a cross-encoder reranker (Cohere Rerank, BGE reranker) to re-score for actual relevance and select the top 3–5
  4. Generate — build a prompt containing the user query plus the top reranked chunks, send to the LLM, stream the response, return citations linking each claim back to its source chunk

A minimal RAG pipeline in LangChain looks like this:

from langchain.vectorstores import Chroma
from langchain.embeddings import OpenAIEmbeddings
from langchain.chains import RetrievalQA
from langchain.chat_models import ChatOpenAI

# 1. Ingest: chunk + embed + store
vectordb = Chroma.from_documents(
    documents=chunks,
    embedding=OpenAIEmbeddings(model="text-embedding-3-small"),
)

# 2. Retrieve: top-4 relevant chunks
retriever = vectordb.as_retriever(search_kwargs={"k": 4})

# 3. Generate: LLM answers with context + citations
qa = RetrievalQA.from_chain_type(
    llm=ChatOpenAI(model="gpt-4o"),
    retriever=retriever,
    return_source_documents=True,
)
result = qa.invoke({"query": "What is our refund policy?"})

RAG vs fine-tuning

The single most common RAG question is: when do I retrieve vs when do I fine-tune?

ConcernRAGFine-tuning
Knowledge locationExternal documents (live)Baked into model weights
Update costRe-index documents (minutes)Retrain on GPUs (hours-days)
CitationsNative — every answer links to sourceImpossible — knowledge is opaque
Best forDynamic knowledge, enterprise docsStyle, tone, structured output
Failure modeBad retrieval = wrong contextCatastrophic forgetting, overfitting
Cost modelInference onlyGPU training + inference

Use RAG when knowledge changes. Use fine-tuning to change how the model responds, not what it knows. Many production systems combine both — fine-tune the model on the company's tone and structured output format, then use RAG to inject up-to-date facts.

RAG vs prompt engineering vs agents

RAG is one of four mainstream approaches to inject knowledge into an LLM. Each has a clear best-fit:

  • Prompt engineering — paste static context into every prompt. Works for small, stable knowledge sets that fit in the context window. Breaks down past a few dozen pages.
  • RAG — dynamically fetch the relevant context per query. Scales to millions of documents. The default for enterprise knowledge.
  • Fine-tuning — train the model on your domain. Better for changing model behavior than model knowledge.
  • Agents with tools — the LLM calls APIs (search, SQL, calculators) and reasons over the results. Best for multi-step reasoning over live data.

Most production AI features combine two or three. A customer-support copilot might use RAG for product docs, a fine-tuned model for response style, and a tool-using agent for live order lookups.

PROJECT · ENTERPRISE-RAG

Build a real enterprise RAG system end-to-end.

Multi-format ingestion, hybrid BM25 + vector search, cross-encoder reranking, retrieval explainability, monitoring, and Docker deployment. Handles 10K+ documents. Mentor-reviewed.

Common mistakes (and what to do instead)

  • Chunks too large or too small — 4,000-token chunks dilute relevance scores; 50-token chunks lose sentence context. Sweet spot is 256–512 tokens with 10–20% overlap. Tune per document type.
  • Vector search alone, no BM25 — vector search misses exact keyword matches like product names, error codes, and version numbers. Hybrid search (BM25 + vector) improves precision by 30–40% on enterprise corpora.
  • Skipping the reranker — vector similarity scores are noisy at retrieval time. A cross-encoder reranker re-scores the top-20 against the query and selects the actual top-4. Without reranking, quality drops noticeably.
  • No retrieval evaluation — most teams ship RAG without measuring retrieval quality. Track hit rate (was the answer chunk in the top-K?), MRR, and NDCG. Without metrics, you are flying blind.
  • Treating RAG as a chat feature, not a pipeline — chunking, embedding, indexing, and reranking all need versioning, monitoring, and regression testing — exactly like any production data pipeline.
  • Mixing embedding models across versions — re-embedding documents with a different model invalidates the entire index. Pin the embedding model + version in metadata.

Who is RAG for?

RAG is for AI engineers, ML engineers, and data engineers building grounded, citation-backed LLM features for production. If your product needs to answer questions from a knowledge base that changes more than once per quarter, RAG is almost certainly the right starting point.

Teams that benefit most:

  • Enterprises shipping internal Q&A copilots over wikis, runbooks, and policy docs
  • Support teams giving agents suggested answers with verifiable source links
  • Legal and compliance teams making contracts, regulations, and case law searchable in natural language
  • Data platform teams indexing logs, metrics, and runbooks for on-call engineers to query during incidents

Frequently asked questions

RAG (Retrieval-Augmented Generation) combines a retrieval system with a language model. When a user asks a question, RAG retrieves relevant document chunks from a vector database, then feeds them as context to the LLM to generate a grounded, citation-backed answer.
RAG works in four stages: ingest (chunk documents and generate embeddings), retrieve (embed the query and run vector search for top-K chunks), rerank (cross-encoder re-scores for precision), and generate (the LLM answers with retrieved chunks as context). The LLM never sees documents it does not need.
RAG injects real-time, updatable context into each LLM call — ideal for dynamic knowledge bases. Fine-tuning bakes knowledge into model weights, which is better for teaching consistent style or domain-specific reasoning patterns. Many production systems combine both.
Chunking splits source documents into smaller segments before embedding. Strategies include fixed-size chunking (around 512 tokens with overlap), recursive character splitting (paragraphs to sentences to characters), and semantic chunking on topic boundaries. Poor chunking is the single largest cause of bad RAG quality.
A vector database alone handles semantic search — finding similar documents. RAG adds a generation layer that synthesizes a natural-language answer from those documents. Use vector search alone when users need raw results; use RAG when they need a conversational answer grounded in those results.
What to do next

Start shipping.

Three steps from a guide to a job-ready portfolio. Pick one and start now — the rest will follow.

Start the RAG skillFREE TIER · NO CREDIT CARD
Press Cmd+K to open