What is RAG (retrieval-augmented generation), and when should you use it?
How RAG works, step by step
A RAG system has two halves: a search step that finds relevant text, and a generation step that writes the answer. The search step runs first, every time someone asks a question. The model never reads your whole document library. It reads only the few passages the search returned.
- Index the documents. Split each file into passages, called chunks, and store a searchable form of each one, along with its source name, section and date.
- Receive the question. Take the question as the user typed it, and check which documents that user is allowed to see.
- Retrieve the passages. Search the index and keep the most relevant chunks, usually a small number.
- Generate the answer. Send the question and those chunks to the language model, with instructions to answer only from them and to say when the answer is missing.
- Return the answer with citations. Show the file and section used, so the reader can open the source and check it.
Why RAG reduces made-up answers, and why it does not remove them
A language model on its own answers from patterns learned during training, which may be out of date or simply absent for your company. When the model is given your current passages and told to answer from them, it has less room to invent. The citations also make errors easier to spot, because a reader can compare the answer with the source.
RAG does not make every answer correct. The model can still misread a passage, combine two unrelated chunks or ignore the instruction to stay within the text. Treat every answer as a draft that a person checks, especially for pricing, legal wording or anything with a deadline.
What RAG needs before it works
A RAG system is only as good as its inputs. Before you build one, check these foundations:
- Clean source documents, with the current version clearly marked and old versions archived.
- Sensible chunking, so each passage holds a complete idea, such as one policy clause or one product specification.
- Good metadata, including owner, date and document type, so the search can prefer current material.
- A search method that suits the content. Keyword search, semantic search or a mix of both each have strengths, and a test on real questions will show which works for your documents.
- Permission checks at the moment of retrieval, so each person sees only the passages they are allowed to read.
Where RAG fails
RAG fails in a few predictable ways. Chunks that cut a table in half, or split a sentence from its condition, give confident but wrong answers. Out-of-date policies sit in the index next to current ones. Questions that need reasoning across many documents, such as comparing every contract with a given clause, may retrieve only part of the evidence. Scanned images, charts and complex tables often need separate handling.
Permissions are a quieter failure. If the check happens only when the document is uploaded, and not when a question is asked, a person who loses access may still see its contents in an answer.
When to use RAG and when not to
RAG suits questions answered by a body of text that changes now and then: policies, product manuals, service terms, internal procedures and past project reports. It is a poor fit for questions that need live data, such as current stock levels or open orders, which belong in a database query, and for tasks where the model must invent new ideas rather than report what the company already knows.
- Use RAG for: staff questions about internal policies, customer support drafted from approved answers, and search across long manuals.
- Avoid RAG for: live status checks, calculations that a spreadsheet or database should do, and decisions with no human review.
How to test a RAG system before people rely on it
Build a test set of fifty or so real questions, written the way your staff actually ask them. Include some questions the documents cannot answer, because the system should say so rather than guess. For each answer, check three things: whether the passage it cited really supports the answer, whether the answer is complete, and whether the reader could find the source.
- Re-run the same test set after every change to the documents, the chunking or the search settings.
- Track the questions that fail, and fix the source document or the chunking rather than only the prompt.
- Check the access rules with a user who should not see certain documents, and confirm the answer does not reveal them.
How Hundred Seas helps
Hundred Seas is a product studio in Taipei that builds AI agents, internal tools and AI CRM systems, and retrieval over company documents is part of much of that work. We design the document index, the permission checks and the test set together, so the answers can be traced back to a source. We build on Claude and on OpenAI models, and we choose the model for each task on cost, speed, quality and where the data has to stay.
Our work begins with a scope step of about one week at a fixed price, which ends in a written plan, a clickable prototype and a firm quote. The build follows in weekly releases of working software, and a monthly run plan keeps the index, the software and the test set up to date after launch.
Questions
- Is RAG the same as fine-tuning a model?
- No. Fine-tuning changes how a model behaves by training it further on examples. RAG leaves the model unchanged and supplies relevant passages from your documents at the moment of each question. RAG is usually easier to update, because you change the documents rather than retrain the model, and it lets you show the source of each answer.
- Does RAG need a vector database?
- Many RAG systems use a vector index to find passages by meaning, but it is not the only option. Keyword search, or a mix of keyword and meaning-based search, can work well for many business documents. Choose the method that gives the best results on your own test questions, and check the current documentation of any tool you adopt.
- Does RAG send my documents to the model provider?
- The passages retrieved for each question are sent to the model provider that generates the answer, not the whole library. Check that provider’s current terms on data retention and training use, and decide which documents may be indexed at all. Sensitive material may need to stay in your own environment, or be left out of the index.
- Can RAG read PDFs, tables and scanned pages?
- It can read many PDFs with selectable text. Scanned pages need text recognition first, and the result depends on scan quality. Tables and charts often lose their structure during chunking, so they usually need special handling. Test these formats separately with real examples before you rely on them.
- How do I stop RAG from showing confidential documents to the wrong person?
- Check permissions at retrieval time, every time a question is asked, not only when a document is uploaded. The search should return only passages the current user may read. Test this with an account that lacks access, and review the logs regularly, because a permission error can expose text in an answer without anyone noticing.