liveBook · Manning

Relation extraction

As explained in Essential GraphRAG

Relationship extraction is the process of identifying and describing semantic connections between entities found in source text.

Relationship extraction identifies entities in source text and describes semantic connections between related entity pairs. It turns unstructured passages into structured records suitable for graph construction. section 7.2.2

A practical extraction prompt specifies:

  • Entity names, types, and comprehensive descriptions. section 7.2.2
  • Source and target entities for every clearly related pair. section 7.2.2
  • A relationship description and numeric strength score. section 7.2.2
  • Delimited output that can be parsed and imported into a graph database. section 7.2.2
Listing 7.5 Entity and relationship extraction
 ENTITY_TYPES = ["PERSON", "ORGANIZATION", "LOCATION",
  "GOD", "EVENT", "CREATURE", "WEAPON_OR_TOOL"]
def extract_entities(text: str) -> List[Dict]:      #1
    messages = [
        {"role": "user",
        "content": ch07_tools.create_extraction_prompt(ENTITY_TYPES, text)},  #2
    ]

    output = chat(messages, model = "gpt-4o") #3

    return ch07_tools.parse_extraction_output(output) #4

The implementation calls an extraction prompt with configured entity types, sends the text to GPT-4o, and parses the structured response. section 7.2.2

How Essential GraphRAG covers it

How deep it goes
Specifies entity and relationship fields, formatting delimiters, model invocation, and parsing, without detailing extraction evaluation.
Examples
Uses PERSON, ORGANIZATION, LOCATION, EVENT, CREATURE, and WEAPON_OR_TOOL entity types.
What it assumes
Assumes text chunks, configured entity types, a chat model, and an output parser.
What you can do after
Operate a Python extraction function that produces parsed entities and relationships for database import.
How it connects
Connects entities, knowledge graphs, GraphRAG, prompt engineering, and Neo4j graph import.

Also explained in

Compare how 3 books explain relation extraction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Essential GraphRAG. The section links point to the parts of the book it draws on.