Posterior
Query an optimization's posterior: the source of every model figure.
Every model figure Levered shows (traffic share and probability of best, expected rewards, lifts, progress, factor effects and importance, per-segment figures) is computed from the optimization's posterior when it is read. The other endpoints return counts and configuration only. To read a model figure, query the posterior with SQL.
Query the posterior
POST /api/v2/posterior/optimizations/:optimizationId/queryAuth: Required. A Clerk bearer token or an API key (Authorization: Bearer <key> or X-API-Key: <key>).
Runs one read-only SQL query (DuckDB dialect) over the optimization's posterior draws and the views described below. Each published posterior is a version, named after the time its fit finished; every fit publishes a new one.
Request body:
{
"sql": "SELECT variant_key, share FROM thompson_traffic_share ORDER BY share DESC",
"params": {},
"model_version": "latest"
}| Field | Type | Required | Description |
|---|---|---|---|
sql | string | Yes | One read-only query, up to 20,000 characters. |
params | object | No | Values bound to $name placeholders: string, number, boolean or null. Pass a list as a JSON string and cast it in SQL, e.g. $q::DOUBLE[] with "q": "[0.025,0.5,0.975]". |
model_version | string | No | latest (default) or a version from available_versions. |
Response:
{
"columns": ["variant_key", "share"],
"rows": [
["{\"cta_text\":\"lv_cta_text_1\",\"headline\":\"lv_headline_0\"}", 0.62],
["{\"cta_text\":\"lv_cta_text_0\",\"headline\":\"lv_headline_0\"}", 0.21]
],
"model_version": "2026-10-26T10-15-00Z",
"available_versions": ["2026-10-26T10-15-00Z", "2026-10-25T10-12-00Z"],
"n_samples": 2000,
"elapsed_ms": 140,
"warnings": []
}| Field | Description |
|---|---|
columns, rows | The result set. Lists and structs come back as JSON arrays and objects. |
model_version | The version the query read. |
available_versions | The newest version of each day, newest first, up to the latest published one. Run the same query over several of them for a trend: nothing else stores model history. An older version of the same day can still be pinned by name. Versions never change, so results are cached per version, query and parameters. |
n_samples | Number of posterior draws. |
Errors carry { "error": "<message>" }:
| Status | Meaning |
|---|---|
400 | Invalid SQL or parameters. |
404 | Optimization not found, or no posterior has been published for it yet. |
422 | The result exceeds the row limit. Aggregate in SQL. |
503 | The posterior store is not available. |
504 | The query timed out. |
Until the first posterior is published, the policy is an even split over the servable variants, and every other model figure has no estimate.
Tables and views
| Name | What |
|---|---|
posterior_reward(variant_id, context_id, sample_id, reward) | Expected reward of every variant in every context, per posterior draw. |
variants(variant_id, variant_key, permitted, …) | The design grid, one column per design factor. permitted is false for disabled and excluded variants. |
contexts(context_id, context_key, weight, …) | The contexts (segments), one column per context factor. weight is the context's share of traffic. A model without context factors has one context, {}. |
thompson_policy, thompson_policy_marginal, baseline_policy | Policies (context_id, context_key, variant_id, variant_key, pi): the live Thompson policy, the same policy blind to context, and the reference: the baseline variant; for an external optimization the current version (variant_key {}, trained on the holdout and in no other view); or an even split over permitted variants when there is neither. A model version without the current version's row (one trained before it existed) has pi NULL everywhere, and every lift against it is NULL. |
thompson_policy_without(context_factors) | The Thompson policy blind to those context factors: contexts that differ only in them pool their rewards by weight, and the policy is taken on the pooled rewards. thompson_policy_marginal is this blind to every context factor. |
thompson_traffic_share(variant_id, variant_key, share, share_mc_se) | Each variant's share of all optimized traffic, which is also its probability of being best. |
policy_draws(pol, alt), policy_draws_by_context(pol, alt) | Per draw (and context): reward, reward_alt, reward_oracle, lift, ceiling_lift, ceiling_lift_hedged of policy pol against alt. |
headroom_captured(pol, alt), headroom_captured_by_context(pol, alt) | Progress of pol against alt (and per context): one value, (E[reward] − E[reward_alt]) / ((E[reward_oracle] + E[reward]) / 2 − E[reward_alt]) over the draws, none unless E[reward] > E[reward_alt]. |
variant_draws(alt), variant_draws_by_context(alt) | The same for serving each variant everywhere. |
importance_draws, importance_draws_by_context | Per design factor and draw (and context): reward, what the live policy earns; reward_ref, what the factor's reference policy earns (the reference's mix over that factor's levels, with each level paired with the other design factors by its own Thompson policy); and lift = reward / reward_ref − 1, the factor uplift. The row with factor NULL is the interaction term, lift = (1 + policy lift over that reference) / Π (1 + factor uplift) − 1. share = ln(1 + lift) / ln(1 + policy lift over that reference) sums to 1 over the rows of a draw. |
factor_importance(q), factor_importance_by_context(q), context_importance(q), context_importance_by_context(q) | Factor importance at quantiles q: per factor, and factor NULL for the interaction term, uplift = dist(lift, q), share (the point share of the lift being split: the policy lift over the reference for design factors, the personalization uplift for context factors; summing to 1) and share_interval = dist(share, q). |
factor_draws(factor), factor_draws_by_context(factor) | Per level of design factor factor and draw (and context): reward of the level with the other design factors mixed by the level's own Thompson policy, reward_ref of the reference, reward_best of each context taking its best level, lift (the level effect) and best_lift (the factor effect, the same on every level of a draw). An unknown factor is an error. |
design_factors(factor), context_factors(factor) | The factor names. |
dist(x, q), p_gt(x, t) | Reducers over draws: {n, mean, mc_se, quantiles, quantiles_mc_se} at quantiles q, and {p, p_mc_se} for P(x > t). |
Pass a policy to a draw macro by name: one of the views above, or a CTE in your query. lift = reward / reward_alt − 1, ceiling_lift = reward_oracle / reward_alt − 1, where reward_oracle is each context's best variant from the whole grid. The averaged (non-_by_context) forms average rewards over contexts by weight first, then take the ratios.
Standard figures
The dashboard, CLI and agent skills derive their figures the same way. Intervals are central credible intervals, and the median is the point estimate.
| Figure | Query |
|---|---|
| Policy lift ("Lift (now)") | lift of policy_draws('thompson_policy', 'baseline_policy') |
| Ceiling ("Lift (best variant)") | ceiling_lift_hedged of the same macro, (reward_oracle + reward) / 2 / reward_alt − 1 per draw (ceiling_lift is the unhedged ceiling). The best-variant figure is shrunk halfway toward the policy lift. |
| P(beats reference) | p_gt(lift, 0) |
| Progress to best ("Converged") | headroom_captured of headroom_captured('thompson_policy', 'baseline_policy'): (E[reward] − E[reward_alt]) / ((E[reward_oracle] + E[reward]) / 2 − E[reward_alt]) over the draws, the hedged ceiling as in Lift (best variant); one value, none unless E[reward] > E[reward_alt] |
| Traffic share, probability of best | share of thompson_traffic_share; per segment, pi of thompson_policy |
| Variant expected reward | reward of variant_draws('baseline_policy') |
| Segment policy and ceiling reward | reward and reward_oracle of policy_draws_by_context('thompson_policy', 'baseline_policy') |
| Level effects, design factor effect | lift and best_lift of factor_draws($factor), one query per design factor |
| Personalization uplift | lift of personalization_draws, i.e. policy_draws('thompson_policy', 'thompson_policy_marginal') |
| Context-factor uplift | lift of context_importance_draws on that factor's row; the same as lift of policy_draws('thompson_policy', p) with p = thompson_policy_without([$factor]) |
| Context-factor importance | share and share_interval of context_importance(q): each row's avg(ln(1 + lift)) of context_importance_draws over avg(ln(1 + lift)) of personalization_draws, with the interval of its per-draw share |
| Factor uplift | lift of importance_draws on that factor's row |
| Factor importance | share and share_interval of factor_importance(q): each row's avg(ln(1 + lift)) of importance_draws over the sum of that over all rows, which is avg(ln(1 + lift)) of the policy lift over the reference of importance_draws, with the interval of its per-draw share |
A design factor's level effects and factor effect are anchored on the current policy. For design factor F, in every draw and context, each level of F gets a reward: the other design factors are mixed by the level's own Thompson policy πℓ(rest), the share of draws in which (ℓ, rest) is the best of the permitted variants with ℓ. It is estimated from every draw, however rarely ℓ wins overall. The level's reward is that mix averaged over contexts by weight. The reference is the reward of the factor's reference policy ρF(ℓ, rest) = ρ(ℓ) · πℓ(rest): the reference policy ρ's marginal on the factor (all on the baseline variant's level, or, without a baseline variant, also when the reference is the current version, each level's share of the permitted variants) combined with each level's own Thompson policy. Its reward is the baseline level's reward, or the level rewards weighted by ρ(ℓ).
- Level effect: level reward / reference − 1. The baseline's level is exactly 0; without a baseline, the level effects average to 0 under the even split's mix.
- Factor effect: what optimizing F is worth when every segment takes its own best level, per draw: Σc wc · maxℓ (level ℓ's reward in context c) / reference − 1. In every draw it is at least as large as every level effect, and it is never negative. Because it takes a maximum over uncertain rewards it is biased upward: a factor with no effect still shows a small positive figure.
factor_draws_by_context treats each context on its own, so there the factor effect is exactly the best level effect, per draw. In factor_draws the three rewards are averaged over contexts by weight first, then the ratios are taken. The dashboard's Factors card shows each level effect as its median (the interval on hover). It does not show the factor effect.
The personalization uplift is what considering context adds: the live Thompson policy, which conditions on every context factor, over the same policy blind to all of them (each draw's rewards averaged over contexts by weight before the policy is taken). Context-factor uplift and context-factor importance split it by context factor, the way factor uplift and factor importance split the policy lift by design factor (below). A context factor's uplift is the live policy over the same policy with that one factor averaged out (its segments pooled by weight before the policy is taken), still conditioning on the others. The interaction term is what the product of 1 + each uplift leaves of 1 + the personalization uplift, so in every draw ln(1 + personalization uplift) is the sum of ln(1 + lift) over the rows of context_importance_draws, and the importances (expected ln(1 + lift) over the expected ln(1 + personalization uplift), with the interval of the per-draw share in share) sum to 1. Its reference policies are the Thompson policy recomputed blind to each factor, not marginals of the live policy: averaging the live policy over a factor's segments would mix choices that each used the factor. The interaction term is negative when personalizing pays on factors together, positive when factors stand in for each other. Design shares are of the policy lift, context shares of the personalization gain: do not compare a context factor's figure with a design factor's.
Factor uplift and factor importance split the policy lift by design factor. A factor's uplift is the live policy over the factor's reference policy ρF above: what the policy's current choices on that factor earn. Without interactions between design factors, πℓ is the live policy's conditional given the level, π(ℓ, rest) / s(ℓ) with s(ℓ) the policy's share of traffic on the level, so the two differ only in their marginal on the factor and the uplift equals the level effects weighted by s(ℓ); with interactions, approximately. Like a context factor's uplift, it is the live policy over a reference policy; only the reference differs. When the reward factorizes across factors and the policy's traffic does too, 1 + the policy lift is exactly the product of 1 + each factor uplift. The interaction term is whatever that product leaves, so in every draw ln(1 + policy lift) is the sum of ln(1 + lift) over the rows of importance_draws. Each row's share is ln(1 + lift) / ln(1 + policy lift), so the shares sum to 1 in every draw. A factor's importance is reported as its expected ln(1 + lift) over the expected ln(1 + policy lift), which also sums to 1 over the factors and the interaction term (medians of per-draw shares would not), with the interval of the per-draw share. Neither is truncated, and both hold whatever the policy lift's sign: with a negative lift the shares allocate the loss, so a factor that lost has a positive share and one that gained a negative one. The interval is wide while the policy lift is near 0. The reference is the baseline variant, or the even split without one. The current version has no level on any design factor, so against it the uplifts and the interaction term split the policy's lift over the even split, and the shares are of that lift. They also split the lift over the current version: what the even split earns over it is shared out among the terms in proportion, since no factor alone moves the design off the current version. The uplifts are signed, like the policy lift: a factor's is below 0 when the policy currently does worse on it than on its reference level. This is not the factor effect, which lets each segment take its best level and so reads what a factor could be worth. A large interaction term means the gain comes from combinations of levels, or from the policy pairing levels across factors: negative when levels pay together, positive when factors stand in for each other.
Example: the headline figures.
SELECT quantile_cont(lift, [0.025, 0.5, 0.975]) AS policy_lift,
quantile_cont(ceiling_lift_hedged, [0.025, 0.5, 0.975]) AS ceiling_lift,
p_gt(lift, 0).p AS p_beats_reference,
(SELECT headroom_captured FROM headroom_captured('thompson_policy', 'baseline_policy')) AS progress
FROM policy_draws('thompson_policy', 'baseline_policy')Example: design factor $factor's level effects and factor effect, with $q the quantiles as a JSON list (e.g. "[0.025,0.5,0.975]"). Every row carries the same best_lift, the factor effect.
SELECT level,
quantile_cont(lift, $q::DOUBLE[]) AS lift,
quantile_cont(best_lift, $q::DOUBLE[]) AS best_lift
FROM factor_draws($factor)
GROUP BY levelFor one segment, read factor_draws_by_context($factor) d JOIN contexts c USING (context_id) and add WHERE c.context_key = $context. For the absolute difference from the reference instead of the lift, reduce reward - reward_ref.
Example: factor uplift and factor importance. The row with factor NULL is the interaction term.
SELECT factor, uplift.quantiles AS uplift, share, share_interval.quantiles AS share_interval
FROM factor_importance([0.025, 0.5, 0.975])For one segment, read factor_importance_by_context([0.025, 0.5, 0.975]) JOIN contexts c USING (context_id) WHERE c.context_key = $context.
Example: what personalizing on context factor $factor adds.
WITH blind AS (FROM thompson_policy_without([$factor]))
SELECT quantile_cont(lift, [0.025, 0.5, 0.975]) AS lift
FROM policy_draws('thompson_policy', 'blind')From the CLI, levered posterior query <optimization-id> --sql '<sql>' [--param name=value] [--version <v>] [--json] runs the same route.