On this page

For AI agents: a documentation index is available at /llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.

Contextual Bandit

Use Statsig Contextual Bandits (Autotune AI) with Warehouse Native to personalize the variant each user sees, with outcomes and training data from your warehouse.

A contextual bandit (Autotune AI) personalizes the variant Statsig serves each user, based on context features you pass on the user object. The bandit learns from outcomes to improve its predictions. In Warehouse Native, outcomes come from a Metric Source in your warehouse, and Statsig trains the model on data it processes in your warehouse. Use a contextual bandit when the best variant depends on who the user is. To find one winning variant for all users, use Autotune instead.

How Warehouse Native changes a contextual bandit

Setup and SDK usage match cloud contextual bandits. Warehouse Native changes where data comes from and where Statsig processes it.

Create a contextual bandit

Before you start, set up a Metric Source that contains your outcome event.

  1. In the Statsig console, go to Experiments > Autotune, then click Create.
  2. Enter a name and, optionally, a goal that explains why you're running the bandit.
  3. Set the autotune type to Contextual.
  4. Choose the outcome type:
    • Event Occurring: For discrete outcomes, such as clicks or checkouts.
    • Event Value: For continuous outcomes, such as revenue or latency. Set whether a higher or lower value is better.
  5. Select the Metric Source that contains your outcome event, and add optional filters. For Event Value, select the field that holds the value.
  6. Review the training settings, such as the exploration window, attribution window, and feature list. For descriptions of each setting, refer to Training settings.
  7. Define the variants that your code fetches.

Serve variants in code

Fetch the assigned variant with getExperiment, and pass context features in the custom field of the user object. Statsig needs a few hundred units to train a model. Training starts only after the attribution window for those units ends. For supported SDKs, refer to Get started with Autotune AI. For a code example, refer to Use the Contextual Autotune in code.

To monitor a running bandit, refer to Monitoring your Contextual MAB. For how Statsig builds and scores the model, refer to Contextual Bandit Methodology.

Was this helpful?