Thompson Sampling is a probabilistic algorithm for sequential decision-making that addresses the exploration-exploitation trade-off by maintaining a posterior probability distribution over each action's reward. At each step, it samples a value from each action's posterior and selects the action with the highest sample, ensuring that actions with high uncertainty are explored proportionally to their chance of being optimal.
Glossary
Thompson Sampling

What is Thompson Sampling?
A Bayesian approach to the exploration-exploitation dilemma that selects actions based on their probability of being optimal given a posterior distribution, naturally balancing uncertainty for new items.
In cold start mitigation, Thompson Sampling excels by naturally allocating exploration budget to new items with wide posterior distributions, while exploiting known high-performers with narrow distributions. Unlike epsilon-greedy strategies that explore uniformly at random, this Bayesian approach directs exploration toward actions that are plausibly superior, making it highly efficient for bootstrapping recommendations with sparse interaction data in contextual bandit frameworks.
Key Characteristics of Thompson Sampling
Thompson Sampling is a Bayesian algorithm for the exploration-exploitation dilemma that selects actions proportionally to their probability of being optimal given current knowledge. It naturally balances trying uncertain options against exploiting known winners.
Probability Matching Mechanism
Thompson Sampling operates by probability matching—the probability of selecting an action equals the probability that the action is optimal given the posterior distribution. For each decision point, the algorithm draws a single sample from the posterior distribution of each arm's expected reward and selects the arm with the highest sampled value. This stochastic selection ensures that arms with high uncertainty but promising potential are explored proportionally to their chance of being the best, while arms with high certainty of being suboptimal are naturally suppressed.
Bayesian Posterior Updating
The algorithm maintains a posterior distribution over each action's reward parameter, updated via Bayes' theorem after every observation. For binary rewards, a Beta distribution serves as the conjugate prior:
- Prior: Beta(α, β) representing initial beliefs
- Update: After observing a success, α → α + 1; after a failure, β → β + 1
- Result: The distribution narrows with more data, reflecting increased certainty This Bayesian framework naturally encodes uncertainty, making it ideal for cold-start items where the posterior remains wide, encouraging exploration.
Regret Minimization Properties
Thompson Sampling achieves logarithmic regret in stationary environments, meaning the cumulative difference between the algorithm's performance and the optimal policy grows only logarithmically over time. Key regret characteristics:
- Lai-Robbins lower bound: Thompson Sampling asymptotically matches the theoretical lower bound for regret in multi-armed bandits
- Empirical performance: Often outperforms UCB and ε-greedy in practice, especially in the finite horizon
- Non-stationary adaptation: With appropriate forgetting mechanisms, it can track changing reward distributions This makes it particularly effective for dynamic retail environments where consumer preferences shift.
Contextual Integration via Generalized Linear Models
Contextual Thompson Sampling extends the algorithm to incorporate side information about users and items. Instead of maintaining independent per-arm distributions, it models expected rewards as a function of context features:
- Linear contextual bandits: Reward = θᵀx + ε, where θ has a multivariate Gaussian posterior
- Logistic contextual bandits: For binary outcomes, using a Bayesian logistic regression with Laplace approximation
- Neural contextual bandits: Using Bayesian neural networks with Monte Carlo dropout for uncertainty estimation This enables cold-start mitigation by allowing the model to generalize from similar items or users based on their feature representations.
Practical Implementation Considerations
Deploying Thompson Sampling in production requires addressing several engineering challenges:
- Prior specification: Weakly informative priors (e.g., Beta(1,1)) for cold-start items to ensure initial exploration
- Batch updating: Accumulating feedback and performing posterior updates in mini-batches to reduce computational overhead
- Delayed feedback: Handling the gap between action selection and reward observation using partial feedback models
- Scalability: For large action spaces, maintaining millions of Beta distributions is memory-efficient; each arm requires only two floating-point parameters (α, β)
- Non-binary rewards: Extending to Gaussian rewards with Normal-Inverse-Gamma conjugate priors or to multinomial outcomes with Dirichlet distributions
Comparison with Alternative Bandit Algorithms
Thompson Sampling distinguishes itself from other exploration strategies:
- vs. ε-greedy: ε-greedy explores uniformly at random with fixed probability ε, wasting exploration on clearly suboptimal arms. Thompson Sampling directs exploration toward arms with high uncertainty and potential
- vs. UCB: Upper Confidence Bound algorithms use optimistic point estimates with deterministic confidence intervals. Thompson Sampling's stochastic sampling often provides better finite-sample performance and handles complex posterior shapes more naturally
- vs. Boltzmann exploration: Softmax exploration uses a temperature parameter to control exploration, requiring careful tuning. Thompson Sampling is parameter-free beyond the prior specification
- Key advantage: Thompson Sampling is the oldest bandit algorithm (proposed in 1933) yet remains state-of-the-art due to its elegant Bayesian foundation and strong empirical results
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.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about Thompson Sampling, the probabilistic algorithm that elegantly solves the exploration-exploitation dilemma in reinforcement learning and personalization systems.
Thompson Sampling is a probabilistic reinforcement learning algorithm that selects actions by randomly drawing from the posterior probability distribution of each action's expected reward, naturally balancing the exploration-exploitation trade-off. Instead of calculating a single point estimate of an action's value, it maintains a full probability distribution representing the uncertainty about that estimate. At each decision step, the algorithm samples a value from each action's distribution and selects the action with the highest sampled value. Actions with high uncertainty have wider distributions, giving them a non-zero probability of being selected even if their current mean estimate is lower. This stochastic selection mechanism ensures that promising but uncertain actions are explored proportionally to their probability of being optimal, while well-understood high-reward actions are exploited most of the time. The posterior distribution is updated using Bayes' rule as new observations arrive, causing the distribution to narrow as confidence increases. For binary reward scenarios, a Beta distribution is commonly used as the conjugate prior, while Gaussian distributions are employed for continuous rewards.
Related Terms
Thompson Sampling is a cornerstone of modern bandit algorithms. These related concepts define the ecosystem of exploration-exploitation strategies and the infrastructure required to deploy them in production personalization systems.

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