No results for ""
EXPAND ALL
  • Home
  • API docs

Target with AI configs

Read time: 6 minutes
Last edited: Nov 27, 2024

Overview

This topic explains how to use AI config targeting to control which of your customers receive a particular version of an AI config, based on their context.

LaunchDarkly contexts are data objects representing users, devices, organizations, and other entities that interact with your application. These data objects contain context attributes that describe what you know about that context, such as their name, location, device type, or organization they are associated with. LaunchDarkly AI SDKs can pass any context attributes you want to LaunchDarkly, where you can then use those attributes in AI config targeting, as well as in the AI config version's prompt messages.

If you are familiar with LaunchDarkly's flag targeting, this process is very similar: with AI configs, you can target individuals or segments, or target contexts with custom rules.

Additionally, every AI config has a default rule and an off version.

Targeting rules are specific to each environment.

Target individuals

You can target specific contexts based on their context key. If you are targeting more than one or two individuals, we recommend targeting a segment instead, because segments are reusable across AI configs and flags.

To target individuals:

  1. Navigate to the Targeting tab for the AI config.
  2. At the top of the tab, select the environment for which you want to create targeting rules. Targeting rules are specific to each environment.
  • To add targeting rules to an environment that's not shown, click the + icon to add another environment to the Targeting tab.
  1. Click the + Add rule button, or + between existing rules, and select Target individuals.
  2. For each AI config version, choose the context kind for the contexts you want to target.
  • By default, the context kind is "user."
  • To update this, click Edit context. In the "Select context kinds" dialog, choose one or more context kinds and click Save.
  • The "Individual targets" section updates to display the context kinds you selected.
  1. Enter context keys for the contexts you want to target with the AI config version.
  2. Click Review and save.

Target segments

Segments are lists of contexts that you can use to manage AI config targeting behavior in bulk. You can target segments to release specific AI config versions to different groups of contexts or end users at once.

We recommend using a segment when you want to target the same group of contexts in multiple AI configs. You can target the segment in each AI config, rather than recreating a targeting rule or set of rules for many AI configs.

To target segments:

  1. Navigate to the Targeting tab for the AI config.
  2. At the top of the tab, select the environment for which you want to create targeting rules. Targeting rules are specific to each environment.
  • To add targeting rules to an environment that's not shown, click the + icon to add another environment to the Targeting tab.
  1. Click the + Add rule button, or + between existing rules, and select Target segments.
  2. (Optional) Enter a name for the rule.
  3. In the Operator menu, select whether you want contexts in these segments or not in these segments to match the targeting rule.
  4. In the Segments menu, enter or select the segments you want to target.
  5. (Optional) Click the + to add additional clauses to your targeting rule.
  6. From the Select... menu, select the version to serve, or set a percentage rollout.
  7. Click Review and save.

Here is an example of a targeting rule for segments:

A targeting rule for segments.
A targeting rule for segments.

To reference this rule when working with other members of your organization, click the three-dot overflow menu and choose Copy link to rule.

To learn more, read Segments.

Target contexts with custom rules

You can create custom targeting rules using any context kinds and any context attributes.

To create a custom targeting rule:

  1. Navigate to the Targeting tab for the AI config.
  2. At the top of the tab, select the environment for which you want to create targeting rules. Targeting rules are specific to each environment.
  • To add targeting rules to an environment that's not shown, click the + icon to add another environment to the Targeting tab.
  1. Click the + Add rule button, or + between existing rules, and select Build a custom rule.
  2. (Optional) Enter a name for the rule.
  3. Select an option from the Context kind menu:
  1. In the Attribute menu, select one of this context's attributes.
  2. In the Operator menu, select the operator for your clause.
  3. In the Values menu, enter one or more values to check against.
  4. (Optional) Click the + to add additional clauses to your targeting rule.
  5. From the Select... menu, select the version to serve, or set a percentage rollout.
  6. Click Review and save.

If a targeting rule references any context kinds or attributes with null values, or that do not exist for a given context, then the AI config skips that rule. For example, in a rule that checks "region is one of Canada," any context whose region attribute is not set or is set to null does not match the rule. Similarly, in a rule that checks "region is not one of Canada," any context whose region attribute is not set or is set to null does not match the rule. This behavior ensures that your rules only target contexts for which you explicitly have attribute information.

To reference this rule when working with other members of your organization, click the three-dot overflow menu and choose Copy link to rule.

To learn more about how to construct targeting rules, read About targeting rules. Although that topic applies specifically to feature flag targeting, the "About targeting rules" section discusses the components of targeting rules, including their descriptions, conditions, rollouts, attributes, and operators. These elements are common to both feature flags and AI configs.

Set the default rule

Each AI config automatically includes a default rule. It describes which AI config version should be served to contexts that don't match any of the previous targeting rules on the AI config.

The default rule is different from the fallback value, which is set in your application's code and is the value that contexts receive if your application can't connect to LaunchDarkly. To learn more, read Fallback value.

The default rule is also different from the off version, which is the value LaunchDarkly serves when the flag is off. To learn more, read The off version, below.

To set the default rule:

  1. Navigate to the Targeting tab for the AI config.
  2. At the top of the tab, select the environment for which you want to create targeting rules. Targeting rules are specific to each environment.
  • To add targeting rules to an environment that's not shown, click the + icon to add another environment to the Targeting tab.
  1. Find the last rule on the Targeting tab, which is labeled "Default rule."
  2. Click Edit to configure the default rule to serve a specific version, or apply a percentage rollout to any remaining contexts.

Here is an image of a default rule:

An AI config's default rule.
An AI config's default rule.

The off version

Each AI config has a special "disabled" version, which is created automatically. It is served when the AI config is toggled off.