Recommended resources
The freely available resources this lesson will direct you to.
Hello! Welcome to a new module in your AI learning journey: Practical Fine-Tuning with LoRA.
In our previous lessons, we focused on building sophisticated AI agents that could plan, use tools, and even remember information across conversations. We achieved this primarily through clever prompting and system design, including techniques like Retrieval-Augmented Generation (RAG). Now, we're going to add another powerful tool to your arsenal: fine-tuning.
This lesson addresses a critical question for any AI application architect: When should you invest in fine-tuning a model, versus relying on prompt engineering or RAG? The learning outcome for this lesson is to explain when fine-tuning is preferable to prompt engineering or RAG.
Making this decision correctly is crucial for building effective, scalable, and cost-efficient LLM applications. We will explore this topic not as a simple choice, but as an architectural decision involving a series of trade-offs.
By the end of this lesson, you will be able to:
- Articulate the core purpose and ideal use case for each technique: prompt engineering, RAG, and fine-tuning.
- Analyze a problem based on key constraints like data privacy, cost, latency, and knowledge volatility.
- Decide which approach, or combination of approaches, is most suitable for a given scenario.
Let's begin by establishing a clear understanding of what each technique brings to the table.
The Three Pillars of LLM Customization
You're already familiar with prompt engineering and RAG from our work on agents. Fine-tuning is the new concept we're introducing. Let's watch a video that concisely explains all three techniques, their goals, and some common misconceptions, especially around fine-tuning.
Prompt Engineering, RAG, and Fine-tuning: Benefits and When to Use
The video 'Prompt Engineering, RAG, and Fine-tuning' by Mark Hennings provides an excellent overview. It clarifies what fine-tuning is truly for and busts some common myths.
Watch the video from 00:21 to 09:52. As you watch, focus on the distinct purpose of each method: Prompt Engineering (00:21 - 01:09): How it steers the model's behavior for a single request. RAG (01:09 - 06:22): How it provides external knowledge to the model at inference time. Fine-tuning (06:22 - 08:21): How it teaches the model new skills or behaviors by updating its internal weights. Pay close attention to the idea that it teaches 'intuition' rather than facts. Misconceptions (08:21 - 09:52): This section is critical. Note the points about fine-tuning not being for teaching facts, and the modern feasibility regarding dataset size and cost.
Core Competencies: Knowledge vs. Skill
From the video, we can distill a fundamental rule of thumb:
- Use RAG to give a model knowledge. If your application needs to answer questions based on information that is proprietary, rapidly changing, or needs to be verifiable, RAG is the right tool. You are plugging in an external, up-to-date brain.
- Use Fine-Tuning to teach a model a skill or behavior. If you need the model to consistently adopt a specific style, tone, format (like always outputting valid JSON), or follow complex, nuanced instructions that are hard to describe in a prompt, fine-tuning is the answer. You are fundamentally altering the model's "personality" or capabilities.
This can be visualized with a simple matrix.
Beyond the "Ladder": An Architectural Framework
A common misconception is to view these techniques as a ladder of complexity: start with prompting, move to RAG if that fails, and finally resort to fine-tuning. For a software engineer, it's more productive to think of them as different architectural patterns, each with specific trade-offs.
The following article argues against the "ladder" model and proposes a more robust, six-dimensional framework for making your decision. This perspective aligns perfectly with the kind of constraint-based analysis common in software architecture.
Prompting vs. RAG vs. fine-tuning: Why it’s not a ladder
The article 'Prompting vs. RAG vs. fine-tuning: Why it’s not a ladder' from The New Stack provides a production-oriented decision framework. It's an essential read for moving from a prototype to a real-world system.
Please read the entire article. It's concise and packed with insights. As you read, focus on understanding how each of the six dimensions influences your choice: Data Privacy: A non-negotiable barrier. Latency: What the user feels first. Degree of Control: Constraining behavior vs. knowledge. Update Frequency: The cost of staying current. Deployment Target: Where the model runs. Cost: What kills successful projects at scale.
Let's summarize the key trade-offs from the article in a table. This is the kind of analysis you would perform when designing an LLM-powered feature.
| Constraint | Prompt Engineering | RAG | Fine-Tuning |
|---|---|---|---|
| Data Privacy | Potentially risky if using third-party APIs with sensitive data. | Better; sensitive data can stay in-house, only snippets sent to LLM. | Can be risky during training with third-party services, but secure if the model is self-hosted. |
| Latency | Lowest latency (single API call). | Higher latency (retrieval + generation steps). | Low inference latency, but high upfront training time. |
| Control | Controls output structure and immediate behavior. Can be fragile. | Controls the knowledge boundary the model can access. | Controls the model's intrinsic behavioral patterns (style, tone, reasoning). |
| Knowledge Updates | Easy to update prompts, but hard to manage at scale. | Best. Knowledge base can be updated independently of the model. | Worst. Requires a full retraining cycle to incorporate new knowledge. |
| Cost | Low initial cost, but can scale unpredictably with prompt size. | Higher operational cost (vector DB, indexing), but can reduce inference cost by grounding the model. | High upfront training cost, but can lower long-term inference cost (smaller prompts, smaller models). |
As the article concludes, the best systems are often hybrids. For example, you might use a fine-tuned model for consistent style, a RAG pipeline for factual grounding, and prompt engineering for task-specific instructions.
A Practical Decision Tree
Now that we have a solid architectural framework, let's look at a more prescriptive decision-making process. The following resource provides a series of questions that can guide you to the right starting point.
Choosing Between RAG, Fine-Tuning, and Prompts: A Decision Tree
The article 'Choosing Between RAG, Fine-Tuning, and Prompts: A Decision Tree' offers a pragmatic flow to help you decide where to start.
Please read the sections 'Pros, Cons, and Trade-offs', 'Decision Criteria: When to Use What', and 'Decision Tree: A Simple Flow'. These sections provide a clear, actionable guide.
To make this even more concrete, here are some common scenarios and the recommended approach, based on the principles we've discussed.

Let's walk through a couple of examples from the table:
- Scenario: "My data is constantly changing."
- Recommendation: RAG.
- Rationale: The knowledge base can be updated in real-time without retraining the model. Trying to use fine-tuning here would be slow and prohibitively expensive. This directly relates to the "Update Frequency" constraint.
- Scenario: "I need the model to have a very specific persona/writing style."
- Recommendation: Fine-Tuning.
- Rationale: This is a behavioral requirement, not a knowledge one. By training the model on examples of the desired style, it internalizes this behavior far more reliably than just describing it in a prompt. This relates to the "Degree of Control" constraint.
Conclusion
In this lesson, we established a robust framework for deciding when to use prompt engineering, RAG, or fine-tuning. As an experienced engineer, you can see that this isn't about which technology is "more advanced," but about choosing the right architectural pattern for the job based on your system's constraints.
Key Takeaways:
- RAG for Knowledge, Fine-Tuning for Skill: Use RAG to provide factual, up-to-date information. Use fine-tuning to teach a model a consistent style, format, or behavioral pattern.
- It's Not a Ladder: The choice is a trade-off across multiple dimensions. Don't assume a linear progression from prompting to RAG to fine-tuning.
- Analyze Your Constraints: The right choice depends on your specific needs regarding data privacy, latency, cost, knowledge update frequency, and degree of control.
- Hybrid is Often Best: The most powerful systems frequently combine these techniques, using each for its strengths.
Now that you understand when to choose fine-tuning, you're ready to learn how to do it. In our next lesson, we will dive into Parameter-Efficient Fine-Tuning (PEFT) methods like LoRA. These are modern, efficient techniques that make fine-tuning accessible and cost-effective, a significant departure from the resource-intensive methods of the past.