Documentation Index
Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
AI SDKs
Here are the configuration options for contexts in AI SDKs:.NET AI
Expand .NET AI SDK code sample
Expand .NET AI SDK code sample
In the .NET AI SDK, you can construct a Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If an attribute is a JSON object, then in your AI Config targeting, you can use
Context that only has a key by calling Context.New. The context kind defaults to “user,” or you can supply a different context kind. Alternatively, you can use the Context.Builder method for building a context with other properties.The argument to Builder is the context’s key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:The optional name and kind attributes, which you can set with
.Name() and .Kind(), expect string values. If the kind attribute is not specified, it is assumed to be “user.” Other attribute values can be booleans, numbers, strings, arrays, or JSON objects. The SDK uses the LdValue type to represent arrays and objects. The .NET SDK is strongly-typed, so be aware of this distinction./ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting rules. You can use . as a delimiter in your AI Config message. Continuing the same example, you could use {{ldctx.address.city}} in your message, and the value of the “city” field will be substituted when you customize the AI Config. To learn more, read Target with flags and Customizing AI Configs.To learn how to configure private attributes in the .NET AI SDK, read Private attributes.To learn how to configure anonymous contexts in the .NET AI SDK, read Anonymous contexts and users.Go AI
Expand Go AI SDK code sample
Expand Go AI SDK code sample
The Go AI SDK defines a Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:Each individual context within a multi-context can have the same attributes. The only restriction is that each context has to have a different context If an attribute is a JSON object, then in your AI Config targeting, you can use
Context struct and a Builder. The context key is the only mandatory context attribute. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:kind from the others within the multi-context.You can also use the context builder to create each of the individual contexts:The kind and name attributes expect string values. You can set the kind, or, if you do not set it, LaunchDarkly assumes that the context kind is “user.” Other attribute values can be booleans, numbers, strings, arrays, or JSON objects. These types are all represented by the
ldvalue.Value type. The Go SDK is strongly-typed, so be aware of this distinction./ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting rules. You can use . as a delimiter in your AI Config message. Continuing the same example, you could use {{ldctx.address.city}} in your message, and the value of the “city” field will be substituted when you customize the AI Config. To learn more, read Target with flags and Customizing AI Configs.To learn how to configure private attributes in the Go AI SDK, read Private attributes.To learn how to configure anonymous contexts in the Go AI SDK, read Anonymous contexts and users.Node.js (server-side) AI
Expand Node.js (server-side) AI SDK code sample
Expand Node.js (server-side) AI SDK code sample
In the Node.js (server-side) AI SDK, contexts are JSON objects. The Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If an attribute is a JSON object, then in your AI Config targeting, you can use
key property is the context key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:The optional
name and kind attributes expect string values. If the kind attribute is not specified, it is assumed to be “user.” Other attribute values can be booleans, numbers, strings, arrays, or JSON objects./ as a delimiter to refer to specific fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting rules. You can use . as a delimiter in your AI Config message. Continuing the same example, you could use {{ldctx.address.city}} in your message, and the value of the “city” field will be substituted when you customize the AI Config. To learn more, read Target with AI Configs and Customizing AI Configs.To learn how to configure private attributes in the Node.js (server-side) AI SDK, read Private attributes.To learn how to configure anonymous contexts in the Node.js (server-side) AI SDK, read Anonymous contexts and users.Python AI
Expand Python AI SDK code sample
Expand Python AI SDK code sample
In the Python AI SDK, the Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If you have many attributes to set, you can also create a context from a dictionary:If an attribute is a JSON object, then in your AI Config targeting, you can use
Context class has a create method for creating a context with a context kind of “user” and with only a key. It has a builder method for building a context with other properties.The argument to Context.builder is the context’s key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key or a hash, as long as the same context always has the same key. We recommend using a hash if possible.Here’s an example:The optional name and kind attributes expect string values. If the “kind” attribute is not specified, it is assumed to be “user.” Other attribute values can be booleans, numbers, strings, arrays, or objects.
/ as a delimiter to refer to specific fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting rules. You can use . as a delimiter in your AI Config message. Continuing the same example, you could use {{LDCTX.address.city}} in your message, and the value of the “city” field will be substituted when you customize the AI Config. To learn more, read Target with AI Configs and Customizing AI Configs.To learn how to configure private attributes in the Python AI SDK, read Private attributes.To learn how to configure anonymous contexts in the Python AI SDK, read Anonymous contexts and users.Ruby AI
Expand Ruby AI SDK code sample
Expand Ruby AI SDK code sample
In the Ruby AI SDK, contexts are instances of Here’s how to construct a context with a context kind of something other than “user”:Here’s how to construct a multi-context, which includes multiple context kinds:If an attribute is a JSON object, then in your flag or segment targeting, you can use
LaunchDarkly::LDContext.The key property is the context’s key. The combination of key and kind must uniquely identify each context. For the key, you can use a primary key, an email address, or a hash string, as long as the same context always has the same key. We recommend using a hash string if possible.Here’s an example:The optional name and kind attributes expect string values. If the “kind” attribute is not specified, it is assumed to be “user” and the hash is assumed to be in the legacy user format. Other attribute values can be booleans, numbers, strings, arrays, or objects.
/ as a delimiter to refer to specific object fields. For example, if you have an “address” attribute that includes several fields, then you could use /address/city in your targeting. To learn more, read Target with flags.You can use . as a delimiter in your AI Config message. Continuing the same example, you could use {{LDCTX.address.city}} in your message, and the value of the “city” field will be substituted when you customize the AI Config. To learn more, read Target with AI Configs and Customizing AI Configs.To learn how to configure private attributes in the Ruby AI SDK, read Private attributes.To learn how to configure anonymous contexts in the Ruby AI SDK, read Anonymous contexts and users.