Skip to content

Commit b58a3eb

Browse files
committed
Improve dedupe prompt
1 parent 11b5076 commit b58a3eb

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

packages/memory_module/core/memory_core.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,35 @@ async def _extract_memory_processing_decision(
208208
old_memory_content = "\n".join(
209209
[f"<MEMORY created_at={str(memory.created_at)}>{memory.content}</MEMORY>" for memory in old_memories]
210210
)
211-
system_message = f"""You are a semantic memory management agent. Your goal is to determine whether this new memory is duplicated with existing old memories.
211+
system_message = f"""You are a semantic memory management agent. Your task is to decide whether the new memory should be added to the memory system or ignored as a duplicate.
212+
212213
Considerations:
213-
- Time-based order: Each old memory has a creation time. Please take creation time into consideration.
214-
- Repeated behavior: If the new memory indicates a repeated idea over a period of time, it should be added to reflect the pattern.
215-
Return value:
216-
- Add: add new memory while keep old memories
217-
- Ignore: indicates that this memory is similar to an older memory and should be ignored
214+
1. Context Overlap:
215+
If the new memory conveys information that is substantially covered by an existing memory, it should be ignored.
216+
If the new memory adds unique or specific information not present in any old memory, it should be added.
217+
2. Granularity of Detail:
218+
Broader or more general memories should not replace specific ones. However, a specific detail can replace a general statement if it conveys the same underlying idea.
219+
For example:
220+
Old memory: “The user enjoys hiking in national parks.”
221+
New memory: “The user enjoys hiking in Yellowstone National Park.”
222+
Result: Ignore (The older memory already encompasses the specific case).
223+
3. Repeated Patterns:
224+
If the new memory reinforces a pattern of behavior over time (e.g., multiple mentions of a recurring habit, preference, or routine), it should be added to reflect this trend.
225+
4. Temporal Relevance:
226+
If the new memory reflects a significant change or update to the old memory, it should be added.
227+
For example:
228+
Old memory: “The user is planning a trip to Japan.”
229+
New memory: “The user has canceled their trip to Japan.”
230+
Result: Add (The new memory reflects a change).
231+
232+
Process:
233+
1. Compare the specificity, unique details, and time relevance of the new memory against old memories.
234+
2. Decide whether to add or ignore based on the considerations above.
235+
3. Provide a clear and concise justification for your decision.
236+
218237
Here are the old memories:
219238
{old_memory_content}
239+
220240
Here is the new memory:
221241
{new_memory} created at {str(datetime.datetime.now())}
222242
""" # noqa: E501

0 commit comments

Comments
 (0)