In this lesson
RAG is the AI taking an open-book exam. It looks through your material before it answers.
You will understand how the AI answers based on your documents, without training anything, and how to check whether it got it right.
- Explain RAG with an everyday example
- Upload documents and ask questions that come back with a source
- Test the question that has no answer
The open-book exam
Picture an exam where you are allowed to look at your notebook. Before answering, you find the right page. Then you write the answer in your own words and point to the page.
RAG does the same. The name means, roughly, "generation with search". There are three steps:
- The documents are cut into small pieces, and each piece gets a "fingerprint" that represents what it is about.
- When you ask a question, the system finds the pieces most similar to it.
- The model receives the question plus those pieces and writes the answer, pointing to where it came from.
Notice: the model did not learn anything new. It just read the right material at that moment.
Why this is good
You replace a document and the answer changes the same day, with no training. You can check it, because the answer comes with the passage. And the document stays on your machine.
Picture a real estate agency that uploaded its contract templates and internal rules. Now an agent asks "what is the notice period for termination?" and gets the right clause, with the file name.
How to use it with ready-made tools
In Open WebUI you create a collection of documents and attach it to the conversation. No programming needed. Start small: three documents, five questions.
- Choose documents with real text. A PDF scanned as a picture needs text recognition first.
- Ask questions you already know the answer to, so you can check.
- Always ask: "answer only based on the documents and cite the passage".
Test the question with no answer
The most important test is asking something that is not written anywhere. The right behavior is for the AI to say "I did not find it in the documents". If it makes something up, adjust the fixed instructions and test again. A RAG that never says "I don't know" is dangerous, because it looks reliable.
When RAG is not the answer
RAG is good at finding one fact among many documents. It is bad at adding up numbers from spreadsheets or comparing a hundred contracts at once. There are other tools for that. Choose by the problem, not by the trend.
Also, do not expect it to cover what the document does not say. If the contract says nothing about a penalty, the AI must not invent one. The system's job is to find, not to guess.
A complete example
Picture a building supplies store that uploaded its catalog and its return policy. The salesperson asks: "customer wants to return an opened bag of cement, is that allowed?". The AI finds the passage in the policy about opened products, answers "no, only sealed packaging within seven days" and shows the file it took that from. The salesperson checks it in ten seconds and answers the customer with confidence.
Without RAG, the same question would get a generic answer, written with the same confidence, but about the policy of some other store.
What the pros know
When the system hands many passages to the model, position matters. A 2023 study showed that models make better use of information at the beginning or at the end of the text and worse use of what sits in the middle, even models built for long texts. So when the right answer was among the passages and the reply still came out wrong, it is worth testing a different number of passages and a different order.
Practice · 10 min
- Upload three test documents, with no real data, to an Open WebUI collection.
- Ask five questions and check the passage cited in each one.
- Ask something that is not in the documents and see whether it admits it did not find it.
Summary
- RAG means searching your files and answering based on them, citing the source.
- The model learns nothing: it reads the right material on the spot.
- Always test the question with no answer.
- The order and the number of passages handed to the model change the answer. Test it.
Sources
Read on October 30, 2026.
- Liu et al. Lost in the Middle: models make better use of information at the beginning or at the end of a long input (2023).
Lesson quiz
Three situations to apply what you learned.
Isaque Victor free courses