Problem
NeuroscienceAssistant stores session data in two in-memory dicts:
self.chat_history: Dict[str, List[str]] = {}
self.session_memory: Dict[str, Dict[str, Any]] = {}
session_memory stores full search result payloads (up to 60 results per session) and is never evicted. On a long-running server with many users this will grow until the process runs out of memory.
chat_history caps at 20 entries per session but sessions themselves are never removed.
Solution
- Add a max session count (e.g. 1000) with LRU eviction using
collections.OrderedDict
- Add a session TTL (e.g. evict sessions inactive for >1 hour)
- Document memory behaviour in the README