From 2fe343f53235fcadc88e1577c95138d7f9116c57 Mon Sep 17 00:00:00 2001 From: Dubberman <48425266+whipser030@users.noreply.github.com> Date: Thu, 5 Feb 2026 16:34:38 +0800 Subject: [PATCH 1/2] hotfix: Code restoration, with the original content of the knowledge base replaced by the sources. (#1020) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit use knowledge source mem Co-authored-by: 黑布林 <11641432+heiheiyouyou@user.noreply.gitee.com> --- src/memos/api/handlers/search_handler.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/memos/api/handlers/search_handler.py b/src/memos/api/handlers/search_handler.py index 6eda1e2aa..f8ab90470 100644 --- a/src/memos/api/handlers/search_handler.py +++ b/src/memos/api/handlers/search_handler.py @@ -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 ( @@ -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}" ) From 97ab6b7ee5bce97c9d8179ca6712bbeb0ce8022e Mon Sep 17 00:00:00 2001 From: harvey_xiang Date: Fri, 6 Feb 2026 17:54:15 +0800 Subject: [PATCH 2/2] fix: format error --- src/memos/api/handlers/chat_handler.py | 24 ++++++++++++++---------- src/memos/mem_os/product.py | 12 +++++++----- src/memos/mem_os/product_server.py | 12 +++++++----- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/memos/api/handlers/chat_handler.py b/src/memos/api/handlers/chat_handler.py index 8292e027b..e847a0397 100644 --- a/src/memos/api/handlers/chat_handler.py +++ b/src/memos/api/handlers/chat_handler.py @@ -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 @@ -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( diff --git a/src/memos/mem_os/product.py b/src/memos/mem_os/product.py index 77a5e70c9..b2c74c384 100644 --- a/src/memos/mem_os/product.py +++ b/src/memos/mem_os/product.py @@ -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 diff --git a/src/memos/mem_os/product_server.py b/src/memos/mem_os/product_server.py index 758f2794d..80aefea85 100644 --- a/src/memos/mem_os/product_server.py +++ b/src/memos/mem_os/product_server.py @@ -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