From 9a12ea7b3cc382da81b11b6bbefec98533f33bf2 Mon Sep 17 00:00:00 2001 From: Saket Aryan Date: Fri, 6 Jun 2025 21:49:03 +0530 Subject: [PATCH] Version Bump/Formatting (#2923) --- docs/changelog.mdx | 8 +++ mem0-ts/package.json | 4 +- mem0-ts/pnpm-lock.yaml | 32 ++++++++++ mem0-ts/src/oss/src/types/index.ts | 2 + .../src/oss/src/vector_stores/vectorize.ts | 58 +++++++++---------- 5 files changed, 74 insertions(+), 30 deletions(-) diff --git a/docs/changelog.mdx b/docs/changelog.mdx index ebe9d49a..7686c381 100644 --- a/docs/changelog.mdx +++ b/docs/changelog.mdx @@ -288,6 +288,14 @@ mode: "wide" + +**New Features:** +- **OSS:** Added Cloudflare support + +**Improvements:** +- **OSS:** Fixed baseURL param in LLM Config. + + **Improvements:** - **Client:** Added Async Mode Param for `add` method. diff --git a/mem0-ts/package.json b/mem0-ts/package.json index d0e4e42d..f6d045bb 100644 --- a/mem0-ts/package.json +++ b/mem0-ts/package.json @@ -1,6 +1,6 @@ { "name": "mem0ai", - "version": "2.1.29", + "version": "2.1.30", "description": "The Memory Layer For Your AI Apps", "main": "./dist/index.js", "module": "./dist/index.mjs", @@ -107,6 +107,8 @@ "@types/sqlite3": "3.1.11", "groq-sdk": "0.3.0", "@langchain/core": "^0.3.44", + "cloudflare": "^4.2.0", + "@cloudflare/workers-types": "^4.20250504.0", "neo4j-driver": "^5.28.1", "ollama": "^0.5.14", "pg": "8.11.3", diff --git a/mem0-ts/pnpm-lock.yaml b/mem0-ts/pnpm-lock.yaml index fc222716..a07a9931 100644 --- a/mem0-ts/pnpm-lock.yaml +++ b/mem0-ts/pnpm-lock.yaml @@ -10,6 +10,9 @@ importers: "@anthropic-ai/sdk": specifier: ^0.40.1 version: 0.40.1(encoding@0.1.13) + "@cloudflare/workers-types": + specifier: ^4.20250504.0 + version: 4.20250606.0 "@google/genai": specifier: ^1.2.0 version: 1.2.0(@modelcontextprotocol/sdk@1.12.1)(encoding@0.1.13) @@ -37,6 +40,9 @@ importers: axios: specifier: 1.7.7 version: 1.7.7 + cloudflare: + specifier: ^4.2.0 + version: 4.3.0(encoding@0.1.13) groq-sdk: specifier: 0.3.0 version: 0.3.0(encoding@0.1.13) @@ -385,6 +391,12 @@ packages: integrity: sha512-gAmrUZSGtKc3AiBL71iNWxDsyUC5uMaKKGdvzYsBoTW/xi42JQHl7eKV2OYzCUqvc+D2RCcf7EXY2iCyFIk6og==, } + "@cloudflare/workers-types@4.20250606.0": + resolution: + { + integrity: sha512-9T/Y/Mxe57UVzqgfjJKheiMplnStj/3CmCHlgoZNLU8JW2waRbXvpY3EEeliiYAJfeHZTjeAaKO2pCabxAoyCw==, + } + "@cspotcode/source-map-support@0.8.1": resolution: { @@ -1811,6 +1823,12 @@ packages: } engines: { node: ">=12" } + cloudflare@4.3.0: + resolution: + { + integrity: sha512-C+4Jhsl/OY4V5sykRB1yJxComDld5BkKW1xd3s0MDJ1yYamT2sFAoC2FEUQg5zipyxMaaGU4N7hZ6il+gfJxZg==, + } + cluster-key-slot@1.1.2: resolution: { @@ -5465,6 +5483,8 @@ snapshots: "@cfworker/json-schema@4.1.1": {} + "@cloudflare/workers-types@4.20250606.0": {} + "@cspotcode/source-map-support@0.8.1": dependencies: "@jridgewell/trace-mapping": 0.3.9 @@ -6397,6 +6417,18 @@ snapshots: strip-ansi: 6.0.1 wrap-ansi: 7.0.0 + cloudflare@4.3.0(encoding@0.1.13): + dependencies: + "@types/node": 18.19.76 + "@types/node-fetch": 2.6.12 + abort-controller: 3.0.0 + agentkeepalive: 4.6.0 + form-data-encoder: 1.7.2 + formdata-node: 4.4.1 + node-fetch: 2.7.0(encoding@0.1.13) + transitivePeerDependencies: + - encoding + cluster-key-slot@1.1.2: {} co@4.6.0: {} diff --git a/mem0-ts/src/oss/src/types/index.ts b/mem0-ts/src/oss/src/types/index.ts index b2bdc0a8..dbc0fa12 100644 --- a/mem0-ts/src/oss/src/types/index.ts +++ b/mem0-ts/src/oss/src/types/index.ts @@ -117,6 +117,7 @@ export const MemoryConfigSchema = z.object({ modelProperties: z.record(z.string(), z.any()).optional(), apiKey: z.string().optional(), model: z.union([z.string(), z.any()]).optional(), + baseURL: z.string().optional(), }), }), vectorStore: z.object({ @@ -135,6 +136,7 @@ export const MemoryConfigSchema = z.object({ apiKey: z.string().optional(), model: z.union([z.string(), z.any()]).optional(), modelProperties: z.record(z.string(), z.any()).optional(), + baseURL: z.string().optional(), }), }), historyDbPath: z.string().optional(), diff --git a/mem0-ts/src/oss/src/vector_stores/vectorize.ts b/mem0-ts/src/oss/src/vector_stores/vectorize.ts index d2b63563..2a1caeaa 100644 --- a/mem0-ts/src/oss/src/vector_stores/vectorize.ts +++ b/mem0-ts/src/oss/src/vector_stores/vectorize.ts @@ -32,7 +32,7 @@ export class VectorizeDB implements VectorStore { async insert( vectors: number[][], ids: string[], - payloads: Record[] + payloads: Record[], ): Promise { try { const vectorObjects: CloudflareVector[] = vectors.map( @@ -40,7 +40,7 @@ export class VectorizeDB implements VectorStore { id: ids[index], values: vector, metadata: payloads[index] || {}, - }) + }), ); const ndjsonPayload = vectorObjects @@ -56,19 +56,19 @@ export class VectorizeDB implements VectorStore { Authorization: `Bearer ${this.client?.apiToken}`, }, body: ndjsonPayload, - } + }, ); if (!response.ok) { const errorText = await response.text(); throw new Error( - `Failed to insert vectors: ${response.status} ${errorText}` + `Failed to insert vectors: ${response.status} ${errorText}`, ); } } catch (error) { console.error("Error inserting vectors:", error); throw new Error( - `Failed to insert vectors: ${error instanceof Error ? error.message : String(error)}` + `Failed to insert vectors: ${error instanceof Error ? error.message : String(error)}`, ); } } @@ -76,7 +76,7 @@ export class VectorizeDB implements VectorStore { async search( query: number[], limit: number = 5, - filters?: SearchFilters + filters?: SearchFilters, ): Promise { try { const result = await this.client?.vectorize.indexes.query( @@ -87,7 +87,7 @@ export class VectorizeDB implements VectorStore { filter: filters, returnMetadata: "all", topK: limit, - } + }, ); return ( @@ -100,7 +100,7 @@ export class VectorizeDB implements VectorStore { } catch (error) { console.error("Error searching vectors:", error); throw new Error( - `Failed to search vectors: ${error instanceof Error ? error.message : String(error)}` + `Failed to search vectors: ${error instanceof Error ? error.message : String(error)}`, ); } } @@ -112,7 +112,7 @@ export class VectorizeDB implements VectorStore { { account_id: this.accountId, ids: [vectorId], - } + }, )) as any; if (!result?.length) return null; @@ -124,7 +124,7 @@ export class VectorizeDB implements VectorStore { } catch (error) { console.error("Error getting vector:", error); throw new Error( - `Failed to get vector: ${error instanceof Error ? error.message : String(error)}` + `Failed to get vector: ${error instanceof Error ? error.message : String(error)}`, ); } } @@ -132,7 +132,7 @@ export class VectorizeDB implements VectorStore { async update( vectorId: string, vector: number[], - payload: Record + payload: Record, ): Promise { try { const data: VectorizeVector = { @@ -150,19 +150,19 @@ export class VectorizeDB implements VectorStore { Authorization: `Bearer ${this.client?.apiToken}`, }, body: JSON.stringify(data) + "\n", // ndjson format - } + }, ); if (!response.ok) { const errorText = await response.text(); throw new Error( - `Failed to update vector: ${response.status} ${errorText}` + `Failed to update vector: ${response.status} ${errorText}`, ); } } catch (error) { console.error("Error updating vector:", error); throw new Error( - `Failed to update vector: ${error instanceof Error ? error.message : String(error)}` + `Failed to update vector: ${error instanceof Error ? error.message : String(error)}`, ); } } @@ -176,7 +176,7 @@ export class VectorizeDB implements VectorStore { } catch (error) { console.error("Error deleting vector:", error); throw new Error( - `Failed to delete vector: ${error instanceof Error ? error.message : String(error)}` + `Failed to delete vector: ${error instanceof Error ? error.message : String(error)}`, ); } } @@ -189,14 +189,14 @@ export class VectorizeDB implements VectorStore { } catch (error) { console.error("Error deleting collection:", error); throw new Error( - `Failed to delete collection: ${error instanceof Error ? error.message : String(error)}` + `Failed to delete collection: ${error instanceof Error ? error.message : String(error)}`, ); } } async list( filters?: SearchFilters, - limit: number = 20 + limit: number = 20, ): Promise<[VectorStoreResult[], number]> { try { const result = await this.client?.vectorize.indexes.query( @@ -207,7 +207,7 @@ export class VectorizeDB implements VectorStore { filter: filters, topK: limit, returnMetadata: "all", - } + }, ); const matches = @@ -221,7 +221,7 @@ export class VectorizeDB implements VectorStore { } catch (error) { console.error("Error listing vectors:", error); throw new Error( - `Failed to list vectors: ${error instanceof Error ? error.message : String(error)}` + `Failed to list vectors: ${error instanceof Error ? error.message : String(error)}`, ); } } @@ -233,7 +233,7 @@ export class VectorizeDB implements VectorStore { const r = (Math.random() * 16) | 0; const v = c === "x" ? r : (r & 0x3) | 0x8; return v.toString(16); - } + }, ); } @@ -267,7 +267,7 @@ export class VectorizeDB implements VectorStore { vector: [0], topK: 1, returnMetadata: "all", - } + }, ); if (result.matches.length > 0) { return result.matches[0].metadata.userId as string; @@ -292,13 +292,13 @@ export class VectorizeDB implements VectorStore { Authorization: `Bearer ${this.client?.apiToken}`, }, body: JSON.stringify(data) + "\n", // ndjson format - } + }, ); return randomUserId; } catch (error) { console.error("Error getting user ID:", error); throw new Error( - `Failed to get user ID: ${error instanceof Error ? error.message : String(error)}` + `Failed to get user ID: ${error instanceof Error ? error.message : String(error)}`, ); } } @@ -313,7 +313,7 @@ export class VectorizeDB implements VectorStore { vector: [0], topK: 1, returnMetadata: "all", - } + }, ); const pointId = result.matches.length > 0 ? result.matches[0].id : this.generateUUID(); @@ -332,12 +332,12 @@ export class VectorizeDB implements VectorStore { Authorization: `Bearer ${this.client?.apiToken}`, }, body: JSON.stringify(data) + "\n", // ndjson format - } + }, ); } catch (error) { console.error("Error setting user ID:", error); throw new Error( - `Failed to set user ID: ${error instanceof Error ? error.message : String(error)}` + `Failed to set user ID: ${error instanceof Error ? error.message : String(error)}`, ); } } @@ -375,7 +375,7 @@ export class VectorizeDB implements VectorStore { account_id: this.accountId, indexType: "string", propertyName, - } + }, ); } } catch (err: any) { @@ -389,7 +389,7 @@ export class VectorizeDB implements VectorStore { this.indexName, { account_id: this.accountId, - } + }, ); const existingMetadataIndexes = new Set(); for (const metadataIndex of metadataIndexes?.metadataIndexes || []) { @@ -404,7 +404,7 @@ export class VectorizeDB implements VectorStore { account_id: this.accountId, indexType: "string", propertyName, - } + }, ); } }