Glossary
In-context learning
A language model's ability to pick up a task from instructions, examples or facts placed in its prompt, without any change to its weights.
In-context learning (ICL) is the ability of a large language model to perform a task it was not specifically trained for by reading instructions, examples or information supplied in its prompt. Show a model three emails labelled as complaint, enquiry or praise, then give it a fourth, and it will usually label the fourth correctly. Nothing about the model has changed: its weights are the same before and after. The "learning" happens entirely within a single forward pass over the prompt, and it disappears when the call ends. The term became widely used after OpenAI's 2020 GPT-3 paper, "Language Models are Few-Shot Learners", which showed that a large enough model could do many tasks from a handful of examples in its input. In-context learning underpins few-shot prompting, retrieval-augmented generation and most of what agents do with the context they are given, and its main limit is that whatever the model learns this way has to be supplied again on every call.
How in-context learning works
During pre-training a transformer model learns to predict the next token across enormous amounts of text, and that text contains countless implicit tasks: lists that follow a pattern, question-and-answer pairs, translations side by side. Learning to continue such text well appears to give models a general ability to infer a task from a few demonstrations and apply it. At inference time, the attention mechanism lets each new token draw on every earlier token in the prompt, so examples and instructions shape the output directly.
Exactly why this works is still an active research question. Proposed explanations include specialised attention circuits that copy patterns forward from earlier in the context (sometimes called induction heads), a view of ICL as implicit inference about which task the prompt describes, and analyses showing that transformers can approximate simple learning algorithms over the examples they are given. These accounts are complementary, and none fully explains the behaviour of large production models. For practitioners, the useful point is empirical: ICL is real, it scales with model size and it is sensitive to how the context is arranged.
Forms of in-context learning
ICL is usually described by how much demonstration the prompt contains. Zero-shot prompting gives instructions only, and relies on the model inferring the task from the description. Few-shot prompting adds a handful of worked examples. Many-shot ICL uses hundreds or thousands of examples, which became practical with long context models and can approach the accuracy of fine-tuning on some tasks.
Examples are only one kind of context. Facts placed in the prompt are learned in the same sense: give a model a product’s refund policy and it can answer refund questions it could not answer before. Retrieval-augmented generation is in-context learning applied to knowledge, with a retriever choosing which facts to place in the context for each query. A system prompt that describes a persona and rules is in-context learning applied to behaviour.
What affects in-context learning
Example selection. Examples similar to the current input help more than random ones. Many systems retrieve examples dynamically, picking the few whose embeddings are closest to the query rather than using a fixed set.
Format and consistency. Models pick up the format of examples very reliably. Some studies found that a consistent input-output format mattered more than whether every example label was correct, which suggests that much of ICL is about identifying the task and the output space.
Order and position. Results can shift with the order of examples, and models tend to weight the most recent ones. Information in the middle of a long context is the most likely to be underused, the effect known as lost in the middle.
Context length and noise. More context is not always better. As prompts grow, models make less reliable use of what is in them, a pattern described as context rot. Irrelevant material competes with relevant material, which is why context distraction and context poisoning are treated as failure modes in their own right.
Model size and training. Larger models show stronger ICL, and instruction tuning makes models better at learning from instructions alone, which shifts the balance towards zero-shot use.
In-context learning vs fine-tuning
The alternative to teaching a model through its context is teaching it through its weights with fine-tuning or a parameter-efficient method such as LoRA.
Aspect | In-context learning | Fine-tuning |
|---|---|---|
Changes the model | No | Yes, updates weights |
Time to apply | Immediate, per request | Hours to days of training |
Cost profile | Pay for context tokens on every call | Pay up front for training; shorter prompts after |
Updating knowledge | Change the context | Retrain |
Per-user customisation | Natural: each request gets its own context | Impractical for many users |
Best for | Changing facts, per-user context, new tasks | Stable formats, style and high-volume narrow tasks |
For facts that change, or that differ from user to user, in-context learning is usually the better tool: you can update a fact by changing what you retrieve, and nothing needs retraining. Fine-tuning suits stable behaviour that would otherwise need long instructions on every call. The trade-offs are explored further in RAG vs fine-tuning and embeddings vs fine-tuning.
In-context learning in agents
Agents depend on in-context learning at every step. Each turn of an agent loop rebuilds the prompt from the system prompt, tool definitions, the task, the results of earlier tool calls and any background the agent has retrieved, and the model learns the current state of the task from that context alone. Tool use is learned in context too: the model reads each tool’s name, description and parameters and infers when to call it. As an agent runs longer, its context fills with tool output, and the quality of its decisions starts to depend on how that context is managed. Context compression, context pruning and context offloading exist to keep the material the model learns from small and relevant, and they belong to the wider discipline of context engineering.
The limits: in-context learning is not memory
Whatever a model learns in context lasts exactly one call. Start a new conversation and the model has forgotten the user’s name, their preferences and the corrections they made. Within a long conversation, the model only learns from what still fits in the context window, so early turns are trimmed or summarised and their details are lost. The difference is set out in memory vs context window and argued at more length in the context window is not memory.
Two approaches address this. One is to update weights continually, which is slow, expensive and risks catastrophic forgetting, as discussed in agents shouldn’t learn in their weights. The other, used by most production systems, is to keep what the agent learns outside the model and put the relevant parts back into context on each call. That is the role of agent memory: a store of facts, preferences and events that is written as the agent works and read selectively before each model call, so in-context learning always has the right material to work from.
ICL also has a security side. Because models follow patterns in their context so readily, untrusted content in the prompt can steer them. Many-shot jailbreaks exploit this with long lists of fabricated examples, and indirect prompt injection plants instructions in documents the model reads.
A worked example
A SaaS company routes support tickets into 40 categories. A zero-shot prompt with category names reaches moderate accuracy but confuses similar categories. Adding a fixed set of 40 examples, one per category, helps but makes every prompt long. The team switches to dynamic examples: they store a few thousand labelled historical tickets, and for each new ticket they retrieve the eight most similar ones and place them in the prompt. Accuracy improves on the confusable categories, and prompts stay short because only relevant examples are included.
Later they add per-customer context. Large customers have custom categories and routing rules, so the retrieval step also pulls that customer’s rules and recent decisions. The model has not been retrained at any point. Everything it knows about each customer arrives through its context, chosen per request, which is how in-context learning scales across many users with different needs.
The team also learns where the approach strains. When the retrieved examples include a mislabelled ticket, the model sometimes copies the mistake, so they add a review step that corrects labels in the example store. When a customer changes its routing rules, the old rules must stop being retrieved straight away, or the model keeps applying them. Keeping the stored context accurate turns out to matter as much as choosing it well.
Where Exabase fits
Exabase does not change how models learn in context; that is a property of the model. Exabase manages what goes into the context, so that in-context learning has precise, current material on every call.
Exabase Memory keeps what an agent learns between calls. Send conversations in and the M-1 engine extracts facts, preferences and events, resolves contradictions as they change and consolidates related memories, so a customer’s updated routing rules replace the old ones. Before each model call, memory search returns the few memories relevant to the current query, which go into the prompt in place of the full history. M-1 reports 96.4% on LongMemEval and first place on the BEAM benchmark at 100K, 1M and 10M tokens. The agent memory solution describes the pattern and about memories covers the API.
Deep Search retrieves the passages, or the stored examples, that a query needs, with page numbers and timestamps for citations. Bases keep each user’s or customer’s memories and documents isolated, so per-customer context in the example above stays separate by construction. Retrieving a few hundred relevant tokens instead of carrying the full history also reduces cost: the reduce token costs solution describes an illustrative request falling by about 81% in input tokens.
Frequently asked questions
What is in-context learning in simple terms?
It is a model learning what to do from the content of its prompt, such as instructions, examples or facts, without being retrained.
Is in-context learning the same as few-shot prompting?
Few-shot prompting is one form of in-context learning. Zero-shot instructions, retrieved facts and system prompts also rely on it.
Does in-context learning change the model?
No. The weights stay the same. What the model learns from the prompt applies only to that call.
Is in-context learning better than fine-tuning?
For changing facts and per-user context, usually yes, because you update the context instead of retraining. Fine-tuning suits stable, high-volume tasks.
How many examples does in-context learning need?
It depends on the task. Many tasks need none or a few. Long-context models can use hundreds, which helps some tasks but costs more per call.
Why do agents forget what they learned in context?
Because context is rebuilt for every call. Anything not stored elsewhere and placed back into the prompt is gone. Agent memory solves this by persisting what matters.
How does Exabase relate to in-context learning?
Exabase supplies the context. Memory returns relevant facts about the user and Deep Search returns relevant passages, so the model learns from precise material on each call.
Related pages: few-shot prompting, zero-shot prompting, fine-tuning, context window, memory vs context window, agent memory, RAG, agent memory solution, the context window is not memory