AI search and RAG: how models find current facts
Models know nothing after their training ends, unless something looks it up for them. How web search and RAG work, where they fail, and how to read the citations.
2 min readPart 16 of 21
On this page
A model's knowledge stops where its training data ends, and it has never seen your files. To answer about this morning's news or your lease, something has to find the text and put it in front of the model. Doing that is called retrieval-augmented generation, or RAG. Web search in a chatbot is one form of it.
Looking it up, then answering
The name comes from a 2020 paper, which connected a language model to an index of Wikipedia. On questions of fact it beat models relying on their parameters alone, and its answers were more specific and more factual. Its authors also named two advantages that still hold: you can see where an answer came from, and you can update what it knows by changing the index, without training again.
- 1QuestionWhat you ask
- 2RetrieveFind relevant passages
- 3AugmentPut them in the text with your question
- 4GenerateThe model writes an answer from them
The model hasn’t learned anything. It was handed something to read.
Web searchPublic pages
For recent or public facts
Found through a search engine
Shows links
RAG over documentsYour files
For manuals, contracts, notes
Found through keywords or vectors
Should show the passage used
NeitherParameters only
From training
Stops at a date
No source to show
How web search works in a chatbot
The model doesn't browse the way you do. It's given a search tool and writes a request to use it; the app runs the search and returns the results as text.
- It decides whether to search. OpenAI says ChatGPT may search automatically when a question would benefit from current information; with Anthropic's tool, Claude determines when to search. In ChatGPT you can also choose Web search yourself.
- Your question is rewritten. OpenAI says that when it uses other search providers, it typically rewrites your question into one or more targeted queries, and those are what the provider receives.
- Results are filtered. Newer versions of Anthropic's tool let the model write code to filter results before they enter the context window, because a page full of menus and ads takes up space.
- It may search again if the first results aren't enough.
Pages are fetched by the provider's servers, not your computer, so the site sees the provider's address.
How RAG finds passages in documents
Documents are cut into passages in advance. When a question arrives, the system picks a few, by keyword, by vector similarity or both, and often a second model reorders them.
Why not give the model everything? For a short document, do. For a large collection it wouldn't fit, it would cost more for each question, and models use very long text unevenly.
Cutting is where many systems quietly fail. If "this doesn't apply to contracts signed before 2024" falls into the next passage, the retrieved one is accurate, relevant and misleading.
Where it goes wrong
- 1Didn’t searchAnswered from memory instead
- 2Searched badlyThe query missed what you meant
- 3Found the wrong pageOld, copied or unreliable
- 4Misread itThe page is right and the answer isn’t
- 5Cited looselyThe link doesn’t support the sentence
Search reduces hallucinations and doesn't end them. OpenAI's own page warns that search results and citations can be incomplete, outdated or incorrect, and advises opening the cited source to check that it supports the answer.
There's also a risk that didn't exist without search: pages are written by strangers, and text on a page can be aimed at the model. That's indirect prompt injection.
Reading citations well
- Is there one? No link on a factual claim means it may be from memory.
- Open it. Find the sentence that supports the claim.
- Look at the date of the page, not only of the answer.
- Is it the origin? A page that repeats a figure is weaker than the one that published it.
- Ask for it directly if not: "Use the official documentation, and give the date of the page."
When it matters that the answer is current, say so: "Search for this; don't answer from memory."