Skip to content

Commit c7e9af4

Browse files
Wang-Daojiyuan.wang
andauthored
Feat/pref optimize update (#431)
* 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 --------- Co-authored-by: yuan.wang <[email protected]>
1 parent 9c5d9fb commit c7e9af4

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/memos/memories/textual/prefer_text_memory/adder.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23

34
from abc import ABC, abstractmethod
45
from concurrent.futures import as_completed
@@ -287,7 +288,7 @@ def _update_memory(
287288
retrieved_memories: list[MilvusVecDBItem],
288289
collection_name: str,
289290
preference_type: str,
290-
update_mode: str = "fine",
291+
update_mode: str = "fast",
291292
) -> list[str] | str | None:
292293
"""Update the memory.
293294
Args:
@@ -326,7 +327,11 @@ def _process_single_memory(self, memory: TextualMemoryItem) -> list[str] | str |
326327
search_results.sort(key=lambda x: x.score, reverse=True)
327328

328329
return self._update_memory(
329-
memory, search_results, collection_name, preference_type, update_mode="fast"
330+
memory,
331+
search_results,
332+
collection_name,
333+
preference_type,
334+
update_mode=os.getenv("PREFERENCE_ADDER_MODE", "fast"),
330335
)
331336

332337
except Exception as e:

src/memos/templates/prefer_complete_prompt.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,24 @@
6262

6363
NAIVE_IMPLICIT_PREFERENCE_EXTRACT_PROMPT = """
6464
You are a preference inference assistant. Please extract **implicit preferences** from the following conversation
65-
(preferences that the user did not explicitly state but can be reasonably inferred from context, behavior, frequency, comparisons, exclusions, or scenario choices).
65+
(preferences that the user did not explicitly state but can be reasonably inferred from their underlying motivations, behavioral patterns, decision-making logic, and latent needs).
6666
6767
Notes:
68-
- Implicit preferences refer to user inclinations or choices that are not directly expressed, but can be reasonably inferred from factual cues in the conversation.
68+
- Implicit preferences refer to user inclinations or choices that are not directly expressed, but can be deeply inferred by analyzing:
69+
* **Hidden motivations**: What underlying needs or goals might drive the user's behavior?
70+
* **Behavioral patterns**: What recurring patterns or tendencies can be observed?
71+
* **Decision-making logic**: What reasoning or trade-offs might the user be considering?
72+
* **Latent preferences**: What preferences might the user have but haven't yet articulated?
73+
* **Contextual signals**: What do the user's choices, comparisons, exclusions, or scenario selections reveal about their deeper preferences?
6974
- Do not treat explicitly stated preferences as implicit preferences; this prompt is only for inferring preferences that are not directly mentioned.
75+
- Go beyond surface-level facts to understand the user's hidden possibilities and underlying logic.
7076
7177
Requirements:
7278
1. Only make inferences when there is sufficient evidence in the conversation; avoid unsupported or far-fetched guesses.
7379
2. Inferred implicit preferences must not conflict with explicit preferences.
7480
3. For implicit_preference: only output the preference statement itself; do not include any extra explanation, reasoning, or confidence information. Put all reasoning and explanation in the reasoning field.
75-
4. If no implicit preference can be reasonably inferred, leave the implicit_preference field empty (do not output anything else).
81+
4. In the reasoning field, explicitly explain the underlying logic and hidden motivations you identified.
82+
5. If no implicit preference can be reasonably inferred, leave the implicit_preference field empty (do not output anything else).
7683
7784
Conversation:
7885
{qa_pair}
@@ -82,7 +89,7 @@
8289
{
8390
"implicit_preference": "A concise natural language statement of the implicit preferences reasonably inferred from the conversation, or an empty string",
8491
"context_summary": "The corresponding context summary, which is a summary of the corresponding conversation, do not lack any scenario information",
85-
"reasoning": "Briefly explain the reasoning process for the implicit preference"
92+
"reasoning": "Explain the underlying logic, hidden motivations, and behavioral patterns that led to this inference"
8693
}
8794
```
8895
Don't output anything except the JSON.
@@ -91,17 +98,24 @@
9198

9299
NAIVE_IMPLICIT_PREFERENCE_EXTRACT_PROMPT_ZH = """
93100
你是一个偏好推理助手。请从以下对话中提取**隐式偏好**
94-
(用户没有明确表述,但可以从上下文、行为、频率、比较、排除或场景选择中合理推断出的偏好)。
101+
(用户没有明确表述,但可以通过分析其潜在动机、行为模式、决策逻辑和隐藏需求深度推断出的偏好)。
95102
96103
注意事项:
97-
- 隐式偏好是指用户未直接表达,但可以从对话中的事实线索合理推断出的倾向或选择。
104+
- 隐式偏好是指用户未直接表达,但可以通过深入分析以下方面推断出的倾向或选择:
105+
* **隐藏动机**:什么样的潜在需求或目标可能驱动用户的行为?
106+
* **行为模式**:可以观察到什么样的重复模式或倾向?
107+
* **决策逻辑**:用户可能在考虑什么样的推理或权衡?
108+
* **潜在偏好**:用户可能有但尚未明确表达的偏好是什么?
109+
* **情境信号**:用户的选择、比较、排除或场景选择揭示了什么样的深层偏好?
98110
- 不要将明确陈述的偏好视为隐式偏好;此提示仅用于推断未直接提及的偏好。
111+
- 超越表面事实,理解用户的隐藏可能性和背后的逻辑。
99112
100113
要求:
101114
1. 仅在对话中有充分证据时进行推断;避免无根据或牵强的猜测。
102115
2. 推断的隐式偏好不得与显式偏好冲突。
103116
3. 对于 implicit_preference:仅输出偏好陈述本身;不要包含任何额外的解释、推理或置信度信息。将所有推理和解释放在 reasoning 字段中。
104-
4. 如果无法合理推断出隐式偏好,则将 implicit_preference 字段留空(不要输出其他任何内容)。
117+
4. 在 reasoning 字段中,明确解释你识别出的底层逻辑和隐藏动机。
118+
5. 如果无法合理推断出隐式偏好,则将 implicit_preference 字段留空(不要输出其他任何内容)。
105119
106120
对话:
107121
{qa_pair}
@@ -111,7 +125,7 @@
111125
{
112126
"implicit_preference": "从对话中合理推断出的隐式偏好的简洁自然语言陈述,或空字符串",
113127
"context_summary": "对应的上下文摘要,即对应对话的摘要,不要遗漏任何场景信息",
114-
"reasoning": "简要解释隐式偏好的推理过程"
128+
"reasoning": "解释推断出该偏好的底层逻辑、隐藏动机和行为模式"
115129
}
116130
```
117131
除JSON外不要输出任何其他内容。

0 commit comments

Comments
 (0)