RAG explained: how AI answers from your documents
GuideCaplan Artificial
Short answer. An assistant answers from your documents using retrieval-augmented generation, or RAG. It finds relevant passages in approved documents, price lists or instructions, answers from those passages and cites a source. The method depends on accurate, current documents and can struggle with missing material, conflicting versions or questions that require calculations.
A language model learned from public texts up to a certain date and knows nothing about your price list. If you ask it the price of item 4417, the answer will sound convincing and will most likely be wrong. RAG, short for retrieval-augmented generation, is a way to give it the correct data at the moment of the question.
How does the assistant use our documents to answer?
- Preparation. Documents are split once into shorter passages, from a paragraph to half a page, and stored in a searchable database. When a document changes, it is loaded again.
- Search. When someone asks a question, the system finds the few passages that best match it in meaning, even when they are not written in the same words.
- Answer. The model gets the question and those passages, with an instruction to answer only from them. Below the answer it names the document and the place the answer came from.
For example, a sales representative asks what the discount on paints is for a group B customer. The assistant finds the discount table and the current price list, answers in one sentence and lists both documents with their dates below.
Why does the assistant give a source with its answer?
Because an answer with a source can be checked in a few seconds. The employee opens the document and sees whether it really says what the assistant claims. Without a source they have to take it on trust, and in work involving money that isn't enough.
The source also helps when the assistant gets it wrong. You see straight away whether the cause is an old document, a wrongly retrieved passage or a poorly worded answer, and each of those mistakes is fixed by someone different.
A well set-up assistant also says when it doesn't know. If the documents do not contain the requested information, it says it did not find it and points to the person who knows.
Which documents does the assistant need?
- Current versions. One price list, one set of sales terms and one rulebook, each dated from when it applies. Old versions go into an archive outside the knowledge base.
- Text that can be read. Word, PDFs with text, Excel and intranet pages work well. Scanned papers are first converted to text and checked.
- Answers that already exist. Old emails to customers and instructions from the most experienced colleagues are often the most useful part of the knowledge base.
- An owner for every document. A person who confirms the document is accurate and reports when it changes.
You don't need everything at once. Start with the documents for one task, say the price lists and terms for sales representatives, and add the rest once the first part works.
How do you decide who can see which answers?
The assistant may show only what the person asking is allowed to see. If a warehouse worker has no access to payroll in the folder, they must not get it through the assistant either. So each document is stored with a record of who has access to it, and the search filters on that before the model sees a single passage.
An assistant that answers customers gets a separate knowledge base, holding only documents written for customers. Internal price lists and margins stay out of it, and management decides which documents each group can use.
Where can a document-based assistant go wrong?
- When a document is missing. If the export terms are not in the knowledge base and the assistant is not set up to admit it, it will fill the gap with something that sounds right.
- When documents disagree. Two price lists with different prices give two possible answers, and the assistant needs a rule for choosing the right one.
- When it needs to calculate. An order total or a discount on top of a discount is better left to a program. The assistant should find the rule and leave the arithmetic to a tool that calculates.
- When data changes all the time. The assistant should read stock levels and order status directly from the system, not from a document uploaded last week.
That's why the assistant is tested before rollout on real questions from past months, including ones the documents don't answer. Caplan Artificial builds a knowledge base from the documents you already have and sets up an assistant that cites the source with every answer.