ExperimentationMulti-armed bandits

Creating multi-armed bandits

This feature is for Early Access Program customers only

Multi-armed bandits are available only to members of LaunchDarkly’s Early Access Program (EAP). If you want access to this feature, join the EAP.

This topic explains how to set up and configure a multi-armed bandit in LaunchDarkly.

Configuring a multi-armed bandit requires several steps:

  1. Creating the flag or AI Config and its variations,
  2. Creating a metric,
  3. Building the multi-armed bandit,
  4. Turning on the flag or AI Config, and
  5. Starting an iteration.

These steps are explained in detail below.

Prerequisites

Before you build a multi-armed bandit, you should read about and understand the following concepts:

Create flags or AI Configs

Before you begin a multi-armed bandit, create a flag or AI Config with the variations you plan to optimize the performance of. You do not need to toggle on the flag before you create the multi-armed bandit, but you do have to toggle flags on before you start an iteration. AI Configs are on by default.

To learn more, read Creating new flags, Creating flag variations, Create AI Configs, and Create and manage AI Config variations.

You cannot run a multi-armed bandit on a flag if:

You can build and run multiple multi-armed bandits on the same flag or AI Config as long as there is only one running multi-armed bandit per targeting rule. You cannot run multiple multi-armed bandits on the same rule at the same time.

Create metrics

Metrics measure audience behaviors affected by your flags. You can use metrics to track all kinds of things, from how often end users access a URL to how long that URL takes to load a page. You can reuse existing metrics in multiple multi-armed bandits, or create new ones for your multi-armed bandits.

To learn how to create your own new metric, read Metrics. LaunchDarkly also automatically creates metrics for AI Configs. To learn more, read Metrics generated from AI SDK events.

Multi-armed bandits do not support metrics using percentile analysis methods

Multi-armed bandits support metrics using the “Average” metric analysis method. You cannot use metrics using a percentile analysis method with a multi-armed bandit.

If you want to learn which variation performs better, it must be possible for that metric to measure something in all of the variations within the multi-armed bandit. To learn more, read Metrics and flag variations.

Build multi-armed bandits

You can view all of the multi-armed bandits in your environment on the Multi-armed bandits list.

To build a multi-armed bandit:

  1. Click Create, then choose Multi-armed bandits. A “Create multi-armed bandit” dialog appears.
  2. Enter a Name.
  3. Enter a Goal.
  4. Click Create multi-armed bandit. The Design tab opens.
  5. Choose a context kind to Randomize by.
  6. Select a Metric.
    • A list of environments displays. It shows which environments have received events for these metrics. If no environments are receiving events, check that your SDKs are configured correctly.
    • Click Create to create and use a new metric.
  7. Choose a Flag or AI Config.
    • Click Create flag or Create AI Config to create and use a new flag or AI Config.
  8. Choose a targeting rule for the Experiment audience.
    • If you want to restrict your audience to only contexts with certain attributes, create a targeting rule on the flag or AI Config you include in the multi-armed bandit and run the multi-armed bandit on that rule.
    • If you don’t want to restrict the audience for your multi-armed bandit, run the multi-armed bandit on the default rule. If the flag or AI Config doesn’t have any targeting rules, the default rule will be the only option.

The "Audience targeting" section with the default rule chosen.

The "Audience targeting" section with the default rule chosen.
  1. (Optional) If you want to exclude contexts in this multi-armed bandit from certain other multi-armed bandit and experiments, click Add experiment to exclusion layer and select a layer.

A layer is a set of experiments and multi-armed bandits that cannot share traffic with each other. All of the experiments and multi-armed bandits within a layer are mutually exclusive, which means that if a context is included in one, LaunchDarkly will exclude it from any other experiments and multi-armed bandits in the same layer.

To add the multi-armed bandit to an existing layer:

  1. Click Select layer.
  2. Search for and choose the layer you want to add the multi-armed bandit to.
  3. Enter a Reservation amount. This is the percentage of the contexts within this layer you want LaunchDarkly to include in this multi-armed bandit.
  4. Click Save layer.

If you need to create a new layer:

  1. Click Create layer.
  2. Add a Name and Description.
  3. Click Create layer.
  4. Enter a Reservation amount. This is the percentage of the contexts within this layer you want LaunchDarkly to include in this multi-armed bandit.
  5. Click Save layer.
  1. Select a Variation served to users outside this experiment.
  2. Select the Sample size for the multi-armed bandit. This is the percentage of all of the contexts that match the multi-armed bandit’s targeting rule that you want to include in the multi-armed bandit.
  3. Select your desired Update frequency. This determines how often the multi-armed bandit shifts traffic to the winning variation.
  4. By default, starting traffic is split equally between all of the included variations. If you want to exclude a variation from the multi-armed bandit:
    • Click Edit next to “Variations split.”
    • For any variation you want to exclude, change the percentage to 0%.
    • Click Save audience split.
  5. (Optional) If you want to include the multi-armed bandit in a holdout, select a Holdout name.
Multi-armed bandits cannot be in a holdout and in a layer at the same time

Multi-armed bandits can either be in a holdout or in a layer, but not both. If you added the multi-armed bandit to a layer, you will not see the option to add it to a holdout.

  1. Scroll to the top of the page and click Save.

If needed, you can save your in-progress multi-armed bandit design to finish later. To save your design, click Save at the top of the creation screen. Your in-progress multi-armed bandit design is saved and appears on the multi-armed bandits list. To finish building the multi-armed bandit, click on the multi-armed bandit’s name and continue editing.

After you have created your multi-armed bandit, the next step is to toggle on the flag. AI Configs are on by default. Then, you can start an iteration.

You can also use the REST API: Create experiment

Turn on flags or AI Configs

For a multi-armed bandit to begin recording data, the flag or AI Config used in the multi-armed bandit must be on. Targeting rules for AI Configs are on by default. To learn how to turn targeting rules on for flags, read Turning flags on and off.

Start iterations

After you create a multi-armed bandit and toggle on the flag, you can start a multi-armed bandit iteration in one or more environments. AI Configs are on by default.

To start a multi-armed bandit iteration:

  1. Navigate to the multi-armed bandits list.
  2. Click on the environment section containing the multi-armed bandit you want to start.
    • If the environment you need isn’t visible, click the + next to the list of environment sections. Search for the environment you want, and select it from the list.

The environment selection menu.

The environment selection menu.
  1. Click on the name of the multi-armed bandit you want to start an iteration for. The Design tab appears.
  2. Click Start.
  3. Repeat steps 1-4 for each environment you want to start an iteration in.

A multi-armed bandit with the "Start" button called out.

A multi-armed bandit with the "Start" button called out.

You can run a multi-armed bandit indefinitely, allowing it to reallocate traffic as needed. If you are running a multi-armed bandit on a time-boxed feature, such as a holiday promotion, then you can stop the multi-armed bandit iteration when the promotion is over.

To learn more about starting and stopping iterations, read Starting and stopping experiment iterations.

You can also use the REST API: Create iteration