diff --git a/src/memos/api/handlers/chat_handler.py b/src/memos/api/handlers/chat_handler.py index d8063a0cd..2a97f1934 100644 --- a/src/memos/api/handlers/chat_handler.py +++ b/src/memos/api/handlers/chat_handler.py @@ -405,7 +405,7 @@ def generate_chat_response() -> Generator[str, None, None]: readable_cube_ids=readable_cube_ids, mode="fast", internet_search=False, - top_k=5, + top_k=20, chat_history=chat_req.history, session_id=chat_req.session_id, include_preference=True, @@ -428,7 +428,7 @@ def generate_chat_response() -> Generator[str, None, None]: memories_list = text_mem_results[0]["memories"] # Filter memories by threshold - filtered_memories = self._filter_memories_by_threshold(memories_list) + filtered_memories = self._filter_memories_by_threshold(memories_list)[:5] # Prepare reference data (first search) reference = prepare_reference_data(filtered_memories) @@ -459,9 +459,7 @@ def generate_chat_response() -> Generator[str, None, None]: searcher = self.dependencies.searcher parsed_goal = searcher.task_goal_parser.parse( task_description=chat_req.query, - context="\n".join( - [memory.get("memory", "") for memory in filtered_memories] - ), + context="\n".join([memory.get("memory", "") for memory in memories_list]), conversation=chat_req.history, mode="fine", ) @@ -481,7 +479,7 @@ def generate_chat_response() -> Generator[str, None, None]: # ====== second deep search ====== search_req = APISearchRequest( query=(parsed_goal.rephrased_query or chat_req.query) - + (f"{parsed_goal.tags}" if parsed_goal.tags else ""), + + (f" {parsed_goal.memories}" if parsed_goal.memories else ""), user_id=chat_req.user_id, readable_cube_ids=readable_cube_ids, mode="fast", diff --git a/src/memos/memories/textual/tree_text_memory/retrieve/utils.py b/src/memos/memories/textual/tree_text_memory/retrieve/utils.py index 8750187a3..bcd47b078 100644 --- a/src/memos/memories/textual/tree_text_memory/retrieve/utils.py +++ b/src/memos/memories/textual/tree_text_memory/retrieve/utils.py @@ -4,7 +4,7 @@ 1. Keys: the high-level keywords directly relevant to the user’s task. 2. Tags: thematic tags to help categorize and retrieve related memories. 3. Goal Type: retrieval | qa | generation -4. Rephrased instruction: Give a rephrased task instruction based on the former conversation to make it less confusing to look alone. Make full use of information related to the query, including user's personal information, such as user's name, location, preferences, etc. If you think the task instruction is easy enough to understand, or there is no former conversation, set "rephrased_instruction" to an empty string. +4. Rephrased instruction: Give a rephrased task instruction based on the former conversation to make it less confusing to look alone. Make full use of information related to the query, including user's personal information, such as user's name, location, preferences, etc. If you think the task instruction is enough for search, or there is no former conversation, set "rephrased_instruction" to an empty string. 5. Need for internet search: If the user's task instruction only involves objective facts or can be completed without introducing external knowledge, set "internet_search" to False. Otherwise, set it to True. 6. Memories: Provide 2–5 short semantic expansions or rephrasings of the rephrased/original user task instruction. These are used for improved embedding search coverage. Each should be clear, concise, and meaningful for retrieval.