Category · Data and retrieval-augmented generation
What is RAG (retrieval-augmented generation)?
RAG (retrieval-augmented generation) means searching before answering. The right passages are first found in a document base, then given to the model along with the question. The answer is up to date, and it cites its sources.
By Laurent Poupet, Claude trainer and artificial intelligence architect · Updated
How it works
- The pipeline runs in two stages: documents are prepared in advance, then, for each question, the passages are retrieved and the answer is written.
- Quality depends above all on retrieval; if the right passage is not found, even the best model in the world cannot give the right answer.
- It is evaluated in two parts: retrieval, with the recall and precision of the passages, and the answer, with its faithfulness to the sources and its relevance.
The trap to avoid
The trap is permissions; the index must respect the permissions of the source documents, otherwise the assistant shows people what they should never have seen.
A concrete example
An employee asks the internal assistant “how many remote-work days am I entitled to?”. The system first searches the company agreement for the two or three passages on the subject, gives them to the model with the question, and the answer cites the article of the agreement. Without that search, the model would answer from memory, with a general rule that may not be yours.
What is the difference with fine-tuning?
| Criterion | RAG (retrieval-augmented generation) | fine-tuning |
|---|---|---|
| What changes | The documents given to the model with each question | The model’s weights, retrained |
| Updates | Re-index a document, and it is immediate | The model must be retrained |
| Cited sources | Yes, the retrieved passages | No |
| Good fit | Facts that change, internal documents | A style, a format, a repetitive task |
Related terms
- RerankerData and retrieval-augmented generation
- EmbeddingData and retrieval-augmented generation
- Cosine similarityData and retrieval-augmented generation
Where this is taught
This idea comes up throughout the lessons; we work on it with your own examples during a lesson.
Lesson content (step-by-step instructions, exercises with solutions, quizzes) is for students only, with an access code received after the first lesson.