Skip to content

Commit db814c3

Browse files
NyakultCaralHsi
andauthored
feat: check nodes existence (#156)
Co-authored-by: CaralHsi <[email protected]>
1 parent 06ca986 commit db814c3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/memos/graph_dbs/neo4j.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ def get_memory_count(self, memory_type: str) -> int:
114114
)
115115
return result.single()["count"]
116116

117-
def count_nodes(self, scope: str) -> int:
117+
def node_not_exist(self, scope: str) -> int:
118118
query = """
119119
MATCH (n:Memory)
120120
WHERE n.memory_type = $scope
121121
"""
122122
if not self.config.use_multi_db and self.config.user_name:
123123
query += "\nAND n.user_name = $user_name"
124-
query += "\nRETURN count(n) AS count"
124+
query += "\nRETURN n LIMIT 1"
125125

126126
with self.driver.session(database=self.db_name) as session:
127127
result = session.run(
@@ -131,7 +131,7 @@ def count_nodes(self, scope: str) -> int:
131131
"user_name": self.config.user_name if self.config.user_name else None,
132132
},
133133
)
134-
return result.single()["count"]
134+
return result.single() is None
135135

136136
def remove_oldest_memory(self, memory_type: str, keep_latest: int) -> None:
137137
"""

src/memos/memories/textual/tree_text_memory/organize/reorganizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def optimize_structure(
198198
logger.info(f"Already optimizing for {scope}. Skipping.")
199199
return
200200

201-
if self.graph_store.count_nodes(scope) == 0:
201+
if self.graph_store.node_not_exist(scope):
202202
logger.debug(f"[GraphStructureReorganize] No nodes for scope={scope}. Skip.")
203203
return
204204

0 commit comments

Comments
 (0)