Skip to content
Arslan Vuzmal Lone
How AI works· Beginner· INTERACTIVE

How RAG actually works, step by step

Technical guide and implementation breakdown for How RAG actually works, step by step.

Arslan Vuzmal Lone·Updated Oct 2026·11 min read
THE SHORT ANSWER

RAG (retrieval-augmented generation) lets an AI model look things up before it answers. Your documents are split into passages and indexed. For each question, the closest passages are found and pasted into the prompt, so the model answers from your content instead of from memory, and can show where the answer came from.

Why models need it

A language model only knows what was in its training data. It has never read your refund policy, last week’s price list or your internal wiki. Ask it about them and it may still give a confident answer, just not a correct one.

You could retrain the model on your documents, but that is slow, expensive, and out of date the moment a document changes. RAG takes the other route: keep the model as it is, and change what it reads.

The five steps, one at a time

Click a step, or use the arrows. The first two happen once, when you add documents. The last three happen every time someone asks a question.

STEP 1 OF 5 · ONCE

Chunk

Split each document into small passages, a few sentences to a few paragraphs each, so every passage is about one thing.

Where it goes wrong: Passages that are too big blur topics together; too small and they lose the context that makes them make sense.

Try a search

Here is a tiny help center with five passages. Pick a question and watch which passages come out on top. Only the top three are sent to the model.

PICK A QUESTION
Refunds are issued to the original card within 5 working days.
0.91SENT TO THE MODEL
Our support team is available Monday to Friday, 9:00–18:00 CET.
0.42SENT TO THE MODEL
To cancel a subscription, open Settings → Billing → Cancel.
0.38SENT TO THE MODEL
Orders over €50 ship free within the EU.
0.21
You can change your delivery address until the order ships.
0.18

Toy example: the scores are illustrative similarity values, not output from a real model.

Where RAG breaks

Most RAG failures are retrieval failures. The model can only be as good as the passages it is given.

The right passage is never found. The question uses different words from the document, or the passage was split in the wrong place.
Exact terms get lost. Product codes and names are where meaning-based search is weakest. Adding keyword search helps.
The documents disagree. An old and a new policy are both retrieved, and the model picks the wrong one.
Nobody checks. Without a test set of real questions, you can’t tell whether a change made answers better or worse.
THE PAPER BEHIND IT · LEWIS ET AL. · 2020

Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks

The method explained, an interactive model of it, and what it changes for a business.

Read the explainer →

Questions people ask

Is RAG the same as fine-tuning?›

No. Fine-tuning adjusts the weights inside the neural network during an expensive offline training run. RAG keeps the model weights frozen and changes what context is passed in the prompt at query time. Fine-tuning teaches tone and syntax; RAG provides live, citable facts.

Does RAG stop hallucinations?›

It dramatically cuts hallucinations when relevant passages are retrieved and strict system prompts enforce citation. However, if the retrieval engine misses the right passage or retrieves contradictory policies, the model can still hallucinate.

How many passages should be retrieved?›

There is no universal number. Too few passages can miss the one that holds the answer; too many give the model more to wade through and cost more per question. Liu et al. (2023) found that models use information in the middle of a long input less reliably than information at its start or end (Lost in the Middle). Start small, measure on your own questions, and adjust.