From 9be1f8429aaa791e68e38da6e8992f0c4b261278 Mon Sep 17 00:00:00 2001 From: gameloader Date: Sun, 12 Oct 2025 19:31:37 +0800 Subject: [PATCH] chore(debug): add script for mem0 operations debugging --- debug_mem0.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 debug_mem0.py diff --git a/debug_mem0.py b/debug_mem0.py new file mode 100644 index 0000000..54bd869 --- /dev/null +++ b/debug_mem0.py @@ -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() \ No newline at end of file