RAG: how AI looks things up in your documents
From closed book to open book: what Retrieval-Augmented Generation is, how it works in four steps, and where you already use it.
A plain AI model is like a student in a closed-book exam: it can only answer from what it learned during training. That knowledge stops at a , and it has never seen your private files. , short for Retrieval-Augmented Generation, turns this into an open-book exam: before answering, the system looks up the right pages in a library you choose and puts them on the desk.
If context is the desk, RAG is the librarian standing next to it. Instead of piling the whole archive onto the desk, the librarian brings only the few pages that matter for your question.
How it works
- Cutting into passages (chunks): long documents are split into short pieces, often a few paragraphs each, ideally along headings so that no sentence is cut in half.
- A map of meaning (): each passage gets a position on a giant “map of meaning”. Passages about similar things sit close together, so a search for “reset my password” also finds a page that says “credential recovery”.
- Search and re-check: good systems combine this meaning search with a classic word search (for exact names and numbers) and then re-rank the best candidates. Only a handful make it onto the desk.
- Answer with sources: because the system knows which passages it used, it can show you where the answer comes from.
Mini RAG: ask the flat handbook
A shared flat has an 8-passage handbook. Pick a question and watch the search, the desk and the answer. A simplified simulation with made-up match scores.
- Search: how well each passage matches
HeatingWi-FiKeysRubbishWashing machineRentCleaningGuests
- On the desk
“Heating problems: call the caretaker, Mr Silva, on weekdays between 8:00 and 17:00.”
- Answer
Call the caretaker, Mr Silva, on a weekday between 8:00 and 17:00.
Source: Flat handbook › Heating
Why RAG is so useful
| Problem of a plain model | What RAG adds |
|---|---|
| Knowledge stops at a cutoff date | Fetches today’s documents or web pages |
| Has never seen your private files | Connects your handbooks, notes and PDFs when you ask |
| Guesses fluently when unsure | Gives concrete passages to work from |
| No way to check where an answer came from | Citations you can open and read |
You already use RAG
- Claude Projects: when the files in a project get close to the context limit, Claude automatically switches to searching them (on paid plans), which lets a project hold up to ten times more.
- Gemini Notebook answers only from the sources you upload, with citations.
- Web search in Claude, ChatGPT, Gemini or Perplexity is RAG with the internet as the library.
- Customer-service chatbots that answer with a link to a help article usually run on RAG.
RAG, a long desk or extra training?
| Approach | Picture | Best for |
|---|---|---|
| Long context | The whole binder on the desk | One fixed document, read as a whole (e.g. “what is missing in this contract?”) |
| RAG | A librarian fetching pages | Big, changing or private libraries, with sources |
| Sending the AI back to school | A fixed style or format, not for facts that change |
These are not rivals. Many real systems combine them: RAG picks the right documents, and a model with a large desk reads them together.
Check yourself
Tip: use ← and → to move between lessons.