Skip to content

Commit 0686fb2

Browse files
authored
feat: add embedding-aware graph query interfaces and parallel retrieval (#212)
* feat: add log timer for presstest * fix: session pool error * feat: can choose whether return embedding in some graph db functions * fix: log * feat: change system prompts
1 parent 2a32911 commit 0686fb2

File tree

10 files changed

+455
-322
lines changed

10 files changed

+455
-322
lines changed

src/memos/graph_dbs/base.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,27 @@ def edge_exists(self, source_id: str, target_id: str, type: str) -> bool:
7070

7171
# Graph Query & Reasoning
7272
@abstractmethod
73-
def get_node(self, id: str) -> dict[str, Any] | None:
73+
def get_node(self, id: str, include_embedding: bool = False) -> dict[str, Any] | None:
7474
"""
7575
Retrieve the metadata and content of a node.
7676
Args:
7777
id: Node identifier.
78+
include_embedding: with/without embedding
7879
Returns:
7980
Dictionary of node fields, or None if not found.
8081
"""
8182

83+
@abstractmethod
84+
def get_nodes(self, id: str, include_embedding: bool = False) -> dict[str, Any] | None:
85+
"""
86+
Retrieve the metadata and memory of a list of nodes.
87+
Args:
88+
ids: List of Node identifier.
89+
include_embedding: with/without embedding
90+
Returns:
91+
list[dict]: Parsed node records containing 'id', 'memory', and 'metadata'.
92+
"""
93+
8294
@abstractmethod
8395
def get_neighbors(
8496
self, id: str, type: str, direction: Literal["in", "out", "both"] = "out"
@@ -163,7 +175,9 @@ def get_by_metadata(self, filters: list[dict[str, Any]]) -> list[str]:
163175
"""
164176

165177
@abstractmethod
166-
def get_structure_optimization_candidates(self, scope: str) -> list[dict]:
178+
def get_structure_optimization_candidates(
179+
self, scope: str, include_embedding: bool = False
180+
) -> list[dict]:
167181
"""
168182
Find nodes that are likely candidates for structure optimization:
169183
- Isolated nodes, nodes with empty background, or nodes with exactly one child.
@@ -205,7 +219,7 @@ def clear(self) -> None:
205219
"""
206220

207221
@abstractmethod
208-
def export_graph(self) -> dict[str, Any]:
222+
def export_graph(self, include_embedding: bool = False) -> dict[str, Any]:
209223
"""
210224
Export the entire graph as a serializable dictionary.
211225
@@ -221,3 +235,16 @@ def import_graph(self, data: dict[str, Any]) -> None:
221235
Args:
222236
data: A dictionary containing all nodes and edges to be loaded.
223237
"""
238+
239+
@abstractmethod
240+
def get_all_memory_items(self, scope: str, include_embedding: bool = False) -> list[dict]:
241+
"""
242+
Retrieve all memory items of a specific memory_type.
243+
244+
Args:
245+
scope (str): Must be one of 'WorkingMemory', 'LongTermMemory', or 'UserMemory'.
246+
include_embedding: with/without embedding
247+
248+
Returns:
249+
list[dict]: Full list of memory items under this scope.
250+
"""

0 commit comments

Comments
 (0)