mem0ai 3.0.5 → 3.0.7
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/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/oss/index.d.mts +1 -0
- package/dist/oss/index.d.ts +1 -0
- package/dist/oss/index.js +51 -19
- package/dist/oss/index.js.map +1 -1
- package/dist/oss/index.mjs +51 -19
- package/dist/oss/index.mjs.map +1 -1
- package/package.json +18 -5
package/dist/oss/index.mjs
CHANGED
|
@@ -68,6 +68,7 @@ var OpenAIEmbedder = class {
|
|
|
68
68
|
const response = await this.openai.embeddings.create({
|
|
69
69
|
model: this.model,
|
|
70
70
|
input: text,
|
|
71
|
+
encoding_format: "float",
|
|
71
72
|
...this.embeddingDims !== void 0 && {
|
|
72
73
|
dimensions: this.embeddingDims
|
|
73
74
|
}
|
|
@@ -82,6 +83,7 @@ var OpenAIEmbedder = class {
|
|
|
82
83
|
const response = await this.openai.embeddings.create({
|
|
83
84
|
model: this.model,
|
|
84
85
|
input: chunk,
|
|
86
|
+
encoding_format: "float",
|
|
85
87
|
...this.embeddingDims !== void 0 && {
|
|
86
88
|
dimensions: this.embeddingDims
|
|
87
89
|
}
|
|
@@ -198,7 +200,7 @@ var LMStudioEmbedder = class {
|
|
|
198
200
|
input: normalized,
|
|
199
201
|
encoding_format: "float"
|
|
200
202
|
});
|
|
201
|
-
return response.data.map((item) => item.embedding);
|
|
203
|
+
return response.data.sort((a, b) => a.index - b.index).map((item) => item.embedding);
|
|
202
204
|
} catch (err) {
|
|
203
205
|
const message = err instanceof Error ? err.message : String(err);
|
|
204
206
|
throw new Error(`LM Studio embedder failed: ${message}`);
|
|
@@ -1885,7 +1887,7 @@ var RedisDB = class {
|
|
|
1885
1887
|
return {
|
|
1886
1888
|
id: doc.value.memory_id,
|
|
1887
1889
|
payload: toCamelCase(resultPayload),
|
|
1888
|
-
score: (_a2 = Number(doc.value.__vector_score)) != null ? _a2 : 0
|
|
1890
|
+
score: Math.max(0, 1 - ((_a2 = Number(doc.value.__vector_score)) != null ? _a2 : 0))
|
|
1889
1891
|
};
|
|
1890
1892
|
});
|
|
1891
1893
|
} catch (error) {
|
|
@@ -5073,7 +5075,7 @@ var parse_vision_messages = async (messages) => {
|
|
|
5073
5075
|
};
|
|
5074
5076
|
|
|
5075
5077
|
// src/oss/src/utils/telemetry.ts
|
|
5076
|
-
var version = true ? "3.0.
|
|
5078
|
+
var version = true ? "3.0.7" : "dev";
|
|
5077
5079
|
var MEM0_TELEMETRY = true;
|
|
5078
5080
|
var _a;
|
|
5079
5081
|
try {
|
|
@@ -5939,7 +5941,7 @@ function getBm25Params(query, lemmatized) {
|
|
|
5939
5941
|
function normalizeBm25(rawScore, midpoint, steepness) {
|
|
5940
5942
|
return 1 / (1 + Math.exp(-steepness * (rawScore - midpoint)));
|
|
5941
5943
|
}
|
|
5942
|
-
function scoreAndRank(semanticResults, bm25Scores, entityBoosts, threshold, topK) {
|
|
5944
|
+
function scoreAndRank(semanticResults, bm25Scores, entityBoosts, threshold, topK, explain = false) {
|
|
5943
5945
|
var _a2, _b, _c;
|
|
5944
5946
|
const hasBm25 = Object.keys(bm25Scores).length > 0;
|
|
5945
5947
|
const hasEntity = Object.keys(entityBoosts).length > 0;
|
|
@@ -5965,11 +5967,23 @@ function scoreAndRank(semanticResults, bm25Scores, entityBoosts, threshold, topK
|
|
|
5965
5967
|
const entityBoost = (_c = entityBoosts[memIdStr]) != null ? _c : 0;
|
|
5966
5968
|
const rawCombined = semanticScore + bm25Score + entityBoost;
|
|
5967
5969
|
const combined = Math.min(rawCombined / maxPossible, 1);
|
|
5968
|
-
|
|
5970
|
+
const entry = {
|
|
5969
5971
|
id: memIdStr,
|
|
5970
5972
|
score: combined,
|
|
5971
5973
|
payload: result.payload
|
|
5972
|
-
}
|
|
5974
|
+
};
|
|
5975
|
+
if (explain) {
|
|
5976
|
+
entry.scoreDetails = {
|
|
5977
|
+
semanticScore,
|
|
5978
|
+
bm25Score,
|
|
5979
|
+
entityBoost,
|
|
5980
|
+
rawScore: rawCombined,
|
|
5981
|
+
maxPossibleScore: maxPossible,
|
|
5982
|
+
finalScore: combined,
|
|
5983
|
+
threshold
|
|
5984
|
+
};
|
|
5985
|
+
}
|
|
5986
|
+
scored.push(entry);
|
|
5973
5987
|
}
|
|
5974
5988
|
scored.sort((a, b) => b.score - a.score);
|
|
5975
5989
|
return scored.slice(0, topK);
|
|
@@ -6817,7 +6831,7 @@ var Memory = class _Memory {
|
|
|
6817
6831
|
}).filter(([, v]) => v !== void 0)
|
|
6818
6832
|
) : {};
|
|
6819
6833
|
await this._ensureInitialized();
|
|
6820
|
-
const { topK = 20, threshold = 0.1 } = config;
|
|
6834
|
+
const { topK = 20, threshold = 0.1, explain = false } = config;
|
|
6821
6835
|
await this._captureEvent("search", {
|
|
6822
6836
|
query_length: query.length,
|
|
6823
6837
|
topK,
|
|
@@ -6887,15 +6901,32 @@ var Memory = class _Memory {
|
|
|
6887
6901
|
}
|
|
6888
6902
|
if (deduped.length > 0) {
|
|
6889
6903
|
const entityStore = await this.getEntityStore();
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
|
|
6904
|
+
const entitySearchFilters = {};
|
|
6905
|
+
for (const k of ["user_id", "agent_id", "run_id"]) {
|
|
6906
|
+
if (effectiveFilters[k])
|
|
6907
|
+
entitySearchFilters[k] = effectiveFilters[k];
|
|
6908
|
+
}
|
|
6909
|
+
const entityTexts = deduped.map((e) => e.text);
|
|
6910
|
+
const embeddings = await this.embedder.embedBatch(entityTexts);
|
|
6911
|
+
if (embeddings.length !== entityTexts.length) {
|
|
6912
|
+
console.warn(
|
|
6913
|
+
`embedBatch returned ${embeddings.length} vectors for ${entityTexts.length} texts \u2014 skipping entity boost`
|
|
6914
|
+
);
|
|
6915
|
+
} else {
|
|
6916
|
+
const searchResults = await Promise.allSettled(
|
|
6917
|
+
deduped.map(
|
|
6918
|
+
(_, i) => entityStore.search(embeddings[i], 500, entitySearchFilters)
|
|
6919
|
+
)
|
|
6920
|
+
);
|
|
6921
|
+
for (const result of searchResults) {
|
|
6922
|
+
if (result.status === "rejected") {
|
|
6923
|
+
console.warn(
|
|
6924
|
+
"Entity boost search failed for one entity:",
|
|
6925
|
+
result.reason
|
|
6926
|
+
);
|
|
6927
|
+
continue;
|
|
6928
|
+
}
|
|
6929
|
+
for (const match of result.value) {
|
|
6899
6930
|
const similarity = (_c = match.score) != null ? _c : 0;
|
|
6900
6931
|
if (similarity < 0.5) continue;
|
|
6901
6932
|
const payload = match.payload || {};
|
|
@@ -6914,7 +6945,6 @@ var Memory = class _Memory {
|
|
|
6914
6945
|
}
|
|
6915
6946
|
}
|
|
6916
6947
|
}
|
|
6917
|
-
} catch (e) {
|
|
6918
6948
|
}
|
|
6919
6949
|
}
|
|
6920
6950
|
}
|
|
@@ -6935,7 +6965,8 @@ var Memory = class _Memory {
|
|
|
6935
6965
|
bm25Scores,
|
|
6936
6966
|
entityBoosts,
|
|
6937
6967
|
threshold != null ? threshold : 0.1,
|
|
6938
|
-
topK
|
|
6968
|
+
topK,
|
|
6969
|
+
explain
|
|
6939
6970
|
);
|
|
6940
6971
|
const excludedKeys = /* @__PURE__ */ new Set([
|
|
6941
6972
|
"user_id",
|
|
@@ -6963,7 +6994,8 @@ var Memory = class _Memory {
|
|
|
6963
6994
|
metadata: Object.entries(payload).filter(([key]) => !excludedKeys.has(key)).reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
|
|
6964
6995
|
...payload.user_id && { user_id: payload.user_id },
|
|
6965
6996
|
...payload.agent_id && { agent_id: payload.agent_id },
|
|
6966
|
-
...payload.run_id && { run_id: payload.run_id }
|
|
6997
|
+
...payload.run_id && { run_id: payload.run_id },
|
|
6998
|
+
...scored.scoreDetails && { score_details: scored.scoreDetails }
|
|
6967
6999
|
};
|
|
6968
7000
|
});
|
|
6969
7001
|
return {
|