mem0ai 3.0.8 → 3.0.9

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.js CHANGED
@@ -99,7 +99,10 @@ var MemoryConfigSchema = import_zod.z.object({
99
99
  modelProperties: import_zod.z.record(import_zod.z.string(), import_zod.z.any()).optional(),
100
100
  baseURL: import_zod.z.string().optional(),
101
101
  url: import_zod.z.string().optional(),
102
- timeout: import_zod.z.number().optional()
102
+ timeout: import_zod.z.number().optional(),
103
+ temperature: import_zod.z.number().optional(),
104
+ topP: import_zod.z.number().optional(),
105
+ maxTokens: import_zod.z.number().optional()
103
106
  })
104
107
  }),
105
108
  historyDbPath: import_zod.z.string().optional(),
@@ -389,25 +392,54 @@ var OpenAIStructuredLLM = class {
389
392
  var import_sdk = __toESM(require("@anthropic-ai/sdk"));
390
393
  var AnthropicLLM = class {
391
394
  constructor(config) {
395
+ var _a2, _b2;
392
396
  const apiKey = config.apiKey || process.env.ANTHROPIC_API_KEY;
393
397
  if (!apiKey) {
394
398
  throw new Error("Anthropic API key is required");
395
399
  }
396
400
  this.client = new import_sdk.default({ apiKey });
397
- this.model = config.model || "claude-3-sonnet-20240229";
401
+ this.model = config.model || "claude-sonnet-4-6";
402
+ this.maxTokens = (_a2 = config.maxTokens) != null ? _a2 : 2e3;
403
+ this.temperature = (_b2 = config.temperature) != null ? _b2 : 0.1;
404
+ this.topP = config.topP;
398
405
  }
399
- async generateResponse(messages, responseFormat) {
406
+ async generateResponse(messages, responseFormat, tools) {
400
407
  const systemMessage = messages.find((msg) => msg.role === "system");
401
408
  const otherMessages = messages.filter((msg) => msg.role !== "system");
402
- const response = await this.client.messages.create({
409
+ const params = {
403
410
  model: this.model,
404
411
  messages: otherMessages.map((msg) => ({
405
412
  role: msg.role,
406
413
  content: typeof msg.content === "string" ? msg.content : msg.content.image_url.url
407
414
  })),
408
415
  system: typeof (systemMessage == null ? void 0 : systemMessage.content) === "string" ? systemMessage.content : void 0,
409
- max_tokens: 4096
410
- });
416
+ max_tokens: this.maxTokens
417
+ };
418
+ if (this.temperature !== void 0) {
419
+ params.temperature = this.temperature;
420
+ } else if (this.topP !== void 0) {
421
+ params.top_p = this.topP;
422
+ }
423
+ if (tools) {
424
+ params.tools = tools;
425
+ params.tool_choice = { type: "auto" };
426
+ }
427
+ const response = await this.client.messages.create(params);
428
+ if (tools) {
429
+ let content = "";
430
+ const toolCalls = [];
431
+ for (const block of response.content) {
432
+ if (block.type === "text") {
433
+ content = block.text;
434
+ } else if (block.type === "tool_use") {
435
+ toolCalls.push({
436
+ name: block.name,
437
+ arguments: JSON.stringify(block.input)
438
+ });
439
+ }
440
+ }
441
+ return { content, role: "assistant", toolCalls };
442
+ }
411
443
  const firstBlock = response.content[0];
412
444
  if (firstBlock.type === "text") {
413
445
  return firstBlock.text;
@@ -417,10 +449,10 @@ var AnthropicLLM = class {
417
449
  }
418
450
  async generateChat(messages) {
419
451
  const response = await this.generateResponse(messages);
420
- return {
421
- content: response,
422
- role: "assistant"
423
- };
452
+ if (typeof response === "string") {
453
+ return { content: response, role: "assistant" };
454
+ }
455
+ return response;
424
456
  }
425
457
  };
426
458
 
@@ -5044,7 +5076,7 @@ var ConfigManager = class {
5044
5076
  llm: {
5045
5077
  provider: ((_c = userConfig.llm) == null ? void 0 : _c.provider) || DEFAULT_MEMORY_CONFIG.llm.provider,
5046
5078
  config: (() => {
5047
- var _a3, _b3, _c2, _d2;
5079
+ var _a3, _b3, _c2, _d2, _e2, _f2, _g2;
5048
5080
  const defaultConf = DEFAULT_MEMORY_CONFIG.llm.config;
5049
5081
  const userConf = (_a3 = userConfig.llm) == null ? void 0 : _a3.config;
5050
5082
  let finalModel = defaultConf.model;
@@ -5054,12 +5086,19 @@ var ConfigManager = class {
5054
5086
  finalModel = userConf.model;
5055
5087
  }
5056
5088
  const llmBaseURL = (_d2 = (_c2 = (_b3 = userConf == null ? void 0 : userConf.baseURL) != null ? _b3 : userConf == null ? void 0 : userConf.lmstudio_base_url) != null ? _c2 : userConf == null ? void 0 : userConf.url) != null ? _d2 : defaultConf.baseURL;
5089
+ const llmRaw = userConf;
5090
+ const temperature = (_e2 = userConf == null ? void 0 : userConf.temperature) != null ? _e2 : llmRaw == null ? void 0 : llmRaw.temperature;
5091
+ const topP = (_f2 = userConf == null ? void 0 : userConf.topP) != null ? _f2 : llmRaw == null ? void 0 : llmRaw.top_p;
5092
+ const maxTokens = (_g2 = userConf == null ? void 0 : userConf.maxTokens) != null ? _g2 : llmRaw == null ? void 0 : llmRaw.max_tokens;
5057
5093
  return {
5058
5094
  baseURL: llmBaseURL,
5059
5095
  url: userConf == null ? void 0 : userConf.url,
5060
5096
  apiKey: (userConf == null ? void 0 : userConf.apiKey) !== void 0 ? userConf.apiKey : defaultConf.apiKey,
5061
5097
  model: finalModel,
5062
- modelProperties: (userConf == null ? void 0 : userConf.modelProperties) !== void 0 ? userConf.modelProperties : defaultConf.modelProperties
5098
+ modelProperties: (userConf == null ? void 0 : userConf.modelProperties) !== void 0 ? userConf.modelProperties : defaultConf.modelProperties,
5099
+ temperature,
5100
+ topP,
5101
+ maxTokens
5063
5102
  };
5064
5103
  })()
5065
5104
  },
@@ -5125,7 +5164,7 @@ var parse_vision_messages = async (messages) => {
5125
5164
  };
5126
5165
 
5127
5166
  // src/oss/src/utils/telemetry.ts
5128
- var version = true ? "3.0.8" : "dev";
5167
+ var version = true ? "3.0.9" : "dev";
5129
5168
  var MEM0_TELEMETRY = true;
5130
5169
  var _a, _b;
5131
5170
  try {
@@ -8424,20 +8463,13 @@ var Memory = class _Memory {
8424
8463
  const prevValue = existingMemory.payload.data;
8425
8464
  const embedding = existingEmbeddings[data] || await this.embedder.embed(data);
8426
8465
  const newMetadata = {
8466
+ ...existingMemory.payload,
8427
8467
  ...metadata,
8428
8468
  data,
8429
8469
  hash: (0, import_crypto2.createHash)("md5").update(data).digest("hex"),
8470
+ textLemmatized: lemmatizeForBm25(data),
8430
8471
  createdAt: existingMemory.payload.createdAt,
8431
- updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
8432
- ...existingMemory.payload.user_id && {
8433
- user_id: existingMemory.payload.user_id
8434
- },
8435
- ...existingMemory.payload.agent_id && {
8436
- agent_id: existingMemory.payload.agent_id
8437
- },
8438
- ...existingMemory.payload.run_id && {
8439
- run_id: existingMemory.payload.run_id
8440
- }
8472
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
8441
8473
  };
8442
8474
  await this.vectorStore.update(memoryId, embedding, newMetadata);
8443
8475
  await this.db.addHistory(