RAG (Retrieval-Augmented Generation)

Grounding a model’s answers in external data via embeddings and a vector store.

Goal

The goal of RAG is to retrieve relevant information from an external data source and add it to the prompt before the foundation model generates an answer. This lets the model answer from your organization’s data instead of relying only on knowledge learned during training.

Basic pipeline

Collect documents → parse → chunk → embed → store in a vector store → retrieve → augment → generate.

flowchart LR
    D[Documents] --> P[Parse]
    P --> C[Chunk]
    C --> E[Embed]
    E --> V[(Vector store)]
    Q[User question] --> R[Retrieve]
    V --> R
    R --> A[Augment prompt]
    A --> M[Foundation model]
    M --> Ans[Answer]
StepRole
ParseRead and extract content from PDF, Word, HTML, or other sources
ChunkingSplit documents into small passages for more precise retrieval
EmbeddingConvert text into numeric vectors that capture semantic meaning
Vector storeStore and index the embeddings
RetrievalFind the passages most relevant to the user’s question
AugmentationInsert the retrieved content into the prompt as context
GenerationThe foundation model uses that context to produce the answer

Embeddings

An embedding converts text into a numeric vector that represents its meaning — text with similar meaning maps to nearby vectors. Use the same embedding model for both documents and the query, and measure relevance with cosine similarity.

Vector database

A vector store stores and indexes embeddings and performs similarity search (often approximate-nearest-neighbor for speed). Examples: pgvector, FAISS, Pinecone, Chroma, Weaviate.

When to use RAG

  • Internal data changes frequently.
  • Answers must be based on company documents.
  • You need to cite sources or keep references.
  • You want to reduce hallucination with trustworthy context.
  • You don’t want to retrain the model every time data changes.
  • You need to control the scope of knowledge the model can use.

RAG vs. fine-tuning

Suppose a company has thousands of product manuals updated weekly. With fine-tuning, they may need to retrain the model every time documents change. With RAG, they only update the data source and re-sync the embeddings. The full comparison — including prompting as the third lever — is in Adaptation.

Variants

“RAG” is a family, not one design — standard, advanced, self-correcting, graph, multimodal, and agentic. And some things you’ll hear (hybrid search, re-ranking) are techniques used inside a variant, not separate types. See Types of RAG to tell an architecture from a control loop from a technique.

Strengths & limitations

  • Strengths — fresh, private, and citable knowledge without retraining; reduces hallucination; update by re-syncing data.
  • Limitations — answer quality is capped by retrieval quality; adds an ingestion pipeline, a vector store, and latency; needs chunking and evaluation tuning.

Sources

  • Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (2020) — arXiv:2005.11401
  • Es et al., RAGAS: Automated Evaluation of Retrieval Augmented Generation (2023) — arXiv:2309.15217