The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.
Python agentic-memoryagentic-memory-systemagentsaiai-agentschatgptgenaillmlong-term-memorymemorymemory-managementpythonragstate-management
Doc: update memory export (#2519)
Dev Khantf4d8647264cf
diff --git a/docs/api-reference/memory/get-memory-export.mdx b/docs/api-reference/memory/get-memory-export.mdxindex 68ef25b0d..bfb1ac755 100644--- a/docs/api-reference/memory/get-memory-export.mdx+++ b/docs/api-reference/memory/get-memory-export.mdx@@ -1,6 +1,6 @@---title: 'Get Memory Export'-openapi: get /v1/exports/+openapi: post /v1/exports/get---Retrieve the latest structured memory export after submitting an export job. You can filter the export by `user_id`, `run_id`, `session_id`, or `app_id` to get the most recent export matching your filters.\ No newline at end of filediff --git a/docs/docs.json b/docs/docs.jsonindex 2ca34fef9..3ce05c796 100644--- a/docs/docs.json+++ b/docs/docs.json@@ -202,7 +202,6 @@"examples/mem0-agentic-tool","examples/openai-inbuilt-tools","examples/mem0-openai-voice-demo",- "examples/mem0-livekit-voice-agent","examples/email_processing"]}diff --git a/docs/features/memory-export.mdx b/docs/features/memory-export.mdxindex 046d281ab..e30b963eb 100644--- a/docs/features/memory-export.mdx+++ b/docs/features/memory-export.mdx@@ -91,10 +91,17 @@ export_instructions = """5. Clearly distinguish between factual statements and inferences"""+# For create operation, using only user_id filter as requested+filters = {+ "AND": [+ {"user_id": "alex"}+ ]+}+response = client.create_memory_export(schema=json_schema,- user_id="alice",- export_instructions=export_instructions+ filters=filters,+ export_instructions=export_instructions # Optional)print(response)@@ -127,7 +134,15 @@ Once the export job is complete, you can retrieve the structured data:<CodeGroup>```python Python-response = client.get_memory_export(user_id="alice")+# Corrected date range (assuming you meant July 10 to July 20)+filters = {+ "AND": [+ {"created_at": {"gte": "2024-07-10", "lte": "2024-07-20"}},+ {"user_id": "alex"}+ ]+}++response = client.get_memory_export(filters=filters)print(response)```@@ -157,6 +172,7 @@ You can apply various filters to customize which memories are included in the ex- `agent_id`: Filter memories by specific agent- `run_id`: Filter memories by specific run- `session_id`: Filter memories by specific session+- `created_at`: Filter memories by date<Note>The export process may take some time to complete, especially when dealing with a large number of memories or complex schemas.diff --git a/docs/openapi.json b/docs/openapi.jsonindex 7a91807dd..4a223b9d4 100644--- a/docs/openapi.json+++ b/docs/openapi.json@@ -379,135 +379,6 @@}},"/v1/exports/": {- "get": {- "tags": [- "exports"- ],- "summary": "Export data based on filters",- "description": "Get the latest memory export.",- "operationId": "exports_list",- "parameters": [- {- "name": "user_id",- "in": "query",- "schema": {- "type": "string"- },- "description": "Filter exports by user ID"- },- {- "name": "run_id",- "in": "query",- "schema": {- "type": "string"- },- "description": "Filter exports by run ID"- },- {- "name": "session_id",- "in": "query",- "schema": {- "type": "string"- },- "description": "Filter exports by session ID"- },- {- "name": "app_id",- "in": "query",- "schema": {- "type": "string"- },- "description": "Filter exports by app 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",- "content": {- "application/json": {- "schema": {- "type": "object",- "description": "Export data response"- }- }- }- },- "400": {- "description": "Bad Request",- "content": {- "application/json": {- "schema": {- "type": "object",- "properties": {- "message": {- "type": "string",- "example": "One of the filters: app_id, user_id, agent_id, run_id is required!"- }- }- }- }- }- },- "404": {- "description": "Not Found",- "content": {- "application/json": {- "schema": {- "type": "object",- "properties": {- "error": {- "type": "string",- "example": "No memory export request found"- }- }- }- }- }- }- },- "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\nresponse = client.get_memory_export(user_id=\"your_user_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\n// Get memory export\nclient.getMemoryExport({ user_id: \"your_user_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/?user_id=your_user_id' \\\n --header 'Authorization: Token <api-key>'"- },- {- "lang": "Go",- "source": "package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io/ioutil\"\n)\n\nfunc main() {\n\turl := \"https://api.mem0.ai/v1/exports/?user_id=your_user_id\"\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}"- },- {- "lang": "PHP",- "source": "<?php\n\n$curl = curl_init();\n\ncurl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.mem0.ai/v1/exports/?user_id=your_user_id\",\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}"- },- {- "lang": "Java",- "source": "HttpResponse<String> response = Unirest.get(\"https://api.mem0.ai/v1/exports/?user_id=your_user_id\")\n .header(\"Authorization\", \"Token <api-key>\")\n .asString();"- }- ]- },"post": {"tags": ["exports"@@ -526,21 +397,15 @@"type": "object","description": "Schema definition for the export"},- "user_id": {- "type": "string",- "description": "Filter exports by user ID"- },- "run_id": {- "type": "string",- "description": "Filter exports by run ID"- },- "session_id": {- "type": "string",- "description": "Filter exports by session ID"- },- "app_id": {- "type": "string",- "description": "Filter exports by app ID"+ "filters": {+ "type": "object",+ "properties": {+ "user_id": {"type": "string"},+ "agent_id": {"type": "string"},+ "app_id": {"type": "string"},+ "run_id": {"type": "string"}+ },+ "description": "Filters to apply while exporting memories. Available fields are: user_id, agent_id, app_id, run_id."},"org_id": {"type": "string",@@ -599,31 +464,146 @@"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=\"your_project_id\")\n\njson_schema = {pydantic_json_schema}\n\nresponse = client.create_memory_export(\n schema=json_schema,\n user_id=\"your_user_id\"\n)\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=\"your_project_id\")\n\njson_schema = {pydantic_json_schema}\nfilters = {\n \"AND\": [\n {\"user_id\": \"alex\"}\n ]\n}\n\nresponse = client.create_memory_export(\n schema=json_schema,\n filters=filters\n)\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 jsonSchema = {pydantic_json_schema};\n\nclient.createMemoryExport({\n schema: jsonSchema,\n user_id: \"your_user_id\"\n})\n .then(result => console.log(result))\n .catch(error => console.error(error));"+ "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 jsonSchema = {pydantic_json_schema};\nconst filters = {\n AND: [\n {user_id: 'alex'}\n ]\n};\n\nclient.createMemoryExport({\n schema: jsonSchema,\n filters: filters\n})\n .then(result => console.log(result))\n .catch(error => console.error(error));"},{"lang": "cURL",- "source": "curl --request POST \\\n --url 'https://api.mem0.ai/v1/exports/' \\\n --header 'Authorization: Token <api-key>' \\\n --header 'Content-Type: application/json' \\\n --data '{\n \"schema\": {pydantic_json_schema},\n \"user_id\": \"your_user_id\"\n }'"+ "source": "curl --request POST \\\n --url 'https://api.mem0.ai/v1/exports/' \\\n --header 'Authorization: Token <api-key>' \\\n --header 'Content-Type: application/json' \\\n --data '{\n \"schema\": {pydantic_json_schema},\n \"filters\": {\n \"AND\": [\n {\"user_id\": \"alex\"}\n ]\n }\n }'"},{"lang": "Go",- "source": "package main\n\nimport (\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"io/ioutil\"\n)\n\nfunc main() {\n\turl := \"https://api.mem0.ai/v1/exports/\"\n\n\tdata := map[string]interface{}{\n\t\t\"schema\": map[string]interface{}{}, // Your schema here\n\t\t\"user_id\": \"user123\",\n\t}\n\n\tjsonData, _ := json.Marshal(data)\n\n\treq, _ := http.NewRequest(\"POST\", url, bytes.NewBuffer(jsonData))\n\n\treq.Header.Add(\"Authorization\", \"Token <api-key>\")\n\treq.Header.Add(\"Content-Type\", \"application/json\")\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\"bytes\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"io/ioutil\"\n)\n\nfunc main() {\n\turl := \"https://api.mem0.ai/v1/exports/\"\n\n\tfilters := map[string]interface{}{\n\t\t\"AND\": []map[string]interface{}{\n\t\t\t{\"user_id\": \"alex\"},\n\t\t},\n\t}\n\n\tdata := map[string]interface{}{\n\t\t\"schema\": map[string]interface{}{}, // Your schema here\n\t\t\"filters\": filters,\n\t}\n\n\tjsonData, _ := json.Marshal(data)\n\n\treq, _ := http.NewRequest(\"POST\", url, bytes.NewBuffer(jsonData))\n\n\treq.Header.Add(\"Authorization\", \"Token <api-key>\")\n\treq.Header.Add(\"Content-Type\", \"application/json\")\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$data = array(\n \"schema\" => array(), // Your schema here\n \"user_id\" => \"your_user_id\"\n);\n\ncurl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.mem0.ai/v1/exports/\",\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 => json_encode($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}"+ "source": "<?php\n\n$curl = curl_init();\n\n$filters = [\n 'AND' => [\n ['user_id' => 'alex']\n ]\n];\n\n$data = array(\n \"schema\" => array(), // Your schema here\n \"filters\" => $filters\n);\n\ncurl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.mem0.ai/v1/exports/\",\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 => json_encode($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": "import com.mashape.unirest.http.HttpResponse;\nimport com.mashape.unirest.http.JsonNode;\nimport com.mashape.unirest.http.Unirest;\nimport org.json.JSONObject;\n\nJSONObject data = new JSONObject()\n .put(\"schema\", new JSONObject()) // Your schema here\n .put(\"user_id\", \"your_user_id\");\n\nHttpResponse<JsonNode> response = Unirest.post(\"https://api.mem0.ai/v1/exports/\")\n .header(\"Authorization\", \"Token <api-key>\")\n .header(\"Content-Type\", \"application/json\")\n .body(data.toString())\n .asJson();"+ "source": "import com.mashape.unirest.http.HttpResponse;\nimport com.mashape.unirest.http.JsonNode;\nimport com.mashape.unirest.http.Unirest;\nimport org.json.JSONObject;\nimport org.json.JSONArray;\n\nJSONObject filters = new JSONObject()\n .put(\"AND\", new JSONArray()\n .put(new JSONObject().put(\"user_id\", \"alex\")));\n\nJSONObject data = new JSONObject()\n .put(\"schema\", new JSONObject()) // Your schema here\n .put(\"filters\", filters);\n\nHttpResponse<JsonNode> response = Unirest.post(\"https://api.mem0.ai/v1/exports/\")\n .header(\"Authorization\", \"Token <api-key>\")\n .header(\"Content-Type\", \"application/json\")\n .body(data.toString())\n .asJson();"}]}},+ "/v1/exports/get": {+ "post": {+ "tags": [+ "exports"+ ],+ "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."+ }+ },+ {+ "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",+ "content": {+ "application/json": {+ "schema": {+ "type": "object",+ "description": "Export data response"+ }+ }+ }+ },+ "400": {+ "description": "Bad Request",+ "content": {+ "application/json": {+ "schema": {+ "type": "object",+ "properties": {+ "message": {+ "type": "string",+ "example": "One of the filters: app_id, user_id, agent_id, run_id is required!"+ }+ }+ }+ }+ }+ },+ "404": {+ "description": "Not Found",+ "content": {+ "application/json": {+ "schema": {+ "type": "object",+ "properties": {+ "error": {+ "type": "string",+ "example": "No memory export request found"+ }+ }+ }+ }+ }+ }+ },+ "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)"+ },+ {+ "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));"+ },+ {+ "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>'"+ },+ {+ "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}"+ },+ {+ "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}"+ },+ {+ "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();"+ }+ ]+ }+ },"/v1/memories/": {"get": {"tags": [diff --git a/mem0/client/main.py b/mem0/client/main.pyindex bff698ab1..ca06e552f 100644--- a/mem0/client/main.py+++ b/mem0/client/main.py@@ -448,7 +448,7 @@ class MemoryClient:Returns:Dict containing the exported data"""- response = self.client.get("/v1/exports/", params=self._prepare_params(kwargs))+ response = self.client.post("/v1/exports/get/", json=self._prepare_params(kwargs))response.raise_for_status()capture_client_event("client.get_memory_export", self, {"keys": list(kwargs.keys())})return response.json()@@ -930,7 +930,7 @@ class AsyncMemoryClient:Returns:Dict containing the exported data"""- response = await self.async_client.get("/v1/exports/", params=self._prepare_params(kwargs))+ response = await self.async_client.post("/v1/exports/get/", json=self._prepare_params(kwargs))response.raise_for_status()capture_client_event("async_client.get_memory_export", self.sync_client, {"keys": list(kwargs.keys())})return response.json()