A function vector (FV) is a compact, causal representation of a specific input-output task extracted from the internal activations produced by a set of in-context learning (ICL) examples. Rather than requiring the original few-shot prompt, this vector summarizes the algorithmic function the model has inferred—such as a grammatical transformation or a lexical mapping—into a single activation direction. When this vector is added to the model's residual stream during a forward pass on a novel query, it causally triggers the target task behavior, effectively acting as a compressed, injectable program.
Glossary
Function Vector

What is a Function Vector?
A function vector is a compact representation of a task derived from in-context examples that can be injected into a model's activations to trigger a specific input-output behavior without the original prompt.
The discovery of function vectors emerged from causal mediation analysis on transformer attention heads, particularly by identifying a small set of heads whose outputs encode the task function independently of the specific example tokens. By averaging the activations of these heads across diverse ICL demonstrations, researchers produce a robust vector that generalizes to unseen inputs. This technique demonstrates that in-context learning compiles explicit examples into an internal, reusable task representation, bridging the gap between prompting and activation engineering.
Core Characteristics of Function Vectors
Function vectors are compact, causal internal representations that summarize a task from in-context examples and can be injected into a model to trigger that behavior without the original prompt.
In-Context Task Compression
A function vector (FV) is formed by extracting and aggregating the activation deltas produced by a set of in-context examples. It compresses the input-output mapping demonstrated in the prompt into a single, compact representation. This vector captures the abstract function rather than the specific tokens, allowing the model to apply the task to novel inputs.
Causal Intervention Mechanism
Function vectors are applied via activation engineering: they are added directly to the residual stream at specific token positions during a forward pass. This is a causal intervention that hijacks the model's computation. Key properties include:
- Summation: The FV is simply added to existing activations.
- Position: Typically applied at the final token position before generation.
- Layer Specificity: Effective FVs are often extracted from and applied to a narrow range of middle layers.
Robustness to Input Variation
Unlike prompt-based few-shot learning, a function vector is remarkably robust to the specific formatting or lexical choices of the target input. Because it encodes the abstract algorithm (e.g., 'perform antonym generation') rather than surface-level patterns, it generalizes across different input templates, synonyms, and even slight task rephrasings without needing new examples.
Natural Task Vectors (NTVs)
A closely related concept is the Natural Task Vector, which is derived not from explicit input-output pairs but from a single, open-ended task definition prompt (e.g., 'Translate to French:'). The NTV is computed as the difference in activations between the task prompt and a neutral baseline. It demonstrates that models internally represent task intent as a directional vector in latent space.
Distinction from Prompting
Function vectors differ fundamentally from in-context learning prompts:
- Prompting: Relies on attention heads (specifically induction heads) to dynamically copy and map patterns from the context window at every generation step.
- Function Vectors: Bypass this dynamic attention mechanism by directly setting the model's computational state. The model no longer needs to 'read' the examples; it is already configured to execute the task.
Extraction Methodology
The standard extraction process involves a causal mediation analysis:
- Run the model on a set of few-shot examples and record the residual stream activations at a target layer.
- Run the model on a null or baseline prompt.
- Compute the activation delta (task activation minus baseline activation).
- Average these deltas across all example tokens to produce the final function vector. This isolates the task-specific signal from the background linguistic processing.
Frequently Asked Questions
Concise answers to the most common technical questions about function vectors, their mechanisms, and their role in mechanistic interpretability.
A function vector (FV) is a compact, causal representation derived from a small set of in-context learning examples that, when injected into a model's forward pass, triggers a specific input-output task behavior without the original prompt. It works by computing the average difference in the residual stream activations between a prompted and a baseline input across multiple examples, isolating the task-specific computation. This vector is then added to the model's activations at a specific layer, effectively 'steering' the model to perform the task on a zero-shot input. Unlike prompt engineering, the function vector represents the internal algorithm the model learned to solve the task, making it a powerful tool for mechanistic interpretability and causal intervention.
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.
Function Vectors vs. Related Concepts
Distinguishing function vectors from other activation-based intervention and representation techniques in transformer models.
| Feature | Function Vector | Steering Vector | Probing Classifier |
|---|---|---|---|
Primary Purpose | Trigger a specific input-output task behavior | Modify model behavior along a conceptual direction | Detect if information is linearly encoded in activations |
Derivation Source | Averaged activations from in-context examples | Contrastive pairs of activations or curated prompts | Supervised training on labeled activation datasets |
Causal Intervention | |||
Requires Original Prompt at Runtime | |||
Modifies Model Output | |||
Typical Injection Location | Residual stream at specific token positions | Residual stream across all layers | Read-only access to intermediate activations |
Interpretability Goal | Extract and replay a compact task algorithm | Induce a behavioral property like refusal or sycophancy | Audit what concepts are linearly separable |
Dependency on In-Context Learning |
Related Terms
Function vectors are a key concept in the broader field of reverse-engineering neural network computations. Explore these related terms to understand the surrounding ecosystem of causal analysis and feature representation.
Residual Stream
The central information highway in a transformer architecture where each layer reads from and writes its output back to a shared, accumulating state vector. Function vectors are typically injected directly into this stream.
- Structure: A sum of the token embedding, positional encoding, and all previous layer outputs
- Role: Allows layers to communicate by reading from and writing to a common bandwidth
- Connection: Function vectors hijack this pathway by adding a learned direction that biases subsequent computations toward a specific task
Linear Representation Hypothesis
The conjecture that high-level concepts are encoded as linear directions in the representation space of a neural network's activation vectors. Function vectors are a direct application of this hypothesis to task-level behaviors.
- Core claim: Features are represented as directions, not isolated neurons
- Evidence: Concepts can be manipulated by adding or subtracting activation vectors
- Implication: A function vector is a linear direction in the residual stream that encodes an entire input-output mapping, supporting the hypothesis that complex behaviors have linear representations

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