Skip to content

Commit 64615d8

Browse files
committed
feat: add logs
1 parent ee76644 commit 64615d8

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/memos/mem_os/core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import time
34
import uuid
45

56
from datetime import datetime
@@ -568,6 +569,7 @@ def search(
568569
and (mem_cube.text_mem is not None)
569570
and self.config.enable_textual_memory
570571
):
572+
time_start = time.time()
571573
memories = mem_cube.text_mem.search(
572574
query,
573575
top_k=top_k if top_k else self.config.top_k,
@@ -579,6 +581,10 @@ def search(
579581
logger.info(
580582
f"🧠 [Memory] Searched memories from {mem_cube_id}:\n{self._str_memories(memories)}\n"
581583
)
584+
search_time_end = time.time()
585+
logger.info(
586+
f"time search graph: search graph time user_id: {target_user_id} time is: {search_time_end - time_start}"
587+
)
582588
return result
583589

584590
def add(

src/memos/mem_os/product.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ def chat_with_references(
748748
internet_search=internet_search,
749749
)["text_mem"]
750750
yield f"data: {json.dumps({'type': 'status', 'data': '1'})}\n\n"
751+
search_time_end = time.time()
752+
logger.info(
753+
f"time chat: search text_mem time user_id: {user_id} time is: {search_time_end - time_start}"
754+
)
751755
self._send_message_to_scheduler(
752756
user_id=user_id, mem_cube_id=cube_id, query=query, label=QUERY_LABEL
753757
)
@@ -799,7 +803,10 @@ def chat_with_references(
799803
response_stream = self.chat_llm.generate(current_messages)
800804

801805
time_end = time.time()
802-
806+
chat_time_end = time.time()
807+
logger.info(
808+
f"time chat: chat time user_id: {user_id} time is: {chat_time_end - search_time_end}"
809+
)
803810
# Simulate streaming output with proper reference handling using tiktoken
804811

805812
# Initialize buffer for streaming
@@ -935,9 +942,14 @@ def get_all(
935942

936943
# Load user cubes if not already loaded
937944
self._load_user_cubes(user_id, self.default_cube_config)
945+
time_start = time.time()
938946
memory_list = super().get_all(
939947
mem_cube_id=mem_cube_ids[0] if mem_cube_ids else None, user_id=user_id
940948
)[memory_type]
949+
get_all_time_end = time.time()
950+
logger.info(
951+
f"time get_all: get_all time user_id: {user_id} time is: {get_all_time_end - time_start}"
952+
)
941953
reformat_memory_list = []
942954
if memory_type == "text_mem":
943955
for memory in memory_list:
@@ -995,6 +1007,10 @@ def get_all(
9951007
"memories": act_mem_params[0].model_dump(),
9961008
}
9971009
)
1010+
make_format_time_end = time.time()
1011+
logger.info(
1012+
f"time get_all: make_format time user_id: {user_id} time is: {make_format_time_end - get_all_time_end}"
1013+
)
9981014
return reformat_memory_list
9991015

10001016
def _get_subgraph(
@@ -1070,8 +1086,17 @@ def search(
10701086
"""Search memories for a specific user."""
10711087

10721088
# Load user cubes if not already loaded
1089+
time_start = time.time()
10731090
self._load_user_cubes(user_id, self.default_cube_config)
1091+
load_user_cubes_time_end = time.time()
1092+
logger.info(
1093+
f"time search: load_user_cubes time user_id: {user_id} time is: {load_user_cubes_time_end - time_start}"
1094+
)
10741095
search_result = super().search(query, user_id, install_cube_ids, top_k, mode=mode)
1096+
search_time_end = time.time()
1097+
logger.info(
1098+
f"time search: search text_mem time user_id: {user_id} time is: {search_time_end - load_user_cubes_time_end}"
1099+
)
10751100
text_memory_list = search_result["text_mem"]
10761101
reformat_memory_list = []
10771102
for memory in text_memory_list:
@@ -1087,7 +1112,10 @@ def search(
10871112
memories_list.append(memories)
10881113
reformat_memory_list.append({"cube_id": memory["cube_id"], "memories": memories_list})
10891114
search_result["text_mem"] = reformat_memory_list
1090-
1115+
time_end = time.time()
1116+
logger.info(
1117+
f"time search: total time for user_id: {user_id} time is: {time_end - time_start}"
1118+
)
10911119
return search_result
10921120

10931121
def add(

0 commit comments

Comments
 (0)