RAG (Retrieval-Augmented Generation)

Definition: A technique where the model first retrieves relevant documents from a specific source — your files, a database, a website — and then generates its answer grounded in what it actually found, rather than relying only on what it memorized during training.

Why it matters: It sharply reduces hallucination for anything the retrieval step actually covers, because the model is summarizing a real document in front of it rather than generating an answer purely from memory — though it's only as accurate as the documents it retrieves from.

Example: A support chatbot that quotes your actual help-center articles when answering, instead of generating a plausible-sounding answer from general training data.

How RAG works, step by step

  1. Prepare: split your documents into chunks and index them, usually as embeddings (numbers that capture meaning) and often with keyword search too.
  2. Retrieve: when a question arrives, find the few chunks most related to it.
  3. Generate: send those chunks to the model with the question, and ask it to answer from them and cite them.

When to use RAG

  • Your knowledge base is larger than the model's context window, or too expensive to send on every request.
  • The information changes often: prices, policies, stock, help articles.
  • You need answers that point to a source a person can check.

If your documents are small and stable, simply putting them in the prompt (long context) can be simpler and just as accurate.

Why RAG systems fail

  • Bad retrieval: the right passage was never found, so the model answers from memory or hallucinates.
  • Bad chunks: a table or a rule split in half loses its meaning.
  • Stale index: documents changed but the index wasn't updated.

Test retrieval on its own first: for a set of real questions, check whether the correct passage appears in the top results. Most RAG quality problems are found there.

Learn more on Lumis