Skip to content
AI|Course
← Implement GraphRAG with Knowledge Graphs

Lesson 3 of 7 · 2 hr

Building a graph from unstructured text

Most real knowledge lives in text, not in a database. This lesson is about turning documents into a graph you can trust.

Watch

A seven-minute Neo4j demo of building a knowledge graph from raw text with a language model.

Watch on YouTube (opens in a new tab)Video by Neo4j. The player loads only when you press play.

The pipeline

documents → chunks → LLM extraction → entity resolution → graph + embeddings
  1. Chunk. Split documents into passages. Chunk size is your first quality lever: too small loses context, too large blurs the extraction.
  2. Extract. Ask an LLM to read each chunk and return entities and relationships, ideally constrained by a schema (the labels and relationship types you allow).
  3. Resolve. "IBM", "International Business Machines" and "the Armonk company" should become one node. Without entity resolution you get a fragmented graph that cannot connect anything.
  4. Store. Write entities, relationships and the chunks they came from, plus embeddings on chunks (and optionally on entities).

Where it goes wrong

  • Unconstrained extraction invents a new relationship type for every sentence. Give the model an allowed list.
  • Duplicates from skipping entity resolution. Merge on normalized names or IDs, and review a sample by hand.
  • Lost provenance. If a fact has no link back to its chunk, you cannot cite it or debug it.
  • Cost surprises. Extraction is one or more LLM calls per chunk. Always run on a tiny sample first and multiply.
Rule of thumb

Look at 20 random extracted facts before you index anything large. If you would not trust them, neither will your users.

Three ways to build it

Pick one and get it working end to end before comparing the others.

  • Neo4j GraphRAG for Python: a pipeline that extracts a graph from text or PDFs into Neo4j, with optional schema guidance.
  • LlamaIndex PropertyGraphIndex: extraction can range from free-form to strict schema to your own extractors, and it can sit on top of Neo4j.
  • Microsoft GraphRAG: an indexing pipeline that also builds the community summaries used in lesson 5.

Resources

Articlegraphrag.com
Chunking guide (opens in a new tab)

How chunking choices affect graph quality.

DocsNeo4j
Neo4j GraphRAG for Python (opens in a new tab)

Official docs for the knowledge graph builder pipeline and retrievers. Follow the installation and quickstart for your version.

CodePyPI
neo4j-graphrag on PyPI (opens in a new tab)

Package page with install instructions and links to examples.

DocsLlamaIndex
Using a Property Graph Index (opens in a new tab)

Constructing a graph with loose or strict extraction.

DocsMicrosoft
Microsoft GraphRAG documentation (opens in a new tab)

The indexing pipeline and configuration reference.

Check yourself

  1. Pick 5 to 10 documents on a topic you know. Build the graph with one of the three tools.
  2. Open the graph in Neo4j Browser or Bloom and inspect 20 random relationships. Note every error.
  3. Tighten your schema or prompt, rebuild, and compare. Keep a short log of what changed the quality.

Found a broken link or a mistake? Report it (opens in a new tab).