Skip to content
Closed
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
24 changes: 14 additions & 10 deletions src/memos/api/handlers/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,12 +1323,14 @@ def run_async_in_thread():
)
# Add exception handling for the background task
task.add_done_callback(
lambda t: self.logger.error(
f"Error in background post-chat processing for user {user_id}: {t.exception()}",
exc_info=True,
lambda t: (
self.logger.error(
f"Error in background post-chat processing for user {user_id}: {t.exception()}",
exc_info=True,
)
if t.exception()
else None
)
if t.exception()
else None
)
except RuntimeError:
# No event loop, run in a new thread with context propagation
Expand Down Expand Up @@ -1390,12 +1392,14 @@ def run_async_in_thread():
)
)
task.add_done_callback(
lambda t: self.logger.error(
f"Error in background add to memory for user {user_id}: {t.exception()}",
exc_info=True,
lambda t: (
self.logger.error(
f"Error in background add to memory for user {user_id}: {t.exception()}",
exc_info=True,
)
if t.exception()
else None
)
if t.exception()
else None
)
except RuntimeError:
thread = ContextThread(
Expand Down
10 changes: 10 additions & 0 deletions src/memos/api/handlers/search_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import Any

from memos.api.handlers.base_handler import BaseHandler, HandlerDependencies
from memos.api.handlers.formatters_handler import rerank_knowledge_mem
from memos.api.product_models import APISearchRequest, SearchResponse
from memos.log import get_logger
from memos.memories.textual.tree_text_memory.retrieve.retrieve_utils import (
Expand Down Expand Up @@ -93,6 +94,15 @@ def handle_search_memories(self, search_req: APISearchRequest) -> SearchResponse
results = self._mmr_dedup_text_memories(results, original_top_k, pref_top_k)
self._strip_embeddings(results)

text_mem = results["text_mem"]
results["text_mem"] = rerank_knowledge_mem(
self.reranker,
query=search_req.query,
text_mem=text_mem,
top_k=original_top_k,
file_mem_proportion=0.5,
)

self.logger.info(
f"[SearchHandler] Final search results: count={len(results)} results={results}"
)
Expand Down
12 changes: 7 additions & 5 deletions src/memos/mem_os/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,12 +798,14 @@ def run_async_in_thread():
)
# Add exception handling for the background task
task.add_done_callback(
lambda t: logger.error(
f"Error in background post-chat processing for user {user_id}: {t.exception()}",
exc_info=True,
lambda t: (
logger.error(
f"Error in background post-chat processing for user {user_id}: {t.exception()}",
exc_info=True,
)
if t.exception()
else None
)
if t.exception()
else None
)
except RuntimeError:
# No event loop, run in a new thread with context propagation
Expand Down
12 changes: 7 additions & 5 deletions src/memos/mem_os/product_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,14 @@ def run_async_in_thread():
)
# Add exception handling for the background task
task.add_done_callback(
lambda t: logger.error(
f"Error in background post-chat processing for user {user_id}: {t.exception()}",
exc_info=True,
lambda t: (
logger.error(
f"Error in background post-chat processing for user {user_id}: {t.exception()}",
exc_info=True,
)
if t.exception()
else None
)
if t.exception()
else None
)
except RuntimeError:
# No event loop, run in a new thread with context propagation
Expand Down
Loading