Sub topic 1
Three Levers for Adapting a Model
Prerequisites
You should know how to call a large language model through a chat-style API. You should also be able to read basic Python and understand that embeddings represent text as vectors.
Three levers for adapting a model
A model can be adapted in three main ways:
- Prompting changes the instructions and examples sent with each request.
- Retrieval-augmented generation (RAG) supplies relevant external facts at query time.
- Fine-tuning changes model parameters using a curated training set.
Prompting is usually the first lever because it is quick, reversible, and inexpensive. RAG is useful when answers depend on private, changing, or specialized information. Fine-tuning is useful when the model repeatedly follows the wrong style, format, or procedure even after careful prompting.
Is it missing knowledge or behaving wrongly?
A knowledge gap means the model lacks the needed information. For example, it cannot answer questions about an internal policy that was never included in its context. RAG can retrieve that policy and place it in the prompt.
A behavior gap means the model has enough information but responds incorrectly. It may include explanations when you require JSON, use the wrong tone, or assign inconsistent labels. Better instructions and examples may fix this. Fine-tuning becomes a candidate when the behavior must be consistent across many requests.
A single failure can have both causes. Diagnose them separately before choosing a tool.
> callout note > Do not fine-tune a model to memorize facts that change frequently. Store those facts externally and retrieve them when needed. > ```
Measure first: an evaluation set and a baseline
Create an evaluation set, which is a fixed collection of representative inputs with expected results. Include normal cases, difficult cases, and known failure cases. Run the unmodified system on this set to establish a baseline, or starting measurement.
Record accuracy, format compliance, latency, and cost when they matter. Change one lever at a time, then compare results with the same evaluation set.
Start with prompting
Use clear task instructions, output constraints, and a few representative examples. A few-shot example is an input paired with the output you want.
def classify_ticket(text):
prompt = f"""Classify this support ticket as billing, bug, or other.
Reply with one word.
Examples:
"I was charged twice." -> billing
"The export button crashes." -> bug
Ticket: {text}
"""
return prompt
print(classify_ticket("My invoice has the wrong amount."))Exercise
A model knows the company policy but returns prose instead of the required JSON. Is this primarily a knowledge gap?
Show answer
No. It is a behavior or format gap, so improve the prompt and examples first.