- 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 🦊💕
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
"""
|
|
Memory search handler.
|
|
|
|
Handles legacy search requests (backward compatibility).
|
|
"""
|
|
import json
|
|
from typing import Dict, Any
|
|
from core.logger import setup_logger
|
|
|
|
logger = setup_logger('search_handler', service_name='memory_service')
|
|
|
|
|
|
class SearchHandler:
|
|
"""Handles legacy memory search requests"""
|
|
|
|
def __init__(self, short_term_ops):
|
|
self.short_term_ops = short_term_ops
|
|
|
|
async def handle(self, msg) -> None:
|
|
"""Handle vi.memory.search requests - backward compatibility"""
|
|
try:
|
|
payload = json.loads(msg.data.decode())
|
|
logger.debug("[μ] Legacy search request - redirecting to short_memory")
|
|
|
|
# Map legacy parameters to new system
|
|
limit = payload.get('limit', 10)
|
|
identity_id = None
|
|
if payload.get('identities'):
|
|
identity_id = payload['identities'][0]
|
|
interaction_id = payload.get('interaction_id')
|
|
|
|
# Query short-term memory
|
|
results = self.short_term_ops.query(
|
|
limit=limit,
|
|
offset=0,
|
|
identity_id=identity_id,
|
|
interaction_id=interaction_id
|
|
)
|
|
|
|
response = {
|
|
"results": results,
|
|
"count": len(results),
|
|
"source": "short_term",
|
|
"note": "Legacy search API redirected to short-term memory. Use short_memory(), long_memory(), or facts() for specific queries."
|
|
}
|
|
await msg.respond(json.dumps(response).encode())
|
|
|
|
except Exception as e:
|
|
logger.exception(f"[μ] Failed to search memories: {e}")
|
|
error_response = {"results": [], "count": 0, "error": str(e)}
|
|
await msg.respond(json.dumps(error_response).encode())
|