mem0 icon indicating copy to clipboard operation
mem0 copied to clipboard

Traceback (most recent call last): File "/home/zengxiangxi/project/LLM/agent/memory/test4.py", line 50, in <module> client.add( TypeError: Memory.add() got an unexpected keyword argument 'expiration_date'

Open dgzxx-2000 opened this issue 1 month ago • 2 comments

🐛 Describe the bug

import os import json from mem0 import Memory import logging # <-- 添加 from datetime import datetime, timedelta

--- 添加日志配置 ---

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

--------------------

您的 OpenAI Key

os.environ["OPENAI_API_KEY"] = "dummy_key"

config = { "llm": { "provider": "openai", "config": { "model": "qwen3", "temperature": 0.1, # 降低温度以获得更确定的输出 "max_tokens": 2048, # 增加 token 限制 "openai_base_url": "http://127.0.0.1:18098/v1" } }, "embedder": { "provider": "ollama", "config": { "model": "quentinz/bge-large-zh-v1.5", "ollama_base_url": "http://localhost:11434", "embedding_dims": 1024 } }, "vector_store": { "provider": "qdrant", "config": { "collection_name": "qdrant_data_cn_final_v2", "embedding_model_dims": 1024, "host": "localhost", # <-- 使用 host "port": 6333 # <-- 使用 port } }, "version": "v1.1" }

假设 config 是您的配置字典

client = Memory.from_config(config)

user_id = "patient_321"

expires_at = (datetime.now() + timedelta(days=7)).isoformat() # 设置7天过期

client.add( "Currently browsing electronics category", user_id=user_id, expiration_date=expires_at, metadata={"type": "session"} )

results = client.get_all(user_id) for memory in results['results']: exp_date = memory.get('expiration_date')

if exp_date:
    print(f"Temporary: {memory['memory']}")
    print(f"  Expires: {exp_date}\\n")
else:
    print(f"Permanent: {memory['memory']}\\n")

https://docs.mem0.ai/cookbooks/essentials/memory-expiration-short-and-long-term I encountered this problem following the tutorial.

dgzxx-2000 avatar Nov 05 '25 08:11 dgzxx-2000

(agent) zengxiangxi@w550-pc:~/project/LLM/agent/memory$ pip show mem0ai Name: mem0ai Version: 1.0.0 Summary: Long-term memory for AI Agents Home-page: Author: Author-email: Mem0 [email protected] License-Expression: Apache-2.0 Location: /data/home/zengxiangxi/app/miniconda3/envs/agent/lib/python3.11/site-packages

dgzxx-2000 avatar Nov 05 '25 08:11 dgzxx-2000

The documents all contain "from mem0 import MemoryClient", and there is also "from /home/zengxiangxi/app/miniconda3/envs/agent/lib/python3.11/site-packages/mem0/memory import from mem0 import Memory" implementation.

dgzxx-2000 avatar Nov 05 '25 09:11 dgzxx-2000