Retrieval-augmented generation (RAG)

Retrieval-augmented generation means finding the documents relevant to a question and putting them in front of the model, so it answers from your content rather than from memory. It is the standard way to make a model reliable about facts it was never trained on.

Also called: RAG · Reviewed

How does it work?

Ahead of time: split your documents into chunks, embed each chunk, and store the vectors. At question time: embed the question, retrieve the closest chunks, paste them into the prompt with an instruction to answer from them and cite which one, and return the model's answer alongside its sources.

Everything hard about RAG lives in the retrieval half. Getting the model to use supplied text is easy; getting the right text supplied is the engineering.

Why not just fine-tune?

Because facts change and weights do not. With retrieval, updating an answer means updating a document; with fine-tuning it means another training run. Retrieval also produces citations, so a reader can check the claim, and it can enforce permissions per user in a way baked-in knowledge simply cannot.

Prompting, retrieval-augmented generation and fine-tuning compared by what each changes, how it is updated, and when to reach for it.
ApproachWhat it changesUpdating itReach for it when
PromptingWhat the model is asked, and nothing elseInstant — edit the textThe knowledge is already in the model and only needs shaping
RAGWhat the model can see at answer timeReindex the documentsAnswers must be grounded in facts the model never saw, and those facts change
Fine-tuningHow the model behaves by defaultRetrain the modelA format, tone or task pattern must hold without being restated every time

What do people get wrong?

Assuming that once documents are in the prompt the answer must be correct. If retrieval returns nothing relevant, most models will answer anyway from general knowledge — so instruct explicitly that "the documents do not cover this" is an acceptable answer, and check that it is ever actually given.

The other is treating chunking as a detail. Splitting mid-sentence, discarding the heading that gave a paragraph its meaning, or using chunks so large that the useful line is buried will cap quality no matter how good the model is. Measure retrieval on its own — did the right chunk come back — before blaming the generation step.

Learning this properly is easier with other people.

OneShopAI is where students, developers and founders work through this material together — sessions, builds and people who answer questions.