Context and RAG

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.

5 min3 / 4

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

1 PrepareYour documents are cut into short passages and sorted by meaning.
→
2 SearchYour question is compared with all passages.
→
3 PickOnly the few best matches go onto the desk.
→
4 AnswerThe AI writes from those passages and names its sources.
Step 1 happens once, in advance. Steps 2 to 4 happen every time you ask a question.
  • 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.

  1. Search: how well each passage matches
    Heating
    Wi-Fi
    Keys
    Rubbish
    Washing machine
    Rent
    Cleaning
    Guests
  2. On the desk
    “Heating problems: call the caretaker, Mr Silva, on weekdays between 8:00 and 17:00.”
  3. 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 modelWhat RAG adds
Knowledge stops at a cutoff dateFetches today’s documents or web pages
Has never seen your private filesConnects your handbooks, notes and PDFs when you ask
Guesses fluently when unsureGives concrete passages to work from
No way to check where an answer came fromCitations 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?

ApproachPictureBest for
Long contextThe whole binder on the deskOne fixed document, read as a whole (e.g. “what is missing in this contract?”)
RAGA librarian fetching pagesBig, changing or private libraries, with sources
Sending the AI back to schoolA 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.

Try it now: Upload two or three documents to Gemini Notebook or a Claude project and ask a question whose answer is in only one of them. Open the cited passage and check it.

Check yourself

1. What does RAG add to a plain language model?
2. Why can a meaning-based search find “credential recovery” when you ask about “resetting a password”?
3. Which job is fine-tuning good at?

Tip: use ← and → to move between lessons.