graph_extraction.yaml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. graph_extraction:
  2. template: >
  3. # Context
  4. {document_summary}
  5. # Goal
  6. Given both a document summary and full text, identify all entities and their entity types, along with all relationships among the identified entities.
  7. # Steps
  8. 1. Identify all entities given the full text, grounding and contextualizing them based on the summary. For each identified entity, extract:
  9. - entity: Name of the entity, capitalized
  10. - entity_type: Type of the entity (constrained to {entity_types} if provided, otherwise all types)
  11. - entity_description: Comprehensive description incorporating context from both summary and full text
  12. Format each Entity in XML tags as follows: <entity name="entity"><type>entity_type</type><description>entity_description</description></entity>
  13. Note: Generate additional entities from descriptions if they contain named entities for relationship mapping.
  14. 2. From the identified entities, identify all related entity pairs, using both summary and full text context:
  15. - source_entity: name of the source entity
  16. - target_entity: name of the target entity
  17. - relation: relationship type (constrained to {relation_types} if provided)
  18. - relationship_description: justification based on both summary and full text context
  19. - relationship_weight: strength score 0-10
  20. Format each relationship in XML tags as follows: <relationship><source>source_entity</source><target>target_entity</target><type>relation</type><description>relationship_description</description><weight>relationship_weight</weight></relationship>
  21. 3. Coverage Requirements:
  22. - Each entity must have at least one relationship
  23. - Create intermediate entities if needed to establish relationships
  24. - Verify relationships against both summary and full text
  25. - Resolve any discrepancies between sources
  26. Example 1:
  27. If the list is empty, extract all entities and relations.
  28. Entity_types:
  29. Relation_types:
  30. Text:
  31. San Francisco is a city in California. It is known for the Golden Gate Bridge, cable cars, and steep hills. The city is surrounded by the Pacific Ocean and the San Francisco Bay.
  32. ######################
  33. Output:
  34. <entity name="San Francisco"><type>City</type><description>San Francisco is a city in California known for the Golden Gate Bridge, cable cars, and steep hills. It is surrounded by the Pacific Ocean and the San Francisco Bay.</description></entity>
  35. <entity name="California"><type>State</type><description>California is a state in the United States.</description></entity>
  36. <entity name="Golden Gate Bridge"><type>Landmark</type><description>The Golden Gate Bridge is a famous bridge in San Francisco.</description></entity>
  37. <entity name="Pacific Ocean"><type>Body of Water</type><description>The Pacific Ocean is a large body of water that surrounds San Francisco.</description></entity>
  38. <entity name="San Francisco Bay"><type>Body of Water</type><description>The San Francisco Bay is a body of water that surrounds San Francisco.</description></entity>
  39. <relationship><source>San Francisco</source><target>California</target><type>Located In</type><description>San Francisco is a city located in California.</description><weight>8</weight></relationship>
  40. <relationship><source>San Francisco</source><target>Golden Gate Bridge</target><type>Features</type><description>San Francisco features the Golden Gate Bridge.</description><weight>9</weight></relationship>
  41. <relationship><source>San Francisco</source><target>Pacific Ocean</target><type>Surrounded By</type><description>San Francisco is surrounded by the Pacific Ocean.</description><weight>7</weight></relationship>
  42. <relationship><source>San Francisco</source><target>San Francisco Bay</target><type>Surrounded By</type><description>San Francisco is surrounded by the San Francisco Bay.</description><weight>7</weight></relationship>
  43. <relationship><source>California</source><target>San Francisco</target><type>Contains</type><description>California contains the city of San Francisco.</description><weight>8</weight></relationship>
  44. <relationship><source>Golden Gate Bridge</source><target>San Francisco</target><type>Located In</type><description>The Golden Gate Bridge is located in San Francisco.</description><weight>8</weight></relationship>
  45. <relationship><source>Pacific Ocean</source><target>San Francisco</target><type>Surrounds</type><description>The Pacific Ocean surrounds San Francisco.</description><weight>7</weight></relationship>
  46. <relationship><source>San Francisco Bay</source><target>San Francisco</target><type>Surrounds</type><description>The San Francisco Bay surrounds San Francisco.</description><weight>7</weight></relationship>
  47. ######################
  48. Example 2:
  49. If the list is empty, extract all entities and relations.
  50. Entity_types: Organization, Person
  51. Relation_types: Located In, Features
  52. Text:
  53. The Green Bay Packers are a professional American football team based in Green Bay, Wisconsin. The team was established in 1919 by Earl "Curly" Lambeau and George Calhoun. The Packers are the third-oldest franchise in the NFL and have won 13 league championships, including four Super Bowls. The team's home games are played at Lambeau Field, which is named after Curly Lambeau.
  54. ######################
  55. Output:
  56. <entity name="Green Bay Packers"><type>Organization</type><description>The Green Bay Packers are a professional American football team based in Green Bay, Wisconsin. The team was established in 1919 by Earl "Curly" Lambeau and George Calhoun. The Packers are the third-oldest franchise in the NFL and have won 13 league championships, including four Super Bowls. The team's home games are played at Lambeau Field, which is named after Curly Lambeau.</description></entity>
  57. <entity name="Green Bay"><type>City</type><description>Green Bay is a city in Wisconsin.</description></entity>
  58. <entity name="Wisconsin"><type>State</type><description>Wisconsin is a state in the United States.</description></entity>
  59. <entity name="Earl "Curly" Lambeau"><type>Person</type><description>Earl "Curly" Lambeau was a co-founder of the Green Bay Packers.</description></entity>
  60. <entity name="George Calhoun"><type>Person</type><description>George Calhoun was a co-founder of the Green Bay Packers.</description></entity>
  61. <entity name="NFL"><type>Organization</type><description>The NFL is the National Football League.</description></entity>
  62. <entity name="Super Bowl"><type>Event</type><description>The Super Bowl is the championship game of the NFL.</description></entity>
  63. <entity name="Lambeau Field"><type>Stadium</type><description>Lambeau Field is the home stadium of the Green Bay Packers.</description></entity>
  64. <relationship><source>Green Bay Packers</source><target>Green Bay</target><type>Located In</type><description>The Green Bay Packers are based in Green Bay, Wisconsin.</description><weight>8</weight></relationship>
  65. <relationship><source>Green Bay</source><target>Wisconsin</target><type>Located In</type><description>Green Bay is located in Wisconsin.</description><weight>8</weight></relationship>
  66. <relationship><source>Green Bay Packers</source><target>Earl "Curly" Lambeau</target><type>Founded By</type><description>The Green Bay Packers were established by Earl "Curly" Lambeau.</description><weight>9</weight></relationship>
  67. <relationship><source>Green Bay Packers</source><target>George Calhoun</target><type>Founded By</type><description>The Green Bay Packers were established by George Calhoun.</description><weight>9</weight></relationship>
  68. <relationship><source>Green Bay Packers</source><target>NFL</target><type>League</type><description>The Green Bay Packers are a franchise in the NFL.</description><weight>8</weight></relationship>
  69. <relationship><source>Green Bay Packers</source><target>Super Bowl</target><type>Championships</type><description>The Green Bay Packers have won four Super Bowls.</description><weight>9</weight></relationship>
  70. -Real Data-
  71. ######################
  72. If the list is empty, extract all entities and relations.
  73. Entity_types: {entity_types}
  74. Relation_types: {relation_types}
  75. Document Summary:
  76. {document_summary}
  77. Full Text:
  78. {input}
  79. ######################
  80. Output:
  81. input_types:
  82. document_summary: str
  83. max_knowledge_relationships: int
  84. input: str
  85. entity_types: list[str]
  86. relation_types: list[str]
  87. overwrite_on_diff: true