Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graph memory update_memory_prompt use both entities and relations #2008

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GingerMoon
Copy link
Contributor

@GingerMoon GingerMoon commented Nov 4, 2024

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.

  • [Bug fix (non-breaking change which fixes an issue)

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.

  • Unit Test

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Made sure Checks passed

@GingerMoon
Copy link
Contributor Author

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'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant