No Description

天问 f6b70d6a10 Update 'README.md' 4 months ago
README.md f6b70d6a10 Update 'README.md' 4 months ago

README.md

mem0

为大型语言模型(LLMs)提供智能、自我改进记忆层的工具,旨在实现跨应用的个性化AI体验

Usage

pip install mem0ai


import os
from mem0 import Memory

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

# 初始化 Mem0
m = Memory()

# 从任何非结构化文本存储记忆
result = m.add("I am working on improving my tennis skills. Suggest some online courses.", user_id="alice", metadata={"category": "hobbies"})
print(result)
# 输出: Improving her tennis skills. Looking for online suggestions.

# 获取所有记忆
all_memories = m.get_all()
memory_id = all_memories[0]["id"]  # 获取一个 memory_id
print(all_memories)

# 搜索记忆
related_memories = m.search(query="What are Alice's hobbies?", user_id="alice")
print(related_memories)

# 更新记忆
result = m.update(memory_id=memory_id, data="Likes to play tennis on weekends")
print(result)

# 获取记忆历史
history = m.history(memory_id=memory_id)
print(history)