Skip to content

Commit 0c00c70

Browse files
committed
doc: contextual bandit README section and changelog entries
1 parent d5727e1 commit 0c00c70

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
* Contextual bandit support in both clients, at behavioral parity with the JavaScript SDK:
8+
* Consumes the `contextualBandits` payload section (and `encryptedContextualBandits`), evaluates `contextualBanditRef`/`contextualVariations` rules with per-leaf weight substitution, and reports `leafId`, `variationWeights`, and `banditVersion` on experiment results for exposure logging.
9+
* New `set_payload()` on `GrowthBook` and `GrowthBookClient` for seeding full SDK payloads; only the sections present are overwritten, and encrypted sections are decrypted with the configured `decryption_key` (JS `setPayload` semantics).
10+
* Payload refreshes missing a section (`savedGroups`, `contextualBandits`) preserve the previous value at every layer instead of wiping it; refreshes publish one coherent evaluation snapshot atomically in the synchronous client, matching the async client.
11+
* Malformed bandit definitions or leaves degrade to the rule's aggregate weights instead of raising during evaluation.
12+
13+
### Bug Fixes
14+
15+
* `savedGroups` from a feature refresh were applied to the evaluation context one refresh late in the synchronous client.
16+
* The built-in tracking plugin now sends the exposure-time user context attributes with experiment events (previously async client events had none).
17+
318
## [3.0.0](https://github.com/growthbook/growthbook-python/compare/v2.4.0...v3.0.0) (2026-08-26)
419

520

‎README.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,34 @@ Behaviors to be aware of:
611611

612612
With `GrowthBookClient`, the `on_experiment_viewed` and `on_feature_usage` options — and callbacks registered via `client.subscribe()` — may be either regular functions or coroutines. Coroutine callbacks are scheduled on the event loop without blocking evaluation, and a tracking callback that raises is retried on the next evaluation of the same experiment/user pair.
613613

614+
## Contextual Bandits
615+
616+
Contextual bandit experiments (GrowthBook Enterprise) learn which variation works best for each kind of user. All learning happens server-side: GrowthBook trains a model that partitions users into leaves and computes per-leaf variation weights. The SDK routes each user to the first leaf whose condition matches their attributes and buckets them with that leaf's weights — there is no model or sampling client-side.
617+
618+
Support is automatic once features are loaded from the GrowthBook API. Payloads for contextual bandit experiments contain:
619+
620+
- A top-level `contextualBandits` map (or `encryptedContextualBandits`, decrypted with your `decryption_key` like the other encrypted sections) holding each bandit's `banditVersion` and its per-leaf `condition`/`weights`.
621+
- Feature rules carrying `contextualBanditRef` (which bandit to use) and `contextualVariations` (the variation values).
622+
623+
Payloads can also be seeded or updated manually. `set_payload` (both clients) overwrites only the sections present, so a payload without `contextualBandits` preserves the current map — the same semantics background refreshes use:
624+
625+
```python
626+
gb.set_payload({
627+
"features": {...},
628+
"contextualBandits": {...}, # omitted sections are preserved
629+
})
630+
```
631+
632+
When a user is exposed through a contextual bandit rule, the experiment `Result` (including the result passed to `on_experiment_viewed`) carries three extra fields:
633+
634+
- **leafId** — the matched leaf (`-1` when no leaf matched and the rule's aggregate weights were used)
635+
- **variationWeights** — the weight vector actually used for bucketing (the assignment propensities)
636+
- **banditVersion** — the version of the bandit model that produced the weights
637+
638+
Log these to your data warehouse in your tracking callback — along with the `user_context` attributes used at exposure time — so GrowthBook can train the bandit and attribute exposures to the right model version. Because weights change as the bandit learns, users may be re-bucketed during the experiment; sticky bucketing is disabled server-side for these rules and analysis attributes each user to their first exposure.
639+
640+
Older SDK versions ignore contextual bandit rules entirely and serve the feature's default value.
641+
614642
## Inline Experiments
615643

616644
Instead of declaring all features up-front and referencing them by ids in your code, you can also just run an experiment directly. This is done with the `run` method:

0 commit comments

Comments
 (0)