FrontierAI.Engineer
AI System Design & Interviews

Retrieve vs. Fine-Tune: Making the Decision

8 min read

A framework for deciding when retrieval-augmented generation is the right choice versus fine-tuning the model.

When a base model does not perform well enough on your task, you have two primary improvement levers: give it better information at inference time via retrieval, or bake better knowledge and behavior into the model weights via fine-tuning. Both can work; the right choice depends on the nature of the gap and the constraints of your project.

When retrieval is the right answer

Retrieval is the right choice when the model's outputs are wrong because it lacks access to specific, up-to-date, or proprietary information. If a customer support model gives incorrect answers because it does not know your current product specifications, retrieval fixes that by supplying the right specs at query time. Retrieval is also cheaper and faster to iterate: you can update the knowledge base without touching the model.

When fine-tuning is the right answer

Fine-tuning is the right choice when the model's behavior is wrong rather than its knowledge. If the model consistently formats outputs incorrectly, uses the wrong tone, fails to follow a complex output schema, or underperforms on a specialized domain that requires implicit skills (like writing legal clauses or medical differential diagnoses), fine-tuning can instill those behaviors more reliably than prompt engineering alone.

  • Use RAG when: the model needs access to documents it was not trained on
  • Use RAG when: the knowledge changes frequently and retraining would be costly
  • Use RAG when: you need citations or source attribution in the response
  • Use fine-tuning when: you need a consistent output format the model ignores in prompting
  • Use fine-tuning when: you need specialized domain vocabulary or writing style
  • Use fine-tuning when: latency requires a smaller model but quality demands a larger one's capability

The combined approach

RAG and fine-tuning are not mutually exclusive. A common high-performance architecture fine-tunes a model to follow a specific output schema and reasoning style, then augments it with retrieval at inference time for factual grounding. The fine-tuned model is better at using retrieved context than the base model, and the retrieval provides the knowledge the fine-tuning cannot bake in.

# Decision heuristic as code
def choose_approach(problem: dict) -> str:
    if problem["knowledge_is_proprietary"] or problem["knowledge_changes_frequently"]:
        if problem["behavior_is_also_wrong"]:
            return "rag_plus_fine_tune"
        return "rag"
    if problem["format_or_style_is_wrong"] or problem["domain_is_specialized"]:
        return "fine_tune"
    return "prompt_engineering"  # try this first before either
note

Fine-tuning requires a labeled training dataset that is expensive to collect and requires ongoing maintenance. Verify that prompt engineering cannot close the gap before committing to a fine-tuning workflow.

tip

A quick diagnostic: if adding 5 to 10 representative examples as few-shot examples in the prompt closes most of the quality gap, fine-tuning those examples into the model weights is likely to work well. If few-shot examples don't help, the problem is probably knowledge-based and retrieval is the better path.