In-context learning (ICL) is a meta-learning capability where a foundation model dynamically adapts to a new task based solely on the demonstrations and instructions embedded in its current context window. Unlike traditional fine-tuning, ICL does not modify the model's internal parameters; it leverages the model's pre-existing knowledge and pattern recognition to perform few-shot or zero-shot inference. This emergent property is a hallmark of sufficiently large and capable transformer-based architectures.
Glossary
In-Context Learning (ICL)

What is In-Context Learning (ICL)?
In-context learning (ICL) is the emergent ability of a large language model (LLM) to learn a new task or pattern dynamically during inference by analyzing the examples and instructions provided within its prompt, without updating its weights.
The mechanism relies on the model's attention mechanism to identify patterns and relationships between the provided demonstration examples and the new query. Effective ICL requires careful prompt engineering, including the selection, ordering, and formatting of examples. Performance is highly sensitive to these factors, making systematic prompt versioning and optimization critical for reliable production use. ICL is the foundational technique enabling few-shot prompting and advanced methods like chain-of-thought.
Key Characteristics of In-Context Learning
In-context learning (ICL) is an emergent ability of large language models to perform new tasks by analyzing examples provided within a prompt, without weight updates. Its core characteristics define its power, limitations, and practical application.
Weight-Free Adaptation
The defining feature of ICL is that the model's underlying parameters remain frozen. Learning occurs dynamically during the forward pass as the model processes the prompt's demonstration examples and task description. This creates a temporary, ephemeral adjustment to the model's output distribution based on the provided context, contrasting sharply with fine-tuning which permanently alters model weights.
Demonstration-Dependent Performance
ICL performance is highly sensitive to the quality, quantity, and ordering of the few-shot examples provided.
- Example Quality: Accurate, clear demonstrations are critical. Noisy or incorrect examples can teach the wrong task.
- Example Quantity: Performance typically improves with more examples but plateaus, constrained by the context window.
- Example Ordering: The sequence of examples can introduce bias; models often perform better on formats seen later in the prompt (recency bias). Systematic selection and ordering of demonstrations is a key engineering challenge.
Emergent & Scale-Dependent
ICL is an emergent ability that appears reliably only in models above a certain scale (typically tens of billions of parameters). Smaller models may show limited or no ICL capability. This occurs because larger models develop sufficiently robust internal representations and meta-learning capabilities during pre-training on diverse internet-scale data, allowing them to recognize and generalize patterns from the in-context demonstrations.
Task Formulation & Instruction Following
Effective ICL requires precise task formulation. The prompt must clearly delineate:
- The Instruction: A natural language description of the task.
- The Demonstration Format: Input-output pairs that exemplify the instruction.
- The Query: The new input for the model to act upon. The model must infer the mapping rule from the demonstrations and apply it consistently to the query. This reliance on instructional understanding links ICL closely to models that have undergone instruction tuning.
Temporary & Non-Persistent
The "learning" in ICL is confined to a single inference call. The adapted behavior does not persist beyond the current prompt's context window. Each new query requires the relevant demonstrations to be re-supplied within the prompt (unless cached). This makes ICL highly flexible for rapid prototyping but inefficient for repeated execution of the same task, where prompt templates or fine-tuning may be more suitable.
Theoretical Underpinnings: Implicit Bayesian Inference
A leading theoretical framework posits that ICL is analogous to the model performing implicit Bayesian inference. The pre-trained model has a prior over tasks learned from its training data. The in-context demonstrations act as observations that allow the model to infer the most likely task posterior (e.g., 'this is a sentiment classification task with this specific label format'). The model then generates outputs conditioned on this inferred task for the final query.
In-Context Learning vs. Fine-Tuning
A technical comparison of the two primary methods for adapting a pre-trained large language model (LLM) to a new task or domain.
| Feature | In-Context Learning (ICL) | Full Fine-Tuning | Parameter-Efficient Fine-Tuning (PEFT) |
|---|---|---|---|
Core Mechanism | Dynamically infers task from examples in the prompt. | Updates all model weights via gradient descent on a task-specific dataset. | Updates a small subset of parameters (e.g., adapters, LoRA matrices) while freezing the base model. |
Weight Updates | |||
Inference Latency Impact | Increases linearly with the number of in-context examples. | No direct impact; model runs at base speed. | Adds minor overhead from adapter modules (< 5%). |
Task-Specific Data Required | A few to several dozen examples (few-shot). | Typically thousands to millions of examples. | Hundreds to thousands of examples. |
Compute Cost | None for adaptation; cost is in extended prompt tokens. | Very High (GPU/TPU clusters for days). | Low to Moderate (single GPU for hours). |
Adaptation Speed | Instant (performed at inference time). | Slow (training loop required). | Fast (training loop, but on a small parameter set). |
Persistence of Learning | Ephemeral (lasts only for the current prompt). | Permanent (new model checkpoint is saved). | Permanent (small adapter checkpoint is saved). |
Catastrophic Forgetting Risk | None (base model is unchanged). | High (can degrade performance on original tasks). | Very Low (base model knowledge is preserved). |
Best For | Rapid prototyping, dynamic tasks, and black-box APIs. | Creating a dedicated, high-performance model for a static, data-rich task. | Efficiently specializing a model for a new domain with limited data and compute. |
Frequently Asked Questions
In-context learning (ICL) is a core capability of modern large language models. This FAQ addresses common technical questions about its mechanisms, applications, and relationship to other prompt engineering techniques.
In-context learning (ICL) is the emergent ability of a large language model (LLM) to learn a new task or pattern dynamically during inference by analyzing the examples and instructions provided within its prompt, without updating its underlying weights. It works by leveraging the model's pre-trained knowledge of language and patterns to perform few-shot or zero-shot generalization. The model treats the provided demonstrations within its context window as a conditional template, using its attention mechanism to identify the mapping between the input examples and their corresponding outputs, then applies this inferred mapping to the new query. This process is a form of meta-learning where the prompt itself acts as the training signal for that specific inference call.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
In-context learning (ICL) is a core capability within prompt engineering. These related concepts define the specific techniques and frameworks used to structure prompts and demonstrations to elicit this behavior.
Few-Shot Prompting
The foundational technique that operationalizes in-context learning. It provides the model with a small number of input-output examples (demonstrations) within the prompt to illustrate the task pattern before inference.
- Core Mechanism: Supplies the task demonstrations that the model uses for its in-context learning.
- Key Distinction: Explicitly provides examples, unlike zero-shot prompting. The quality and relevance of these examples directly determine ICL performance.
- Example: For sentiment classification, a prompt would include examples like
"I loved the movie!" -> Positiveand"It was terribly boring." -> Negativebefore the new query.
Chain-of-Thought (CoT) Prompting
An advanced ICL technique that improves reasoning by prompting the model to generate intermediate reasoning steps before the final answer. It often requires few-shot examples that include the reasoning chain.
- Mechanism: Extends standard few-shot prompting by including the step-by-step rationale within the demonstration examples.
- Impact: Unlocks complex arithmetic
Instruction Tuning
A supervised fine-tuning process that prepares a base model to better follow instructions and perform in-context learning. It trains the model on datasets of (instruction, output) pairs.
- Relationship to ICL: Creates a model pre-aligned to follow prompts, making it more responsive and reliable when presented with in-context examples. It is a pre-training prerequisite for effective ICL.
- Contrast with ICL: Instruction tuning updates the model's weights during training, while ICL is a dynamic, weightless inference-time adaptation.
- Outcome: Models like InstructGPT or Llama-2-Chat are instruction-tuned, exhibiting stronger zero-shot and few-shot capabilities.
Context Window
The fixed maximum token limit (input + output) for a single LLM interaction. It is the absolute boundary within which all in-context learning demonstrations must fit.
- Technical Constraint: ICL demonstrations consume the context window, competing with the user's query and the model's generated response. Models like GPT-4 have windows of 128K tokens, while others may be 4K or 8K.
- Engineering Implication: Prompts must be designed to be concise and efficient. For long-context tasks, techniques like demonstration selection or summary-based examples are critical.
- Trade-off: More demonstrations can improve ICL accuracy but reduce space for complex queries or long-form generation.
Retrieval-Augmented Generation (RAG)
An architecture that dynamically augments the LLM's prompt with relevant information retrieved from an external knowledge base. It modifies the context for ICL.
- Synergy with ICL: RAG retrieves factual snippets or documents that can be inserted into the prompt as contextual demonstrations or grounding evidence. The model then performs ICL over this augmented context.
- Primary Benefit: Mitigates hallucinations by providing authoritative source material, making the model's in-context learning factually grounded.
- Example: A customer service bot's prompt is augmented with the latest FAQ entries before it generates a response, effectively doing ICL on the retrieved policy documents.
Self-Consistency
A decoding and aggregation strategy that improves the reliability of answers generated via chain-of-thought ICL. It involves sampling multiple reasoning paths and selecting the most frequent final answer.
- Process: 1. Use a CoT prompt to perform few-shot ICL. 2. Generate multiple outputs (e.g., via temperature > 0). 3. Extract the final answer from each. 4. Perform a majority vote.
- Advantage: Reduces the variability and potential errors from any single reasoning path, leading to more robust and accurate outcomes from ICL.
- Application: Particularly effective for complex reasoning tasks in mathematics, logic, and commonsense QA where a single CoT path might diverge.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us