#!/usr/bin/env python3 """ Test mem0 configuration validation with Supabase """ import os import sys from dotenv import load_dotenv from config import load_config, get_mem0_config import vecs def test_supabase_vector_store_connection(): """Test direct connection to Supabase vector store using vecs""" print("๐Ÿ”— Testing direct Supabase vector store connection...") try: # Connection string for our Supabase instance connection_string = "postgresql://supabase_admin:CzkaYmRvc26Y@localhost:5435/postgres" # Create vecs client db = vecs.create_client(connection_string) # List existing collections collections = db.list_collections() print(f"โœ… Connected to Supabase PostgreSQL") print(f"๐Ÿ“ฆ Existing collections: {[c.name for c in collections]}") # Test creating a collection (this will create the table if it doesn't exist) collection_name = "mem0_test_vectors" collection = db.get_or_create_collection( name=collection_name, dimension=1536 # OpenAI text-embedding-3-small dimension ) print(f"โœ… Collection '{collection_name}' ready") # Test basic vector operations print("๐Ÿงช Testing basic vector operations...") # Insert a test vector test_id = "test_vector_1" test_vector = [0.1] * 1536 # Dummy vector test_metadata = {"content": "This is a test memory", "user_id": "test_user"} collection.upsert( records=[(test_id, test_vector, test_metadata)] ) print("โœ… Vector upserted successfully") # Search for similar vectors query_vector = [0.1] * 1536 # Same as test vector results = collection.query( data=query_vector, limit=5, include_metadata=True ) print(f"โœ… Search completed, found {len(results)} results") if results: print(f" First result: {results[0]}") # Cleanup collection.delete(ids=[test_id]) print("โœ… Test data cleaned up") return True except Exception as e: print(f"โŒ Supabase vector store connection failed: {e}") import traceback traceback.print_exc() return False def test_configuration_validation(): """Test mem0 configuration validation""" print("โš™๏ธ Testing mem0 configuration validation...") try: config = load_config() mem0_config = get_mem0_config(config, "openai") print("โœ… Configuration loaded successfully") print(f"๐Ÿ“‹ Vector store provider: {mem0_config['vector_store']['provider']}") print(f"๐Ÿ“‹ Graph store provider: {mem0_config.get('graph_store', {}).get('provider', 'Not configured')}") # Validate required fields vector_config = mem0_config['vector_store']['config'] required_fields = ['connection_string', 'collection_name', 'embedding_model_dims'] for field in required_fields: if field not in vector_config: raise ValueError(f"Missing required field: {field}") print("โœ… All required configuration fields present") return True except Exception as e: print(f"โŒ Configuration validation failed: {e}") return False def main(): """Main test function""" print("=" * 60) print("MEM0 + SUPABASE CONFIGURATION TESTS") print("=" * 60) # Load environment load_dotenv() results = [] # Test 1: Configuration validation results.append(("Configuration Validation", test_configuration_validation())) # Test 2: Direct Supabase vector store connection results.append(("Supabase Vector Store", test_supabase_vector_store_connection())) # Summary print("\n" + "=" * 60) print("TEST SUMMARY") print("=" * 60) passed = 0 for test_name, result in results: status = "โœ… PASS" if result else "โŒ FAIL" print(f"{status} {test_name}") if result: passed += 1 print(f"\nOverall: {passed}/{len(results)} tests passed") if passed == len(results): print("๐ŸŽ‰ Supabase configuration is ready!") sys.exit(0) else: print("๐Ÿ’ฅ Some tests failed - check configuration") sys.exit(1) if __name__ == "__main__": main()