Research Careers Contact

GlossaryRetrieval-augmented generation

Retrieval-augmented generation

Retrieval-augmented generation, or RAG, is a method where an AI system first retrieves relevant documents or data from an outside source and then gives them to a language model, so the model's answer is based on that material rather than only on what it learned in training. The term comes from a 2020 research paper that combined a retriever with a text generator.

How it works

A RAG system has two main parts: a retriever and a generator.

  1. Indexing. Source documents, such as datasheets, standards, specifications or work instructions, are split into chunks. Each chunk is turned into an embedding, a vector that captures its meaning, and stored in an index. Many systems also keep a keyword index.
  2. Retrieval. When a question arrives, the system turns it into an embedding and finds the chunks with the closest vectors, often combined with keyword search and filters such as document type, revision or product.
  3. Reranking. A second, more precise model reorders the top candidates. First-stage search compares the query with each chunk separately, which is fast enough for millions of passages and aims for recall. A reranker, such as a cross-encoder, reads the query and each candidate together and scores the fit, which aims for precision. It cannot recover a passage the first stage missed, so retrieve enough candidates.
  4. Generation. The selected chunks go into the model's prompt along with the question, and the LLM writes an answer from them, ideally citing which chunks it used.

The retrieval step can also call databases, APIs or search engines instead of a vector index. What makes it RAG is that the generation depends on content fetched for that question.

The collection a RAG system retrieves from is often called a knowledge base: the curated documents and facts an organization trusts. Its quality caps the system's quality. Each source needs an owner, a revision and a review date, superseded documents need to be removed or marked, and access control has to carry through, so retrieval respects who can see what. Resources in the Model Context Protocol give applications a standard way to expose those documents to a model.

In agentic RAG, the model or an agent decides when to retrieve, rewrites the query, retrieves again when results fall short and checks passages before answering, instead of running one fixed search. Research on self-reflective retrieval trained a model to decide when retrieval is needed and to critique what it retrieved.

RAG vs fine-tuning

Fine-tuning changes the model's weights by training it on more data, which shapes its behavior, style or skill at a task. RAG leaves the model unchanged and gives it information at the time of the question. RAG is the better choice when facts change, when answers must cite sources, or when the data is private and large. Fine-tuning suits teaching a model a format or task. Many systems use both.

Why it matters

Language models do not know a company's documents, and their training data goes out of date. Without a source, they fill gaps with plausible guesses. RAG gives them the right material at the right moment, which reduces hallucination and lets answers be checked against the source. It also lets a system update its knowledge by updating the index, with no retraining.

RAG is a form of grounding: tying a model's output to specific, trusted data.

How to get it right

  • Clean the source. Retrieval returns what is in the index. Remove superseded revisions, duplicates and drafts, or tag them clearly.
  • Chunk sensibly. Split documents along natural boundaries, such as sections, tables and pages, and keep enough context in each chunk to stand on its own.
  • Combine search methods. Pair embedding search with keyword search for part numbers, standards and exact terms, which embeddings handle poorly.
  • Filter by metadata. Restrict results by product, revision, date or document type where the question implies it.
  • Cite and check. Have the model cite the chunks it used, and check that its claims appear in them.
  • Measure retrieval. Track whether the right chunks were retrieved for a set of test questions, since a good model cannot answer from the wrong documents.

RAG in robotics and drone hardware

Electronics work runs on documents: datasheets, application notes, standards, design rules, change histories and test records. A RAG system over those documents can answer questions like which parts on a BOM have a given footprint, what a datasheet says about layout, or which past builds hit a defect, with a link to the source.

The details matter. Datasheets have many revisions, tables are easy to mangle in chunking, and part numbers need exact matching. Systems that handle those well are useful to hardware teams, and systems that do not produce confident, wrong answers.

Learn more