: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(warehouse_sources): support Mem0 API version v3 (#74151)
Tom Owersb265e0d6a18c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mem0/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mem0/settings.pyindex 06a07f1ccf86..e2ea561e3996 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mem0/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mem0/settings.py@@ -14,10 +14,21 @@ Reference: https://docs.mem0.ai/api-referencefrom dataclasses import dataclass, field+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import UNVERSIONED_API_VERSIONfrom products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldTypeMEM0_BASE_URL = "https://api.mem0.ai"+# Mem0's memory API is served at v3 (``POST /v3/memories/`` — the version we already read from),+# while entities and operation events stay on the stable ``/v1/`` paths. UNVERSIONED_API_VERSION+# ("v1") is the framework placeholder that pre-versioning source rows carry; it resolves to the+# exact same wire as "v3" here (memories on ``/v3/``, entities and events on ``/v1/``), so nothing+# on the request branches on the version. Declaring "v3" as the default just labels new sources for+# the memory API they actually target.+MEM0_API_VERSION_V3 = "v3"+SUPPORTED_VERSIONS = (UNVERSIONED_API_VERSION, MEM0_API_VERSION_V3)+DEFAULT_VERSION = MEM0_API_VERSION_V3+MEMORIES_ENDPOINT = "memories"ENTITIES_ENDPOINT = "entities"EVENTS_ENDPOINT = "events"diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mem0/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mem0/source.pyindex cec6af88bb5d..852cb59add2e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mem0/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mem0/source.py@@ -27,10 +27,12 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.mem0.mem0validate_credentials as validate_mem0_credentials,)from products.warehouse_sources.backend.temporal.data_imports.sources.mem0.settings import (+ DEFAULT_VERSION,ENDPOINTS,INCREMENTAL_FIELDS,MEM0_ENDPOINTS,MEMORIES_ENDPOINT,+ SUPPORTED_VERSIONS,)from products.warehouse_sources.backend.types import ExternalDataSourceType@@ -49,6 +51,9 @@ class Mem0Source(ResumableSource[Mem0SourceConfig, Mem0ResumeConfig]):lists_tables_without_credentials = True # static endpoint catalog — safe for public docsapi_docs_url = "https://docs.mem0.ai/api-reference"+ supported_versions = SUPPORTED_VERSIONS+ default_version = DEFAULT_VERSION+@propertydef source_type(self) -> ExternalDataSourceType:return ExternalDataSourceType.MEM0diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mem0/tests/test_mem0_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mem0/tests/test_mem0_source.pyindex 75f0c9002d5c..477d1c939ac2 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mem0/tests/test_mem0_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mem0/tests/test_mem0_source.py@@ -2,6 +2,7 @@ from unittest.mock import MagicMock, patchfrom posthog.schema import SourceFieldInputConfig+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import UNVERSIONED_API_VERSIONfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.mem0 import Mem0SourceConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.mem0.mem0 import Mem0ResumeConfig@@ -9,6 +10,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.mem0.settiENDPOINTS,ENTITIES_ENDPOINT,EVENTS_ENDPOINT,+ MEM0_API_VERSION_V3,MEMORIES_ENDPOINT,)from products.warehouse_sources.backend.temporal.data_imports.sources.mem0.source import Mem0Source@@ -84,6 +86,19 @@ class TestMem0SourceSchemas:assert "Incremental" in tables[MEMORIES_ENDPOINT]["sync_methods"]+class TestMem0SourceVersions:+ def test_supports_v1_and_v3_with_v3_default(self):+ # v3 is the memory API the source already reads and the new default for fresh sources; the+ # unversioned placeholder stays supported so existing pinned (or NULL) rows keep resolving+ # to their unchanged wire behaviour. Both labels resolve to the same requests.+ source = Mem0Source()++ assert source.supported_versions == (UNVERSIONED_API_VERSION, MEM0_API_VERSION_V3)+ assert source.default_version == MEM0_API_VERSION_V3+ assert source.resolve_api_version(None) == MEM0_API_VERSION_V3+ assert source.resolve_api_version(UNVERSIONED_API_VERSION) == UNVERSIONED_API_VERSION++class TestMem0SourceCredentials:@patch(f"{_SOURCE_MODULE}.validate_mem0_credentials", return_value=True)def test_valid_key(self, mock_validate):