Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(signals): store per-head ranking lift next to inbox scores (#110553)

posthog[bot]4c4efbeda430
diff --git a/products/signals/backend/artefact_schemas.py b/products/signals/backend/artefact_schemas.py
index 779e1a79520e..6d1cbd46f00f 100644
--- a/products/signals/backend/artefact_schemas.py
+++ b/products/signals/backend/artefact_schemas.py
@@ -335,6 +335,15 @@ class RankingModelResult(BaseModel):
default_factory=dict,
description="Outcome head name to its calibrated probability. Empty on a skipped model.",
)
+ # No upper bound: a lift reaches `1 / base_rate`.
+ lifts: dict[str, Annotated[float, Field(ge=0.0)]] = Field(
+ default_factory=dict,
+ description=(
+ "Outcome head name to its probability divided by the head's base rate "
+ "(`refit_classification_threshold`) from the model's metadata. Empty on a skipped model. "
+ "A head without a saved threshold has no entry."
+ ),
+ )
metadata: dict[str, Any] = Field(
default_factory=dict,
description=(
diff --git a/products/signals/backend/ranking/model_contract.py b/products/signals/backend/ranking/model_contract.py
index c9f4d0f690d0..a7807d591667 100644
--- a/products/signals/backend/ranking/model_contract.py
+++ b/products/signals/backend/ranking/model_contract.py
@@ -61,6 +61,15 @@ def classification_thresholds(metadata: Mapping[str, Any]) -> dict[str, float]:
}
+def head_lifts(scores: Mapping[str, float], metadata: Mapping[str, Any]) -> dict[str, float]:
+ """Each head's probability over its base rate, the saved refit threshold. A head without a
+ positive saved threshold has no lift, and no other value may stand in for it."""
+ thresholds = classification_thresholds(metadata)
+ return {
+ head: probability / thresholds[head] for head, probability in scores.items() if thresholds.get(head, 0.0) > 0.0
+ }
+
+
def trained_head_files(metadata: Mapping[str, Any], known_heads: Collection[str]) -> dict[str, str]:
"""The `<head>.ubj` object name per head the candidate fit, of the heads in `known_heads`.
diff --git a/products/signals/backend/ranking/scorer.py b/products/signals/backend/ranking/scorer.py
index 409414429e3d..b8a1eb4f888b 100644
--- a/products/signals/backend/ranking/scorer.py
+++ b/products/signals/backend/ranking/scorer.py
@@ -28,6 +28,7 @@ from products.signals.backend.ranking.features import (
FeatureSet,
ReportEmbeddingsFeatureSet,
)
+from products.signals.backend.ranking.model_contract import head_lifts
from products.signals.backend.ranking.model_store import LoadedModel, ServingSet, load_serving_set
from products.signals.backend.ranking.serving_manifest import ServingManifestEntry
from products.signals.backend.ranking.sinks import persist_scores
@@ -150,6 +151,7 @@ def _result(model_scores: _ModelScores, report_id: str) -> RankingModelResult:
status="skipped" if skip_reason else "scored",
skip_reason=skip_reason,
scores=dict(scores or {}),
+ lifts=head_lifts(scores or {}, model.metadata),
metadata=_copied_metadata(model.metadata),
)
diff --git a/products/signals/backend/ranking/sinks.py b/products/signals/backend/ranking/sinks.py
index 59cb632983c0..7a094ccb8cb5 100644
--- a/products/signals/backend/ranking/sinks.py
+++ b/products/signals/backend/ranking/sinks.py
@@ -14,7 +14,7 @@ from posthog.ph_client import ScopedCapture, ph_scoped_capture
from products.signals.backend.artefact_schemas import RankingModelResult, RankingScore
from products.signals.backend.models import SignalActorKind, SignalReport, SignalReportArtefact
-from products.signals.backend.ranking.model_contract import classification_thresholds, readable_head_names
+from products.signals.backend.ranking.model_contract import classification_thresholds, head_lifts, readable_head_names
REPORT_SCORED_EVENT = "inbox_ranking_report_scored"
DISTINCT_ID = "inbox_ranking_scoring"
@@ -76,7 +76,7 @@ def persist_scores(
def classification_properties(result: RankingModelResult) -> dict[str, object]:
- """The served threshold and the flag it gives, per head, read from the result's copied metadata.
+ """The served threshold, the flag it gives and the lift over it, per head, read from the result's copied metadata.
A serving copy is immutable per model key, so its metadata holds the threshold that scored the
report. A head without a saved threshold gets neither property: a model trained before
@@ -92,4 +92,5 @@ def classification_properties(result: RankingModelResult) -> dict[str, object]:
for head, probability in result.scores.items()
if head in thresholds
},
+ **{f"lift_{head}": lift for head, lift in head_lifts(result.scores, result.metadata).items()},
}
diff --git a/products/signals/backend/serializers.py b/products/signals/backend/serializers.py
index 70795593e8e7..bd9383398571 100644
--- a/products/signals/backend/serializers.py
+++ b/products/signals/backend/serializers.py
@@ -1146,6 +1146,13 @@ class ReportRankingSerializer(serializers.Serializer):
child=serializers.FloatField(),
help_text="Outcome head name to its calibrated probability. Empty when the served model skipped the report.",
)
+ lifts = serializers.DictField(
+ child=serializers.FloatField(),
+ help_text=(
+ "Outcome head name to its probability divided by the head's training base rate, e.g. 2.7 means "
+ "2.7x as likely as the average report. A head without a saved base rate has no entry."
+ ),
+ )
readable_heads = serializers.ListField(
child=serializers.CharField(),
help_text="Heads whose holdout AUC the training run could read. Treat scores of other heads with caution.",
@@ -1451,6 +1458,7 @@ class SignalReportSerializer(serializers.ModelSerializer):
return None
from products.signals.backend.ranking.model_contract import ( # noqa: PLC0415 — keeps numpy and pandas off the API import path
+ head_lifts,
readable_head_names,
)
@@ -1472,6 +1480,8 @@ class SignalReportSerializer(serializers.ModelSerializer):
if not all(isinstance(head, str) and head for head in heads):
raise ValueError("readable head names must be non-empty strings")
readable_heads = sorted(heads)
+ # A score written before lifts were stored carries the metadata to compute them.
+ lifts = served.lifts or head_lifts(served.scores, served.metadata)
except (ValueError, KeyError, TypeError, AttributeError):
logger.warning("signals.ranking_score.invalid_content", report_id=str(obj.id), artefact_id=str(art.id))
return None
@@ -1482,6 +1492,7 @@ class SignalReportSerializer(serializers.ModelSerializer):
"manifest_version": score.manifest_version,
"scored_at": score.scored_at,
"scores": served.scores,
+ "lifts": lifts,
"readable_heads": readable_heads,
}
diff --git a/products/signals/backend/test/test_ranking_scoring.py b/products/signals/backend/test/test_ranking_scoring.py
index 5d55d29206ac..def1c7779a52 100644
--- a/products/signals/backend/test/test_ranking_scoring.py
+++ b/products/signals/backend/test/test_ranking_scoring.py
@@ -330,7 +330,7 @@ class TestScorer(_ScorerTestMixin, SimpleTestCase):
assert sorted(fake_vectors.calls) == sorted([EMBEDDING_RENDERING_TITLE_SUMMARY, EMBEDDING_RENDERING_TITLE])
def test_challengers_without_a_vector_or_a_served_feature_set_are_skipped_results(self) -> None:
- served = self._served()
+ served = self._served(thresholds={"open": 0.25})
title = self._challenger("title_embeddings", TITLE_EMBEDDINGS_FEATURE_SET)
tabular = self._challenger("tabular_xgb", TABULAR_FEATURE_SET)
manifest = self.store.publish_manifest([served, title, tabular])
@@ -344,6 +344,9 @@ class TestScorer(_ScorerTestMixin, SimpleTestCase):
assert outcome.score is not None
results = outcome.score.results
assert (results[served.key].status, set(results[served.key].scores)) == ("scored", set(HEADS))
+ # thumbs_up saved no threshold, so it has no base rate to divide by.
+ assert results[served.key].lifts == {"open": results[served.key].scores["open"] / 0.25}
+ assert results[title.key].lifts == {}
assert (results[title.key].status, results[title.key].skip_reason) == ("skipped", NO_VECTOR)
assert (results[tabular.key].status, results[tabular.key].skip_reason) == (
"skipped",
@@ -378,6 +381,7 @@ class TestClassificationProperties(SimpleTestCase):
"readable_heads": ["open"],
"threshold_open": 0.3,
"predicted_open": predicted,
+ "lift_open": score / 0.3,
}
@@ -424,11 +428,11 @@ class TestScorerPersists(_ScorerTestMixin, BaseTest):
event["properties"]["model_key"]: {
key: value
for key, value in event["properties"].items()
- if key.startswith(("threshold_", "predicted_", "readable_heads"))
+ if key.startswith(("threshold_", "predicted_", "lift_", "readable_heads"))
}
for event in captured.events
}
- # thumbs_up saved no threshold, and a model without one gets no stand-in.
+ # thumbs_up saved no threshold, and a model without one gets no stand-in. A zero threshold gives no lift.
assert classification == {
served.key: {"readable_heads": ["open"], "threshold_open": 0.0, "predicted_open": True},
title.key: {"readable_heads": ["open"]},
diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.py
index 4f6a183750aa..c83ad9759230 100644
--- a/products/signals/backend/test/test_signal_report_api.py
+++ b/products/signals/backend/test/test_signal_report_api.py
@@ -730,6 +730,7 @@ class TestSignalReportListAPI(APIBaseTest):
content: str | None = None,
scores: dict[str, float] | None = None,
heads: list[dict] | None = None,
+ lifts: dict[str, float] | None = None,
) -> SignalReportArtefact:
served = RankingModelResult(
model_name="report_embeddings",
@@ -739,6 +740,7 @@ class TestSignalReportListAPI(APIBaseTest):
feature_schema_version=1,
status="scored",
scores=scores or {"open": 0.5, "merged": 0.2},
+ lifts=lifts or {},
metadata={"heads": heads or [{"head": "open", "readable": True}, {"head": "merged", "readable": False}]},
)
challenger = RankingModelResult(
@@ -768,6 +770,7 @@ class TestSignalReportListAPI(APIBaseTest):
True,
None,
None,
+ {"open": 2.5},
{
"served_key": "report_embeddings@2026-09-01",
"model_name": "report_embeddings",
@@ -775,21 +778,42 @@ class TestSignalReportListAPI(APIBaseTest):
"manifest_version": "manifest",
"scored_at": "2026-09-20T12:00:00Z",
"scores": {"open": 0.5, "merged": 0.2},
+ "lifts": {"open": 2.5},
"readable_heads": ["open"],
},
),
- ("non_staff_sees_nothing", False, None, None, None),
- ("invalid_content_reads_as_none", True, '{"served_key": "missing"}', None, None),
- ("null_readable_head_reads_as_none", True, None, [{"head": None, "readable": True}], None),
+ (
+ "legacy_score_without_lifts_computes_them_from_the_metadata",
+ True,
+ None,
+ [
+ {"head": "open", "readable": True, "refit_classification_threshold": 0.25},
+ {"head": "merged", "readable": False, "refit_classification_threshold": 0.0},
+ ],
+ None,
+ {
+ "served_key": "report_embeddings@2026-09-01",
+ "model_name": "report_embeddings",
+ "model_version": "2026-09-01",
+ "manifest_version": "manifest",
+ "scored_at": "2026-09-20T12:00:00Z",
+ "scores": {"open": 0.5, "merged": 0.2},
+ "lifts": {"open": 2.0},
+ "readable_heads": ["open"],
+ },
+ ),
+ ("non_staff_sees_nothing", False, None, None, None, None),
+ ("invalid_content_reads_as_none", True, '{"served_key": "missing"}', None, None, None),
+ ("null_readable_head_reads_as_none", True, None, [{"head": None, "readable": True}], None, None),
]
)
- def test_ranking_field_in_the_list_and_the_detail(self, _name, is_staff, content, heads, expected):
+ def test_ranking_field_in_the_list_and_the_detail(self, _name, is_staff, content, heads, lifts, expected):
self.user.is_staff = is_staff
self.user.save()
report = self._create_report()
stale = self._ranking_score_artefact(report, scores={"open": 0.9})
SignalReportArtefact.objects.filter(pk=stale.pk).update(created_at=timezone.now() - timedelta(days=1))
- self._ranking_score_artefact(report, content=content, heads=heads)
+ self._ranking_score_artefact(report, content=content, heads=heads, lifts=lifts)
unscored = self._create_report(title="Unscored")
list_response = self.client.get(self._list_url())
diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.ts
index dc58216a7579..8e4aabd3d6c2 100644
--- a/products/signals/frontend/generated/api.schemas.ts
+++ b/products/signals/frontend/generated/api.schemas.ts
@@ -583,6 +583,11 @@ export const SignalReportBillingExemptReasonEnumApi = {
*/
export type ReportRankingApiScores = { [key: string]: number }
+/**
+ * Outcome head name to its probability divided by the head's training base rate, e.g. 2.7 means 2.7x as likely as the average report. A head without a saved base rate has no entry.
+ */
+export type ReportRankingApiLifts = { [key: string]: number }
+
export interface ReportRankingApi {
/** Key of the served model in the scoring pass, as `<model_name>@<model_version>`. */
served_key: string
@@ -596,6 +601,8 @@ export interface ReportRankingApi {
scored_at: string
/** Outcome head name to its calibrated probability. Empty when the served model skipped the report. */
scores: ReportRankingApiScores
+ /** Outcome head name to its probability divided by the head's training base rate, e.g. 2.7 means 2.7x as likely as the average report. A head without a saved base rate has no entry. */
+ lifts: ReportRankingApiLifts
/** Heads whose holdout AUC the training run could read. Treat scores of other heads with caution. */
readable_heads: string[]
}
diff --git a/products/signals/frontend/inbox/components/cards/ReportCard.test.tsx b/products/signals/frontend/inbox/components/cards/ReportCard.test.tsx
index 7d90391e9053..7529d0a90117 100644
--- a/products/signals/frontend/inbox/components/cards/ReportCard.test.tsx
+++ b/products/signals/frontend/inbox/components/cards/ReportCard.test.tsx
@@ -385,6 +385,7 @@ describe('ReportCard', () => {
manifest_version: 'manifest',
scored_at: '2026-09-30T12:00:00Z',
scores: { pr_merged: 0.41, action: 0.062 },
+ lifts: {},
readable_heads: ['action', 'pr_merged'],
},
})
diff --git a/products/signals/frontend/inbox/inboxAnalytics.test.ts b/products/signals/frontend/inbox/inboxAnalytics.test.ts
index c227c039b942..566c72996d45 100644
--- a/products/signals/frontend/inbox/inboxAnalytics.test.ts
+++ b/products/signals/frontend/inbox/inboxAnalytics.test.ts
@@ -127,6 +127,7 @@ describe('inboxAnalytics', () => {
manifest_version: 'manifest',
scored_at: '2026-09-30T12:00:00Z',
scores: { pr_merged: 0.4 },
+ lifts: {},
readable_heads: ['pr_merged'],
},
}),
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 0f4acaad53aa..ae94e89ea634 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -70015,6 +70015,11 @@ export namespace Schemas {
*/
export type ReportRankingScores = {[key: string]: number};
+ /**
+ * Outcome head name to its probability divided by the head's training base rate, e.g. 2.7 means 2.7x as likely as the average report. A head without a saved base rate has no entry.
+ */
+ export type ReportRankingLifts = {[key: string]: number};
+
export interface ReportRanking {
/** Key of the served model in the scoring pass, as `<model_name>@<model_version>`. */
served_key: string;
@@ -70028,6 +70033,8 @@ export namespace Schemas {
scored_at: string;
/** Outcome head name to its calibrated probability. Empty when the served model skipped the report. */
scores: ReportRankingScores;
+ /** Outcome head name to its probability divided by the head's training base rate, e.g. 2.7 means 2.7x as likely as the average report. A head without a saved base rate has no entry. */
+ lifts: ReportRankingLifts;
/** Heads whose holdout AUC the training run could read. Treat scores of other heads with caution. */
readable_heads: string[];
}