Implement comprehensive LLM provider system with global cost protection
- Add multi-provider LLM architecture supporting OpenRouter, OpenAI, Gemini, and custom providers - Implement global LLM on/off switch with default DISABLED state for cost protection - Add per-character LLM configuration with provider-specific models and settings - Create performance-optimized caching system for LLM enabled status checks - Add API key validation before enabling LLM providers to prevent broken configurations - Implement audit logging for all LLM enable/disable actions for cost accountability - Create comprehensive admin UI with prominent cost warnings and confirmation dialogs - Add visual indicators in character list for custom AI model configurations - Build character-specific LLM client system with global fallback mechanism - Add database schema support for per-character LLM settings - Implement graceful fallback responses when LLM is globally disabled - Create provider testing and validation system for reliable connections
This commit is contained in:
73
sync_vectors.py
Normal file
73
sync_vectors.py
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Sync existing PostgreSQL memories to Qdrant vector database
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
from database.connection import init_database, get_db_session
|
||||
from database.models import Memory, Character
|
||||
from rag.vector_store import VectorStoreManager, VectorMemory, MemoryType
|
||||
from sqlalchemy import select
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def sync_memories_to_qdrant():
|
||||
"""Sync all existing memories from PostgreSQL to Qdrant"""
|
||||
|
||||
# Initialize database
|
||||
await init_database()
|
||||
|
||||
# Initialize vector store
|
||||
vector_store = VectorStoreManager()
|
||||
|
||||
print("🔄 Starting memory sync to Qdrant...")
|
||||
|
||||
async with get_db_session() as session:
|
||||
# Get all memories with character names
|
||||
query = select(Memory, Character.name).join(
|
||||
Character, Memory.character_id == Character.id
|
||||
).order_by(Memory.timestamp)
|
||||
|
||||
results = await session.execute(query)
|
||||
memories_with_chars = results.fetchall()
|
||||
|
||||
print(f"Found {len(memories_with_chars)} memories to sync")
|
||||
|
||||
synced_count = 0
|
||||
error_count = 0
|
||||
|
||||
for memory, character_name in memories_with_chars:
|
||||
try:
|
||||
# Convert to vector memory format
|
||||
vector_memory = VectorMemory(
|
||||
id=str(memory.id),
|
||||
character_name=character_name,
|
||||
content=memory.content,
|
||||
memory_type=MemoryType.PERSONAL,
|
||||
importance=memory.importance_score,
|
||||
timestamp=memory.timestamp or datetime.now(timezone.utc),
|
||||
metadata={
|
||||
"tags": memory.tags or [],
|
||||
"memory_id": memory.id,
|
||||
"character_id": memory.character_id,
|
||||
"memory_type": memory.memory_type
|
||||
}
|
||||
)
|
||||
|
||||
# Store in vector database
|
||||
await vector_store.store_memory(vector_memory)
|
||||
synced_count += 1
|
||||
|
||||
if synced_count % 10 == 0:
|
||||
print(f" Synced {synced_count}/{len(memories_with_chars)} memories...")
|
||||
|
||||
except Exception as e:
|
||||
error_count += 1
|
||||
print(f" Error syncing memory {memory.id}: {e}")
|
||||
|
||||
print(f"✅ Sync complete: {synced_count} synced, {error_count} errors")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(sync_memories_to_qdrant())
|
||||
Reference in New Issue
Block a user