Skip to content

Commit 387fe8a

Browse files
Wang-Daojiyuan.wang
andauthored
Feat/pref optimize update (#432)
* add hybrid search and fine extractor * add dialog and modify spliter chunk * optmize the update and retriever code * modify pref field * add pref mem update srategy * add pref mem update srategy * fix bug in pre_commit * modify pref filed * fix bug * fix pre_commit * fix bug in adder * fast * modify pref and adder mode * modify code * make pre_commit * fix pref_string for memos online api * modify code * modify code * modify code * pre comimt * modify code --------- Co-authored-by: yuan.wang <[email protected]>
1 parent c7e9af4 commit 387fe8a

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

evaluation/scripts/utils/client.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ def search(self, query, user_id, top_k):
234234
"user_id": user_id,
235235
"memory_limit_number": top_k,
236236
"mode": os.getenv("SEARCH_MODE", "fast"),
237+
"include_preference": True,
238+
"pref_top_k": 6,
237239
}
238240
)
239241

@@ -243,10 +245,38 @@ def search(self, query, user_id, top_k):
243245
response = requests.request("POST", url, data=payload, headers=self.headers)
244246
assert response.status_code == 200, response.text
245247
assert json.loads(response.text)["message"] == "ok", response.text
246-
res = json.loads(response.text)["data"]["memory_detail_list"]
247-
for i in res:
248+
text_mem_res = json.loads(response.text)["data"]["memory_detail_list"]
249+
pref_mem_res = json.loads(response.text)["data"]["preference_detail_list"]
250+
preference_note = json.loads(response.text)["data"]["preference_note"]
251+
for i in text_mem_res:
248252
i.update({"memory": i.pop("memory_value")})
249-
return {"text_mem": [{"memories": res}], "pref_str": ""}
253+
254+
explicit_prefs = [
255+
p["preference"]
256+
for p in pref_mem_res
257+
if p.get("preference_type", "") == "explicit_preference"
258+
]
259+
implicit_prefs = [
260+
p["preference"]
261+
for p in pref_mem_res
262+
if p.get("preference_type", "") == "implicit_preference"
263+
]
264+
265+
pref_parts = []
266+
if explicit_prefs:
267+
pref_parts.append(
268+
"Explicit Preference:\n"
269+
+ "\n".join(f"{i + 1}. {p}" for i, p in enumerate(explicit_prefs))
270+
)
271+
if implicit_prefs:
272+
pref_parts.append(
273+
"Implicit Preference:\n"
274+
+ "\n".join(f"{i + 1}. {p}" for i, p in enumerate(implicit_prefs))
275+
)
276+
277+
pref_string = "\n".join(pref_parts) + preference_note
278+
279+
return {"text_mem": [{"memories": text_mem_res}], "pref_string": pref_string}
250280
except Exception as e:
251281
if attempt < max_retries - 1:
252282
time.sleep(2**attempt)

0 commit comments

Comments
 (0)