Skip to content

Commit 72d0423

Browse files
authored
fix: remove old mem (#361)
1 parent cd7b7e8 commit 72d0423

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/memos/graph_dbs/nebular.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -443,21 +443,20 @@ def remove_oldest_memory(self, memory_type: str, keep_latest: int) -> None:
443443
if not self.config.use_multi_db and self.config.user_name:
444444
optional_condition = f"AND n.user_name = '{self.config.user_name}'"
445445

446-
count = self.count_nodes(memory_type)
447-
448-
if count > keep_latest:
449-
delete_query = f"""
450-
MATCH (n@Memory)
451-
WHERE n.memory_type = '{memory_type}'
452-
{optional_condition}
453-
ORDER BY n.updated_at DESC
454-
OFFSET {keep_latest}
455-
DETACH DELETE n
456-
"""
457-
try:
446+
try:
447+
count = self.count_nodes(memory_type)
448+
if count > keep_latest:
449+
delete_query = f"""
450+
MATCH (n@Memory)
451+
WHERE n.memory_type = '{memory_type}'
452+
{optional_condition}
453+
ORDER BY n.updated_at DESC
454+
OFFSET {keep_latest}
455+
DETACH DELETE n
456+
"""
458457
self.execute_query(delete_query)
459-
except Exception as e:
460-
logger.warning(f"Delete old mem error: {e}")
458+
except Exception as e:
459+
logger.warning(f"Delete old mem error: {e}")
461460

462461
@timed
463462
def add_node(self, id: str, memory: str, metadata: dict[str, Any]) -> None:

0 commit comments

Comments
 (0)