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): emit an activity summary vector that includes the profile (#127422)

posthog[bot]d122f6eb12aa
diff --git a/posthog/dags/locations/signals.py b/posthog/dags/locations/signals.py
index d8cc2e852657..d6c504a9f79a 100644
--- a/posthog/dags/locations/signals.py
+++ b/posthog/dags/locations/signals.py
@@ -28,6 +28,7 @@ if is_inbox_ranking_registered():
inbox_ranking_dataset.inbox_user_vectors,
inbox_ranking_dataset.inbox_engagement_export,
inbox_ranking_dataset.inbox_activity_summary_vectors,
+ inbox_ranking_dataset.inbox_activity_summary_profile_vectors,
inbox_ranking_training.inbox_ranking_serving_manifest,
inbox_ranking_served.inbox_ranking_served_scores,
inbox_ranking_training.inbox_ranking_unseen_graded,
diff --git a/products/signals/backend/activity_summary/config.py b/products/signals/backend/activity_summary/config.py
index 561bc0b34b73..88d27d06df61 100644
--- a/products/signals/backend/activity_summary/config.py
+++ b/products/signals/backend/activity_summary/config.py
@@ -71,6 +71,8 @@ class ActivitySummaryConfig:
min_update_interval_hours: float = MIN_UPDATE_INTERVAL.total_seconds() / 3600
max_versions: int = MAX_VERSIONS
emit_embeddings: bool = True
+ # Also emits the vector of `summary_profile_text`. `emit_embeddings: false` stops both vectors.
+ emit_profile_embeddings: bool = False
capture_events: bool = True
# Count viewed objects in the queue. When off, the view weights and the view cold start do not apply.
count_views: bool = False
@@ -222,6 +224,7 @@ def parse_config(payload: Any) -> ActivitySummaryConfig:
),
max_versions=_positive_int(payload.get("max_versions"), defaults.max_versions),
emit_embeddings=_bool(payload.get("emit_embeddings"), defaults.emit_embeddings),
+ emit_profile_embeddings=_bool(payload.get("emit_profile_embeddings"), defaults.emit_profile_embeddings),
capture_events=_bool(payload.get("capture_events"), defaults.capture_events),
count_views=_bool(payload.get("count_views"), defaults.count_views),
source_weights=parse_source_weights(payload.get("source_weights")),
diff --git a/products/signals/backend/activity_summary/prompt.py b/products/signals/backend/activity_summary/prompt.py
index 7f50b4354e0f..d3792041871b 100644
--- a/products/signals/backend/activity_summary/prompt.py
+++ b/products/signals/backend/activity_summary/prompt.py
@@ -371,3 +371,15 @@ def summary_text(summary: dict[str, Any]) -> str:
"""The text that gets embedded: the headline, then the theme labels in the model's order."""
labels = [theme["label"] for theme in summary.get("themes", [])]
return f"{summary['headline']}\nThemes: {'; '.join(labels)}" if labels else summary["headline"]
+
+
+def summary_profile_text(summary: dict[str, Any]) -> str | None:
+ """The `summary_text`, then the profile. None when the summary has no profile, because the text would
+ match `summary_text`.
+
+ A second embedded rendering, so a backtest can compare it with `summary_text` on the same builds. A
+ format change needs a new rendering name, so old and new vectors never share one."""
+ profile = summary.get("profile")
+ if not isinstance(profile, str) or not profile.strip():
+ return None
+ return f"{summary_text(summary)}\n\n{profile.strip()}"
diff --git a/products/signals/backend/activity_summary/tick.py b/products/signals/backend/activity_summary/tick.py
index af5d85b4c792..b97744ad90b9 100644
--- a/products/signals/backend/activity_summary/tick.py
+++ b/products/signals/backend/activity_summary/tick.py
@@ -40,7 +40,7 @@ from products.signals.backend.activity_summary.logic import (
update_activity_summary,
)
from products.signals.backend.activity_summary.mcp_buffer import publish_team_ids
-from products.signals.backend.activity_summary.prompt import PROMPT_VERSION
+from products.signals.backend.activity_summary.prompt import PROMPT_VERSION, summary_profile_text
from products.signals.backend.activity_summary.queue import (
TRIGGERS,
VIEW_TRIGGERS,
@@ -65,6 +65,9 @@ logger = structlog.get_logger(__name__)
TICK_WORKFLOW_NAME = "activity-summary-tick"
EMBEDDING_DOCUMENT_TYPE = "activity_summary"
EMBEDDING_RENDERING = "summary_text"
+# The same document as `EMBEDDING_RENDERING`, embedded with the profile, the way report embeddings
+# separate `title` from `title_summary`.
+EMBEDDING_RENDERING_PROFILE = "summary_profile"
# Where a summary came from: the tick, or a build as of a past date.
SOURCE_LIVE = "live"
@@ -129,6 +132,7 @@ class ActivitySummaryTickPlan:
due_by_trigger: dict[str, int] = dataclasses.field(default_factory=dict)
# The days of the MCP intent buffer each update reads. None when `mcp_render_enabled` is off.
mcp_buffer_days: int | None = None
+ emit_profile_embeddings: bool = False
@frozen
@@ -149,6 +153,7 @@ class ActivitySummaryPairInput:
trigger: str | None = None
view_update_interval_hours: float | None = None
mcp_buffer_days: int | None = None
+ emit_profile_embeddings: bool = False
@frozen
@@ -228,6 +233,7 @@ def plan_tick(limit: int | None, now: datetime.datetime) -> ActivitySummaryTickP
min_update_interval_hours=config.min_update_interval_hours,
view_update_interval_hours=config.view_update_interval_hours,
emit_embeddings=config.emit_embeddings,
+ emit_profile_embeddings=config.emit_profile_embeddings,
capture_events=config.capture_events,
limits=config.limits,
max_error_rate=config.max_error_rate,
@@ -250,6 +256,7 @@ def emit_summary_embedding(
document_id: str,
timestamp: datetime.datetime,
metadata: dict[str, Any],
+ rendering: str = EMBEDDING_RENDERING,
) -> None:
# Deferred so importing the tick does not load the Kafka and ClickHouse chain behind the producer.
from posthog.api.embedding_worker import emit_embedding_request # noqa: PLC0415
@@ -259,7 +266,7 @@ def emit_summary_embedding(
team_id=team_id,
product=EMBEDDING_PRODUCT,
document_type=document_type,
- rendering=EMBEDDING_RENDERING,
+ rendering=rendering,
document_id=document_id,
# The models of the report embeddings, so both share one vector space.
models=[model.value for model in EmbeddingModelName],
@@ -268,23 +275,41 @@ def emit_summary_embedding(
)
-def _emit_embedding(team_id: int, user_id: int) -> None:
+def _emit_embedding(team_id: int, user_id: int, *, emit_profile: bool) -> None:
stored = UserActivitySummary.objects.for_team(team_id).filter(user_id=user_id).first()
if stored is None or not stored.summary_text or stored.generated_at is None:
return
+ # One vector per user per day, so an analysis can read the vector a user had on a given day.
+ document_id = f"{user_id}:{stored.generated_at.date().isoformat()}"
+ metadata = {
+ "prompt_version": stored.prompt_version,
+ "render_version": stored.render_version,
+ "model": stored.model,
+ }
emit_summary_embedding(
team_id,
content=stored.summary_text,
document_type=EMBEDDING_DOCUMENT_TYPE,
- # One vector per user per day, so an analysis can read the vector a user had on a given day.
- document_id=f"{user_id}:{stored.generated_at.date().isoformat()}",
+ document_id=document_id,
timestamp=stored.generated_at,
- metadata={
- "prompt_version": stored.prompt_version,
- "render_version": stored.render_version,
- "model": stored.model,
- },
+ metadata=metadata,
)
+ if not emit_profile:
+ return
+ try:
+ profile_text = summary_profile_text(stored.summary) if isinstance(stored.summary, dict) else None
+ if profile_text is not None:
+ emit_summary_embedding(
+ team_id,
+ content=profile_text,
+ document_type=EMBEDDING_DOCUMENT_TYPE,
+ document_id=document_id,
+ timestamp=stored.generated_at,
+ metadata=metadata,
+ rendering=EMBEDDING_RENDERING_PROFILE,
+ )
+ except Exception:
+ logger.exception("activity_summary_profile_embedding_failed", team_id=team_id, user_id=user_id)
def capture_generated(
@@ -363,7 +388,7 @@ def run_pair(input: ActivitySummaryPairInput, *, last_attempt: bool = True) -> A
logger.exception("activity_summary_queue_sync_failed", team_id=input.team_id, user_id=input.user_id)
if update.status == UpdateStatus.OK and input.emit_embeddings:
try:
- _emit_embedding(input.team_id, input.user_id)
+ _emit_embedding(input.team_id, input.user_id, emit_profile=input.emit_profile_embeddings)
except Exception:
logger.exception("activity_summary_embedding_failed", team_id=input.team_id, user_id=input.user_id)
if update.status in CALLED_MODEL_STATUSES and input.capture_events:
@@ -491,6 +516,7 @@ class ActivitySummaryTickWorkflow:
min_units=plan.min_units,
min_update_interval_hours=plan.min_update_interval_hours,
emit_embeddings=plan.emit_embeddings,
+ emit_profile_embeddings=plan.emit_profile_embeddings,
capture_events=plan.capture_events,
limits=plan.limits,
rebuild_before=plan.rebuild_before,
diff --git a/products/signals/backend/test/test_activity_summary_render.py b/products/signals/backend/test/test_activity_summary_render.py
index 538f11e6ebc8..7e5ab1118c80 100644
--- a/products/signals/backend/test/test_activity_summary_render.py
+++ b/products/signals/backend/test/test_activity_summary_render.py
@@ -16,6 +16,7 @@ from products.signals.backend.activity_summary.prompt import (
EmptyProfileError,
MalformedSummaryError,
normalize_summary,
+ summary_profile_text,
summary_text,
user_message,
)
@@ -1285,6 +1286,13 @@ def test_summary_text_is_the_headline_and_the_theme_labels_in_order() -> None:
reloaded = json.loads(json.dumps(summary, sort_keys=True))
assert summary_text(summary) == summary_text(reloaded) == "Builds the signup funnel.\nThemes: b; a"
assert summary_text({**summary, "themes": []}) == "Builds the signup funnel."
+ assert (
+ summary_profile_text(reloaded)
+ == "Builds the signup funnel.\nThemes: b; a\n\n## Funnels\n- Builds the signup funnel."
+ )
+ without_profile = {key: value for key, value in summary.items() if key != "profile"}
+ for profile in ({}, {"profile": None}, {"profile": " "}):
+ assert summary_profile_text({**without_profile, **profile}) is None
_PRICES = SummaryPrices(input_price_per_million_tokens=0.1, output_price_per_million_tokens=0.5)
diff --git a/products/signals/backend/test/test_activity_summary_tick.py b/products/signals/backend/test/test_activity_summary_tick.py
index 37ff9d7f71aa..0e03597f9a9f 100644
--- a/products/signals/backend/test/test_activity_summary_tick.py
+++ b/products/signals/backend/test/test_activity_summary_tick.py
@@ -122,6 +122,7 @@ _CONFIG_CASES: list[tuple[str, Any, ActivitySummaryConfig]] = [
"min_update_interval_hours": 0,
"max_versions": -3,
"emit_embeddings": "no",
+ "emit_profile_embeddings": 1,
"rebuild_before": "not a time",
"max_org_share": 2,
"rebuild_budget_share": 2,
@@ -154,6 +155,7 @@ _CONFIG_CASES: list[tuple[str, Any, ActivitySummaryConfig]] = [
"min_update_interval_hours": 12,
"max_versions": 5,
"capture_events": False,
+ "emit_profile_embeddings": True,
"rebuild_before": "2026-10-01T00:00:00",
"enroll_all_approved": True,
"count_views": True,
@@ -179,6 +181,7 @@ _CONFIG_CASES: list[tuple[str, Any, ActivitySummaryConfig]] = [
min_update_interval_hours=12.0,
max_versions=5,
capture_events=False,
+ emit_profile_embeddings=True,
rebuild_before=datetime.datetime(2026, 10, 1, tzinfo=datetime.UTC),
enroll_all_approved=True,
count_views=True,
@@ -987,6 +990,56 @@ class TestActivitySummaryQueue(BaseTest):
assert event["properties"]["trigger"] == trigger
assert "signup funnel" not in json.dumps(event["properties"]).lower()
+ @parameterized.expand(
+ [
+ ("both switches on", True, True, False, ["summary_text", "summary_profile"]),
+ ("profile switch off", True, False, False, ["summary_text"]),
+ ("embeddings off stops both", False, True, False, []),
+ ("a failed profile vector keeps the summary vector", True, True, True, ["summary_text"]),
+ ]
+ )
+ def test_the_profile_vector_follows_its_switch_and_never_affects_the_summary_vector(
+ self, _name: str, emit_embeddings: bool, emit_profile: bool, profile_fails: bool, expected: list[str]
+ ) -> None:
+ self._changes(self.user, 3)
+ emitted: list[dict[str, Any]] = []
+
+ def emit(**kwargs: Any) -> None:
+ if profile_fails and kwargs["rendering"] == "summary_profile":
+ raise RuntimeError("embedding producer down")
+ emitted.append(kwargs)
+
+ with (
+ patch("products.signals.backend.activity_summary.logic.gateway_client", return_value=FakeLLM([ANSWER])),
+ patch("posthog.api.embedding_worker.emit_embedding_request", side_effect=emit),
+ ):
+ result = run_pair(
+ ActivitySummaryPairInput(
+ team_id=self.team.id,
+ user_id=self.user.id,
+ min_units=3,
+ min_update_interval_hours=24,
+ emit_embeddings=emit_embeddings,
+ emit_profile_embeddings=emit_profile,
+ capture_events=False,
+ )
+ )
+
+ headline_and_themes = "Builds the signup funnel.\nThemes: Signup funnel"
+ contents = {
+ "summary_text": headline_and_themes,
+ "summary_profile": f"{headline_and_themes}\n\n## Funnels\n- Builds the signup funnel.",
+ }
+ assert result.status == "ok"
+ assert [(call["rendering"], call["content"]) for call in emitted] == [
+ (rendering, contents[rendering]) for rendering in expected
+ ]
+ shared = [
+ {key: value for key, value in call.items() if key not in ("rendering", "content")} for call in emitted
+ ]
+ assert all(fields == shared[0] for fields in shared)
+ assert all(fields["document_id"] == f"{self.user.id}:2026-10-19" for fields in shared)
+
@pytest.mark.asyncio
async def test_an_update_keeps_an_operator_pause() -> None:
diff --git a/products/signals/dags/inbox_ranking/README.md b/products/signals/dags/inbox_ranking/README.md
index d60dabea9372..ac4973492210 100644
--- a/products/signals/dags/inbox_ranking/README.md
+++ b/products/signals/dags/inbox_ranking/README.md
@@ -43,7 +43,8 @@ s3://<bucket>/<prefix>/
├── inbox_user_report_interactions/v1/dt=YYYY-MM-DD/ # cumulative interactions per (report, person)
├── inbox_project_vectors/v1/dt=YYYY-MM-DD/ # per-team mean report vectors of past engagement, by kind
├── inbox_user_vectors/v1/dt=YYYY-MM-DD/ # per-user mean report vectors of past engagement, by kind
-└── inbox_activity_summary_vectors/v1/dt=YYYY-MM-DD/ # one row per activity summary vector generated during the day
+├── inbox_activity_summary_vectors/v1/dt=YYYY-MM-DD/ # one row per activity summary vector generated during the day
+└── inbox_activity_summary_profile_vectors/v1/dt=YYYY-MM-DD/ # the same shape, for the rendering with the profile
```
The first four are report grain and land in one table. `inbox_signal_embeddings` is signal grain, feeds the group-level model, and is read on its own — training joins it to `inbox_report_model_data` by `report_id`.
@@ -191,6 +192,13 @@ That table drops a row 3 months after its `timestamp`, and `UserActivitySummaryV
- **It is a leaf.** Nothing joins it, so a failure here does not fail the training table. A day of vectors is small, so it has no ordering dependency.
- Backfill: materialize every partition from the first activity summary build that is still inside the source TTL. Repeat for the matching partitions after a backfill of past-dated summaries, before those vectors expire.
+`inbox_activity_summary_profile_vectors` is the same leaf for the `summary_profile` rendering, with its own `ACTIVITY_SUMMARY_PROFILE_VECTORS_SCHEMA_VERSION`.
+That rendering embeds `summary_profile_text`: the headline, the theme labels and the profile.
+It shares the `document_id` and `timestamp` of the `summary_text` vector of the same build, so a backtest can compare the two user vectors on the same builds.
+The tick emits it only while `emit_profile_embeddings` is on in the `activity-summary` flag payload, and only for a summary with a profile.
+The activity summary backfill does not emit it.
+Each asset reads only its own rendering.
+
## The training dag
`inbox_ranking_training_job` runs daily at 05:00 UTC on the same partition definition (gated like the dataset job).
@@ -546,7 +554,7 @@ The dags train only on reports from organizations whose `Organization.is_ai_trai
`consent.training_consent_team_ids()` returns the consenting teams that hold an inbox report, and every asset reads it once per run.
- `inbox_report_state` keeps only the spine reports of those teams. A label event that names another team's report does not pull it back in. That report's labels still land in `inbox_report_model_data` as a label-only row, which training skips.
-- `inbox_report_embeddings`, `inbox_report_title_embeddings`, `inbox_signal_embeddings` and `inbox_activity_summary_vectors` read only those teams, through `team_id IN (...)` in the ClickHouse query.
+- `inbox_report_embeddings`, `inbox_report_title_embeddings`, `inbox_signal_embeddings`, `inbox_activity_summary_vectors` and `inbox_activity_summary_profile_vectors` read only those teams, through `team_id IN (...)` in the ClickHouse query.
- The `nn` examples asset drops every state row whose `report_team_id` is not in the current set, before it builds examples. The lookback window reaches partitions written before an organization opted out, so this filter is what makes an opt-out take effect on the next training run.
The filter follows the current setting, so an organization that opts back in is trained on again.
diff --git a/products/signals/dags/inbox_ranking/dataset/dag.py b/products/signals/dags/inbox_ranking/dataset/dag.py
index 0231c4ee8c32..0ee3f17813e1 100644
--- a/products/signals/dags/inbox_ranking/dataset/dag.py
+++ b/products/signals/dags/inbox_ranking/dataset/dag.py
@@ -1,6 +1,6 @@
"""Daily modeling dataset for the Self-driving Inbox report-ranking model.
-Eleven assets on one daily partition, each writing Parquet under the configured S3 prefix:
+Twelve assets on one daily partition, each writing Parquet under the configured S3 prefix:
inbox_report_state/v1/dt=D/ Postgres spine + report-state columns
inbox_report_embeddings/v1/dt=D/ report_id -> small-1536 vector as of snapshot end
@@ -13,6 +13,7 @@ Eleven assets on one daily partition, each writing Parquet under the configured
inbox_project_vectors/v1/dt=D/ per-team mean report vectors of past engagement, by kind
inbox_user_vectors/v1/dt=D/ per-user mean report vectors of past engagement, by kind
inbox_activity_summary_vectors/v1/dt=D/ one row per activity summary vector generated during D
+ inbox_activity_summary_profile_vectors/v1/dt=D/ the same shape, for the rendering with the profile
inbox_engagement_export writes no dataset object. It sends the dt=D engagement moments of the other
region's reports to the serving mirror store, for that region's project vectors.
@@ -28,6 +29,7 @@ inbox_user_vectors is an (organization, user, kind) leaf with its own schema ver
embeddings and interactions snapshots.
inbox_activity_summary_vectors is a (team, user, day) leaf with its own schema version: the durable
copy of the per-user activity summary vectors, which the source table drops after its 3-month TTL.
+inbox_activity_summary_profile_vectors is the same leaf for the rendering with the profile.
Partition dt=D is a full snapshot of the eligible report inventory (promoted or ever-labeled),
with every label aggregate bounded `event_time < D+1 00:00 UTC`. Label columns are cumulative,
@@ -90,6 +92,7 @@ from posthog.models import OrganizationMembership, Team, User
from products.signals.backend.activity_summary.tick import (
EMBEDDING_DOCUMENT_TYPE as ACTIVITY_SUMMARY_DOCUMENT_TYPE,
EMBEDDING_RENDERING as ACTIVITY_SUMMARY_RENDERING,
+ EMBEDDING_RENDERING_PROFILE as ACTIVITY_SUMMARY_RENDERING_PROFILE,
)
from products.signals.backend.models import (
SignalReport,
@@ -201,6 +204,7 @@ PROJECT_VECTORS_TABLE = "inbox_project_vectors"
USER_VECTORS_TABLE = "inbox_user_vectors"
ENGAGEMENT_EXPORT = "inbox_engagement_export"
ACTIVITY_SUMMARY_VECTORS_TABLE = "inbox_activity_summary_vectors"
+ACTIVITY_SUMMARY_PROFILE_VECTORS_TABLE = "inbox_activity_summary_profile_vectors"
# The reviewers asset is a leaf with its own columns, so its schema moves apart from
# FEATURE_SCHEMA_VERSION. The same rule applies: additive nullable columns bump it.
@@ -210,6 +214,7 @@ REVIEWERS_SCHEMA_VERSION = 1
ENGAGEMENT_EXPORT_SCHEMA_VERSION = 2
# The activity summary vectors are a (team, user, day) leaf, so their shape moves apart too.
ACTIVITY_SUMMARY_VECTORS_SCHEMA_VERSION = 1
+ACTIVITY_SUMMARY_PROFILE_VECTORS_SCHEMA_VERSION = 1
# Every document type that carries an activity summary vector. A backfilled type joins this tuple,
# and its rows say so through `source`.
ACTIVITY_SUMMARY_DOCUMENT_TYPES = (ACTIVITY_SUMMARY_DOCUMENT_TYPE,)
@@ -1594,9 +1599,12 @@ def inbox_user_vectors(context: dagster.AssetExecutionContext) -> None:
)
-def activity_summary_vectors_table(partition_key: str, consent_team_ids: Collection[int]) -> tuple[pa.Table, int]:
- """The activity summary vectors generated during dt=D for the teams in `consent_team_ids`, one row
- per document, and the number of rows skipped because their document_id names no user."""
+def activity_summary_vectors_table(
+ partition_key: str, rendering: str, consent_team_ids: Collection[int]
+) -> tuple[pa.Table, int]:
+ """The activity summary vectors of one rendering generated during dt=D for the teams in
+ `consent_team_ids`, one row per document, and the number of rows skipped because their document_id
+ names no user."""
window_start, window_end = snapshot_bounds(partition_key)
results = (
cast(
@@ -1606,7 +1614,7 @@ def activity_summary_vectors_table(partition_key: str, consent_team_ids: Collect
{
"product": EMBEDDING_PRODUCT,
"document_types": list(ACTIVITY_SUMMARY_DOCUMENT_TYPES),
- "rendering": ACTIVITY_SUMMARY_RENDERING,
+ "rendering": rendering,
"window_start": window_start.replace(tzinfo=None),
"window_end": window_end.replace(tzinfo=None),
"team_ids": sorted(consent_team_ids),
@@ -1679,32 +1687,23 @@ def merge_activity_summary_vectors(existing: pa.Table, fresh: pa.Table, consent_
return pa.concat_tables([fresh, existing.filter(keep)])
[email protected](name=ACTIVITY_SUMMARY_VECTORS_TABLE, **COMMON_ASSET_KWARGS)
-def inbox_activity_summary_vectors(context: dagster.AssetExecutionContext) -> None:
- """One row per activity summary vector generated during dt=D, for user vectors in ranking training.
-
- The source table drops a vector 3 months after its timestamp, and `UserActivitySummaryVersion`
- keeps only the newest versions of a pair, so this partition is the durable history: a vector
- that is not copied before it expires cannot be rebuilt. Partition D holds only the vectors
- generated during D, not a cumulative snapshot. Training reads the union of partitions and takes
- the vector a user had at a moment through `activity_vector_as_of`.
-
- A leaf: nothing joins it, and it carries no summary text. A re-run replaces the rows the source
- still returns and keeps the rest (`merge_activity_summary_vectors`).
- """
+def _snapshot_activity_summary_vectors(
+ context: dagster.AssetExecutionContext, table_name: str, rendering: str, schema_version: int, query_type: str
+) -> None:
+ """Write one activity summary rendering's vectors of dt=D, shared by the two vector assets."""
if skip_unconfigured(context):
return
- tag_dagster_queries(context, query_type="inbox_ranking_activity_summary_vectors")
+ tag_dagster_queries(context, query_type=query_type)
partition_key = context.partition_key
consent_team_ids = training_consent_team_ids()
- fresh, malformed = activity_summary_vectors_table(partition_key, consent_team_ids)
+ fresh, malformed = activity_summary_vectors_table(partition_key, rendering, consent_team_ids)
bucket = dataset_bucket()
- key = partition_object_key(settings.INBOX_RANKING_DATASET_S3_PREFIX, ACTIVITY_SUMMARY_VECTORS_TABLE, partition_key)
+ key = partition_object_key(settings.INBOX_RANKING_DATASET_S3_PREFIX, table_name, partition_key)
client = s3_client()
existing = read_parquet_if_exists(client, bucket, key)
table = fresh if existing is None else merge_activity_summary_vectors(existing, fresh, consent_team_ids)
- write_parquet(client, bucket, key, table, schema_version=ACTIVITY_SUMMARY_VECTORS_SCHEMA_VERSION)
+ write_parquet(client, bucket, key, table, schema_version=schema_version)
team_ids = table.column("team_id").to_pylist()
user_ids = table.column("user_id").to_pylist()
@@ -1723,6 +1722,42 @@ def inbox_activity_summary_vectors(context: dagster.AssetExecutionContext) -> No
)
[email protected](name=ACTIVITY_SUMMARY_VECTORS_TABLE, **COMMON_ASSET_KWARGS)
+def inbox_activity_summary_vectors(context: dagster.AssetExecutionContext) -> None:
+ """One row per activity summary vector generated during dt=D, for user vectors in ranking training.
+
+ The source table drops a vector 3 months after its timestamp, and `UserActivitySummaryVersion`
+ keeps only the newest versions of a pair, so this partition is the durable history: a vector
+ that is not copied before it expires cannot be rebuilt. Partition D holds only the vectors
+ generated during D, not a cumulative snapshot. Training reads the union of partitions and takes
+ the vector a user had at a moment through `activity_vector_as_of`.
+
+ A leaf: nothing joins it, and it carries no summary text. A re-run replaces the rows the source
+ still returns and keeps the rest (`merge_activity_summary_vectors`).
+ """
+ _snapshot_activity_summary_vectors(
+ context,
+ ACTIVITY_SUMMARY_VECTORS_TABLE,
+ ACTIVITY_SUMMARY_RENDERING,
+ ACTIVITY_SUMMARY_VECTORS_SCHEMA_VERSION,
+ query_type="inbox_ranking_activity_summary_vectors",
+ )
+
+
[email protected](name=ACTIVITY_SUMMARY_PROFILE_VECTORS_TABLE, **COMMON_ASSET_KWARGS)
+def inbox_activity_summary_profile_vectors(context: dagster.AssetExecutionContext) -> None:
+ """The same leaf as `inbox_activity_summary_vectors`, for the rendering with the profile, so a
+ backtest can compare the two user vectors on the same builds. The tick emits this rendering only
+ while `emit_profile_embeddings` is on, so a day without it writes an empty object."""
+ _snapshot_activity_summary_vectors(
+ context,
+ ACTIVITY_SUMMARY_PROFILE_VECTORS_TABLE,
+ ACTIVITY_SUMMARY_RENDERING_PROFILE,
+ ACTIVITY_SUMMARY_PROFILE_VECTORS_SCHEMA_VERSION,
+ query_type="inbox_ranking_activity_summary_profile_vectors",
+ )
+
+
def remote_engagement_rows(labels: pa.Table, local_report_ids: Collection[str]) -> pa.Table:
"""The label rows of reports that do not exist in this region's Postgres.
@@ -2019,6 +2054,7 @@ inbox_ranking_dataset_job = dagster.define_asset_job(
USER_VECTORS_TABLE,
ENGAGEMENT_EXPORT,
ACTIVITY_SUMMARY_VECTORS_TABLE,
+ ACTIVITY_SUMMARY_PROFILE_VECTORS_TABLE,
],
# The seven label streams run sequentially and each may take its full 600s query timeout, so an
# hour left a slow-but-valid pass no room for the join, the S3 writes, or an asset retry — and
diff --git a/products/signals/dags/inbox_ranking/tests/test_dataset.py b/products/signals/dags/inbox_ranking/tests/test_dataset.py
index bac4dbd9bdc8..f07fe919f2b3 100644
--- a/products/signals/dags/inbox_ranking/tests/test_dataset.py
+++ b/products/signals/dags/inbox_ranking/tests/test_dataset.py
@@ -1259,6 +1259,7 @@ def test_an_empty_result_still_writes_the_full_schema(monkeypatch, asset):
dag.inbox_report_title_embeddings,
dag.inbox_signal_embeddings,
dag.inbox_activity_summary_vectors,
+ dag.inbox_activity_summary_profile_vectors,
],
)
@pytest.mark.parametrize("consent_team_ids", [frozenset({2, 7}), frozenset()])
@@ -1272,11 +1273,20 @@ def test_embeddings_are_read_only_for_teams_opted_in_to_ai_training(monkeypatch,
assert written["table"].num_rows == 0
-def test_activity_summary_vectors_read_the_day_and_parse_the_user_from_the_document_id(monkeypatch):
+ "asset,table,rendering",
+ [
+ (dag.inbox_activity_summary_vectors, "inbox_activity_summary_vectors", "summary_text"),
+ (dag.inbox_activity_summary_profile_vectors, "inbox_activity_summary_profile_vectors", "summary_profile"),
+ ],
+)
+def test_activity_summary_vectors_read_the_day_and_parse_the_user_from_the_document_id(
+ monkeypatch, asset, table, rendering
+):
generated_at = datetime.datetime(2026, 7, 29, 23, 50)
written = _run_embeddings_asset(
monkeypatch,
- dag.inbox_activity_summary_vectors,
+ asset,
[
(2, "41:2026-07-29", generated_at, [0.5, 0.25], datetime.datetime(2026, 7, 30, 0, 5), 6, 7, "m", "live"),
(2, "not-a-user:2026-07-29", generated_at, [0.1], generated_at, 6, 7, "m", "backfill"),
@@ -1288,9 +1298,8 @@ def test_activity_summary_vectors_read_the_day_and_parse_the_user_from_the_docum
datetime.datetime(2026, 7, 30),
)
assert written["params"]["document_types"] == ["activity_summary"]
- assert written["key"] == common.partition_object_key(
- "inbox_ranking", "inbox_activity_summary_vectors", SNAPSHOT_DATE.isoformat()
- )
+ assert written["params"]["rendering"] == rendering
+ assert written["key"] == common.partition_object_key("inbox_ranking", table, SNAPSHOT_DATE.isoformat())
assert written["table"].schema == ACTIVITY_SUMMARY_VECTORS_SCHEMA
assert written["table"].to_pylist() == [
{
@@ -1352,6 +1361,7 @@ def test_the_leaf_snapshots_run_in_the_job_without_feeding_the_join():
dag.inbox_user_vectors,
dag.inbox_engagement_export,
dag.inbox_activity_summary_vectors,
+ dag.inbox_activity_summary_profile_vectors,
]
)
model_data_deps = {key.path[-1] for key in dag.inbox_report_model_data.keys_by_input_name.values()}
@@ -1363,6 +1373,7 @@ def test_the_leaf_snapshots_run_in_the_job_without_feeding_the_join():
dag.USER_VECTORS_TABLE,
dag.ENGAGEMENT_EXPORT,
dag.ACTIVITY_SUMMARY_VECTORS_TABLE,
+ dag.ACTIVITY_SUMMARY_PROFILE_VECTORS_TABLE,
):
assert dagster.AssetKey(leaf) in selection
assert leaf not in model_data_deps