mem0ai / mem0

The Memory layer for your AI apps
https://mem0.ai
Apache License 2.0
22.94k stars 2.11k forks source link

graph memory update_memory_prompt use both entities and relations #2008

Open GingerMoon opened 2 weeks ago

GingerMoon commented 2 weeks ago

Description

graph memory update_memory_prompt only contains entites, does't contain relations. Hence the function call results (memory_updates) returns NOOP.

before fix:

update_memory_prompt is:

You are an AI expert specializing in graph memory management and optimization. Your task is to analyze existing graph memories alongside new information, and update the relationships in the memory list to ensure the most accurate, current, and coherent representation of knowledge.

Input:
1. Existing Graph Memories: A list of current graph memories, each containing source, target, and relationship information.
2. New Graph Memory: Fresh information to be integrated into the existing graph structure.

Guidelines:
1. Identification: Use the source and target as primary identifiers when matching existing memories with new information.
2. Conflict Resolution:
   - If new information contradicts an existing memory:
     a) For matching source and target but differing content, update the relationship of the existing memory.
     b) If the new memory provides more recent or accurate information, update the existing memory accordingly.
3. Comprehensive Review: Thoroughly examine each existing graph memory against the new information, updating relationships as necessary. Multiple updates may be required.
4. Consistency: Maintain a uniform and clear style across all memories. Each entry should be concise yet comprehensive.
5. Semantic Coherence: Ensure that updates maintain or improve the overall semantic structure of the graph.
6. Temporal Awareness: If timestamps are available, consider the recency of information when making updates.
7. Relationship Refinement: Look for opportunities to refine relationship descriptions for greater precision or clarity.
8. Redundancy Elimination: Identify and merge any redundant or highly similar relationships that may result from the update.

Task Details:
- Existing Graph Memories:
[]

- New Graph Memory: [{'node': 'wx', 'type': 'person'}, {'alias_of': 'wx女儿', 'node': '李四', 'type': 'person'}, {'node': '张三', 'type': 'person'}, {'node': '王二', 'type': 'person'}, {'node': '道格', 'type': 'cat'}, {'node': '凯蒂', 'type': 'dog'}, {'node': '咪咪', 'type': 'cat'}, {'node': '旺财', 'type': 'dog'}]

Output:
Provide a list of update instructions, each specifying the source, target, and the new relationship to be set. Only include memories that require updates.

tool_calls return noop

after fix:

update_memory_prompt is:

You are an AI expert specializing in graph memory management and optimization. Your task is to analyze existing graph memories alongside new information, and update the relationships in the memory list to ensure the most accurate, current, and coherent representation of knowledge.

Input:
1. Existing Graph Memories: A list of current graph memories, each containing source, target, and relationship information.
2. New Graph Memory: Fresh information to be integrated into the existing graph structure.

Guidelines:
1. Identification: Use the source and target as primary identifiers when matching existing memories with new information.
2. Conflict Resolution:
   - If new information contradicts an existing memory:
     a) For matching source and target but differing content, update the relationship of the existing memory.
     b) If the new memory provides more recent or accurate information, update the existing memory accordingly.
3. Comprehensive Review: Thoroughly examine each existing graph memory against the new information, updating relationships as necessary. Multiple updates may be required.
4. Consistency: Maintain a uniform and clear style across all memories. Each entry should be concise yet comprehensive.
5. Semantic Coherence: Ensure that updates maintain or improve the overall semantic structure of the graph.
6. Temporal Awareness: If timestamps are available, consider the recency of information when making updates.
7. Relationship Refinement: Look for opportunities to refine relationship descriptions for greater precision or clarity.
8. Redundancy Elimination: Identify and merge any redundant or highly similar relationships that may result from the update.

Task Details:
- Existing Graph Memories:
[]

- New Graph Memory: [[{'entity': 'wx', 'type': 'person'}, {'alias_of': 'wx女儿', 'entity': '李四', 'type': 'person'}, {'entity': '张三', 'type': 'person'}, {'entity': '王二', 'type': 'person'}, {'entity': '道格', 'type': 'cat'}, {'entity': '凯蒂', 'type': 'dog'}, {'entity': '咪咪', 'type': 'cat'}, {'entity': '旺财', 'type': 'dog'}], [{'relation': [{'object': '李四', 'predicate': 'DAUGHTER', 'subject': 'wx'}]}, {'relation': [{'object': '张三', 'predicate': 'FRIEND', 'subject': '李四'}, {'object': '王二', 'predicate': 'FRIEND', 'subject': '李四'}]}, {'relation': [{'object': '道格', 'predicate': 'PET', 'subject': '李四'}, {'object': '凯蒂', 'predicate': 'PET', 'subject': '李四'}]}, {'relation': [{'object': '咪咪', 'predicate': 'PET', 'subject': '张三'}]}, {'relation': [{'object': '旺财', 'predicate': 'PET', 'subject': '王二'}]}]]

Output:
Provide a list of update instructions, each specifying the source, target, and the new relationship to be set. Only include memories that require updates.

tool_calls return add_graph_memory

Fixes # (issue)

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Please delete options that are not relevant.

Checklist:

Maintainer Checklist

GingerMoon commented 2 weeks ago

I was using ollama "qwen2.5:14b" and get the above result (array containing two elements: entities and relations.). When I try another bigger model, the extracted_entities contains relations as below: {'destination_node': '李四', 'destination_type': 'person', 'relation': 'HAS_CHILD', 'source_node': 'wx', 'source_type': 'person'}