Retrieval-augmented generation explained with your own documents

RAG lets an AI system answer from your documents instead of its memory: find the relevant passages, then write from them. How it works and where it fails.

3 minread 674words last updated

The short answer

A language model on its own answers from patterns it learned in training. It does not know your policies, your prices or your procedures, and when asked about them it produces a plausible guess. Retrieval-augmented generation, RAG, fixes that by changing the order of operations: first search your documents for the passages relevant to the question, then hand those passages to the model together with the question and an instruction to answer only from them. The answer comes from your material, with citations, and it changes when your documents change.

It is the pattern behind nearly every useful business AI system, from internal search to customer-facing assistants.

Four steps: a question arrives; the system retrieves the most relevant passages from your documents; the model generates an answer from the question and those passages with an instruction to answer only from them; the answer is returned with the passages cited.
Retrieval first, then generation. The model never has to remember your facts; it is handed them.

The four steps

  1. Index. Your documents are split into passages and indexed so they can be searched by meaning, not just by keyword. Done once, and again whenever a document changes.
  2. Retrieve. A question comes in. The system finds the passages most relevant to it, typically a handful.
  3. Generate. The model receives the question, the passages, and instructions: answer from these, cite them, and say so if the answer is not there.
  4. Answer. The response, with references to the passages used, so a person can check it.

Why it beats a plain chatbot

Model aloneRetrieval-augmented
Source of factsTraining data, frozenYour documents, current
When your policy changesThe answer does notThe answer changes when the document does
CheckableNoYes, against the cited passages
Says “I do not know”Rarely; it guessesBy instruction, when nothing relevant is retrieved
Data leaving your controlDepends on the providerSame, plus you choose which documents are indexed

Where it fails, and what to do

  • The right passage was not retrieved. The question used different words than the document, or the passage was split badly. Fix: better indexing, more passages, testing with real questions.
  • Documents disagree. Drafts, old versions, contradictory sources. Fix: clean the store before indexing; one current version of each thing.
  • The answer needs reasoning across many sources. A single retrieval step is not enough. Fix: multi-step retrieval, or a person for that class of question.
  • The model answers anyway. No relevant passage, but a fluent guess. Fix: strict instructions, and a check that the answer references retrieved text.

What this means for you

If you want an AI system that answers about your business, retrieval-augmented generation is the approach, and the documents are the project. Clean them, keep one current version of each, index them, test with real questions, and instruct the system to say when it does not know. Done that way, the assistant is as accurate as your documentation, which is the right thing for it to be.

Written by the CivSec S.M.A.R.T team

We build and run websites, software and AI systems for businesses. We write about what we see in that work, in plain language, and we update articles when things change.

Last checked . Spotted something outdated? Tell us.

Frequently asked questions

Why not just train the model on our documents?

Training is slow, expensive, hard to update and does not give citations. Retrieval works with the documents as they are today, updates the moment a document changes, and shows which passages the answer came from. For nearly every business use, retrieval is the right approach and training is not.

What documents work well?

Clear, current, non-contradictory ones: policies, procedures, product specifications, past answers that were approved, manuals. What works badly: drafts next to finals, five versions of the same policy, documents nobody has reviewed in years. The system will retrieve the wrong version as happily as the right one.

Can it answer questions the documents do not cover?

It should say that it cannot, and a well-built system is instructed to do exactly that. A system that answers anyway, from the model's general knowledge, has left retrieval behind and is now guessing. The 'I do not have that information' response is a feature.