Skip to content

What is RAG? How AI answers from your documents

RAG (Retrieval-Augmented Generation) is a way for AI to answer questions from specific documents - your company's policies, for example - rather than only from the model's "memory". First the system finds the passages that match the question, and only then does the model write an answer based on them.

In short

  • A language model does not know your documents. RAG searches them for matching passages on every question and hands those to the model.
  • The search works by meaning, not by words - a question about "annual leave" also finds the paragraph about "holiday allowance".
  • Answers are more up to date and can cite their source, but they still deserve a check.

The open-book exam

Remember exams where you could bring your notes? You did not have to know everything by heart - just where to look, find the right page and answer from it.

An LLM without RAG sits the exam from memory: it answers with what it learned in training. About your staff handbook, price list or product documentation it knows nothing. RAG hands it the open book: with every question, it slips in the right pages from your documents.

How it works, step by step

First, once, the documents are prepared:

  1. Chunking - the documents are split into pieces, a few paragraphs each.
  2. Embeddings - each piece is turned into a list of numbers that describes its meaning. Pieces with similar content get similar numbers, even when they use different words.
  3. A vector database - those numbers go into a database that can quickly find the pieces closest in meaning.

Then, on every question:

  1. The question is turned into numbers too, and the system looks for the closest pieces.
  2. The best few pieces go into the prompt, along with an instruction like: "answer using the passages below and cite the source".
  3. The model writes the answer - not from memory this time, but from the material it was given.

So RAG is really a good search engine plus a language model that can sum up what the search found.

Why not just paste in the whole document?

With a single document, that is often exactly what people do - and it works. Today's models have large context windows. But a company knowledge base runs to thousands of pages that will not fit, and even if they did, every question would cost a fortune in tokens and take ages. RAG picks only what is needed.

What about training a model on your own documents? Pricier, slower, and poorly suited to facts that change often. Update your prices, and with RAG you swap one document and you are done.

Where you meet RAG

  • "Chat with your PDF" - you upload a document and ask questions about it.
  • Company assistants - answer staff questions from internal procedures.
  • AI search in notes, cloud documents and knowledge bases.
  • Search engines with AI answers - essentially RAG over the whole web: find pages first, then answer with links.

Limitations

  • Poor search, poor answer - if the system does not find the right passage, the model answers from the wrong one, or fills in the rest itself. RAG reduces hallucinations but does not end them - which is why an answer should always point to its source.
  • Outdated documents - RAG repeats whatever is in the database. An old version of a policy in there means an old answer.
  • Permissions - if HR documents end up in the database, the assistant may quote them to someone who should never see them. Good systems check permissions when they search.
  • Privacy - uploaded documents go to the service provider. Before uploading anything with personal data, read AI and privacy or anonymise the text first.

When it matters to you

  • You ask a chat about your own document - you are already using RAG, or something very close to it.
  • Your company wants "a chat that knows our procedures" - that will almost always be RAG. The hard part is not the model but getting the documents in order.
  • You are choosing an AI tool for work - check whether it shows the sources of its answers. It is the simplest test of whether you can trust it.

LLM, prompt, embedding, vector database, AI agent.

Advertisement