A contextual bandit is a reinforcement learning algorithm that selects an action—such as recommending a product—by observing the current context (e.g., user demographics, time of day) before making a decision. Unlike a standard multi-armed bandit, it leverages this side information to generalize across similar situations, making it uniquely suited for the cold start problem where no historical interaction data exists for a new user or item.
Glossary
Contextual Bandit

What is Contextual Bandit?
A reinforcement learning algorithm that selects actions based on contextual information about the user or situation, enabling a system to intelligently explore new items for cold-start users by leveraging side information.
The algorithm operates by receiving a context vector x, choosing an arm a, and observing a reward r, then updating its policy to maximize cumulative reward over time. This framework directly addresses the exploration-exploitation trade-off: it exploits known high-reward actions for familiar contexts while strategically exploring uncertain arms to gather data on new items, enabling real-time personalization from the very first interaction.
Key Characteristics of Contextual Bandits
Contextual bandits extend the classic multi-armed bandit problem by incorporating side information (context) about the user, item, or situation before selecting an action. This enables intelligent exploration for cold-start scenarios by leveraging observable features to predict reward potential without prior interaction history.
Contextual Feature Vector
The algorithm receives a d-dimensional feature vector x summarizing the current context—such as user demographics, device type, time of day, or item metadata. This side information allows the model to generalize across similar contexts rather than treating each action independently. For a new user with no history, the context vector provides the only signal for initial action selection, making feature engineering critical for cold-start performance.
Linear Reward Model Assumption
Most contextual bandit implementations assume a linear relationship between the context features and expected reward: E[r | x, a] = θ_a^T x. Each arm a maintains a coefficient vector θ_a that is updated via ridge regression as feedback arrives. This linear assumption enables efficient closed-form updates and provides theoretical regret bounds, though neural bandits using deep networks can capture non-linear patterns at the cost of increased sample complexity.
Exploration via Upper Confidence Bound
The LinUCB algorithm selects arms by computing an optimistic estimate: the predicted reward plus a confidence bonus proportional to the uncertainty in the arm's parameters. This bonus shrinks as more data is collected for a given context region, naturally shifting from exploration to exploitation. For cold-start items, the high initial uncertainty drives exploration, ensuring new inventory receives traffic proportional to its potential value.
Thompson Sampling with Context
A Bayesian alternative to UCB that maintains a posterior distribution over model parameters. At each decision point, the algorithm samples a parameter vector from the posterior and selects the arm with the highest predicted reward under that sample. This naturally balances exploration—arms with high variance are chosen when their sampled parameters happen to be optimistic. For cold-start users, the broad initial posterior ensures diverse recommendations until preferences are inferred.
Real-Time Parameter Updates
Unlike batch-trained supervised models, contextual bandits update arm parameters incrementally after each interaction using online learning. The update rule for LinUCB involves a recursive least-squares formulation: A_a = A_a + x x^T and b_a = b_a + r x, where A_a is the covariance matrix and b_a accumulates reward-weighted features. This allows the system to adapt to shifting user preferences without costly retraining cycles.
Regret Minimization Guarantee
Contextual bandits provide theoretical regret bounds that grow sub-linearly with time—typically O(√(T d)) for LinUCB, where T is the number of rounds and d is the feature dimension. This means the average per-round regret approaches zero, proving the algorithm eventually matches the performance of the best fixed policy in hindsight. For cold-start mitigation, this guarantees the system learns efficient exploration strategies rather than wasting impressions on irrelevant items.
Frequently Asked Questions
A contextual bandit is a reinforcement learning algorithm that selects actions based on side information about the user or situation, enabling a system to intelligently explore new items for cold-start users by leveraging observable context rather than relying solely on historical interaction data.
A contextual bandit is a reinforcement learning algorithm that incorporates observable side information—called context—into its action-selection policy, whereas a standard multi-armed bandit makes decisions based purely on historical reward averages. In a standard bandit, the algorithm maintains a single estimated reward distribution per arm and updates it after each pull. A contextual bandit, by contrast, receives a feature vector describing the current situation before each decision. This context vector might encode user demographics, time of day, device type, or item attributes. The algorithm learns a function mapping context to expected reward for each action, typically using a linear model, neural network, or decision tree. This allows the system to generalize across similar contexts, making it uniquely suited for cold-start personalization where a new user's observable attributes can immediately inform which items to explore. The key mathematical distinction is that the policy π(a|s) is now conditioned on state s, transforming the problem from a single stationary distribution to a supervised learning task embedded within a sequential decision framework.
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
Contextual bandits sit at the intersection of reinforcement learning and personalization. These related concepts form the technical foundation for solving cold-start problems with intelligent exploration.
Exploration-Exploitation Trade-off
The fundamental dilemma that contextual bandits are designed to solve. Exploitation selects the action with the highest known reward given the context, maximizing immediate gain. Exploration chooses suboptimal actions to gather data about their true reward distribution. The regret metric quantifies the cost of exploration—the difference between the reward obtained and the optimal reward that could have been achieved. Contextual bandits use side information to make exploration more efficient than context-free alternatives like epsilon-greedy.
Thompson Sampling
A probabilistic algorithm that elegantly balances exploration and exploitation by maintaining a posterior distribution over each action's reward probability. For each decision, it samples from these distributions and selects the action with the highest sample. Actions with high uncertainty—such as new items in a cold-start scenario—naturally receive more exploration because their wide distributions occasionally produce high samples. This probability matching approach is provably optimal for many bandit formulations and handles non-stationary environments gracefully.
Side Information
The contextual data that distinguishes a contextual bandit from a standard multi-armed bandit. Side information includes any observable attributes available at decision time:
- User features: demographics, device type, referral source, time of day
- Item features: category, brand, price point, color, release date
- Session features: page context, prior clicks in session, geolocation This auxiliary data enables the algorithm to generalize across similar contexts, making it possible to estimate rewards for new items that share features with previously explored ones.
Upper Confidence Bound (UCB)
A deterministic alternative to Thompson Sampling that selects actions by maximizing an optimistic estimate of the expected reward. The UCB formula adds an exploration bonus proportional to the uncertainty of the estimate: actions with fewer trials receive a larger bonus. The LinUCB variant extends this to contextual settings by modeling rewards as a linear function of context features, with a confidence ellipsoid around the parameter estimates. This approach provides strong theoretical regret bounds and is widely deployed in news recommendation systems.
Contextual Bandit vs. A/B Testing
While A/B testing measures the average treatment effect across a population, contextual bandits continuously adapt traffic allocation based on observed outcomes. Key differences:
- Static vs. Dynamic: A/B tests use fixed allocation ratios; bandits shift traffic toward winning variants in real time
- Population vs. Personalization: A/B tests find a single winner; contextual bandits learn which variant works best for each user segment
- Opportunity Cost: Bandits minimize the cumulative regret of showing suboptimal variants during the test For cold-start item launches, bandits reduce the cost of learning by quickly identifying which user segments respond positively.
Off-Policy Evaluation
The methodology for estimating a contextual bandit policy's performance using logged historical data collected under a different policy. Techniques include:
- Inverse Propensity Scoring (IPS): Reweights observed rewards by the inverse probability of the logging policy selecting that action
- Doubly Robust Estimation: Combines IPS with a reward model to reduce variance while maintaining unbiasedness
- Direct Method: Trains a regression model to predict rewards for all actions and evaluates the target policy against these predictions Off-policy evaluation is critical for safely validating new bandit algorithms before deploying them to production traffic.

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