SprintMeUp

RAG: answers from your own documents

The AI first finds the right page in your documents, then answers from it, and tells you where it found it.

What the letters mean

RAG stands for Retrieval-Augmented Generation: first find the right passages in your documents (retrieval), then write the answer from them (generation).

The need

In stage 1 you saw that an AI answers from what it learned in general, and can be wrong with confidence. Your own documents, contracts, policies, manuals, it has never read. RAG gives it those documents for each question, so the answer comes from them and can be checked.

An everyday example: “Am I covered?”

A storm floods your cellar. You have a folder of PDFs: home insurance, contents insurance, the rental contract, the warranty of the washing machine. Forty pages of small print. You ask:

“Am I covered if water gets into the cellar after a storm?”

  1. YouAsk in plain wordsThe question above, nothing more.
  2. AIFinds the passagesThe clauses about water damage and storms, in two policies.
  3. AIAnswers from themOnly from those clauses, not from memory.
  4. AIShows where“Contents insurance, page 12, clause 4.2”.
  5. YouCheck the pageOne click, and you read the clause yourself.

How your documents are prepared

This is the part that makes RAG work, and the part that needs the most care. It happens once, before the first question, and again when a document changes.

  1. Cut into pieces. Each document is cut into short passages of about half a page, so the AI can be given just the clause that matters, not the whole policy.
  2. Turned into numbers that describe the meaning. Each passage is turned into a long list of numbers that describes what it is about. Two passages that mean the same thing get similar numbers, even with different words: “water damage” and “flooding” end up close.
  3. Kept in a database that searches by meaning. The passages and their numbers go into a vector database: a database that finds passages by meaning, not by exact words.
  4. Each question is turned the same way. Your question becomes numbers too, and the database returns the few passages closest in meaning.
  5. The AI writes from those passages. It is told to answer only from them, and to say where each part comes from.
RAGInformation from your documentsYour documents are scanned and stored; each question gets its answer from them YOU your documents, your question writes only from what was foundAI BUILDING THE KNOWLEDGE BASE once, and again when a file changes ASKING a person or an application YOUR DOCUMENTS manuals, contracts, rules A QUESTION Are the courses online or on-campus? THE ANSWER with its source The AI answers from it 1 Find files shared folders you choose 2 Scan every document is read 3 Store in a database made for search ? 1 Ask a question in plain words 2 Search finds the right passages ? 3 Answer written from those passages again when a file changes the knowledge base the answer, with its source RAGInformationfrom your documentsYour documents are scanned and stored;each question is answered from themBUILDING THE KNOWLEDGE BASEonce, and again when a file changesASKINGa person or an application YOU YOUR DOCUMENTS manuals, contracts, rules 1 Find files shared folders you choose 2 Scan every document is read 3 Store in a database made for search YOU A QUESTION Are the courses online or on-campus? ? 1 Ask a question in plain words 2 Search finds the right passages ? 3 Answer written from those passages AIwrites only from what was found The AI answers from it THE ANSWER with its source again when a file changes the knowledge base the answer, with its source

How it is built for a company

  1. Find where the documents are. The shared folders, drives or document systems that hold the knowledge.
  2. Set the rules. Which folders and files go in, who may see what, how often it is updated.
  3. Prepare the database. The database that searches by meaning, described above.
  4. Scan the documents. Every document is read, cut and stored, and scanned again when a file changes.
  5. Ask. A person in a chat, or an application, asks a question.
  6. Use the answer. It comes back with its passages; the person reads it, or the application uses it, for example in a report.

What it does not do

It only knows what is in the documents: an out-of-date document gives an out-of-date answer, and a question the documents do not cover should get “I don't know”. If the search picks the wrong passage, the answer is wrong too, which is why it must always show where it looked. It does not decide who may read what; the rules set in step 2 do.

It costs a little on every question: the passages it adds are read by the model and counted in tokens, plus the place where the database is kept.

Next · stage 6Keep it safe and goodLimits, your yes, checks and traps