Compare commits

..
Author SHA1 Message Date
kartik-mem0 83f2d23ddb chore(tests): fix Gemini embeddings test filename, add Langchain embedder tests
tests/embeddings/test_gemini_emeddings.py has a typo in its name. #6095
reported it as a duplicate of test_gemini_embeddings.py, but the
correctly-spelled file has never existed in this repo, so the typo file is
the only Gemini embeddings coverage there is. Renaming keeps all 119 lines;
deleting it would drop the suite.

mem0/embeddings/langchain.py had no tests at all. Adds five covering the
model-instance validation, the missing-model guard, and embed() delegating
to embed_query, mirroring tests/llms/test_langchain.py including its
importorskip guard.

Closes #6095
2026-08-13 17:41:13 +05:30
4 changed files with 65 additions and 14 deletions
@@ -4,14 +4,10 @@ description: "Retrieve, review, and migrate user memories with structured export
---
Mem0 is a dynamic memory store that lets you retrieve memories as raw records or transform them into a structured export for downstream use.
Mem0 is a dynamic memory store that gives you full control over your data. Along with storing memories, it gives you the ability to retrieve, export, and migrate your data whenever you need.
This cookbook shows you how to retrieve and export your data for inspection, migration, or compliance.
<Warning>
The structured export job is not a raw backup. It uses the schema and instructions you provide to transform matching memories. Use paginated `get_all()` calls when you need the original memory records. For an account-level data access or compliance request that the API cannot complete, contact support.
</Warning>
---
## Setup
@@ -258,7 +254,7 @@ You can also export memories directly from the Mem0 platform UI:
3. Select your filters and schema
4. Download the completed export as JSON
This is useful for one-off structured exports or manual data reviews. It does not create a raw backup of every memory record; use paginated `get_all()` calls for raw retrieval.
This is useful for one-off exports or manual data reviews.
<Warning>
Exported data expires after 7 days. Download and store exports locally if you need long-term archives. After expiration, you'll need to recreate the export job.
@@ -276,13 +272,13 @@ A complete memory export system with multiple retrieval methods:
- **Export instructions** - Guide conflict resolution and data formatting
- **Platform UI exports** - One-off manual downloads via dashboard
These approaches support data inspection, portability workflows, system migrations, and manual reviews. Use raw retrieval or contact support when a compliance request requires the original records rather than a schema-transformed export.
This covers data portability, GDPR compliance, system migrations, and manual reviews.
---
## Summary
Use **`get_all()`** for paginated raw retrieval, **`search()`** for specific questions, and **`create_memory_export()`** for schema-transformed data. Structured exports expire after 7 days, so download completed results promptly. Do not treat them as raw backups.
Use **`get_all()`** for bulk retrieval, **`search()`** for specific questions, and **`create_memory_export()`** for structured data exports with custom schemas. Remember exports expire after 7 days: download them locally for long-term archives.
<CardGroup cols={2}>
<Card title="Build a Mem0 Companion" icon="users" href="/cookbooks/essentials/building-ai-companion">
-6
View File
@@ -7,10 +7,6 @@ description: 'Export memories in a structured format using customizable Pydantic
The Memory Export feature allows you to create structured exports of memories using customizable Pydantic schemas. This process enables you to transform your stored memories into specific data formats that match your needs. You can apply various filters to narrow down which memories to export and define exactly how the data should be structured.
<Warning>
Memory Export transforms matching memories into the schema you provide. It is not a raw backup or a byte-for-byte download of every stored memory record. If you need the original memory records, retrieve them with the paginated `get_all()` API instead. For an account-level data access or compliance request that cannot be completed through the API, contact support.
</Warning>
## Creating a Memory Export
To create a memory export, you'll need to:
@@ -282,8 +278,6 @@ You can apply various filters to customize which memories are included in the ex
The export process may take some time to complete, especially when dealing with a large number of memories or complex schemas.
</Note>
If an export remains in progress unexpectedly, do not submit duplicate jobs. Retrieve the job by its export ID to check its status, then contact support with that ID if it does not complete.
If you have any questions, please feel free to reach out to us using one of the following methods:
<Snippet file="get-help.mdx" />
@@ -0,0 +1,61 @@
from unittest.mock import Mock
import pytest
pytest.importorskip("langchain", reason="langchain not installed")
from mem0.configs.embeddings.base import BaseEmbedderConfig
from mem0.embeddings.langchain import LangchainEmbedding
try:
from langchain.embeddings.base import Embeddings
except ImportError:
from unittest.mock import MagicMock
Embeddings = MagicMock
@pytest.fixture
def mock_langchain_model():
"""Mock a Langchain embeddings model for testing."""
mock_model = Mock(spec=Embeddings)
mock_model.embed_query.return_value = [0.1, 0.2, 0.3]
return mock_model
def test_langchain_initialization(mock_langchain_model):
"""LangchainEmbedding keeps the configured model instance."""
embedder = LangchainEmbedding(BaseEmbedderConfig(model=mock_langchain_model))
assert embedder.langchain_model is mock_langchain_model
def test_embed_delegates_to_embed_query(mock_langchain_model):
"""embed() forwards the text to the model's embed_query and returns its vector."""
embedder = LangchainEmbedding(BaseEmbedderConfig(model=mock_langchain_model))
embedding = embedder.embed("Sample text to embed.")
mock_langchain_model.embed_query.assert_called_once_with("Sample text to embed.")
assert embedding == [0.1, 0.2, 0.3]
def test_embed_ignores_memory_action(mock_langchain_model):
"""memory_action is accepted for interface parity and never reaches the model."""
embedder = LangchainEmbedding(BaseEmbedderConfig(model=mock_langchain_model))
embedder.embed("Sample text to embed.", memory_action="add")
mock_langchain_model.embed_query.assert_called_once_with("Sample text to embed.")
def test_invalid_model():
"""A model that is not an Embeddings instance is rejected."""
with pytest.raises(ValueError, match="`model` must be an instance of Embeddings"):
LangchainEmbedding(BaseEmbedderConfig(model="not-a-valid-model-instance"))
def test_missing_model():
"""A missing model is rejected before any embedding call."""
with pytest.raises(ValueError, match="`model` parameter is required"):
LangchainEmbedding(BaseEmbedderConfig(model=None))