diff --git a/src/memos/api/handlers/chat_handler.py b/src/memos/api/handlers/chat_handler.py index ba98a06a9..02df810c7 100644 --- a/src/memos/api/handlers/chat_handler.py +++ b/src/memos/api/handlers/chat_handler.py @@ -505,15 +505,16 @@ def generate_chat_response() -> Generator[str, None, None]: # Filter memories by threshold, min_num is the min number of memories for playground second_filtered_memories = self._filter_memories_by_threshold( - memories_list, min_num=30 + memories_list, min_num=35 ) # dedup and supplement memories fast_length = len(filtered_memories) supplement_length = max(0, 50 - fast_length) # 50 is the max mem for playground - filtered_memories = self._dedup_and_supplement_memories( + second_dedup_memories = self._dedup_and_supplement_memories( filtered_memories, second_filtered_memories )[:supplement_length] + filtered_memories = filtered_memories + second_dedup_memories # Prepare remain reference data (second search) reference = prepare_reference_data(filtered_memories) diff --git a/src/memos/memories/textual/tree_text_memory/retrieve/bochasearch.py b/src/memos/memories/textual/tree_text_memory/retrieve/bochasearch.py index 940202cc3..8d68e6ea7 100644 --- a/src/memos/memories/textual/tree_text_memory/retrieve/bochasearch.py +++ b/src/memos/memories/textual/tree_text_memory/retrieve/bochasearch.py @@ -46,7 +46,9 @@ def __init__(self, api_key: str, max_results: int = 20): "Content-Type": "application/json", } - def search_web(self, query: str, summary: bool = True, freshness="noLimit") -> list[dict]: + def search_web( + self, query: str, summary: bool = True, freshness="noLimit", max_results=None + ) -> list[dict]: """ Perform a Web Search (equivalent to the first curl). @@ -54,6 +56,7 @@ def search_web(self, query: str, summary: bool = True, freshness="noLimit") -> l query: Search query string summary: Whether to include summary in the results freshness: Freshness filter (e.g. 'noLimit', 'day', 'week') + max_results: Maximum number of results to retrieve, bocha is limited to 50 Returns: A list of search result dicts @@ -62,12 +65,17 @@ def search_web(self, query: str, summary: bool = True, freshness="noLimit") -> l "query": query, "summary": summary, "freshness": freshness, - "count": self.max_results, + "count": max_results or self.max_results, } return self._post(self.web_url, body) def search_ai( - self, query: str, answer: bool = False, stream: bool = False, freshness="noLimit" + self, + query: str, + answer: bool = False, + stream: bool = False, + freshness="noLimit", + max_results=None, ) -> list[dict]: """ Perform an AI Search (equivalent to the second curl). @@ -77,6 +85,7 @@ def search_ai( answer: Whether BochaAI should generate an answer stream: Whether to use streaming response freshness: Freshness filter (e.g. 'noLimit', 'day', 'week') + max_results: Maximum number of results to retrieve, bocha is limited to 50 Returns: A list of search result dicts @@ -84,7 +93,7 @@ def search_ai( body = { "query": query, "freshness": freshness, - "count": self.max_results, + "count": max_results or self.max_results, "answer": answer, "stream": stream, } @@ -276,7 +285,7 @@ def retrieve_from_internet( Returns: List of TextualMemoryItem """ - search_results = self.bocha_api.search_ai(query) # ✅ default to + search_results = self.bocha_api.search_ai(query, max_results=top_k) # ✅ default to # web-search return self._convert_to_mem_items(search_results, query, parsed_goal, info, mode=mode) 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 8659b6112..8750187a3 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. 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 easy enough to understand, 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.