feat: Memory Exports (#3117)
This commit is contained in:
@@ -409,6 +409,11 @@ mode: "wide"
|
|||||||
|
|
||||||
<Tab title="TypeScript">
|
<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">
|
<Update label="2025-07-03" description="v2.1.34">
|
||||||
**New Features:**
|
**New Features:**
|
||||||
- **OSS:** Added Gemini support
|
- **OSS:** Added Gemini support
|
||||||
|
|||||||
@@ -497,40 +497,38 @@
|
|||||||
"summary": "Export data based on filters",
|
"summary": "Export data based on filters",
|
||||||
"description": "Get the latest memory export.",
|
"description": "Get the latest memory export.",
|
||||||
"operationId": "exports_list",
|
"operationId": "exports_list",
|
||||||
"parameters": [
|
"requestBody": {
|
||||||
{
|
"content": {
|
||||||
"name": "filters",
|
"application/json": {
|
||||||
"in": "query",
|
"schema": {
|
||||||
"schema": {
|
"type": "object",
|
||||||
"type": "object",
|
"properties": {
|
||||||
"properties": {
|
"memory_export_id": {"type": "string", "description": "The unique identifier of the memory export"},
|
||||||
"user_id": {"type": "string"},
|
"filters": {
|
||||||
"agent_id": {"type": "string"},
|
"type": "object",
|
||||||
"app_id": {"type": "string"},
|
"properties": {
|
||||||
"run_id": {"type": "string"},
|
"user_id": {"type": "string"},
|
||||||
"created_at": {"type": "string"},
|
"agent_id": {"type": "string"},
|
||||||
"updated_at": {"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, created_at, updated_at."
|
"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": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Successful export",
|
"description": "Successful export",
|
||||||
@@ -538,7 +536,7 @@
|
|||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Export data response"
|
"description": "Export data response in a object format"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -579,27 +577,27 @@
|
|||||||
"x-code-samples": [
|
"x-code-samples": [
|
||||||
{
|
{
|
||||||
"lang": "Python",
|
"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",
|
"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",
|
"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",
|
"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",
|
"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",
|
"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();"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mem0ai",
|
"name": "mem0ai",
|
||||||
"version": "2.1.34",
|
"version": "2.1.35",
|
||||||
"description": "The Memory Layer For Your AI Apps",
|
"description": "The Memory Layer For Your AI Apps",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.mjs",
|
"module": "./dist/index.mjs",
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import {
|
|||||||
WebhookPayload,
|
WebhookPayload,
|
||||||
Message,
|
Message,
|
||||||
FeedbackPayload,
|
FeedbackPayload,
|
||||||
|
CreateMemoryExportPayload,
|
||||||
|
GetMemoryExportPayload,
|
||||||
} from "./mem0.types";
|
} from "./mem0.types";
|
||||||
import { captureClientEvent, generateHash } from "./telemetry";
|
import { captureClientEvent, generateHash } from "./telemetry";
|
||||||
|
|
||||||
@@ -705,6 +707,57 @@ export default class MemoryClient {
|
|||||||
);
|
);
|
||||||
return response;
|
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 };
|
export { MemoryClient };
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
interface Common {
|
||||||
|
project_id?: string | null;
|
||||||
|
org_id?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
export interface MemoryOptions {
|
export interface MemoryOptions {
|
||||||
api_version?: API_VERSION | string;
|
api_version?: API_VERSION | string;
|
||||||
version?: API_VERSION | string;
|
version?: API_VERSION | string;
|
||||||
@@ -187,3 +192,14 @@ export interface FeedbackPayload {
|
|||||||
feedback?: Feedback | null;
|
feedback?: Feedback | null;
|
||||||
feedback_reason?: string | 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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import type { TelemetryClient, TelemetryOptions } from "./telemetry.types";
|
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
|
// Safely check for process.env in different environments
|
||||||
let MEM0_TELEMETRY = true;
|
let MEM0_TELEMETRY = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user