(self)
| 360 | return sorted(results, key=lambda x: x["session_relevance_score"], reverse=True) |
| 361 | |
| 362 | def save(self): |
| 363 | # Make a copy for saving to avoid modifying heap during iteration if it happens |
| 364 | # Though current heap is list of tuples, so direct modification risk is low |
| 365 | # sessions_to_save = {sid: data for sid, data in self.sessions.items()} |
| 366 | data_to_save = { |
| 367 | "sessions": self.sessions, |
| 368 | "access_frequency": dict(self.access_frequency), # Convert defaultdict to dict for JSON |
| 369 | # Heap is derived, no need to save typically, but can if desired for faster load |
| 370 | # "heap_snapshot": self.heap |
| 371 | } |
| 372 | try: |
| 373 | with open(self.file_path, "w", encoding="utf-8") as f: |
| 374 | json.dump(data_to_save, f, ensure_ascii=False, indent=2) |
| 375 | except IOError as e: |
| 376 | print(f"Error saving MidTermMemory to {self.file_path}: {e}") |
| 377 | |
| 378 | def load(self): |
| 379 | try: |
no outgoing calls
no test coverage detected