Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/memos/mem_reader/multi_modal_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,19 @@ def _build_window_from_items(
if aggregated_file_ids:
extra_kwargs["file_ids"] = aggregated_file_ids

# Propagate manager_user_id and project_id from constituent items
for item in items:
metadata = getattr(item, "metadata", None)
if metadata is not None:
if not extra_kwargs.get("manager_user_id"):
mid = getattr(metadata, "manager_user_id", None)
if mid:
extra_kwargs["manager_user_id"] = mid
if not extra_kwargs.get("project_id"):
pid = getattr(metadata, "project_id", None)
if pid:
extra_kwargs["project_id"] = pid

# Extract info fields
info_ = info.copy()
user_id = info_.pop("user_id", "")
Expand Down Expand Up @@ -1055,6 +1068,7 @@ def _process_multi_modal_data(
custom_tags=custom_tags,
info=info,
lang=lang,
user_context=kwargs.get("user_context"),
)
fine_memory_items.extend(items)
return fine_memory_items
Expand Down Expand Up @@ -1124,7 +1138,12 @@ def _process_transfer_multi_modal_data(
for source in sources:
lang = getattr(source, "lang", "en")
items = self.multi_modal_parser.process_transfer(
source, context_items=[raw_node], info=info, custom_tags=custom_tags, lang=lang
source,
context_items=[raw_node],
info=info,
custom_tags=custom_tags,
lang=lang,
user_context=kwargs.get("user_context"),
)
fine_memory_items.extend(items)
return fine_memory_items
Expand Down
26 changes: 25 additions & 1 deletion src/memos/mem_reader/simple_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
if TYPE_CHECKING:
from memos.graph_dbs.base import BaseGraphDB
from memos.memories.textual.tree_text_memory.retrieve.searcher import Searcher
from memos.types.general_types import UserContext
from memos.mem_reader.read_multi_modal import coerce_scene_data, detect_lang
from memos.mem_reader.utils import (
count_tokens_text,
Expand Down Expand Up @@ -340,6 +341,14 @@ def _process_chat_data(self, scene_data_info, info, **kwargs):
"custom_tags", None
) # must pop here, avoid add to info, only used in sync fine mode

user_context: UserContext | None = kwargs.get("user_context")
ctx_kwargs: dict[str, Any] = {}
if user_context:
if user_context.manager_user_id:
ctx_kwargs["manager_user_id"] = user_context.manager_user_id
if user_context.project_id:
ctx_kwargs["project_id"] = user_context.project_id

if mode == "fast":
logger.debug("Using unified Fast Mode")

Expand All @@ -349,7 +358,12 @@ def _build_fast_node(w):
mem_type = "UserMemory" if roles == {"user"} else "LongTermMemory"
tags = ["mode:fast"]
return self._make_memory_item(
value=text, info=info, memory_type=mem_type, tags=tags, sources=w["sources"]
value=text,
info=info,
memory_type=mem_type,
tags=tags,
sources=w["sources"],
**ctx_kwargs,
)

with ContextThreadPoolExecutor(max_workers=8) as ex:
Expand Down Expand Up @@ -385,6 +399,7 @@ def _build_fast_node(w):
key=m.get("key", ""),
sources=w["sources"],
background=resp.get("summary", ""),
**ctx_kwargs,
)
chat_read_nodes.append(node)
except Exception as e:
Expand All @@ -397,6 +412,14 @@ def _process_transfer_chat_data(
raw_memory = raw_node.memory
response_json = self._get_llm_response(raw_memory, custom_tags)

user_context: UserContext | None = kwargs.get("user_context")
ctx_kwargs: dict[str, Any] = {}
if user_context:
if user_context.manager_user_id:
ctx_kwargs["manager_user_id"] = user_context.manager_user_id
if user_context.project_id:
ctx_kwargs["project_id"] = user_context.project_id

chat_read_nodes = []
for memory_i_raw in response_json.get("memory list", []):
try:
Expand All @@ -423,6 +446,7 @@ def _process_transfer_chat_data(
background=response_json.get("summary", ""),
type_="fact",
confidence=0.99,
**ctx_kwargs,
)
chat_read_nodes.append(node_i)
except Exception as e:
Expand Down
Loading
Loading