File size: 2,098 Bytes
c4a2296 64cc56e c4a2296 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | """
Project Friday — Master Learning Queue Flush
Bridges existing ConversationMemory patterns into the LearningTarget queue for high-velocity maturation.
"""
import sys
import os
from pathlib import Path
import logging
# Add backend to path
sys.path.append(os.path.join(os.getcwd(), "backend"))
from app.core import database
from app.models.entities import ConversationMemory
from app.services import holocron
logging.basicConfig(level=logging.INFO, format="%(asctime)s | FLUSH | %(message)s")
logger = logging.getLogger("friday.flush")
def flush_memory_to_queue():
"""Converts 310,000+ memory patterns into formal learning targets."""
logger.info("Initializing Master Queue Sync...")
with database.SessionLocal() as db:
# 1. Fetch distinct topics from memory that aren't already targets
logger.info("Scanning for unqueued mandates in memory store...")
# In this context, 'entities' holds the unique reference ID like MANAGEMENT_MASTER_X
# We'll use the memory ID ranges or categories
# Map categories
for category, target_type in [("ManagementSkill", "management"), ("PersonalityExample", "personality")]:
logger.info(f"Processing category: {category} -> {target_type}")
# Use chunks to avoid memory issues
batch_size = 5000
offset = 0
while True:
mem_items = db.query(ConversationMemory.entities)\
.filter_by(topic=category)\
.offset(offset).limit(batch_size).all()
if not mem_items: break
topics = [m.entities for m in mem_items]
holocron.add_learning_targets(topics, category=target_type)
offset += batch_size
logger.info(f"Synchronized {offset} patterns for {target_type}...")
logger.info("✓ Master Learning Queue Flush Complete.")
if __name__ == "__main__":
flush_memory_to_queue()
|