Articles
RAG vs. Fine-Tuning: Which Should You Use for Large Language Models?
This guide compares retrieval-augmented generation (RAG) and fine-tuning for building LLM-based systems that answer questions over internal documents…
If you are interviewing for an AI Engineering or Machine Learning role, one question is nearly unavoidable: "We want a chatbot that answers questions over our internal documents. Should we fine-tune a model or build a RAG system?" This guide gives you a precise mental model for that decision, the architectural trade-offs behind it, and the answer structure that signals senior judgment rather than buzzword recall.
You'll get a clear definition of each approach, a side-by-side comparison table, a decision flow you can reason out loud, concrete example answers, and the follow-up traps interviewers use to probe how deep your understanding actually goes.
The core distinction in one sentence
RAG changes what the model knows. Fine-tuning changes how the model behaves. Almost every correct answer in an interview flows from holding those two axes separate and refusing to let the interviewer collapse them.
A surprising number of candidates get this backwards. They reach for fine-tuning to inject company facts (the wrong tool) or reach for RAG to fix tone and output format (also the wrong tool). Keep the axes clean and the rest of the conversation becomes easy to navigate.
Video: RAG vs. Fine Tuning - IBM Technology walkthrough
Retrieval-Augmented Generation (RAG)
RAG connects a general-purpose LLM to an external, updatable knowledge source at query time. The model's weights are never touched; instead, relevant context is fetched and placed into the prompt before the model reasons over it.
How a RAG pipeline works
- Ingest and chunk. Your documents are split into chunks (often a few hundred tokens each, with some overlap so meaning isn't cut mid-thought).
- Embed and store. Each chunk is converted into a high-dimensional vector by an embedding model and stored in a vector database (for example Pinecone, Milvus, Weaviate, or pgvector).
- Retrieve. When a user asks something, the query is embedded and the system pulls the most semantically similar chunks (a typical starting point is the top 3 to 10).
- Augment and generate. Those chunks are injected into the prompt alongside the question. The LLM acts as a reasoning engine, synthesizing an answer grounded in the retrieved context.
Where RAG wins
- Fresh, changing knowledge. Update a document, re-embed it, and the system is current. No retraining.
- Grounding and citations. Because answers are constrained to retrieved text, the model is far less likely to hallucinate, and you can show the source chunk to the user.
- Access control. You can filter retrieval by user permissions, so people only ever see context they're allowed to see - much harder to enforce once knowledge is baked into weights.
- Fast to ship. No training infrastructure or labeled dataset required to get a useful first version.
Where RAG struggles
- Per-query cost and latency. Stuffing thousands of tokens of context into every call raises compute cost and can slow time-to-first-token.
- Retrieval quality is the ceiling. If the right chunk isn't retrieved, the model can't use it. "Garbage retrieved, garbage generated." Chunking strategy, embedding choice, and re-ranking matter enormously.
- It doesn't teach behavior. RAG won't reliably make a model adopt a house style, a strict output schema, or a specialized reasoning pattern.
Fine-Tuning (and why PEFT / LoRA changed the math)
Fine-tuning adjusts a model's weights by continuing training on a curated dataset of input-output examples. You're not teaching it new facts so much as teaching it a new behavior: a format, a tone, a domain vocabulary, a reasoning style.
Few teams do full fine-tuning anymore. Parameter-efficient methods dominate:
- PEFT (Parameter-Efficient Fine-Tuning) is the umbrella term for techniques that train a small fraction of parameters instead of the whole model.
- LoRA (Low-Rank Adaptation) freezes the base weights and trains small low-rank adapter matrices, which dramatically cuts memory and compute. QLoRA goes further by quantizing the base model so larger models can be tuned on a single GPU.
Where fine-tuning wins
- Form, tone, and structure. Reliable JSON output, a consistent brand voice, or a fixed response template are things fine-tuning teaches well.
- Specialized style and vocabulary. Domains with their own phrasing (legal, medical, internal jargon) benefit when the model internalizes the patterns.
- Smaller prompts at inference. Behavior baked into the model means you don't have to re-explain it in every prompt, which can lower per-call cost.
Where fine-tuning struggles
- Knowledge goes stale. Bake last quarter's policy into the weights and it's wrong the day the policy changes - and the only fix is another training run.
- No native citations. A fine-tuned model can't point to the source of a "fact" it produces.
- Real operational overhead. You need a quality dataset, an evaluation harness, and a versioning story for adapters. Poor data can degrade the base model's general ability.
- Hallucination risk on facts. Tuning teaches patterns, not a lookup table; the model may confidently produce plausible-but-wrong specifics.
RAG vs. fine-tuning: the comparison table
| Dimension | RAG | Fine-Tuning |
|---|---|---|
| Primary purpose | Inject new / changing knowledge | Shape behavior, tone, format |
| Knowledge freshness | Update the data store, instant | Requires a retraining run |
| Hallucination control | Strong (grounded in retrieved text) | Weaker on facts |
| Source citations | Native and easy | Not available |
| Time to first version | Fast (no training) | Slower (needs data + training) |
| Per-query latency / cost | Higher (large context each call) | Lower (shorter prompts) |
| Upfront effort | Pipeline + retrieval tuning | Dataset curation + GPU training |
| Access control per user | Straightforward (filter retrieval) | Hard (knowledge is global) |
| Best for | Q&A over docs, support, search | JSON output, brand voice, jargon |
The interview verdict: how to actually answer
When asked to recommend an approach, structure your answer as a decision, not a list. Senior interviewers want to hear why and in what order.
- Default to RAG for knowledge. For most enterprise cases - Q&A over documents, customer support, internal search - RAG is cheaper to start, keeps facts current, and supports citations. The HR-chatbot prompt is a textbook RAG problem because policies change.
- Reach for fine-tuning when behavior is the gap. If retrieval is finding the right context but the output is wrong - wrong format, wrong tone, ignoring instructions - that's a behavior problem fine-tuning solves.
- Combine them when both gaps exist. Mature teams often fine-tune a smaller open model to internalize house style and structure, then layer RAG on top to feed it live data at query time. You get cheap, on-brand behavior plus current, citable facts.
- Mention the cheaper options first. Before either, good engineers try prompt engineering and few-shot examples. If a better system prompt or a couple of in-context examples fixes it, you've saved a vector store and a training pipeline.
The decision tree below is a clean way to talk through it out loud.
Example answer (the HR chatbot prompt)
"I'd start with RAG. HR policies change, and RAG lets me update a document and have answers stay current without retraining, while also letting me cite the exact policy section - which matters for trust and compliance. I'd scope retrieval to each employee's access level. I'd only consider fine-tuning if, after retrieval is solid, the model still won't follow our required answer format or tone. If both gaps existed, I'd fine-tune a small open model for format and keep RAG for the live policy data."
That answer names the decision, the reason, an access-control nuance, and a fallback - which reads as experience, not theory.
Example answer (structured-output requirement)
"For instance, if the task is converting support tickets into a strict JSON schema, that's a behavior problem, not a knowledge one. I'd reach for fine-tuning (likely LoRA) on a dataset of ticket-to-JSON pairs, because I want the format reliably baked in rather than re-explained in every prompt. RAG wouldn't help here - there's no external knowledge to retrieve."
Common pitfalls that sink interview answers
- Treating them as competitors. They solve different problems. Framing it as "RAG vs. fine-tuning, pick one" misses the hybrid reality.
- Using fine-tuning to memorize facts. A frequent and costly mistake. Facts belong in retrieval, not weights.
- Ignoring retrieval quality. Saying "build a RAG system" without mentioning chunking, embeddings, or re-ranking signals shallow knowledge.
- Skipping the cheap options. Jumping straight to training when a better prompt would do is a red flag for cost awareness.
- Forgetting evaluation. Either approach needs a way to measure whether answers actually improved.
Want to pressure-test these answers against real questions? Browse the full question bank, explore role-specific prep for the software engineer and machine learning engineer tracks, or work through company-specific sets like Google. More AI and system-design write-ups live in resources and the interview guides.
How to Use This Page as a Prep Plan
Do not treat this as passive reading. Convert the ideas in this page into a short weekly loop: learn one idea, practice it under interview conditions, then write down what changed. That is the fastest way to turn advice into visible interview behavior.
| Prep area | What you need to prove | Practice artifact |
|---|---|---|
| Understand | Turn the prompt into a concrete goal. | Clarifying questions and success criteria. |
| Practice | Use realistic constraints and timed reps. | Worked examples with edge cases. |
| Explain | Make reasoning visible. | Tradeoffs, assumptions, and test strategy. |
| Improve | Review misses quickly. | A short feedback log and next action. |
For RAG vs. Fine-Tuning: Which Should You Use for Large Language Models?, the strongest candidates usually do three things well: they make their assumptions explicit, they use concrete examples instead of vague claims, and they review mistakes quickly enough that the next practice rep is better than the last one.
FAQ
Is RAG always cheaper than fine-tuning?
Not always. RAG has low upfront cost (no training), but every query carries a large context, so per-call inference cost and latency are higher. Fine-tuning has high upfront cost but can lower per-call cost with shorter prompts. The right answer depends on query volume: at very high volume, the amortized savings from shorter prompts can favor fine-tuning.
Can I use RAG and fine-tuning together?
Yes, and it's a common production pattern. Fine-tune a smaller model to handle behavior - tone, format, domain vocabulary - and use RAG to feed it current, citable facts at query time. You get on-brand, structured responses grounded in up-to-date data.
When should I use neither and just engineer the prompt?
Start there. If a clearer system prompt or a few in-context examples gets the behavior you need, you've avoided the cost of a vector store or a training run. Prompt engineering is the cheapest lever; reach for RAG or fine-tuning only when prompting can't close the gap.
Does fine-tuning teach the model new facts?
It can absorb some, but it's the wrong tool for facts that change or need to be cited. Fine-tuning teaches patterns and behavior, not a reliable lookup table - and baked-in facts go stale and can't be sourced. For knowledge, prefer RAG.
What is LoRA and why does it matter for interviews?
LoRA (Low-Rank Adaptation) is a parameter-efficient fine-tuning method that freezes the base model and trains small adapter matrices instead of all the weights. It cuts the memory and compute needed to fine-tune, which is why most teams use it (or QLoRA) rather than full fine-tuning. Mentioning it shows you know the practical, cost-aware version of the technique.
How do I know if my RAG system is the problem or the model is?
Inspect retrieval first. If the correct chunk isn't being retrieved, the issue is your chunking, embeddings, or re-ranking - not the LLM. If the right context is retrieved but the answer is still wrong in form (format, tone, instruction-following), that points to a behavior gap where fine-tuning may help.