liveBook · Manning

Chapter 6: Constructing knowledge graphs with LLMs

What you will learn in chapter 6 of Essential GraphRAG

This chapter introduces using LLMs to extract structured information from unstructured text and turn it into a knowledge graph for queries that embeddings alone handle poorly.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduces using LLMs to extract structured information from unstructured text and turn it into a knowledge graph for queries that embeddings alone handle poorly.

Key terms: text embeddings, structured data extraction, filtering, counting, aggregation, knowledge graph, unstructured text, structured information, knowledge graph model, graph database

6.1 Extracting structured data from text

This section explains why embedding-only retrieval can fail for legal-document questions and introduces using LLMs to extract structured data for a Neo4j knowledge graph.

Key terms: text embeddings, text chunks, top k chunks, semantic similarity, structured data, unstructured data, structured data extraction, structured output, JSON, Neo4j

6.1.1 Structured Outputs model definition

This section explains how to define a Pydantic-based Structured Outputs schema that guides an LLM to extract reliable contract data from text.

Key terms: Structured Outputs, function calling, schema definitions, Pydantic, attributes, description, str, date, yyyy-MM-dd, String

6.1.2 Structured Outputs extraction request

This section shows how to request contract-data extraction from an LLM using OpenAI Structured Outputs, a guiding system message, and a function that returns a contract-model dictionary.

Key terms: OpenAI Structured Outputs, Contract data model, structured information, system message, domain, context, trial and error, extract function, GPT-4o, raw user-provided document text

6.1.3 CUAD dataset

This section demonstrates extracting a structured contract record from a CUAD legal-contract document with the previously defined data model and interpreting missing versus descriptive fields.

Key terms: CUAD dataset, contract data model, structured data, unstructured legal documents, end_date, total_amount, None, contract_scope, parties, renewal conditions

6.2 Constructing the graph

This section introduces the contract graph model and outlines the steps for importing, validating, and refining extracted contract data in Neo4j.

Key terms: Contract, Organization, Location, HAS_PARTY, HAS_LOCATION, graph model, address, city, state, country

6.2.1 Data import

This section prepares and runs a Cypher import that loads extracted contract data into Neo4j, while noting integrity, performance, and duplicate-import concerns.

Key terms: unique constraints, indexes, Contract, Organization, Location, graph integrity, import Cypher statement, dictionary output, Neo4j, graph schema

6.2.2 Entity resolution

This section explains entity resolution as the domain-specific process of detecting and merging duplicate representations of the same real-world entity in a knowledge graph.

Key terms: entity resolution, real-world entity, duplicate, single, coherent node, spelling variations, naming conventions, data formats, UTI Asset Management Company Limited, UTI Asset Management Company Ltd, domain-specific ontologies

6.2.3 Adding unstructured data to the graph

This section explains why a knowledge graph should retain original unstructured documents alongside extracted structured data, and how chunking should preserve meaningful document structure.

Key terms: structured data, unstructured data, knowledge graph, extracted structured data, chunking, token count, word length, semantic structure, clauses

6.3 Summary

This summary explains why LLM-extracted structured data, clear schemas, entity resolution, and combined graph content improve retrieval over document chunks alone.

Where this is used later

Concepts explained in this chapter

← Chapter 5: Agentic RAG Chapter 7: Microsoft’s GraphRAG implementation →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.