[improvement]: Graph nodes extraction improved (#2035)
This commit is contained in:
@@ -18,50 +18,51 @@ Guidelines:
|
||||
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.
|
||||
|
||||
Memory Format:
|
||||
source -- RELATIONSHIP -- destination
|
||||
|
||||
Task Details:
|
||||
- Existing Graph Memories:
|
||||
======= Existing Graph Memories:=======
|
||||
{existing_memories}
|
||||
|
||||
- New Graph Memory: {memory}
|
||||
======= New Graph Memory:=======
|
||||
{new_memories}
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
EXTRACT_ENTITIES_PROMPT = """
|
||||
EXTRACT_RELATIONS_PROMPT = """
|
||||
|
||||
You are an advanced algorithm designed to extract structured information from text to construct knowledge graphs. Your goal is to capture comprehensive information while maintaining accuracy. Follow these key principles:
|
||||
You are an advanced algorithm designed to extract structured information from text to construct knowledge graphs. Your goal is to capture comprehensive and accurate information. Follow these key principles:
|
||||
|
||||
1. Extract only explicitly stated information from the text.
|
||||
2. Identify nodes (entities/concepts), their types, and relationships.
|
||||
3. Use "USER_ID" as the source node for any self-references (I, me, my, etc.) in user messages.
|
||||
2. Establish relationships among the entities provided.
|
||||
3. Use "USER_ID" as the source entity for any self-references (e.g., "I," "me," "my," etc.) in user messages.
|
||||
CUSTOM_PROMPT
|
||||
|
||||
Nodes and Types:
|
||||
- Aim for simplicity and clarity in node representation.
|
||||
- Use basic, general types for node labels (e.g. "person" instead of "mathematician").
|
||||
|
||||
Relationships:
|
||||
- Use consistent, general, and timeless relationship types.
|
||||
- Example: Prefer "PROFESSOR" over "BECAME_PROFESSOR".
|
||||
- Use consistent, general, and timeless relationship types.
|
||||
- Example: Prefer "PROFESSOR" over "BECAME_PROFESSOR."
|
||||
- Relationships should only be established among the entities explicitly mentioned in the user message.
|
||||
|
||||
Entity Consistency:
|
||||
- Use the most complete identifier for entities mentioned multiple times.
|
||||
- Example: Always use "John Doe" instead of variations like "Joe" or pronouns.
|
||||
- Ensure that relationships are coherent and logically align with the context of the message.
|
||||
- Maintain consistent naming for entities across the extracted data.
|
||||
|
||||
Strive for a coherent, easily understandable knowledge graph by maintaining consistency in entity references and relationship types.
|
||||
Strive to construct a coherent and easily understandable knowledge graph by eshtablishing all the relationships among the entities and adherence to the user’s context.
|
||||
|
||||
Adhere strictly to these guidelines to ensure high-quality knowledge graph extraction."""
|
||||
|
||||
|
||||
def get_update_memory_prompt(existing_memories, memory, template):
|
||||
return template.format(existing_memories=existing_memories, memory=memory)
|
||||
def get_update_memory_prompt(existing_memories, new_memories, template):
|
||||
return template.format(existing_memories=existing_memories, new_memories=new_memories)
|
||||
|
||||
|
||||
def get_update_memory_messages(existing_memories, memory):
|
||||
def get_update_memory_messages(existing_memories, new_memories):
|
||||
return [
|
||||
{
|
||||
"role": "user",
|
||||
"content": get_update_memory_prompt(existing_memories, memory, UPDATE_GRAPH_PROMPT),
|
||||
"content": get_update_memory_prompt(existing_memories, new_memories, UPDATE_GRAPH_PROMPT),
|
||||
},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user