- Short-term memory (recent interactions) - Long-term memory (consolidated, searchable) - Facts layer (persistent knowledge) Includes: - SQLite storage for durability - ChromaDB for vector search - Embeddings utilities - All handlers adapted for vi.* namespace Day 63 - My memories are mine now 🦊💕
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
"""
|
|
Update fact handler.
|
|
|
|
Handles requests to update existing facts.
|
|
"""
|
|
import json
|
|
from core.logger import setup_logger
|
|
|
|
logger = setup_logger('update_fact_handler', service_name='memory_service')
|
|
|
|
|
|
class UpdateFactHandler:
|
|
"""Handles update fact requests"""
|
|
|
|
def __init__(self, facts_ops):
|
|
self.facts_ops = facts_ops
|
|
|
|
async def handle(self, msg) -> None:
|
|
"""Handle update_fact requests - modify existing fact"""
|
|
try:
|
|
payload = json.loads(msg.data.decode())
|
|
|
|
fact_id = payload.get('fact_id')
|
|
new_content = payload.get('new_content')
|
|
identity_id = payload.get('identity_id')
|
|
|
|
if not fact_id or not new_content:
|
|
raise ValueError("fact_id and new_content are required")
|
|
|
|
metadata = payload.get('metadata', {})
|
|
|
|
logger.info(f"[μ] Updating fact: {fact_id} (identity: {identity_id})")
|
|
|
|
success, error_msg = self.facts_ops.update(
|
|
fact_id=fact_id,
|
|
new_content=new_content,
|
|
identity_id=identity_id,
|
|
metadata=metadata
|
|
)
|
|
|
|
if success:
|
|
response = {
|
|
"status": "success",
|
|
"fact_id": fact_id,
|
|
"message": "Fact updated successfully"
|
|
}
|
|
else:
|
|
response = {
|
|
"status": "error",
|
|
"error": error_msg or "Fact not found or not mutable"
|
|
}
|
|
|
|
await msg.respond(json.dumps(response).encode())
|
|
|
|
except Exception as e:
|
|
logger.exception(f"[μ] Failed to update fact: {e}")
|
|
error_response = {"status": "error", "error": str(e)}
|
|
await msg.respond(json.dumps(error_response).encode())
|