|
|
#!/usr/bin/env python3 |
|
|
""" |
|
|
mem0 功能测试脚本 |
|
|
""" |
|
|
|
|
|
import sys |
|
|
import os |
|
|
sys.path.insert(0, '/root/.openclaw/workspace/skills/mem0-integration') |
|
|
|
|
|
from mem0_client import Mem0Client |
|
|
|
|
|
print("=" * 60) |
|
|
print("🧪 mem0 功能测试") |
|
|
print("=" * 60) |
|
|
|
|
|
# 测试 1:初始化 |
|
|
print("\n🔍 测试 1: 初始化 mem0 Client...") |
|
|
try: |
|
|
client = Mem0Client() |
|
|
print("✅ Client 创建成功") |
|
|
except Exception as e: |
|
|
print(f"❌ Client 创建失败:{e}") |
|
|
sys.exit(1) |
|
|
|
|
|
# 测试 2:状态检查 |
|
|
print("\n📊 测试 2: 状态检查...") |
|
|
status = client.get_status() |
|
|
print(f" 本地记忆:{'✅' if status['local_initialized'] else '❌'}") |
|
|
print(f" 共享记忆:{'✅' if status['master_initialized'] else '❌'}") |
|
|
|
|
|
if not status['local_initialized']: |
|
|
print("\n⚠️ 本地记忆未初始化,可能原因:") |
|
|
print(" 1. Qdrant 未启动") |
|
|
print(" 2. 配置错误") |
|
|
print(" 3. mem0ai 版本问题") |
|
|
sys.exit(1) |
|
|
|
|
|
# 测试 3:添加记忆 |
|
|
print("\n📝 测试 3: 添加记忆...") |
|
|
test_content = "测试记忆:OpenClaw mem0 集成测试" |
|
|
result = client.add( |
|
|
[{"role": "user", "content": test_content}], |
|
|
user_id="test_user", |
|
|
agent_id="main" |
|
|
) |
|
|
|
|
|
if 'error' in result: |
|
|
print(f"❌ 添加失败:{result['error']}") |
|
|
else: |
|
|
print(f"✅ 记忆已添加") |
|
|
print(f" 内容:{test_content}") |
|
|
|
|
|
# 测试 4:搜索记忆 |
|
|
print("\n🔍 测试 4: 搜索记忆...") |
|
|
results = client.search("OpenClaw", user_id="test_user", agent_id="main", limit=5) |
|
|
print(f" 找到 {len(results)} 条记忆") |
|
|
|
|
|
if results: |
|
|
for i, mem in enumerate(results, 1): |
|
|
memory_text = mem.get('memory', 'N/A') |
|
|
print(f" {i}. {memory_text[:100]}...") |
|
|
else: |
|
|
print(" ⚠️ 未找到记忆(可能 Qdrant 集合为空)") |
|
|
|
|
|
# 测试 5:获取所有记忆 |
|
|
print("\n📋 测试 5: 获取所有记忆...") |
|
|
all_memories = client.get_all(user_id="test_user", agent_id="main") |
|
|
print(f" 共 {len(all_memories)} 条记忆") |
|
|
|
|
|
# 测试 6:状态报告 |
|
|
print("\n📊 测试 6: 最终状态...") |
|
|
final_status = client.get_status() |
|
|
print(f" 本地 Qdrant: {final_status['config']['local']['vector_store']['config']['host']}:{final_status['config']['local']['vector_store']['config']['port']}") |
|
|
print(f" 中心 Qdrant: {final_status['config']['master']['vector_store']['config']['host']}:{final_status['config']['master']['vector_store']['config']['port']}") |
|
|
|
|
|
print("\n" + "=" * 60) |
|
|
print("✅ 测试完成") |
|
|
print("=" * 60)
|
|
|
|