Learning path: Build and Measure a RAG System · Step 2 of 12
Why RAG Exists: The Problem It Solves, Compared With Pasting Everything and Fine-Tuning
A smart model has never read your company's files, and they change every month. Three ways to give it the facts: paste everything, fine-tune, or retrieve only the right pieces. Follow a refund-policy question through all three and see why RAG wins when documents change.
What you will learn
- Name the three problems behind a model that cannot answer from your documents
- Compare pasting everything, fine-tuning and RAG when a document changes
- Follow one question from embedding to an answer with its source
- Know the three things RAG cannot fix: bad documents, bad chunks and no evaluation
Before you start
- What an LLM Can and Cannot Do
- LLM Tokens, Context Windows and Cost
You have a smart model, and it has never read your company's files. That's the whole reason RAG exists. The fix is simple to say: find the right page, and hand it over. This article is about the why. For the stages and the code, read The RAG Pipeline Explained next.
Don't retrain. Open the book.
Think of an open-book exam. A smart student meets a question they've never seen. We don't send the student back to school. We open the book at the right page, the student reads that one page, and answers from it.
The student is the model. The book is your documents. The right pages are what we retrieve.
A chatbot that cannot answer
A policy assistant for a support team. A teammate types: What is our refund window?
The answer sits in refund-policy.pdf. Your company wrote it, it's on a shared drive, and somebody edits it every month. The model never saw it. So the reply comes back empty, something like I'm not sure, I haven't seen your company's policy (an illustrative reply). The model is smart. It simply doesn't have your documents, and they keep changing.
One small problem, three problems
- Knowledge cut-off. A model only knows what it read before its training stopped. If the policy changed after that, it has no idea.
- Private data. Your contracts, tickets and handbooks were never public, so they were never in the training data.
- Made-up answers. With no facts at hand, a model may still sound very sure. That confident guess is a hallucination, and a wrong refund window sounds just as nice as the right one.
Three problems, one cause: the facts are not in front of the model.
Three ways to give it the facts
Way 1: paste everything
Put every document into the prompt. But a context window limits how much text fits in one prompt. Keep adding documents and you pass the limit; the file you need may not even fit. And all of it is sent, and paid for, on every single question, though most of it has nothing to do with the question.
Way 2: fine-tune the model
Train the model again on your documents. That loop is slow and costly to repeat. When it finishes, the model and the policy match, for now. Then somebody edits the file, and the model stays where it was. A teammate asks and gets the old rule. If your documents change every month, a fine-tuned model always lags behind.
Way 3: RAG, only the right pieces
Keep your documents in small pieces. When a question comes in, search them and put only the few pieces that match into the prompt. It needs a search step, but when a document changes, you update the index for that piece. Nothing is trained again.
RAG means retrieval augmented generation: retrieve first, then generate the answer.
One question rides the whole line
Follow What is our refund window? through a RAG system:
- Embed the question. That turns it into a list of numbers, a location on a map of meaning (see real embedding models).
- Search for the pieces sitting closest on that map.
- Keep the top chunks. A chunk is a small piece of a document; we keep the best few.
- Build the prompt. It starts with a rule like Answer using only the pages below, then the matching text from the refund policy, then the question.
- Answer. The model replies, and the source comes with it, so a person can open the file and check.
Two times, two lanes
This work happens at two different times.
- Before anyone asks: documents are split into chunks, and each chunk is embedded and stored in a vector database. We do this once, and again only when a file changes.
- On every question: embed the question, retrieve, build the prompt, answer. Retrieve searches what the first lane stored.
Notice that embedding happens in both lanes. It has to be the same model both times, so a question and a chunk can be compared fairly.
RAG brings the pages. It can't improve the book.
RAG isn't magic. Three things still go wrong:
- Bad documents. An old policy and a new one both sit in the folder. Search finds the old one, so the answer is old.
- Bad chunking. The cut goes right through the rule, the exception lands in the next chunk, and the answer misses it. See chunking strategies.
- No evaluation. Answers keep coming and nobody can tell if they're right. Write a few test questions where you already know the answer. See why you cannot ship without an eval.
Better retrieval needs good documents, sensible chunks and a way to measure.
Common mistakes
- Reaching for fine-tuning to teach facts that change. Facts belong in documents you can edit. (For the full decision, see When NOT to Fine-Tune.)
- Assuming a big context window removes the need for retrieval. You still pay for every token, on every question.
- Embedding questions and documents with different models.
- Leaving old versions of a document in the index.
- Shipping without a handful of known-answer test questions.
Quick recap
| Approach | Fresh facts? | Prompt size | When a file changes |
|---|---|---|---|
| Paste everything | Yes | Huge, may not fit | Paste again, pay again on every question |
| Fine-tune | Only until the next edit | Small | Train again |
| RAG | Yes | Small, only the right pieces | Update that piece in the index |
Try it yourself
Pick one document you know well. Write three questions you can already answer from it, and mark the page for each. Those three lines are the start of a test set for any RAG system you build on that document.
Related course on Udemy
Machine Learning Engineer: From First Model to ML Engineer
Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (paid course, opens in a new tab)Related posts
What an Embedding Actually Is: Meaning as Numbers, Search by Closeness, and Where Hand-Made Numbers Break
A customer types "I cannot log in" and keyword search finds nothing, although a password-reset article exists. Turn meaning into numbers by hand, find the nearest point with math.dist, build a three-topic toy embedder that finds the right article at 1.00, and watch it score 0.00 on "I can't get into my account".
The RAG Pipeline Explained: 7 Stages From Documents to a Cited Answer
Ingest, chunk, embed, store, retrieve, rerank and generate, in one Python file. Follow one question through a 26-chunk employee handbook to an answer that cites its source.
Similarity Search: Finding the Closest Vectors with NumPy and NearestNeighbors
Ask one question of a whole collection of vectors: which items are closest to this one? Normalise, score every row with one matrix multiply, keep the top k or everything above a threshold, and check it with NearestNeighbors.
Real Embedding Models: an Open Model or a Provider API, Then Search, Duplicates and Recommendations
Swap a toy embedder for a model that learned. Two roads (all-MiniLM-L6-v2 on your machine, or OpenAI's API with your key), three sizes (384, 1,536 and 3,072 numbers), one rule, and three use cases built on the same rank function, with real scores.