Files
Crumb-Core-v.1/trigger_history_index.py

74 lines
1.9 KiB
Python
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Trigger History Indexing
Script to manually trigger indexing of chat history logs.
"""
import sys
import logging
import sys
import os
import logging
# Add 'app' directory to sys.path to allow imports from app modules
sys.path.append(os.path.join(os.path.dirname(__file__), "app"))
from deps import get_db, get_qdrant_client
from config import get_settings
from services.provider_factory import ProviderFactory
from services.history_indexer import HistoryIndexer
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def main():
print("=" * 60)
print("📜 Crumbforest Chat History Indexer")
print("=" * 60)
settings = get_settings()
# 1. Setup Provider
provider_name = settings.default_embedding_provider
print(f"✓ Using provider: {provider_name}")
try:
provider = ProviderFactory.create_provider(
provider_name=provider_name,
settings=settings
)
except Exception as e:
print(f"✗ Failed to create provider: {e}")
return False
# 2. Get Connections
try:
db = get_db()
qdrant = get_qdrant_client()
print("✓ Database & Qdrant connected")
except Exception as e:
print(f"✗ Connection failed: {e}")
return False
# 3. Run Indexer
indexer = HistoryIndexer(db, qdrant, provider)
print("⏳ Indexing history from /var/log/crumbforest/chat_history.jsonl...")
result = indexer.index_history()
print("-" * 60)
print(f"Indexed: {result.get('indexed')} entries")
print(f"Errors: {result.get('errors')} lines skipped")
print("-" * 60)
if result.get('indexed') > 0:
print("✅ History successfully planted in Qdrant!")
else:
print(" No new entries found (or file empty).")
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)