mem0ai 2.4.4 → 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 +3 -3
- package/dist/oss/index.d.ts +3 -3
- package/dist/oss/index.js +45 -13
- package/dist/oss/index.js.map +1 -1
- package/dist/oss/index.mjs +45 -13
- package/dist/oss/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/oss/index.mjs
CHANGED
|
@@ -68,19 +68,25 @@ var OpenAIEmbedder = class {
|
|
|
68
68
|
baseURL: config.baseURL || config.url
|
|
69
69
|
});
|
|
70
70
|
this.model = config.model || "text-embedding-3-small";
|
|
71
|
-
this.embeddingDims = config.embeddingDims
|
|
71
|
+
this.embeddingDims = config.embeddingDims;
|
|
72
72
|
}
|
|
73
73
|
async embed(text) {
|
|
74
74
|
const response = await this.openai.embeddings.create({
|
|
75
75
|
model: this.model,
|
|
76
|
-
input: text
|
|
76
|
+
input: text,
|
|
77
|
+
...this.embeddingDims !== void 0 && {
|
|
78
|
+
dimensions: this.embeddingDims
|
|
79
|
+
}
|
|
77
80
|
});
|
|
78
81
|
return response.data[0].embedding;
|
|
79
82
|
}
|
|
80
83
|
async embedBatch(texts) {
|
|
81
84
|
const response = await this.openai.embeddings.create({
|
|
82
85
|
model: this.model,
|
|
83
|
-
input: texts
|
|
86
|
+
input: texts,
|
|
87
|
+
...this.embeddingDims !== void 0 && {
|
|
88
|
+
dimensions: this.embeddingDims
|
|
89
|
+
}
|
|
84
90
|
});
|
|
85
91
|
return response.data.map((item) => item.embedding);
|
|
86
92
|
}
|
|
@@ -2010,7 +2016,7 @@ See the SQL migration instructions in the code comments.`
|
|
|
2010
2016
|
}
|
|
2011
2017
|
async get(vectorId) {
|
|
2012
2018
|
try {
|
|
2013
|
-
const { data, error } = await this.client.from(this.tableName).select("*").eq("id", vectorId).
|
|
2019
|
+
const { data, error } = await this.client.from(this.tableName).select("*").eq("id", vectorId).maybeSingle();
|
|
2014
2020
|
if (error) throw error;
|
|
2015
2021
|
if (!data) return null;
|
|
2016
2022
|
return {
|
|
@@ -2270,13 +2276,15 @@ var GoogleEmbedder = class {
|
|
|
2270
2276
|
apiKey: config.apiKey || process.env.GOOGLE_API_KEY
|
|
2271
2277
|
});
|
|
2272
2278
|
this.model = config.model || "gemini-embedding-001";
|
|
2273
|
-
this.embeddingDims = config.embeddingDims
|
|
2279
|
+
this.embeddingDims = config.embeddingDims;
|
|
2274
2280
|
}
|
|
2275
2281
|
async embed(text) {
|
|
2276
2282
|
const response = await this.google.models.embedContent({
|
|
2277
2283
|
model: this.model,
|
|
2278
2284
|
contents: text,
|
|
2279
|
-
|
|
2285
|
+
...this.embeddingDims !== void 0 && {
|
|
2286
|
+
config: { outputDimensionality: this.embeddingDims }
|
|
2287
|
+
}
|
|
2280
2288
|
});
|
|
2281
2289
|
return response.embeddings[0].values;
|
|
2282
2290
|
}
|
|
@@ -2284,7 +2292,9 @@ var GoogleEmbedder = class {
|
|
|
2284
2292
|
const response = await this.google.models.embedContent({
|
|
2285
2293
|
model: this.model,
|
|
2286
2294
|
contents: texts,
|
|
2287
|
-
|
|
2295
|
+
...this.embeddingDims !== void 0 && {
|
|
2296
|
+
config: { outputDimensionality: this.embeddingDims }
|
|
2297
|
+
}
|
|
2288
2298
|
});
|
|
2289
2299
|
return response.embeddings.map((item) => item.values);
|
|
2290
2300
|
}
|
|
@@ -2426,19 +2436,25 @@ var AzureOpenAIEmbedder = class {
|
|
|
2426
2436
|
...rest
|
|
2427
2437
|
});
|
|
2428
2438
|
this.model = config.model || "text-embedding-3-small";
|
|
2429
|
-
this.embeddingDims = config.embeddingDims
|
|
2439
|
+
this.embeddingDims = config.embeddingDims;
|
|
2430
2440
|
}
|
|
2431
2441
|
async embed(text) {
|
|
2432
2442
|
const response = await this.client.embeddings.create({
|
|
2433
2443
|
model: this.model,
|
|
2434
|
-
input: text
|
|
2444
|
+
input: text,
|
|
2445
|
+
...this.embeddingDims !== void 0 && {
|
|
2446
|
+
dimensions: this.embeddingDims
|
|
2447
|
+
}
|
|
2435
2448
|
});
|
|
2436
2449
|
return response.data[0].embedding;
|
|
2437
2450
|
}
|
|
2438
2451
|
async embedBatch(texts) {
|
|
2439
2452
|
const response = await this.client.embeddings.create({
|
|
2440
2453
|
model: this.model,
|
|
2441
|
-
input: texts
|
|
2454
|
+
input: texts,
|
|
2455
|
+
...this.embeddingDims !== void 0 && {
|
|
2456
|
+
dimensions: this.embeddingDims
|
|
2457
|
+
}
|
|
2442
2458
|
});
|
|
2443
2459
|
return response.data.map((item) => item.embedding);
|
|
2444
2460
|
}
|
|
@@ -2704,7 +2720,23 @@ function getUpdateMemoryMessages(retrievedOldMemory, newRetrievedFacts) {
|
|
|
2704
2720
|
Do not return anything except the JSON format.`;
|
|
2705
2721
|
}
|
|
2706
2722
|
function removeCodeBlocks(text) {
|
|
2707
|
-
|
|
2723
|
+
const stripped = text.replace(/```(?:\w+)?\n?([\s\S]*?)(?:```|$)/g, "$1").trim();
|
|
2724
|
+
return stripped.replace(/<think>[\s\S]*?<\/think>/g, "").trim();
|
|
2725
|
+
}
|
|
2726
|
+
function extractJson(text) {
|
|
2727
|
+
const cleaned = removeCodeBlocks(text);
|
|
2728
|
+
const trimmed = cleaned.trim();
|
|
2729
|
+
const firstBrace = trimmed.indexOf("{");
|
|
2730
|
+
const lastBrace = trimmed.lastIndexOf("}");
|
|
2731
|
+
if (firstBrace !== -1 && lastBrace > firstBrace) {
|
|
2732
|
+
return trimmed.substring(firstBrace, lastBrace + 1);
|
|
2733
|
+
}
|
|
2734
|
+
const firstBracket = trimmed.indexOf("[");
|
|
2735
|
+
const lastBracket = trimmed.lastIndexOf("]");
|
|
2736
|
+
if (firstBracket !== -1 && lastBracket > firstBracket) {
|
|
2737
|
+
return trimmed.substring(firstBracket, lastBracket + 1);
|
|
2738
|
+
}
|
|
2739
|
+
return trimmed;
|
|
2708
2740
|
}
|
|
2709
2741
|
|
|
2710
2742
|
// src/oss/src/graphs/tools.ts
|
|
@@ -5066,7 +5098,7 @@ ${parsedMessages}`
|
|
|
5066
5098
|
],
|
|
5067
5099
|
{ type: "json_object" }
|
|
5068
5100
|
);
|
|
5069
|
-
const cleanResponse =
|
|
5101
|
+
const cleanResponse = extractJson(response);
|
|
5070
5102
|
let facts = [];
|
|
5071
5103
|
try {
|
|
5072
5104
|
const parsed = FactRetrievalSchema.parse(JSON.parse(cleanResponse));
|
|
@@ -5106,7 +5138,7 @@ ${parsedMessages}`
|
|
|
5106
5138
|
[{ role: "user", content: updatePrompt }],
|
|
5107
5139
|
{ type: "json_object" }
|
|
5108
5140
|
);
|
|
5109
|
-
const cleanUpdateResponse =
|
|
5141
|
+
const cleanUpdateResponse = extractJson(updateResponse);
|
|
5110
5142
|
let memoryActions = [];
|
|
5111
5143
|
try {
|
|
5112
5144
|
memoryActions = JSON.parse(cleanUpdateResponse).memory || [];
|