mem0ai 2.4.3 → 2.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/oss/index.d.mts +17 -3
- package/dist/oss/index.d.ts +17 -3
- package/dist/oss/index.js +51 -13
- package/dist/oss/index.js.map +1 -1
- package/dist/oss/index.mjs +51 -13
- package/dist/oss/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/oss/index.d.mts
CHANGED
|
@@ -484,7 +484,7 @@ interface Embedder {
|
|
|
484
484
|
declare class OpenAIEmbedder implements Embedder {
|
|
485
485
|
private openai;
|
|
486
486
|
private model;
|
|
487
|
-
private embeddingDims
|
|
487
|
+
private embeddingDims;
|
|
488
488
|
constructor(config: EmbeddingConfig);
|
|
489
489
|
embed(text: string): Promise<number[]>;
|
|
490
490
|
embedBatch(texts: string[]): Promise<number[][]>;
|
|
@@ -513,7 +513,7 @@ declare class LMStudioEmbedder implements Embedder {
|
|
|
513
513
|
declare class GoogleEmbedder implements Embedder {
|
|
514
514
|
private google;
|
|
515
515
|
private model;
|
|
516
|
-
private embeddingDims
|
|
516
|
+
private embeddingDims;
|
|
517
517
|
constructor(config: EmbeddingConfig);
|
|
518
518
|
embed(text: string): Promise<number[]>;
|
|
519
519
|
embedBatch(texts: string[]): Promise<number[][]>;
|
|
@@ -522,7 +522,7 @@ declare class GoogleEmbedder implements Embedder {
|
|
|
522
522
|
declare class AzureOpenAIEmbedder implements Embedder {
|
|
523
523
|
private client;
|
|
524
524
|
private model;
|
|
525
|
-
private embeddingDims
|
|
525
|
+
private embeddingDims;
|
|
526
526
|
constructor(config: EmbeddingConfig);
|
|
527
527
|
embed(text: string): Promise<number[]>;
|
|
528
528
|
embedBatch(texts: string[]): Promise<number[][]>;
|
|
@@ -679,6 +679,20 @@ declare class MemoryVectorStore implements VectorStore {
|
|
|
679
679
|
}
|
|
680
680
|
|
|
681
681
|
interface QdrantConfig extends VectorStoreConfig {
|
|
682
|
+
/**
|
|
683
|
+
* Pre-configured QdrantClient instance. If using Qdrant Cloud, you must pass
|
|
684
|
+
* `port` explicitly when constructing the client to avoid "Illegal host" errors
|
|
685
|
+
* caused by a known upstream bug (qdrant/qdrant-js#59).
|
|
686
|
+
*
|
|
687
|
+
* @example
|
|
688
|
+
* ```typescript
|
|
689
|
+
* const client = new QdrantClient({
|
|
690
|
+
* url: "https://xxx.cloud.qdrant.io:6333",
|
|
691
|
+
* port: 6333,
|
|
692
|
+
* apiKey: "xxx",
|
|
693
|
+
* });
|
|
694
|
+
* ```
|
|
695
|
+
*/
|
|
682
696
|
client?: QdrantClient;
|
|
683
697
|
host?: string;
|
|
684
698
|
port?: number;
|
package/dist/oss/index.d.ts
CHANGED
|
@@ -484,7 +484,7 @@ interface Embedder {
|
|
|
484
484
|
declare class OpenAIEmbedder implements Embedder {
|
|
485
485
|
private openai;
|
|
486
486
|
private model;
|
|
487
|
-
private embeddingDims
|
|
487
|
+
private embeddingDims;
|
|
488
488
|
constructor(config: EmbeddingConfig);
|
|
489
489
|
embed(text: string): Promise<number[]>;
|
|
490
490
|
embedBatch(texts: string[]): Promise<number[][]>;
|
|
@@ -513,7 +513,7 @@ declare class LMStudioEmbedder implements Embedder {
|
|
|
513
513
|
declare class GoogleEmbedder implements Embedder {
|
|
514
514
|
private google;
|
|
515
515
|
private model;
|
|
516
|
-
private embeddingDims
|
|
516
|
+
private embeddingDims;
|
|
517
517
|
constructor(config: EmbeddingConfig);
|
|
518
518
|
embed(text: string): Promise<number[]>;
|
|
519
519
|
embedBatch(texts: string[]): Promise<number[][]>;
|
|
@@ -522,7 +522,7 @@ declare class GoogleEmbedder implements Embedder {
|
|
|
522
522
|
declare class AzureOpenAIEmbedder implements Embedder {
|
|
523
523
|
private client;
|
|
524
524
|
private model;
|
|
525
|
-
private embeddingDims
|
|
525
|
+
private embeddingDims;
|
|
526
526
|
constructor(config: EmbeddingConfig);
|
|
527
527
|
embed(text: string): Promise<number[]>;
|
|
528
528
|
embedBatch(texts: string[]): Promise<number[][]>;
|
|
@@ -679,6 +679,20 @@ declare class MemoryVectorStore implements VectorStore {
|
|
|
679
679
|
}
|
|
680
680
|
|
|
681
681
|
interface QdrantConfig extends VectorStoreConfig {
|
|
682
|
+
/**
|
|
683
|
+
* Pre-configured QdrantClient instance. If using Qdrant Cloud, you must pass
|
|
684
|
+
* `port` explicitly when constructing the client to avoid "Illegal host" errors
|
|
685
|
+
* caused by a known upstream bug (qdrant/qdrant-js#59).
|
|
686
|
+
*
|
|
687
|
+
* @example
|
|
688
|
+
* ```typescript
|
|
689
|
+
* const client = new QdrantClient({
|
|
690
|
+
* url: "https://xxx.cloud.qdrant.io:6333",
|
|
691
|
+
* port: 6333,
|
|
692
|
+
* apiKey: "xxx",
|
|
693
|
+
* });
|
|
694
|
+
* ```
|
|
695
|
+
*/
|
|
682
696
|
client?: QdrantClient;
|
|
683
697
|
host?: string;
|
|
684
698
|
port?: number;
|
package/dist/oss/index.js
CHANGED
|
@@ -132,19 +132,25 @@ var OpenAIEmbedder = class {
|
|
|
132
132
|
baseURL: config.baseURL || config.url
|
|
133
133
|
});
|
|
134
134
|
this.model = config.model || "text-embedding-3-small";
|
|
135
|
-
this.embeddingDims = config.embeddingDims
|
|
135
|
+
this.embeddingDims = config.embeddingDims;
|
|
136
136
|
}
|
|
137
137
|
async embed(text) {
|
|
138
138
|
const response = await this.openai.embeddings.create({
|
|
139
139
|
model: this.model,
|
|
140
|
-
input: text
|
|
140
|
+
input: text,
|
|
141
|
+
...this.embeddingDims !== void 0 && {
|
|
142
|
+
dimensions: this.embeddingDims
|
|
143
|
+
}
|
|
141
144
|
});
|
|
142
145
|
return response.data[0].embedding;
|
|
143
146
|
}
|
|
144
147
|
async embedBatch(texts) {
|
|
145
148
|
const response = await this.openai.embeddings.create({
|
|
146
149
|
model: this.model,
|
|
147
|
-
input: texts
|
|
150
|
+
input: texts,
|
|
151
|
+
...this.embeddingDims !== void 0 && {
|
|
152
|
+
dimensions: this.embeddingDims
|
|
153
|
+
}
|
|
148
154
|
});
|
|
149
155
|
return response.data.map((item) => item.embedding);
|
|
150
156
|
}
|
|
@@ -734,6 +740,12 @@ var Qdrant = class {
|
|
|
734
740
|
}
|
|
735
741
|
if (config.url) {
|
|
736
742
|
params.url = config.url;
|
|
743
|
+
try {
|
|
744
|
+
const parsedUrl = new URL(config.url);
|
|
745
|
+
params.port = parsedUrl.port ? parseInt(parsedUrl.port, 10) : 6333;
|
|
746
|
+
} catch (_) {
|
|
747
|
+
params.port = 6333;
|
|
748
|
+
}
|
|
737
749
|
}
|
|
738
750
|
if (config.host && config.port) {
|
|
739
751
|
params.host = config.host;
|
|
@@ -2068,7 +2080,7 @@ See the SQL migration instructions in the code comments.`
|
|
|
2068
2080
|
}
|
|
2069
2081
|
async get(vectorId) {
|
|
2070
2082
|
try {
|
|
2071
|
-
const { data, error } = await this.client.from(this.tableName).select("*").eq("id", vectorId).
|
|
2083
|
+
const { data, error } = await this.client.from(this.tableName).select("*").eq("id", vectorId).maybeSingle();
|
|
2072
2084
|
if (error) throw error;
|
|
2073
2085
|
if (!data) return null;
|
|
2074
2086
|
return {
|
|
@@ -2328,13 +2340,15 @@ var GoogleEmbedder = class {
|
|
|
2328
2340
|
apiKey: config.apiKey || process.env.GOOGLE_API_KEY
|
|
2329
2341
|
});
|
|
2330
2342
|
this.model = config.model || "gemini-embedding-001";
|
|
2331
|
-
this.embeddingDims = config.embeddingDims
|
|
2343
|
+
this.embeddingDims = config.embeddingDims;
|
|
2332
2344
|
}
|
|
2333
2345
|
async embed(text) {
|
|
2334
2346
|
const response = await this.google.models.embedContent({
|
|
2335
2347
|
model: this.model,
|
|
2336
2348
|
contents: text,
|
|
2337
|
-
|
|
2349
|
+
...this.embeddingDims !== void 0 && {
|
|
2350
|
+
config: { outputDimensionality: this.embeddingDims }
|
|
2351
|
+
}
|
|
2338
2352
|
});
|
|
2339
2353
|
return response.embeddings[0].values;
|
|
2340
2354
|
}
|
|
@@ -2342,7 +2356,9 @@ var GoogleEmbedder = class {
|
|
|
2342
2356
|
const response = await this.google.models.embedContent({
|
|
2343
2357
|
model: this.model,
|
|
2344
2358
|
contents: texts,
|
|
2345
|
-
|
|
2359
|
+
...this.embeddingDims !== void 0 && {
|
|
2360
|
+
config: { outputDimensionality: this.embeddingDims }
|
|
2361
|
+
}
|
|
2346
2362
|
});
|
|
2347
2363
|
return response.embeddings.map((item) => item.values);
|
|
2348
2364
|
}
|
|
@@ -2484,19 +2500,25 @@ var AzureOpenAIEmbedder = class {
|
|
|
2484
2500
|
...rest
|
|
2485
2501
|
});
|
|
2486
2502
|
this.model = config.model || "text-embedding-3-small";
|
|
2487
|
-
this.embeddingDims = config.embeddingDims
|
|
2503
|
+
this.embeddingDims = config.embeddingDims;
|
|
2488
2504
|
}
|
|
2489
2505
|
async embed(text) {
|
|
2490
2506
|
const response = await this.client.embeddings.create({
|
|
2491
2507
|
model: this.model,
|
|
2492
|
-
input: text
|
|
2508
|
+
input: text,
|
|
2509
|
+
...this.embeddingDims !== void 0 && {
|
|
2510
|
+
dimensions: this.embeddingDims
|
|
2511
|
+
}
|
|
2493
2512
|
});
|
|
2494
2513
|
return response.data[0].embedding;
|
|
2495
2514
|
}
|
|
2496
2515
|
async embedBatch(texts) {
|
|
2497
2516
|
const response = await this.client.embeddings.create({
|
|
2498
2517
|
model: this.model,
|
|
2499
|
-
input: texts
|
|
2518
|
+
input: texts,
|
|
2519
|
+
...this.embeddingDims !== void 0 && {
|
|
2520
|
+
dimensions: this.embeddingDims
|
|
2521
|
+
}
|
|
2500
2522
|
});
|
|
2501
2523
|
return response.data.map((item) => item.embedding);
|
|
2502
2524
|
}
|
|
@@ -2758,7 +2780,23 @@ function getUpdateMemoryMessages(retrievedOldMemory, newRetrievedFacts) {
|
|
|
2758
2780
|
Do not return anything except the JSON format.`;
|
|
2759
2781
|
}
|
|
2760
2782
|
function removeCodeBlocks(text) {
|
|
2761
|
-
|
|
2783
|
+
const stripped = text.replace(/```(?:\w+)?\n?([\s\S]*?)(?:```|$)/g, "$1").trim();
|
|
2784
|
+
return stripped.replace(/<think>[\s\S]*?<\/think>/g, "").trim();
|
|
2785
|
+
}
|
|
2786
|
+
function extractJson(text) {
|
|
2787
|
+
const cleaned = removeCodeBlocks(text);
|
|
2788
|
+
const trimmed = cleaned.trim();
|
|
2789
|
+
const firstBrace = trimmed.indexOf("{");
|
|
2790
|
+
const lastBrace = trimmed.lastIndexOf("}");
|
|
2791
|
+
if (firstBrace !== -1 && lastBrace > firstBrace) {
|
|
2792
|
+
return trimmed.substring(firstBrace, lastBrace + 1);
|
|
2793
|
+
}
|
|
2794
|
+
const firstBracket = trimmed.indexOf("[");
|
|
2795
|
+
const lastBracket = trimmed.lastIndexOf("]");
|
|
2796
|
+
if (firstBracket !== -1 && lastBracket > firstBracket) {
|
|
2797
|
+
return trimmed.substring(firstBracket, lastBracket + 1);
|
|
2798
|
+
}
|
|
2799
|
+
return trimmed;
|
|
2762
2800
|
}
|
|
2763
2801
|
|
|
2764
2802
|
// src/oss/src/graphs/tools.ts
|
|
@@ -5116,7 +5154,7 @@ ${parsedMessages}`
|
|
|
5116
5154
|
],
|
|
5117
5155
|
{ type: "json_object" }
|
|
5118
5156
|
);
|
|
5119
|
-
const cleanResponse =
|
|
5157
|
+
const cleanResponse = extractJson(response);
|
|
5120
5158
|
let facts = [];
|
|
5121
5159
|
try {
|
|
5122
5160
|
const parsed = FactRetrievalSchema.parse(JSON.parse(cleanResponse));
|
|
@@ -5156,7 +5194,7 @@ ${parsedMessages}`
|
|
|
5156
5194
|
[{ role: "user", content: updatePrompt }],
|
|
5157
5195
|
{ type: "json_object" }
|
|
5158
5196
|
);
|
|
5159
|
-
const cleanUpdateResponse =
|
|
5197
|
+
const cleanUpdateResponse = extractJson(updateResponse);
|
|
5160
5198
|
let memoryActions = [];
|
|
5161
5199
|
try {
|
|
5162
5200
|
memoryActions = JSON.parse(cleanUpdateResponse).memory || [];
|