Guide

RAG explained simply: how AI answers from your documents

RAG (Retrieval-Augmented Generation) is the method by which an AI answers from your documents: it first searches for the relevant passages, then writes the answer on top of them and tells you where they came from. The model does not memorise your documents; it consults them for every question, much as you would use the index of a manual. Answer quality therefore depends on three things you control: how the documents are organised, how precise the question is, and whether the source gets checked.

Updated on 8 minutes’ readingBy LLMONTECH

What RAG is, in brief

A language model knows what it read during training, and that never included your manuals, your contracts or your mail. To make it answer from those texts there are two routes: retrain it, a long and costly job that has to be repeated whenever something changes, or let it consult the documents at the moment the question is asked.

The second route is RAG, described in a 2020 research paper by Lewis and colleagues. Its practical advantage is that the knowledge stays in the documents: update a file and the next answer relies on the new version; remove it and it stops appearing in answers. Think of a colleague who does not know the archive by heart but knows which binder to open and tells you on which page the information was found.

Step by step: the P-200 press manual

An invented example. The technical office of Rossi Meccanica S.r.l. loads the maintenance manual of its P-200 press, a PDF of many pages. A maintenance technician asks: “How many operating hours apart should the hydraulic fluid level of the P-200 be checked?” These are the steps, from loading to answer:

  1. Reading: the text is extracted from the PDF. If the file is a scan, the text must first be recognised in the image, letter by letter, through OCR.
  2. Splitting: the manual is cut into passages a few paragraphs long, called chunks, and each keeps a reference to its document and page.
  3. Representation: each passage is turned into an embedding, a long sequence of numbers that captures its meaning. Passages about similar subjects end up with sequences close to one another.
  4. Search: the question also becomes an embedding, and the system looks for the passages closest in meaning; at the same time it looks for passages containing the exact words, such as “P-200”.
  5. Answer: the best passages enter the model’s context together with the question, and the model writes the answer based on them.
  6. Citation: below the answer appear the document and the passage, in this case “P-200 manual, page 47”.

The two searches do different jobs. Searching by meaning finds the passage on “circuit lubrication” even if you typed “oil”; searching by exact words tells the P-200 from the P-250, one spare-part code from another, clause 12.3 of a contract from clause 12.4. Codes and numbers carry little meaning for a semantic search, and without exact matching two machines with near-identical names would be confused. LLMON runs both searches together.

Why the answer cites the passage

A language model writes fluent sentences even when the passage it found does not actually contain the answer. The citation lets you check in seconds: open page 47, read the value, compare. If the cited passage does not say what the answer says, discard the answer.

The citation also reveals which version was used. If the source shown is the 2019 revision of the manual while the workshop runs on the 2024 revision, you have caught an outdated document before it causes a mistake. In LLMON every answer built on the knowledge bases gives the document and the passage; for mail archives the source shows the message’s subject, date and sender.

An answer in the LLMON chat with, below the text, its source: the document’s name and the passage cited.
The source below the answer: where to start when checking a figure against the original.

How to prepare your documents

An AI that searches documents is only as orderly as the folders it draws on. A few rules applied before the archive is connected are worth more than any later setting:

  • Folders by department and by subject: in LLMON a NAS sub-folder can become a department’s knowledge base, visible to that department only.
  • One valid version: move superseded revisions to an archive outside the connected folder, otherwise the search finds both.
  • Meaningful names: “P-200_manual_rev2024.pdf” rather than “scan0034.pdf”, because the name appears in the citation and lets you recognise the source at a glance.
  • Native PDFs where they exist: a PDF exported from a word processor already holds the text, while a scan is an image, and recognition can fail on stamps, handwriting, skewed pages or faded copies, reading an 8 as a 3, for example.
  • Mail saved as files: .eml, .mbox and .msg archives become searchable documents; a .pst archive has to be converted first.

When connected to shared folders, LLMON re-reads them at regular intervals: a changed file replaces the previous version and a deleted file drops out of the answers, while an empty or unreachable folder removes nothing. A read-only account is recommended for access; details are in the shared folders section.

How to ask good questions

A knowledge base is queried, not read in full: the system hands the model a limited number of passages, the ones most relevant to the question. A question that names the object, the document and what you want to know finds the right passages; a generic question finds generic ones.

Questions that work and questions that work badly
Good questionQuestion that works badlyWhy
“In the P-200 manual, how many hours apart should the hydraulic fluid be checked?”“How is maintenance done?”The second names neither the machine nor the task
“What penalty does the 2025 framework contract with Supplier Alfa set for late delivery?”“List every contract with a penalty”The search returns a few passages, not the whole archive, so the list would be incomplete
“What is the spare-part code for the main cylinder seal of the P-200?”“Which spare parts does the press need?”Without a specific component, the passages found are too many and too varied
“Summarise the termination terms in the contract with client Bianchi”“What do our contracts say?”A question about everything yields a summary of a few passages picked almost at random
“Compare the warranty clause in the 2023 and 2025 revisions of the contract with Supplier Alfa”“Has anything changed?”The system cannot tell what to compare against

If an answer misses the mark, rephrase it using the document’s own words: if the manual says “hydraulic fluid”, typing “oil” works less well. You can also ask for the passage to be quoted verbatim, which makes the comparison with the original immediate.

Why “list all documents” works badly

Search returns the most relevant passages, not a census. Ask how many contracts contain a penalty and the model sees only the few passages retrieved, so it may answer “three” when there are forty, with nothing to warn you. For an inventory, the right tool is still the list of files in the folder.

Widening the context does not fully solve this: a 2023 study by Liu and colleagues found that models make less use of information placed in the middle of a very long context than of information at its beginning or end. Many precise questions therefore beat one all-encompassing question.

When the answer is wrong: how to notice

  • Contradictory documents: two versions with different values, and the model picks one or blends them. The sign: citations from two different files, or from an old revision.
  • Outdated document: the answer is faithful to the text, but the text no longer applies. The sign: the date or revision in the source’s name.
  • Missing passage: the information is not in the documents and the model fills the gap with general knowledge. The sign: no source, or a source that does not contain the figure given.
  • Badly read scan: altered digits or codes. The sign: odd characters or broken words in the cited passage.
  • Similar codes: the answer concerns the P-250 instead of the P-200. The sign: the source is another machine’s manual.
  • Split table: chunking separated a table from its header row. The sign: a value given without its unit or the column it belongs to.

Many of these errors are prevented upstream, by the folder discipline described above; the rest are caught by reading the source. LLMON’s knowledge bases are described on the Product page, and the 8-question readiness check helps you judge how ready your documents are.

Sources

  1. Lewis et al. (2020), “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks”
  2. Liu et al. (2023), “Lost in the Middle: How Language Models Use Long Contexts”
  3. Product: documents and knowledge bases (RAG)
  4. Product: connecting the NAS and shared folders

LLMON at work on documents, in a live demonstration.

In a 30-minute video call we show you the chat, the knowledge bases and the admin dashboard, and answer your company’s questions.

Book a demo

A 30-minute video call: LLMON live on sample documents, with answers to your questions.