#!/usr/bin/env python3 """ Debug the fact extraction system """ import asyncio import sys import os # Add the API directory to the path sys.path.insert(0, '/home/klas/langmem-project/src/api') from fact_extraction import FactExtractor async def debug_fact_extraction(): """Debug fact extraction""" print("šŸ” Debugging Fact Extraction System") print("=" * 50) # Test content test_content = "Ondrej has a son named Cyril who is 8 years old and loves playing soccer. Cyril goes to elementary school in Prague and his favorite color is blue. Ondrej works as a software engineer and lives in Czech Republic." print(f"Content to extract facts from:") print(f"'{test_content}'") print() # Create fact extractor extractor = FactExtractor() print("1. Testing fact extraction...") facts = await extractor.extract_facts(test_content) print(f"Extracted {len(facts)} facts:") for i, fact in enumerate(facts, 1): print(f" {i}. {fact}") if not facts: print("āŒ No facts extracted - there might be an issue with the extraction system") return False else: print("āœ… Fact extraction working!") print() # Test memory action determination print("2. Testing memory action determination...") existing_memories = [ { "id": "test-memory-1", "content": "Ondrej has a son named Cyril", "similarity": 0.8 } ] new_fact = "Ondrej has a son named Cyril who is 8 years old" action_data = await extractor.determine_memory_action(new_fact, existing_memories) print(f"New fact: '{new_fact}'") print(f"Action: {action_data.get('action', 'unknown')}") print(f"Reason: {action_data.get('reason', 'no reason')}") return True async def main(): """Main function""" try: success = await debug_fact_extraction() if success: print("\nšŸŽ‰ Fact extraction debugging complete!") else: print("\nāŒ Fact extraction has issues that need to be fixed.") except Exception as e: print(f"āŒ Error during debugging: {e}") import traceback traceback.print_exc() if __name__ == "__main__": asyncio.run(main())