Skip to content

Commit c9840e4

Browse files
authored
Merge branch 'dev' into dev
2 parents 9d869ed + c1e1a85 commit c9840e4

File tree

21 files changed

+1284
-437
lines changed

21 files changed

+1284
-437
lines changed

.github/workflows/python-tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ jobs:
4141
steps:
4242
- uses: actions/checkout@v4
4343
- name: Install poetry
44-
run: pipx install poetry
44+
# This is a temporary fix to ensure compatibility with Poetry & virtualenv
45+
# Revert to the original installation method once the poetry==2.1.4 is released
46+
run: |
47+
echo "virtualenv==20.32.0" > constraints.txt
48+
pipx install poetry==2.1.3 --pip-args="--constraint=constraints.txt"
49+
rm constraints.txt
4550
- name: Set up Python ${{ matrix.python-version }}
4651
uses: actions/setup-python@v5
4752
with:

docs/openapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@
884884
"type": "string",
885885
"title": "Session Id",
886886
"description": "Session ID for the MOS. This is used to distinguish between different dialogue",
887-
"default": "842877f4-c3f7-4c22-ad38-5950026870fe"
887+
"default": "0ce84b9c-0615-4b9d-83dd-fba50537d5d3"
888888
},
889889
"chat_model": {
890890
"$ref": "#/components/schemas/LLMConfigFactory",

src/memos/api/context/dependencies.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23

34
from fastapi import Depends, Header, Request
45

@@ -24,6 +25,13 @@ def get_trace_id_from_header(
2425
return g_trace_id or x_trace_id or trace_id
2526

2627

28+
def generate_trace_id() -> str:
29+
"""
30+
Get a random trace_id.
31+
"""
32+
return os.urandom(16).hex()
33+
34+
2735
def get_request_context(
2836
request: Request, trace_id: str | None = Depends(get_trace_id_from_header)
2937
) -> RequestContext:
@@ -57,6 +65,9 @@ def get_g_object(trace_id: str | None = Depends(get_trace_id_from_header)) -> G:
5765
This creates a RequestContext and sets it globally for access
5866
throughout the request lifecycle.
5967
"""
68+
if trace_id is None:
69+
trace_id = generate_trace_id()
70+
6071
g = RequestContext(trace_id=trace_id)
6172
set_request_context(g)
6273
logger.info(f"Request g object created with trace_id: {g.trace_id}")

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)