What is RAG (Retrieval-Augmented Generation)?
RAG (Retrieval-Augmented Generation) is a method that lets a language model access current or private data it never saw in training (company documents, maintenance manuals, a database) through an external source while generating an answer. The answer is grounded in selected source text without retraining the model.
Why Is It Important?
Standard LLMs are limited to their training data, which has a cutoff date. They cannot know a fault code specific to your company or a procedure updated last month. RAG bridges this gap by:
- Retrieving the passages relevant to the question from a knowledge base.
- Augmenting the user's prompt with these passages.
- Generating an answer based on both the question and the retrieved data.
How Is RAG Built?
- Chunking: documents are split into slightly overlapping chunks of, for example, 300-800 tokens.
- Indexing: each chunk is turned into an embedding vector and written to a vector database.
- Search: the question is embedded too, and the k most similar chunks (e.g. k = 4) are found. Where exact matches matter, such as fault codes, it is combined with keyword search.
- Generation: the chunks are given to the model with an instruction such as "rely only on these sources and cite them".
Example: A Context Budget
A maintenance assistant retrieves 4 chunks of 500 tokens for each question:
- Retrieved chunks: 4 × 500 = 2,000 tokens
- System instruction and question: ≈ 300 tokens
- Reserved for the answer: ≈ 500 tokens
The total of ≈ 2,800 tokens fits comfortably even in the context window of small local models. Giving only the 4 relevant chunks instead of the whole manual (hundreds of pages) lowers cost and keeps the model focused on the right place.
Common Mistakes
- Chunking that splits tables: if a parameter table is split across two chunks, values get separated from their units.
- A stale index: if vectors are not regenerated when a manual changes, the system gives outdated information.
- No citations: if the operator cannot see which document an answer came from, they cannot verify it.
- Not measuring retrieval quality: when an answer is wrong, the problem is often the retrieved chunks rather than the language model; test retrieval separately.
Industrial Use Case
Imagine an AI assistant for a Cloud & IoT Platform. Using RAG, the assistant could look up the current status of a connected device or consult the latest user manual to help an operator troubleshoot a specific error code, without the AI model itself needing to be retrained.
Worked example: A Local LLM and RAG Agronomy Assistant. More: Industrial AI.
Related Terms
- What are Embeddings and Vector Search?What is an embedding? Turning text, images or signals into meaning-preserving vectors, a cosine similarity example and vector search in RAG systems.
- What is an LLM (Large Language Model)?What is an LLM and how does it work? Next-token prediction, its limits, and industrial uses in log interpretation, reporting and maintenance assistants.
- LLM Data Processing: Tokens, Embeddings, Temperature, HallucinationKey LLM input and output terms: tokens, embeddings, temperature and hallucination, with a softmax example and safe use on industrial data.
- What is Prompt Engineering?What is prompt engineering? Using role, context, constraints and examples, with a prompt that turns alarm logs into a JSON summary and common mistakes.
- Model Training and Optimization: Pre-training, Fine-tuning, LoRA, QuantizationWhat are pre-training, fine-tuning, LoRA and quantization? Core concepts for running models on edge devices, with parameter and memory examples.