Skip to content

Commit cffe75c

Browse files
committed
feat: bocha search -> ai search
1 parent 6b17cc8 commit cffe75c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""BochaAI Search API retriever for tree text memory."""
22

3+
import json
4+
35
from concurrent.futures import ThreadPoolExecutor, as_completed
46
from datetime import datetime
57

@@ -87,7 +89,20 @@ def _post(self, url: str, body: dict) -> list[dict]:
8789
resp.raise_for_status()
8890
raw_data = resp.json()
8991

90-
# ✅ parse the nested structure correctly
92+
# parse the nested structure correctly
93+
# ✅ AI Search
94+
if "messages" in raw_data:
95+
results = []
96+
for msg in raw_data["messages"]:
97+
if msg.get("type") == "source" and msg.get("content_type") == "webpage":
98+
try:
99+
content_json = json.loads(msg["content"])
100+
results.extend(content_json.get("value", []))
101+
except Exception as e:
102+
logger.error(f"Failed to parse message content: {e}")
103+
return results
104+
105+
# ✅ Web Search
91106
return raw_data.get("data", {}).get("webPages", {}).get("value", [])
92107

93108
except Exception:
@@ -136,7 +151,8 @@ def retrieve_from_internet(
136151
Returns:
137152
List of TextualMemoryItem
138153
"""
139-
search_results = self.bocha_api.search_web(query) # ✅ default to web-search
154+
search_results = self.bocha_api.search_ai(query) # ✅ default to
155+
# web-search
140156
return self._convert_to_mem_items(search_results, query, parsed_goal, info)
141157

142158
def retrieve_from_web(

0 commit comments

Comments
 (0)