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.
The pipeline
documents → chunks → LLM extraction → entity resolution → graph + embeddings
- Chunk. Split documents into passages. Chunk size is your first quality lever: too small loses context, too large blurs the extraction.
- 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).
- 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.
- 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.
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
How chunking choices affect graph quality.
Official docs for the knowledge graph builder pipeline and retrievers. Follow the installation and quickstart for your version.
Package page with install instructions and links to examples.
Constructing a graph with loose or strict extraction.
The indexing pipeline and configuration reference.
Check yourself
- Pick 5 to 10 documents on a topic you know. Build the graph with one of the three tools.
- Open the graph in Neo4j Browser or Bloom and inspect 20 random relationships. Note every error.
- Tighten your schema or prompt, rebuild, and compare. Keep a short log of what changed the quality.