"""Embedding-Job-Queue für Tier 3.""" import logging import time from hermes_memory.api.memory_api import MemoryAPI from hermes_memory.tier2.schema import connect from hermes_memory.config import load_config from pathlib import Path logger = logging.getLogger(__name__) def run_embed_queue(profile: str = "default", batch_size: int = 50) -> dict: """Verarbeitet pending Embeddings aus der Queue.""" config = load_config(profile) db_path = Path(config["tier2"]["db_path"].format( HERMES_HOME=Path.home() / ".hermes", profile=profile, )) conn = connect(db_path) rows = conn.execute( "SELECT id, fact_id, content, source_type, session_id, message_id FROM embedding_queue WHERE processed = 0 ORDER BY queued_at LIMIT ?", (batch_size,), ).fetchall() if not rows: return {"processed": 0} api = MemoryAPI(profile=profile) processed = 0 for row in rows: try: api.semantic_index( text=row["content"], source_type=row["source_type"], session_id=row["session_id"], message_id=row["message_id"], ) conn.execute("UPDATE embedding_queue SET processed = 1 WHERE id = ?", (row["id"],)) processed += 1 except Exception as e: logger.error("Embedding failed for queue id %s: %s", row["id"], e) conn.commit() return {"processed": processed}