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 CHANGED
@@ -50,7 +50,7 @@ module.exports = __toCommonJS(index_exports);
50
50
  var import_axios = __toESM(require("axios"));
51
51
 
52
52
  // src/client/telemetry.ts
53
- var version = true ? "3.0.5" : "dev";
53
+ var version = true ? "3.0.7" : "dev";
54
54
  var MEM0_TELEMETRY = true;
55
55
  var _a;
56
56
  try {
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import axios from "axios";
3
3
 
4
4
  // src/client/telemetry.ts
5
- var version = true ? "3.0.5" : "dev";
5
+ var version = true ? "3.0.7" : "dev";
6
6
  var MEM0_TELEMETRY = true;
7
7
  var _a;
8
8
  try {
@@ -333,6 +333,7 @@ interface SearchMemoryOptions {
333
333
  topK?: number;
334
334
  filters?: SearchFilters;
335
335
  threshold?: number;
336
+ explain?: boolean;
336
337
  }
337
338
  interface GetAllMemoryOptions {
338
339
  topK?: number;
@@ -333,6 +333,7 @@ interface SearchMemoryOptions {
333
333
  topK?: number;
334
334
  filters?: SearchFilters;
335
335
  threshold?: number;
336
+ explain?: boolean;
336
337
  }
337
338
  interface GetAllMemoryOptions {
338
339
  topK?: number;
package/dist/oss/index.js CHANGED
@@ -126,6 +126,7 @@ var OpenAIEmbedder = class {
126
126
  const response = await this.openai.embeddings.create({
127
127
  model: this.model,
128
128
  input: text,
129
+ encoding_format: "float",
129
130
  ...this.embeddingDims !== void 0 && {
130
131
  dimensions: this.embeddingDims
131
132
  }
@@ -140,6 +141,7 @@ var OpenAIEmbedder = class {
140
141
  const response = await this.openai.embeddings.create({
141
142
  model: this.model,
142
143
  input: chunk,
144
+ encoding_format: "float",
143
145
  ...this.embeddingDims !== void 0 && {
144
146
  dimensions: this.embeddingDims
145
147
  }
@@ -256,7 +258,7 @@ var LMStudioEmbedder = class {
256
258
  input: normalized,
257
259
  encoding_format: "float"
258
260
  });
259
- return response.data.map((item) => item.embedding);
261
+ return response.data.sort((a, b) => a.index - b.index).map((item) => item.embedding);
260
262
  } catch (err) {
261
263
  const message = err instanceof Error ? err.message : String(err);
262
264
  throw new Error(`LM Studio embedder failed: ${message}`);
@@ -1943,7 +1945,7 @@ var RedisDB = class {
1943
1945
  return {
1944
1946
  id: doc.value.memory_id,
1945
1947
  payload: toCamelCase(resultPayload),
1946
- score: (_a2 = Number(doc.value.__vector_score)) != null ? _a2 : 0
1948
+ score: Math.max(0, 1 - ((_a2 = Number(doc.value.__vector_score)) != null ? _a2 : 0))
1947
1949
  };
1948
1950
  });
1949
1951
  } catch (error) {
@@ -5123,7 +5125,7 @@ var parse_vision_messages = async (messages) => {
5123
5125
  };
5124
5126
 
5125
5127
  // src/oss/src/utils/telemetry.ts
5126
- var version = true ? "3.0.5" : "dev";
5128
+ var version = true ? "3.0.7" : "dev";
5127
5129
  var MEM0_TELEMETRY = true;
5128
5130
  var _a;
5129
5131
  try {
@@ -5989,7 +5991,7 @@ function getBm25Params(query, lemmatized) {
5989
5991
  function normalizeBm25(rawScore, midpoint, steepness) {
5990
5992
  return 1 / (1 + Math.exp(-steepness * (rawScore - midpoint)));
5991
5993
  }
5992
- function scoreAndRank(semanticResults, bm25Scores, entityBoosts, threshold, topK) {
5994
+ function scoreAndRank(semanticResults, bm25Scores, entityBoosts, threshold, topK, explain = false) {
5993
5995
  var _a2, _b, _c;
5994
5996
  const hasBm25 = Object.keys(bm25Scores).length > 0;
5995
5997
  const hasEntity = Object.keys(entityBoosts).length > 0;
@@ -6015,11 +6017,23 @@ function scoreAndRank(semanticResults, bm25Scores, entityBoosts, threshold, topK
6015
6017
  const entityBoost = (_c = entityBoosts[memIdStr]) != null ? _c : 0;
6016
6018
  const rawCombined = semanticScore + bm25Score + entityBoost;
6017
6019
  const combined = Math.min(rawCombined / maxPossible, 1);
6018
- scored.push({
6020
+ const entry = {
6019
6021
  id: memIdStr,
6020
6022
  score: combined,
6021
6023
  payload: result.payload
6022
- });
6024
+ };
6025
+ if (explain) {
6026
+ entry.scoreDetails = {
6027
+ semanticScore,
6028
+ bm25Score,
6029
+ entityBoost,
6030
+ rawScore: rawCombined,
6031
+ maxPossibleScore: maxPossible,
6032
+ finalScore: combined,
6033
+ threshold
6034
+ };
6035
+ }
6036
+ scored.push(entry);
6023
6037
  }
6024
6038
  scored.sort((a, b) => b.score - a.score);
6025
6039
  return scored.slice(0, topK);
@@ -6867,7 +6881,7 @@ var Memory = class _Memory {
6867
6881
  }).filter(([, v]) => v !== void 0)
6868
6882
  ) : {};
6869
6883
  await this._ensureInitialized();
6870
- const { topK = 20, threshold = 0.1 } = config;
6884
+ const { topK = 20, threshold = 0.1, explain = false } = config;
6871
6885
  await this._captureEvent("search", {
6872
6886
  query_length: query.length,
6873
6887
  topK,
@@ -6937,15 +6951,32 @@ var Memory = class _Memory {
6937
6951
  }
6938
6952
  if (deduped.length > 0) {
6939
6953
  const entityStore = await this.getEntityStore();
6940
- for (const entity of deduped) {
6941
- try {
6942
- const entityEmbedding = await this.embedder.embed(entity.text);
6943
- const matches = await entityStore.search(
6944
- entityEmbedding,
6945
- 500,
6946
- effectiveFilters
6947
- );
6948
- for (const match of matches) {
6954
+ const entitySearchFilters = {};
6955
+ for (const k of ["user_id", "agent_id", "run_id"]) {
6956
+ if (effectiveFilters[k])
6957
+ entitySearchFilters[k] = effectiveFilters[k];
6958
+ }
6959
+ const entityTexts = deduped.map((e) => e.text);
6960
+ const embeddings = await this.embedder.embedBatch(entityTexts);
6961
+ if (embeddings.length !== entityTexts.length) {
6962
+ console.warn(
6963
+ `embedBatch returned ${embeddings.length} vectors for ${entityTexts.length} texts \u2014 skipping entity boost`
6964
+ );
6965
+ } else {
6966
+ const searchResults = await Promise.allSettled(
6967
+ deduped.map(
6968
+ (_, i) => entityStore.search(embeddings[i], 500, entitySearchFilters)
6969
+ )
6970
+ );
6971
+ for (const result of searchResults) {
6972
+ if (result.status === "rejected") {
6973
+ console.warn(
6974
+ "Entity boost search failed for one entity:",
6975
+ result.reason
6976
+ );
6977
+ continue;
6978
+ }
6979
+ for (const match of result.value) {
6949
6980
  const similarity = (_c = match.score) != null ? _c : 0;
6950
6981
  if (similarity < 0.5) continue;
6951
6982
  const payload = match.payload || {};
@@ -6964,7 +6995,6 @@ var Memory = class _Memory {
6964
6995
  }
6965
6996
  }
6966
6997
  }
6967
- } catch (e) {
6968
6998
  }
6969
6999
  }
6970
7000
  }
@@ -6985,7 +7015,8 @@ var Memory = class _Memory {
6985
7015
  bm25Scores,
6986
7016
  entityBoosts,
6987
7017
  threshold != null ? threshold : 0.1,
6988
- topK
7018
+ topK,
7019
+ explain
6989
7020
  );
6990
7021
  const excludedKeys = /* @__PURE__ */ new Set([
6991
7022
  "user_id",
@@ -7013,7 +7044,8 @@ var Memory = class _Memory {
7013
7044
  metadata: Object.entries(payload).filter(([key]) => !excludedKeys.has(key)).reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
7014
7045
  ...payload.user_id && { user_id: payload.user_id },
7015
7046
  ...payload.agent_id && { agent_id: payload.agent_id },
7016
- ...payload.run_id && { run_id: payload.run_id }
7047
+ ...payload.run_id && { run_id: payload.run_id },
7048
+ ...scored.scoreDetails && { score_details: scored.scoreDetails }
7017
7049
  };
7018
7050
  });
7019
7051
  return {