Friday-Subconscious / backend /scripts /flush_learning_queue.py
Paritosh Upadhyay
Neural Core Maturation: Self-Evolution Initiated
64cc56e
"""
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()