RAG (retrieval-augmented generation)
A language model only knows patterns from its training data. It does not automatically know your private documents, fresh information after its training cutoff, or niche details that were not well covered during training. When asked about something outside what it knows, it may still produce a fluent answer that sounds confident while being wrong. This is called hallucination.
RAG, retrieval-augmented generation, adds a retrieval step before the model answers. Instead of answering from memory alone, the system first retrieves relevant documents and gives them to the model as context. The model can then answer from real, specific, current sources rather than guessing from training patterns.
The pipeline has three steps. First, Retrieve: find the document chunks most relevant to the question. Second, Augment: insert those chunks into the prompt alongside the question. Third, Generate: the model writes an answer grounded in the provided chunks.
Retrieval usually uses embeddings. The question is turned into an embedding, and each document chunk has one too. The system finds the chunks whose embeddings are closest to the question's. Closeness means relevance, the same similarity idea from the embeddings topic: nearby vectors usually mean related meaning.
RAG matters because it lets a model answer about things it was never trained on, like private data or recent information. It also reduces hallucination, because the answer is grounded in retrieved text rather than guessed from memory. And you can update what the system knows by changing the documents, with no retraining.
The figure below uses a small hand-authored knowledge base and illustrative similarity scores, not real embeddings or a real model, but the retrieve, augment, generate pipeline is the real architecture.
Retrieve, augment, generate
Retrieval-augmented generation, step by step
- Nimbus Robotics was founded in 2021 and is based in Lisbon, Portugal.
- The Nimbus R2 has a 5200 mAh battery and runs for 180 minutes on a full charge.
- Nimbus offers a 2-year warranty, and returns are accepted within 30 days of delivery.
- Voice control for the R2 was added in firmware 3.4, used through the Nimbus app.
- The R2 maps your home with lidar and can store up to 5 separate floor plans.
- Nimbus support is open 9am to 6pm WET, Monday to Friday.
Illustrative only: the similarity scores and both answers are hand-authored, not from a real embedding model or language model. The pipeline, retrieve then augment then generate, is the real architecture. Retrieval reuses the embeddings idea: the question and each chunk become vectors, and closeness means relevance.
- knowledge base
- 6 chunks
- retrieved
- —
- grounded
- —