: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(data-warehouse): add twelve labs asset transcriptions table (#113862)
Tom Owersb875a7fbf63a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex 6ce0fdfe3da0..2440129c7be3 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -9077,6 +9077,7 @@ Diffed against: <https://docs.twelvelabs.io/openapi.json>- [ ] `embed tasks (GET /embed/tasks and /embed-v2/tasks)` — embedding job history, parallel to the indexing tasks already synced (medium)- [ ] `entity-collections and their entities (GET /entity-collections, /entity-collections/{id}/entities)` — lookup tables that resolve entity ids appearing on assets (medium)- [ ] `asset entities (GET /assets/{asset_id}/entities)` — asset-to-entity mapping for face/object analytics (medium)+- [x] `asset transcriptions (GET /assets/{asset_id}/transcription)` — per-asset speech transcription with status and timestamped sentences and speaker turns (medium)- [ ] `knowledge-stores, item-collections, items (GET /knowledge-stores, .../item-collections, .../items)` — the retrieval corpus objects; items resolve ids used by search (medium)- [ ] `connection imports (GET /connections/{connection_id}/imports)` — per-import job records for bulk ingestion runs (low)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/canonical_descriptions.pyindex 45f7d220e447..54fcfc3123ba 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/canonical_descriptions.py@@ -45,4 +45,16 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"system_metadata": "Platform-derived metadata about the video (filename, duration, fps, width, height, size).",},},+ "asset_transcriptions": {+ "description": "The speech transcription of a video or audio asset, with its status and timestamped segments.",+ "docs_url": "https://docs.twelvelabs.io/v1.3/api-reference/manage-assets/retrieve-transcription",+ "columns": {+ "asset_id": "Identifier of the transcribed asset (injected during fan-out).",+ "asset_created_at": "Date and time, in RFC 3339 format, the asset was created (injected during fan-out).",+ "status": "Transcription status: pending, processing, ready, or failed.",+ "sentences": "One entry for each detected sentence, with start and end timestamps in seconds and the recognized text. Present when the status is ready.",+ "utterances": "One entry for each speaker turn, with start and end timestamps in seconds, the recognized text, and the speaker identifier when available. Present when the status is ready.",+ "error": "Details about the failure, with a human-readable message. Present when the status is failed.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/settings.pyindex d1e790a44d5b..26ef429cc55b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/settings.py@@ -1,5 +1,5 @@from dataclasses import dataclass, field-from typing import Optional+from typing import Any, Literal, Optionalfrom products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType@@ -13,10 +13,10 @@ def _datetime_field(name: str) -> IncrementalField:}-@dataclass+@dataclass(frozen=True)class TwelveLabsEndpointConfig:name: str- # `path` may contain a `{index_id}` placeholder for fan-out endpoints.+ # `path` may contain an `{index_id}` or `{asset_id}` placeholder for fan-out endpoints.path: strincremental_fields: list[IncrementalField]# Field to partition by. Must be a STABLE creation-time field so partitions don't rewrite@@ -24,10 +24,13 @@ class TwelveLabsEndpointConfig:partition_key: Optional[str] = "created_at"primary_keys: list[str] = field(default_factory=lambda: ["_id"])should_sync_default: bool = True- # Fan out one paginated request per index (used by the videos endpoint, which is nested- # under an index). When True, `path` is a template with an `{index_id}` placeholder and the- # parent index id is injected into every row.- fan_out_over_indexes: bool = False+ # Fan out one request per parent index or asset. `path` is then a template with the parent's+ # placeholder, and the parent id is injected into every row.+ fan_out_over: Optional[Literal["indexes", "assets"]] = None+ # The child returns one object per parent instead of a paginated `data` list.+ single_object: bool = False+ # Extra static query params sent with every request to this endpoint.+ params: dict[str, Any] = field(default_factory=dict)# Twelve Labs list endpoints all use page-number pagination (page + page_limit, max 50) and expose@@ -60,7 +63,24 @@ TWELVE_LABS_ENDPOINTS: dict[str, TwelveLabsEndpointConfig] = {incremental_fields=[],primary_keys=["index_id", "_id"],should_sync_default=False,- fan_out_over_indexes=True,+ fan_out_over="indexes",+ ),+ # One transcription per video or audio asset, fetched with one request per asset. The endpoint+ # has no list form and no time filter, so it ships as full refresh, which also picks up+ # transcriptions that move from pending/processing to ready. Assets without a transcription 404+ # and are skipped. Partitioned on the parent asset's creation time, the only stable timestamp.+ # Word-level segmentation is left out: it multiplies row size for little analytical value over+ # sentences and speaker turns. Off by default because of the per-asset API cost.+ "asset_transcriptions": TwelveLabsEndpointConfig(+ name="asset_transcriptions",+ path="/assets/{asset_id}/transcription",+ incremental_fields=[],+ partition_key="asset_created_at",+ primary_keys=["asset_id"],+ should_sync_default=False,+ fan_out_over="assets",+ single_object=True,+ params={"include": "sentences,utterances"},),}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/tests/test_twelve_labs.py b/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/tests/test_twelve_labs.pyindex 9004dec95919..d6419114882c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/tests/test_twelve_labs.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/tests/test_twelve_labs.py@@ -209,6 +209,56 @@ class TestFanOut:"https://api.twelvelabs.io/v1.3/indexes/idx2/videos",]+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_asset_transcriptions_skip_assets_without_a_transcription(self, MockSession) -> None:+ # An asset with no transcription 404s. That must skip the asset, not fail the sync, and each+ # transcription row must carry its asset's id and creation time.+ session = MockSession.return_value+ not_found = Response()+ not_found.status_code = 404+ not_found.reason = "Not Found"+ not_found.url = "https://api.twelvelabs.io/v1.3/assets/a1/transcription"+ not_found._content = b'{"code": "resource_not_found"}'+ transcription = Response()+ transcription.status_code = 200+ transcription.url = "https://api.twelvelabs.io/v1.3/assets/a2/transcription"+ transcription._content = json.dumps(+ {"status": "ready", "sentences": [{"start": 0.0, "end": 1.5, "value": "Hello."}]}+ ).encode()+ snapshots = _wire(+ session,+ [+ _page(+ [+ {"_id": "a1", "created_at": "2026-08-01T00:00:00Z"},+ {"_id": "a2", "created_at": "2026-08-02T00:00:00Z"},+ ],+ page=1,+ total_page=1,+ ),+ not_found,+ transcription,+ ],+ )++ rows = _rows(_source("asset_transcriptions"))++ assert rows == [+ {+ "status": "ready",+ "sentences": [{"start": 0.0, "end": 1.5, "value": "Hello."}],+ "asset_id": "a2",+ "asset_created_at": "2026-08-02T00:00:00Z",+ }+ ]+ assert [url for url, _ in snapshots] == [+ "https://api.twelvelabs.io/v1.3/assets",+ "https://api.twelvelabs.io/v1.3/assets/a1/transcription",+ "https://api.twelvelabs.io/v1.3/assets/a2/transcription",+ ]+ assert snapshots[0][1]["asset_types"] == ["video", "audio"]+ assert snapshots[1][1] == {"include": "sentences,utterances"}+def test_old_shape_saved_state_still_parses(self) -> None:# ResumableSourceManager._load_json does dataclass(**saved) — state saved before the# migration must still construct.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/twelve-labs.md b/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/twelve-labs.mdindex 3abdfe4a5db0..0e039479531b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/twelve-labs.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/twelve-labs.md@@ -14,9 +14,10 @@ import AlphaRelease from "../\_snippets/alpha-release.mdx"<AlphaRelease />Sync your [Twelve Labs](https://www.twelvelabs.io) video understanding library into PostHog. This-connector imports your indexes, the videos in each index, and the video indexing tasks that track the-upload and indexing lifecycle, so you can analyze library growth, indexing throughput, and indexing-failures alongside the rest of your data.+connector imports your indexes, the videos in each index, the video indexing tasks that track the+upload and indexing lifecycle, and the transcriptions of your video and audio assets, so you can+analyze library growth, indexing throughput, indexing failures, and spoken content alongside the rest+of your data.## Prerequisites@@ -40,6 +41,10 @@ recommended for ongoing syncs. `videos` is nested per index and syncs by full reby default because fanning out one request per index can consume a meaningful share of a free plan'sdaily request quota. Enable it when you need per-video metadata.+`asset_transcriptions` works the same way: it makes one request per video or audio asset, syncs by+full refresh, and is disabled by default. Each row holds the transcription status plus its sentences+and speaker turns. Assets without a transcription are skipped.+## Configuration<SourceParameters />diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/twelve_labs.py b/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/twelve_labs.pyindex 8581434c9bdf..1a85eae3d921 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/twelve_labs.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/twelve_labs/twelve_labs.py@@ -9,12 +9,17 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.resrest_api_resource,rest_api_resources,)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.config_setup import (+ make_parent_key_name,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (PageNumberPaginator,+ SinglePagePaginator,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.resource import Resourcefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (AuthConfig,+ Endpoint,EndpointResource,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager@@ -30,11 +35,37 @@ TWELVE_LABS_BASE_URL = "https://api.twelvelabs.io/v1.3"# Max page size the API allows; larger values are rejected.PAGE_LIMIT = 50-# The internal parent resource that drives the videos fan-out. include_from_parent lands the parent-# index id under `_{name}__id` (the `_id` field starts with an underscore), which the child data_map-# renames to the composite `index_id` primary-key column.-_INDEXES_PARENT_NAME = "indexes_list"-_PARENT_INDEX_ID_KEY = f"_{_INDEXES_PARENT_NAME}__id"+[email protected](frozen=True)+class _FanOutParent:+ # Internal resource name. include_from_parent lands each parent field under+ # `_{resource_name}_{field}`, which the child data_map renames to the column in `include`.+ resource_name: str+ path: str+ params: dict[str, Any]+ resolve_param: str+ # Parent field -> child column.+ include: dict[str, str]+++_FAN_OUT_PARENTS: dict[str, _FanOutParent] = {+ "indexes": _FanOutParent(+ resource_name="indexes_list",+ path="/indexes",+ params={"page_limit": PAGE_LIMIT},+ resolve_param="index_id",+ include={"_id": "index_id"},+ ),+ # Only video and audio assets can carry a transcription, so images and documents are filtered+ # out server-side instead of paying a 404 per asset.+ "assets": _FanOutParent(+ resource_name="assets_list",+ path="/assets",+ params={"page_limit": PAGE_LIMIT, "asset_types": ["video", "audio"]},+ resolve_param="asset_id",+ include={"_id": "asset_id", "created_at": "asset_created_at"},+ ),+}# Twelve Labs list endpoints paginate with page/page_limit and report the page count as# page_info.total_page, so termination stops after the last page instead of paying an extra request.@@ -192,46 +223,56 @@ def _top_level_resource(def _fan_out_resource(config: TwelveLabsEndpointConfig,+ parent: _FanOutParent,api_key: str,team_id: int,job_id: str,manager: ResumableSourceManager[TwelveLabsResumeConfig],) -> Resource:- """Fan out over every index, yielding that index's videos with the parent ``index_id`` injected.+ """Fan out over every parent index or asset, injecting the parent id into each child row.- The [index_id, _id] primary key keeps rows unique table-wide, so videos from different indexes- never collide and merge dedupes cleanly.+ The parent id is part of the primary key, so rows from different parents never collide and+ merge dedupes cleanly."""- child_params = _build_params(config, False, None, None)- def _inject_index_id(row: dict[str, Any]) -> dict[str, Any]:- # include_from_parent lands the parent index id under the mangled key; expose it under the- # plain `index_id` column exactly as the hand-rolled source produced (`{**row, "index_id": ...}`).- row["index_id"] = row.pop(_PARENT_INDEX_ID_KEY)+ def _inject_parent_fields(row: dict[str, Any]) -> dict[str, Any]:+ for parent_field, column in parent.include.items():+ row[column] = row.pop(make_parent_key_name(parent.resource_name, parent_field))return rowparent_resource: EndpointResource = {- "name": _INDEXES_PARENT_NAME,+ "name": parent.resource_name,"endpoint": {- "path": "/indexes",- "params": {"page_limit": PAGE_LIMIT},+ "path": parent.path,+ "params": parent.params,"paginator": _paginator(),"data_selector": "data",},}- child_resource: EndpointResource = {- "name": config.name,- "include_from_parent": ["_id"],- "data_map": _inject_index_id,- "endpoint": {+ resolve_params: dict[str, Any] = {+ parent.resolve_param: {"type": "resolve", "resource": parent.resource_name, "field": "_id"}+ }+ child_endpoint: Endpoint+ if config.single_object:+ child_endpoint = {"path": config.path,- "params": {- "index_id": {"type": "resolve", "resource": _INDEXES_PARENT_NAME, "field": "_id"},- **child_params,- },+ "params": {**resolve_params, **config.params},+ "paginator": SinglePagePaginator(),+ # A parent with no child object (e.g. an asset without a transcription) returns 404.+ "response_actions": [{"status_code": 404, "action": "ignore"}],+ }+ else:+ child_endpoint = {+ "path": config.path,+ "params": {**resolve_params, **_build_params(config, False, None, None), **config.params},"paginator": _paginator(),"data_selector": "data",- },+ }+ child_resource: EndpointResource = {+ "name": config.name,+ "include_from_parent": list(parent.include),+ "data_map": _inject_parent_fields,+ "endpoint": child_endpoint,}rest_config: RESTAPIConfig = {@@ -279,8 +320,10 @@ def twelve_labs_source() -> SourceResponse:config = TWELVE_LABS_ENDPOINTS[endpoint]- if config.fan_out_over_indexes:- resource = _fan_out_resource(config, api_key, team_id, job_id, resumable_source_manager)+ if config.fan_out_over:+ resource = _fan_out_resource(+ config, _FAN_OUT_PARENTS[config.fan_out_over], api_key, team_id, job_id, resumable_source_manager+ )else:resource = _top_level_resource(config,