diff --git a/docs/changelog.mdx b/docs/changelog.mdx index 8bd1093c..5c2d85b1 100644 --- a/docs/changelog.mdx +++ b/docs/changelog.mdx @@ -409,6 +409,11 @@ mode: "wide" + +**New Features:** +- **Client:** Added `createMemoryExport` and `getMemoryExport` methods. + + **New Features:** - **OSS:** Added Gemini support diff --git a/docs/openapi.json b/docs/openapi.json index f7eafc70..cd038cdf 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 = \"\"\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 = \"\";\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 '" + "source": "curl --request POST \\\n --url 'https://api.mem0.ai/v1/exports/get/' \\\n --header 'Authorization: Token ' \\\n --data '{\n \"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 \")\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 := \"\"\n\n\treq, _ := http.NewRequest(\"POST\", \"https://api.mem0.ai/v1/exports/get/\", nil)\n\n\treq.Header.Add(\"Authorization\", \"Token \")\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": " \"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 \"\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": " '']);\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 \",\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 response = Unirest.get(\"https://api.mem0.ai/v1/exports/?filters=\" + filters)\n .header(\"Authorization\", \"Token \")\n .asString();" + "source": "String data = \"{\\\"memory_export_id\\\":\\\"\\\"}\";\n\nHttpResponse response = Unirest.post(\"https://api.mem0.ai/v1/exports/get/\")\n .header(\"Authorization\", \"Token \")\n .header(\"Content-Type\", \"application/json\")\n .body(data)\n .asString();" } ] } diff --git a/mem0-ts/package.json b/mem0-ts/package.json index 93a096d0..2a9617ed 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 43d38f47..60d3238b 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 3e6a0192..e9cbc8c2 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; + filters: Record; + export_instructions?: string; +} + +export interface GetMemoryExportPayload extends Common { + filters?: Record; + memory_export_id?: string; +} diff --git a/mem0-ts/src/client/telemetry.ts b/mem0-ts/src/client/telemetry.ts index a1bc698d..7463c9aa 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;