Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

feat: Memory Exports (#3117)

Saket Aryan842903b1b1b9
diff --git a/docs/changelog.mdx b/docs/changelog.mdx
index 8bd1093ca..5c2d85b10 100644
--- a/docs/changelog.mdx
+++ b/docs/changelog.mdx
@@ -409,6 +409,11 @@ mode: "wide"
<Tab title="TypeScript">
+<Update label="2025-07-08" description="v2.1.35">
+**New Features:**
+- **Client:** Added `createMemoryExport` and `getMemoryExport` methods.
+</Update>
+
<Update label="2025-07-03" description="v2.1.34">
**New Features:**
- **OSS:** Added Gemini support
diff --git a/docs/openapi.json b/docs/openapi.json
index f7eafc70d..cd038cdf5 100644
--- a/docs/openapi.json
+++ b/docs/openapi.json
@@ -497,40 +497,38 @@
"summary": "Export data based on filters",
"description": "Get the latest memory export.",
"operationId": "exports_list",
- "parameters": [
- {
- "name": "filters",
- "in": "query",
- "schema": {
- "type": "object",
- "properties": {
- "user_id": {"type": "string"},
- "agent_id": {"type": "string"},
- "app_id": {"type": "string"},
- "run_id": {"type": "string"},
- "created_at": {"type": "string"},
- "updated_at": {"type": "string"}
- },
- "description": "Filters to apply while exporting memories. Available fields are: user_id, agent_id, app_id, run_id, created_at, updated_at."
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "memory_export_id": {"type": "string", "description": "The unique identifier of the memory export"},
+ "filters": {
+ "type": "object",
+ "properties": {
+ "user_id": {"type": "string"},
+ "agent_id": {"type": "string"},
+ "app_id": {"type": "string"},
+ "run_id": {"type": "string"},
+ "created_at": {"type": "string"},
+ "updated_at": {"type": "string"}
+ },
+ "description": "Filters to apply while exporting memories. Available fields are: user_id, agent_id, app_id, run_id, created_at, updated_at."
+ },
+ "org_id": {
+ "type": "string",
+ "description": "Filter exports by organization ID"
+ },
+ "project_id": {
+ "type": "string",
+ "description": "Filter exports by project ID"
+ }
+ }
+ }
}
- },
- {
- "name": "org_id",
- "in": "query",
- "schema": {
- "type": "string"
- },
- "description": "Filter exports by organization ID"
- },
- {
- "name": "project_id",
- "in": "query",
- "schema": {
- "type": "string"
- },
- "description": "Filter exports by project ID"
}
- ],
+ },
"responses": {
"200": {
"description": "Successful export",
@@ -538,7 +536,7 @@
"application/json": {
"schema": {
"type": "object",
- "description": "Export data response"
+ "description": "Export data response in a object format"
}
}
}
@@ -579,27 +577,27 @@
"x-code-samples": [
{
"lang": "Python",
- "source": "# To use the Python SDK, install the package:\n# pip install mem0ai\n\nfrom mem0 import MemoryClient\n\nclient = MemoryClient(api_key=\"your_api_key\", org_id=\"your_org_id\", project_id=\"project_id\")\n\nfilters = {\n \"AND\": [\n {\"created_at\": {\"gte\": \"2024-07-10\", \"lte\": \"2024-07-20\"}},\n {\"user_id\": \"alex\"}\n ]\n}\n\nresponse = client.get_memory_export(filters=filters)\nprint(response)"
+ "source": "# To use the Python SDK, install the package:\n# pip install mem0ai\n\nfrom mem0 import MemoryClient\n\nclient = MemoryClient(api_key=\"your_api_key\", org_id=\"your_org_id\", project_id=\"project_id\")\n\nmemory_export_id = \"<memory_export_id>\"\n\nresponse = client.get_memory_export(memory_export_id=memory_export_id)\nprint(response)"
},
{
"lang": "JavaScript",
- "source": "// To use the JavaScript SDK, install the package:\n// npm i mem0ai\n\nimport MemoryClient from 'mem0ai';\nconst client = new MemoryClient({ apiKey: \"your-api-key\" });\n\nconst filters = {\n AND: [\n {created_at: {gte: \"2024-07-10\", lte: \"2024-07-20\"}},\n {user_id: \"alex\"}\n ]\n};\n\n// Get memory export\nclient.getMemoryExport({ filters })\n .then(result => console.log(result))\n .catch(error => console.error(error));"
+ "source": "// To use the JavaScript SDK, install the package:\n// npm i mem0ai\n\nimport MemoryClient from 'mem0ai';\nconst client = new MemoryClient({ apiKey: \"your-api-key\" });\n\nconst memory_export_id = \"<memory_export_id>\";\n\n// Get memory export\nclient.getMemoryExport({ memory_export_id })\n .then(result => console.log(result))\n .catch(error => console.error(error));"
},
{
"lang": "cURL",
- "source": "curl --request GET \\\n --url 'https://api.mem0.ai/v1/exports/?filters={\"AND\":[{\"created_at\":{\"gte\":\"2024-07-10\",\"lte\":\"2024-07-20\"}},{\"user_id\":\"alex\"}]}' \\\n --header 'Authorization: Token <api-key>'"
+ "source": "curl --request POST \\\n --url 'https://api.mem0.ai/v1/exports/get/' \\\n --header 'Authorization: Token <api-key>' \\\n --data '{\n \"memory_export_id\": \"<memory_export_id>\"\n}'"
},
{
"lang": "Go",
- "source": "package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io/ioutil\"\n)\n\nfunc main() {\n\tfilters := `{\"AND\":[{\"created_at\":{\"gte\":\"2024-07-10\",\"lte\":\"2024-07-20\"}},{\"user_id\":\"alex\"}]}`\n\turl := fmt.Sprintf(\"https://api.mem0.ai/v1/exports/?filters=%s\", filters)\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\treq.Header.Add(\"Authorization\", \"Token <api-key>\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := ioutil.ReadAll(res.Body)\n\n\tfmt.Println(string(body))\n}"
+ "source": "package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io/ioutil\"\n)\n\nfunc main() {\n\tmemory_export_id := \"<memory_export_id>\"\n\n\treq, _ := http.NewRequest(\"POST\", \"https://api.mem0.ai/v1/exports/get/\", nil)\n\n\treq.Header.Add(\"Authorization\", \"Token <api-key>\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := ioutil.ReadAll(res.Body)\n\n\tfmt.Println(string(body))\n}"
},
{
"lang": "PHP",
- "source": "<?php\n\n$curl = curl_init();\n\n$filters = urlencode('{\"AND\":[{\"created_at\":{\"gte\":\"2024-07-10\",\"lte\":\"2024-07-20\"}},{\"user_id\":\"alex\"}]}');\n\ncurl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.mem0.ai/v1/exports/?filters=\" . $filters,\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 30,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"GET\",\n CURLOPT_HTTPHEADER => [\n \"Authorization: Token <api-key>\"\n ],\n]);\n\n$response = curl_exec($curl);\n$err = curl_error($curl);\n\ncurl_close($curl);\n\nif ($err) {\n echo \"cURL Error #:\" . $err;\n} else {\n echo $response;\n}"
+ "source": "<?php\n\n$curl = curl_init();\n\n$data = json_encode(['memory_export_id' => '<memory_export_id>']);\n\ncurl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.mem0.ai/v1/exports/get/\",\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 30,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"POST\",\n CURLOPT_POSTFIELDS => $data,\n CURLOPT_HTTPHEADER => [\n \"Authorization: Token <api-key>\",\n \"Content-Type: application/json\"\n ],\n]);\n\n$response = curl_exec($curl);\n$err = curl_error($curl);\n\ncurl_close($curl);\n\nif ($err) {\n echo \"cURL Error #:\" . $err;\n} else {\n echo $response;\n}"
},
{
"lang": "Java",
- "source": "String filters = \"{\\\"AND\\\":[{\\\"created_at\\\":{\\\"gte\\\":\\\"2024-07-10\\\",\\\"lte\\\":\\\"2024-07-20\\\"}},{\\\"user_id\\\":\\\"alex\\\"}]}\";\n\nHttpResponse<String> response = Unirest.get(\"https://api.mem0.ai/v1/exports/?filters=\" + filters)\n .header(\"Authorization\", \"Token <api-key>\")\n .asString();"
+ "source": "String data = \"{\\\"memory_export_id\\\":\\\"<memory_export_id>\\\"}\";\n\nHttpResponse<String> response = Unirest.post(\"https://api.mem0.ai/v1/exports/get/\")\n .header(\"Authorization\", \"Token <api-key>\")\n .header(\"Content-Type\", \"application/json\")\n .body(data)\n .asString();"
}
]
}
diff --git a/mem0-ts/package.json b/mem0-ts/package.json
index 93a096d00..2a9617edf 100644
--- a/mem0-ts/package.json
+++ b/mem0-ts/package.json
@@ -1,6 +1,6 @@
{
"name": "mem0ai",
- "version": "2.1.34",
+ "version": "2.1.35",
"description": "The Memory Layer For Your AI Apps",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
diff --git a/mem0-ts/src/client/mem0.ts b/mem0-ts/src/client/mem0.ts
index 43d38f472..60d3238b2 100644
--- a/mem0-ts/src/client/mem0.ts
+++ b/mem0-ts/src/client/mem0.ts
@@ -13,6 +13,8 @@ import {
WebhookPayload,
Message,
FeedbackPayload,
+ CreateMemoryExportPayload,
+ GetMemoryExportPayload,
} from "./mem0.types";
import { captureClientEvent, generateHash } from "./telemetry";
@@ -705,6 +707,57 @@ export default class MemoryClient {
);
return response;
}
+
+ async createMemoryExport(
+ data: CreateMemoryExportPayload,
+ ): Promise<{ message: string; id: string }> {
+ if (this.telemetryId === "") await this.ping();
+ this._captureEvent("create_memory_export", []);
+
+ // Return if missing filters or schema
+ if (!data.filters || !data.schema) {
+ throw new Error("Missing filters or schema");
+ }
+
+ // Add Org and Project ID
+ data.org_id = this.organizationId?.toString() || null;
+ data.project_id = this.projectId?.toString() || null;
+
+ const response = await this._fetchWithErrorHandling(
+ `${this.host}/v1/exports/`,
+ {
+ method: "POST",
+ headers: this.headers,
+ body: JSON.stringify(data),
+ },
+ );
+
+ return response;
+ }
+
+ async getMemoryExport(
+ data: GetMemoryExportPayload,
+ ): Promise<{ message: string; id: string }> {
+ if (this.telemetryId === "") await this.ping();
+ this._captureEvent("get_memory_export", []);
+
+ if (!data.memory_export_id && !data.filters) {
+ throw new Error("Missing memory_export_id or filters");
+ }
+
+ data.org_id = this.organizationId?.toString() || "";
+ data.project_id = this.projectId?.toString() || "";
+
+ const response = await this._fetchWithErrorHandling(
+ `${this.host}/v1/exports/get/`,
+ {
+ method: "POST",
+ headers: this.headers,
+ body: JSON.stringify(data),
+ },
+ );
+ return response;
+ }
}
export { MemoryClient };
diff --git a/mem0-ts/src/client/mem0.types.ts b/mem0-ts/src/client/mem0.types.ts
index 3e6a01921..e9cbc8c2d 100644
--- a/mem0-ts/src/client/mem0.types.ts
+++ b/mem0-ts/src/client/mem0.types.ts
@@ -1,3 +1,8 @@
+interface Common {
+ project_id?: string | null;
+ org_id?: string | null;
+}
+
export interface MemoryOptions {
api_version?: API_VERSION | string;
version?: API_VERSION | string;
@@ -187,3 +192,14 @@ export interface FeedbackPayload {
feedback?: Feedback | null;
feedback_reason?: string | null;
}
+
+export interface CreateMemoryExportPayload extends Common {
+ schema: Record<string, any>;
+ filters: Record<string, any>;
+ export_instructions?: string;
+}
+
+export interface GetMemoryExportPayload extends Common {
+ filters?: Record<string, any>;
+ memory_export_id?: string;
+}
diff --git a/mem0-ts/src/client/telemetry.ts b/mem0-ts/src/client/telemetry.ts
index a1bc698d5..7463c9aa2 100644
--- a/mem0-ts/src/client/telemetry.ts
+++ b/mem0-ts/src/client/telemetry.ts
@@ -1,7 +1,7 @@
// @ts-nocheck
import type { TelemetryClient, TelemetryOptions } from "./telemetry.types";
-let version = "2.1.33";
+let version = "2.1.35";
// Safely check for process.env in different environments
let MEM0_TELEMETRY = true;