Target with AI configs
Read time: 6 minutes
Last edited: Dec 17, 2024
Overview
This topic explains how to use AI config targeting to control which of your customers receive a particular variation 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 variation's 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 variation.
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:
- Navigate to the Targeting tab for the AI config.
- 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.
- Click the + Add rule button, or + between existing rules, and select Target individuals.
- For each AI config variation, 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.
- Enter context keys for the contexts you want to target with the AI config variation.
- 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 variations 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:
- Navigate to the Targeting tab for the AI config.
- 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.
- Click the + Add rule button, or + between existing rules, and select Target segments.
- (Optional) Enter a name for the rule.
- In the Operator menu, select whether you want contexts in these segments or not in these segments to match the targeting rule.
- In the Segments menu, enter or select the segments you want to target.
- (Optional) Click the + to add additional clauses to your targeting rule.
- From the Select... menu, select the variation to serve, or set a percentage rollout.
- Click Review and save.
Here is an example of 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:
- Navigate to the Targeting tab for the AI config.
- 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.
- Click the + Add rule button, or + between existing rules, and select Build a custom rule.
- (Optional) Enter a name for the rule.
- Select an option from the Context kind menu:
- Choosing a specific context kind lets you target on attributes for contexts of that kind.
- Choosing "Context kind" lets you target one or more context kinds. If you choose "Context kind," skip to step 7.
- Context kinds are included in this menu after either you create them from the Contexts list or customize an AI config using a LaunchDarkly AI SDK.
- In the Attribute menu, select one of this context's attributes.
- In the Operator menu, select the operator for your clause.
- In the Values menu, enter one or more values to check against.
- (Optional) Click the + to add additional clauses to your targeting rule.
- From the Select... menu, select the variation to serve, or set a percentage rollout.
- 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 variation 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 variation, which is the value LaunchDarkly serves when the flag is off. To learn more, read The off variation, below.
To set the default rule:
- Navigate to the Targeting tab for the AI config.
- 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.
- Find the last rule on the Targeting tab, which is labeled "Default rule."
- Click Edit to configure the default rule to serve a specific variation, or apply a percentage rollout to any remaining contexts.
Here is an image of a default rule:
The off variation
Each AI config has a special "disabled" variation, which is created automatically. It is served when the AI config is toggled off.