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.

May guess
Questionfrom the user
LLMmemory alone
Answermay guess

With RAG

Retrieved evidence enters before generation.

Grounded
Questionfrom the user
Retrievesearch the index
Evidencetop matching chunks
LLMquestion + context
Answercites its source
Your documentsoutside the LLM

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.

Continue to Problem 1