What is retrieval-augmented generation (RAG), and when should you choose it instead of fine-tuning an LLM (large language model)?

Sequence models and transformers, Retrieval-augmented generation
Level L1 Beginner. Length Short. Nature Th Theoretical.

What's being asked

Whether you understand how RAG adds external knowledge to an LLM at query time, and when to pick retrieval over updating model weights.

Key idea

RAG retrieves relevant passages from an external document store and pastes them into the prompt before the LLM generates an answer. Use RAG when you need fresh, private or citable facts, and use fine-tuning when you want to change the model's style, tone, output format or task behaviour.

Steps

  1. Explain how RAG works in two steps: when a user asks a question, a retriever searches your document collection (using keyword search, dense embeddings, or both) for the top matching passages, and then the LLM reads those passages in its prompt to write the answer.
  2. State when RAG is the right choice: use RAG for information that changes daily, lives in private company documents, or needs source citations, because updating an index is far cheaper and faster than retraining weights.
  3. State when fine-tuning is better: use fine-tuning when the model must follow a strict output format, adopt a domain tone, or learn a specialised skill that prompting alone cannot teach reliably.
  4. Note the main limitation of RAG: the generator can only answer as well as the retriever performs—if the wrong passages are fetched or the real answer is missing from the chunks, the LLM may miss the answer or hallucinate. Harder RAG questions build on this to cover chunking, vector indexes and reranking.

Common mistakes

How long your answer should be

About 2 minutes; two-step mechanism plus RAG vs fine-tuning comparison.

Read this

Previous in Sequence models and transformers: How much memory do the weights of a 7-billion-parameter LLM (large language model) need in fp32, fp16, int8 and int4? What are these four number formats, why does lower precision help, and what else uses GPU (graphics processing unit) memory at inference time?
Next in Sequence models and transformers: What is teacher forcing when training a sequence-to-sequence decoder, and what is exposure bias?