Skip to content

Commit 38b495e

Browse files
Wang-Daojiyuan.wangfridayL
authored
Feat/fix palyground bug (#701)
* fix playground bug, internet search judge * fix playground internet bug * modify delete mem * modify tool resp bug in multi cube * fix bug in playground chat handle and search inter * modify prompt * fix bug in playground * fix bug playfround * fix bug * fix code * fix model bug in playground * modify plan b * llm param modify * add logger in playground * modify code * fix bug * modify code * modify code * fix bug * fix search bug in plarground * fixx bug * move schadualr to back * modify pref location * modify fast net search * add tags and new package * modify prompt fix bug * remove nltk due to image promblem * prompt modify * modify bug remove redundant field * modify bug * fix playground bug * fix bug * bust internet topk * bust to 50 * fix bug cite * modify search --------- Co-authored-by: yuan.wang <[email protected]> Co-authored-by: chunyu li <[email protected]>
1 parent 87e1833 commit 38b495e

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/memos/api/handlers/chat_handler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,15 +505,16 @@ def generate_chat_response() -> Generator[str, None, None]:
505505

506506
# Filter memories by threshold, min_num is the min number of memories for playground
507507
second_filtered_memories = self._filter_memories_by_threshold(
508-
memories_list, min_num=30
508+
memories_list, min_num=35
509509
)
510510

511511
# dedup and supplement memories
512512
fast_length = len(filtered_memories)
513513
supplement_length = max(0, 50 - fast_length) # 50 is the max mem for playground
514-
filtered_memories = self._dedup_and_supplement_memories(
514+
second_dedup_memories = self._dedup_and_supplement_memories(
515515
filtered_memories, second_filtered_memories
516516
)[:supplement_length]
517+
filtered_memories = filtered_memories + second_dedup_memories
517518

518519
# Prepare remain reference data (second search)
519520
reference = prepare_reference_data(filtered_memories)

src/memos/memories/textual/tree_text_memory/retrieve/bochasearch.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,17 @@ def __init__(self, api_key: str, max_results: int = 20):
4646
"Content-Type": "application/json",
4747
}
4848

49-
def search_web(self, query: str, summary: bool = True, freshness="noLimit") -> list[dict]:
49+
def search_web(
50+
self, query: str, summary: bool = True, freshness="noLimit", max_results=None
51+
) -> list[dict]:
5052
"""
5153
Perform a Web Search (equivalent to the first curl).
5254
5355
Args:
5456
query: Search query string
5557
summary: Whether to include summary in the results
5658
freshness: Freshness filter (e.g. 'noLimit', 'day', 'week')
59+
max_results: Maximum number of results to retrieve, bocha is limited to 50
5760
5861
Returns:
5962
A list of search result dicts
@@ -62,12 +65,17 @@ def search_web(self, query: str, summary: bool = True, freshness="noLimit") -> l
6265
"query": query,
6366
"summary": summary,
6467
"freshness": freshness,
65-
"count": self.max_results,
68+
"count": max_results or self.max_results,
6669
}
6770
return self._post(self.web_url, body)
6871

6972
def search_ai(
70-
self, query: str, answer: bool = False, stream: bool = False, freshness="noLimit"
73+
self,
74+
query: str,
75+
answer: bool = False,
76+
stream: bool = False,
77+
freshness="noLimit",
78+
max_results=None,
7179
) -> list[dict]:
7280
"""
7381
Perform an AI Search (equivalent to the second curl).
@@ -77,14 +85,15 @@ def search_ai(
7785
answer: Whether BochaAI should generate an answer
7886
stream: Whether to use streaming response
7987
freshness: Freshness filter (e.g. 'noLimit', 'day', 'week')
88+
max_results: Maximum number of results to retrieve, bocha is limited to 50
8089
8190
Returns:
8291
A list of search result dicts
8392
"""
8493
body = {
8594
"query": query,
8695
"freshness": freshness,
87-
"count": self.max_results,
96+
"count": max_results or self.max_results,
8897
"answer": answer,
8998
"stream": stream,
9099
}
@@ -276,7 +285,7 @@ def retrieve_from_internet(
276285
Returns:
277286
List of TextualMemoryItem
278287
"""
279-
search_results = self.bocha_api.search_ai(query) # ✅ default to
288+
search_results = self.bocha_api.search_ai(query, max_results=top_k) # ✅ default to
280289
# web-search
281290
return self._convert_to_mem_items(search_results, query, parsed_goal, info, mode=mode)
282291

src/memos/memories/textual/tree_text_memory/retrieve/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
1. Keys: the high-level keywords directly relevant to the user’s task.
55
2. Tags: thematic tags to help categorize and retrieve related memories.
66
3. Goal Type: retrieval | qa | generation
7-
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.
7+
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.
88
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.
99
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.
1010

0 commit comments

Comments
 (0)