orbitchem-api / api /memory.py
Shehan Makani
Claude Sonnet 4.6
Deploy OrbitChem FastAPI backend on Docker HF Space
8c867c9
Raw History Blame Contribute Delete
1.2 kB
"""
api/memory.py
Bridge: exposes the FormulationMemoryNetwork as the `memory` singleton
used throughout the API (controller.py, main.py, odata endpoints).
Replaces the previous 21-line MemoryBus stub with the full 568-line
engine from modules/memory_network.py.
"""
import types
from modules.memory_network import get_memory_network
# Module-level singleton β€” same interface the rest of the app expects
memory = get_memory_network()
# ── Add the thin compat methods the rest of the app still calls ────────────────
# (FormulationMemoryNetwork already has .record() with matching positional args)
def _recent(self, n=10):
"""Return last n events (MemoryBus compat)."""
return self.state.events[-n:]
def _query(self, filter_fn):
"""Filter events by predicate (MemoryBus compat)."""
return [e for e in self.state.events if filter_fn(e)]
def _get_all(self):
"""Return all recorded events."""
return self.state.events
# Bind as instance methods (self will be passed correctly)
memory.recent = types.MethodType(_recent, memory)
memory.query = types.MethodType(_query, memory)
memory.get_all = types.MethodType(_get_all, memory)