The problem it solves
A language model on its own answers from patterns it learned during training. That works for general knowledge. It does not work for your company handbook, your product manuals, last month's meeting notes or the thousands of support tickets in your helpdesk. The model never saw them. Ask about them and it will either say it does not know or, worse, produce a confident guess.
The obvious fix is to paste the right document into the chat, and for one document that works well. But what if the answer is somewhere in five thousand documents? You cannot paste them all, they would not fit in the model's context window, and you do not know which one holds the answer.
Retrieval-augmented generation, usually shortened to RAG, is the standard way to solve this. It is behind many "chat with your documents" features, internal company assistants and support bots.
The idea in one sentence
Before the model answers, a search step finds the few passages most likely to contain the answer and puts them into the prompt, so the model answers from those passages instead of from memory.
That is all the name means. Retrieval: find relevant text. Augmented: add it to the prompt. Generation: the model writes the answer. It is the same "give it the source" habit from the prompting lessons, automated.
How it works, step by step
A typical RAG system has two phases: preparing the documents once, then answering each question.
Preparing the documents:
- Collect the documents you want the assistant to use: PDFs, web pages, notes, tickets.
- Split them into chunks, such as a few paragraphs each, because a whole manual is too big to hand to the model and too vague to search well.
- Index the chunks so they can be searched. Many systems turn each chunk into an embedding, a list of numbers that represents its meaning, so that searches can find passages about the same idea even when the words differ. Others use ordinary keyword search, or both.
Answering a question:
- Search. The user's question is used to find the handful of chunks that match best.
- Build the prompt. Those chunks are placed into the prompt along with the question and an instruction such as "answer using only these passages and cite them".
- Generate. The model reads the passages and writes the answer, ideally with references to where each point came from.
From the user's side, it just looks like a chat that knows about your documents.
Embeddings in plain words
The search step is where much of the cleverness sits, so it is worth understanding one term you will see a lot: embeddings.
An embedding turns a piece of text into a long list of numbers that captures roughly what it is about. Texts with similar meanings end up with similar lists. "How do I reset my password?" and "I forgot my login details" use different words but land close together, while "password requirements for new accounts" lands nearby but not as close. When you ask a question, the system turns it into an embedding too and looks for chunks whose numbers are nearest.
This is why RAG search can find a passage even when your wording does not match the document. It is also why it sometimes finds a passage that is about a similar topic but does not answer your question. Many systems combine embedding search with plain keyword search, so that exact terms like product codes or names are not missed.
Worked example: a staff handbook bot
Imagine a company puts its 200-page staff handbook into a RAG system. An employee asks: "How many days of carer's leave can I take?"
- The search step finds three chunks: the leave policy section, a paragraph in the FAQ about carers, and an older memo that mentions leave.
- The prompt says, in effect: "Here are three passages from the handbook. Answer the question using only these. Quote the passage you rely on. If they don't answer it, say so."
- The model replies with the number of days from the leave policy, quotes it and links to the section.
When it works, this is faster than searching the handbook yourself, and the quote lets you check. Note the older memo, though. If it gives a different number, the answer depends on which passage the model leans on. That is one of the failure modes below.
Where you will meet RAG
- "Chat with your files" features in AI assistants, where you upload documents and ask questions about them.
- Company knowledge assistants that answer from internal wikis, policies and documentation.
- Customer support bots that answer from help-center articles.
- Search engines with AI answers, which retrieve web pages and then summarize them with links.
- Personal setups, where people point a model running on their own computer at their notes or documents. LocalUseCases has guides on this kind of local setup.
Where it goes wrong
RAG reduces made-up answers a lot, but it moves the risk rather than removing it. Most problems come from the retrieval step, not the model.
- The search misses. If the right passage is not found, the model answers from the wrong passages or says it does not know. A question worded very differently from the document is a common cause.
- The chunk is cut badly. A rule might sit in one chunk and its exception in the next. The model sees the rule without the exception.
- Old and new versions disagree. If outdated documents stay in the collection, the system may retrieve them. Keeping the collection clean matters as much as the AI.
- The model still adds things. Even with good passages, a model can blend in general knowledge or overstate what the passage says. Asking for quotes helps catch this.
- Confident answers to the wrong question. If the passages are about a similar topic, the answer can sound right and still not address what was asked.
- Permissions. In a company, a RAG system must only retrieve what the person asking is allowed to see. That is a design question, not something the model handles by itself.
Using RAG tools well
If you use a "chat with your documents" feature, a few habits make the answers far more reliable:
- Ask for citations and open them. A quote from the actual document is the fastest check there is.
- Ask specific questions. "What is the notice period for ending the lease early?" retrieves better than "tell me about the lease".
- Use the document's own words when you can. If the handbook calls it "compassionate leave", ask about that, not "bereavement days".
- Check what it looked at. If the tool shows which files or passages it used, glance at them.
- Allow "not found". "If the documents don't answer this, say so" stops it from filling the gap.
Using only the uploaded tenancy agreement, what does it say about ending the tenancy early? Quote the clause and give its number. If the agreement doesn't cover this, say "not covered".
Questions to ask before you trust a document bot
If your workplace rolls out an assistant that answers from internal documents, a few questions are worth asking, either of the tool or of whoever set it up:
- Which documents does it search, and how often are they updated?
- Are old versions removed when policies change?
- Does it show which document each answer came from?
- Can it see documents I am not allowed to see, or only what I could open myself?
- Who do I tell when it gives a wrong answer?
Good answers to these matter more than which model sits underneath.
RAG compared with other options
- Pasting the document yourself. Simplest and very reliable for one or a few documents that fit in the context window. RAG is for when there are too many.
- A bigger context window. Newer models can read much more at once, which reduces the need for RAG for medium-sized collections. For very large or constantly changing collections, searching first is still more practical and cheaper.
- Training the model on your documents. Sometimes called fine-tuning. It changes how a model writes and behaves more than what facts it can reliably quote, and it has to be redone whenever documents change. For answering questions from documents, RAG is usually the simpler and more checkable choice.
Try it
You can try the core idea in any chat assistant without building anything.
- Find three short documents on related topics, such as three policies or three product pages.
- Ask a question whose answer is in only one of them, without pasting anything. Note the answer.
- Now paste all three, labelled, and ask again with "answer only from these, quote the passage".
- Compare. You have just done retrieval by hand. A RAG system automates step 3 for thousands of documents.
Questions people ask
Does RAG mean the AI cannot make things up?
No. It makes it much less likely, especially when the tool shows sources. The search can still miss, and the model can still overstate. Check quotes for anything important.
Do I need to be a developer to use RAG?
No. Many assistants include document upload features that work this way behind the scenes. Building your own system is a developer task, though there are tools that make it easier, including ones that run locally.
Is my data safe in a RAG tool?
That depends entirely on the tool: where documents are stored, who can access them and whether they are used for training. Read the tool's data terms, and for sensitive documents consider tools that run on your own hardware.
On LocalUseCases: Ollama use cases (includes chatting with your notes) · Paperless-ngx auto tagging with Ollama · How to run an LLM locally