What is RAG?
Introduction
Project introduction
What is RAG?
A language model answers from information learned during training and information placed in its current conversation. It does not automatically know a private handbook, your product documentation, or a document published after its training data was collected.
RAG stands for Retrieval-Augmented Generation. Before the model answers, the application searches a trusted document collection for passages related to the question. It places those passages beside the question, then asks the model to answer from that evidence and cite the sources it used.
For a longer walk through every stage, from chunking to grounded answers, read the RAG explainer.
Why split documents into retrieval chunks?
A long document may discuss many unrelated topics. Searching it as one large block makes it difficult to identify the small passage that answers a specific question. RAG systems therefore divide documents into shorter passages called chunks.
Each chunk keeps its text, an identifier, and its source. A small overlap between neighboring chunks can preserve a sentence or fact that crosses a boundary. Later, retrieval ranks these chunks and sends only the most relevant evidence to the model.
Without retrieval
The model relies on memory alone.
With RAG
Retrieved evidence enters before generation.
The three parts of a RAG system
01
Prepare documents
Split documents into searchable chunks and keep the source attached to every chunk.
02
Retrieve evidence
Compare the question with the chunks and select the passages most likely to contain the answer.
03
Generate an answer
Give the question and retrieved evidence to the model, then require an answer grounded in those sources.
Start with document preparation
The first coding problem turns a document into searchable chunks.