chore(debug): add script for mem0 operations debugging
Some checks failed
Build and Push Docker / build-and-push (push) Failing after 20m52s
Some checks failed
Build and Push Docker / build-and-push (push) Failing after 20m52s
This commit is contained in:
83
debug_mem0.py
Normal file
83
debug_mem0.py
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Debug script for mem0 operations."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
from memory_module.memory_integration import Mem0Integration
|
||||||
|
from config import MEM0_CONFIG
|
||||||
|
|
||||||
|
|
||||||
|
def test_mem0_operations():
|
||||||
|
"""Test each mem0 operation step by step."""
|
||||||
|
print("=== Testing Mem0 Operations ===\n")
|
||||||
|
|
||||||
|
# Initialize mem0
|
||||||
|
mem = Mem0Integration(MEM0_CONFIG)
|
||||||
|
user_id = "debug_user"
|
||||||
|
|
||||||
|
# Test 1: Simple add
|
||||||
|
print("Test 1: Adding a simple memory...")
|
||||||
|
try:
|
||||||
|
result = mem.memory.add(
|
||||||
|
messages=[{"role": "user", "content": "I love pizza"}],
|
||||||
|
user_id=user_id,
|
||||||
|
metadata={"type": "test"}
|
||||||
|
)
|
||||||
|
print(f"Add result: {result}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error in add: {type(e).__name__}: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
print("\n" + "="*50 + "\n")
|
||||||
|
|
||||||
|
# Test 2: Get all memories
|
||||||
|
print("Test 2: Getting all memories...")
|
||||||
|
try:
|
||||||
|
all_memories = mem.memory.get_all(user_id=user_id)
|
||||||
|
print(f"All memories: {all_memories}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error in get_all: {type(e).__name__}: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
print("\n" + "="*50 + "\n")
|
||||||
|
|
||||||
|
# Test 3: Search memories
|
||||||
|
print("Test 3: Searching memories...")
|
||||||
|
try:
|
||||||
|
search_results = mem.memory.search(
|
||||||
|
query="pizza",
|
||||||
|
user_id=user_id
|
||||||
|
)
|
||||||
|
print(f"Search results: {search_results}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error in search: {type(e).__name__}: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
print("\n" + "="*50 + "\n")
|
||||||
|
|
||||||
|
# Test 4: Add conversation-style memory
|
||||||
|
print("Test 4: Adding conversation-style memory...")
|
||||||
|
try:
|
||||||
|
messages = [
|
||||||
|
{"role": "user", "content": "Hi, my name is Alice"},
|
||||||
|
{"role": "assistant", "content": "Nice to meet you Alice"}
|
||||||
|
]
|
||||||
|
result = mem.memory.add(
|
||||||
|
messages=messages,
|
||||||
|
user_id=user_id,
|
||||||
|
metadata={"type": "conversation_test"}
|
||||||
|
)
|
||||||
|
print(f"Conversation add result: {result}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error in conversation add: {type(e).__name__}: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_mem0_operations()
|
Reference in New Issue
Block a user