RAG and search engineeringMiddleLesson 2076 min read

Why retrieval beats retraining

A model only knows what it saw in training. Retrieval lets it read your fresh and private documents at answer time, and show where each answer came from.

Lesson in motion

In 60 seconds

Why retrieval beats retraining

A model only knows what it saw in training. Retrieval lets it read your fresh and private documents at answer time, and show where each answer came from.

1/5
In simple words
Imagine an exam. One student tries to memorise every book in the library the night before. Another is allowed to bring the right book into the exam and look things up. The second student is more likely to be right, can show the page, and does not need to re-study when the book changes. Retrieval is the open-book exam for AI.
A large language model learns from a huge amount of text, and then its training stops. After that it does not know about new events, and it never saw your company's private documents: your HR policy, your product manual, last week's circular. Ask it about them and it may guess, and a guess can sound very confident.
Retrieval-augmented generation (RAG) fixes this at answer time. Your app first searches your documents for the parts that match the question. Then it puts those parts into the prompt and asks the model to answer from them. The model does the reading and writing. Your search does the remembering.

The basic RAG loop

  1. 1

    Prepare (once, then keep updated)

    Split your documents into chunks, and store them in a search index with their source and date.
  2. 2

    Search

    When a question comes in, find the few chunks most likely to contain the answer.
  3. 3

    Build the prompt

    Put the question and the chunks together, each chunk with an id such as [S1], [S2].
  4. 4

    Generate

    The model writes an answer using only those chunks, and cites them.
  5. 5

    Show sources

    The user sees the answer and can click through to the original text.

Why this usually wins

NeedRetrieval (RAG)Retraining or fine-tuning
Fresh informationUpdate the index today; the next question sees itTrain again, test again, deploy again
Private documentsStay in your own store; you control who can search whatKnowledge is baked into the weights for anyone who can use the model
CitationsEach answer can point to the exact chunk it usedThe model cannot reliably say where a fact came from
Removing a factDelete the document and its chunksVery hard to make a trained model truly forget one fact
Cost to startAn index and a search stepTraining data, compute and evaluation for each change
Note
Long context windows help, but do not remove the need for search. You still pay for every token you send, answers can get slower, and researchers have shown that, in some settings, models use information in the middle of a very long prompt less well than information near the start or end. Sending the right five pages usually beats sending five hundred.

When fine-tuning is the right tool

Fine-tuning changes the model's weights using your examples. It is good at teaching how to respond, and weak at teaching what is true today.
Fine-tuning is a poor fit for
  • Facts that change: prices, rules, stock, schedules
  • Knowledge where you must show the source
  • Documents only some users are allowed to see
  • Anything you may need to delete later
Fine-tuning can be a good fit for
  • A fixed style, tone or output format
  • A narrow, repeated task such as classifying tickets
  • Making a small model do one job well and cheaply
  • Domain wording the base model handles badly
The two also combine. A team might fine-tune a small model to write short, polite answers in a fixed format, and still use retrieval to give it the facts.
Real example
A cooperative bank in Kerala wants a bot that answers staff questions about its loan rules. The rules change after every board meeting. With RAG, the team uploads the new circular and the bot uses it the same day, quoting the circular number. With fine-tuning, every change would mean new training data, a new training run and new tests.
Watch out
RAG adds its own risks. A search can hand the model a document the user should not see, and a document can contain hidden instructions. These are covered in Securing RAG: permissions for retrieved documents and Vector stores and embedding leaks. Take those lessons before you ship to real users.
Try this. Think of one question you would like to ask your college's or office's documents. Would the answer change next month? Does the person asking need to see the source? If yes to either, that is a retrieval problem.

Watch and read more

Lab

A one-page decision note: RAG, fine-tuning, both or neither, for three real-looking use cases.

~20 min

The problem

For each use case below, write 4–6 lines: which approach you would choose (RAG, fine-tuning, both, or neither), and why. Mention freshness, sources, privacy and cost.

  1. A hospital's staff bot that answers questions from internal duty rosters and procedure notes. (Do not design medical advice for patients.)
  2. A tool that turns rough notes from field officers into a fixed, three-part inspection report format.
  3. A support bot for a phone company that answers questions about current recharge plans.

Finally, write one use case of your own where plain prompting, with no retrieval and no fine-tuning, is enough.

You are done when

Hard questions

Try to answer before you reveal. If you can answer these, you understood the lesson.

Q1A manager says: "Let's fine-tune on all our PDFs so the model just knows everything." Give two strong reasons against this as the only plan.Reveal

First, the knowledge will go stale: every change in the PDFs needs new training and testing, while an index can be updated the same day. Second, the model cannot cite where an answer came from, and cannot respect per-user permissions: anything trained in is available to everyone who uses the model, and hard to delete later. Fine-tuning may still help with tone or format, alongside retrieval.

Q2When might "put everything in the prompt" be a reasonable first version?Reveal

When the document set is small and stable, for example one short policy of a few pages, and everyone who uses the bot may read all of it. Then a long prompt is simple and gives a useful baseline. Keep a small test set so you can compare later, and switch to retrieval when the set grows, changes often or has permissions.

Please sign in to continue.

Questions people ask

Does RAG stop hallucinations completely?

No. It reduces them when the right text is found, because the model has the facts in front of it. But the search can miss, and the model can still misread or add things. That is why this track covers citations, "not found" answers and measurement.

Is RAG only for chatbots?

No. The same retrieval step powers search pages, "related articles", support tools that suggest answers to human agents, and agents that look things up before acting.

Do I need a special vector database to start?

Not always. For a few thousand chunks, a simple in-memory search, or a search extension in a database you already run, can be enough. Choose a dedicated tool when size, speed or features really need it, and check its current docs.

Can I put all my documents in the prompt instead?

For a small, fixed set of pages, sometimes yes, and it is a fair baseline to compare against. As the collection grows, cost and speed get worse, and the model may miss details. Retrieval keeps the prompt short and focused.

Lesson test

5 questions. Get 3 right (60%) to pass and complete this lesson.

Sign in to take the test and save your progress