Inferensys

Glossary

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.
Developer building agentic RAG system, retrieval pipeline diagram on laptop, technical workspace with notes.
REINFORCEMENT LEARNING

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.

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.

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.

MECHANISM

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.

01

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.

02

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.

03

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.

04

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.

05

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.

06

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.

CONTEXTUAL BANDITS EXPLAINED

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.

Prasad Kumkar

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.