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

Lesson 2 of 7 · 2 hr

Knowledge graph foundations

You cannot build or debug a GraphRAG system without being comfortable with the graph itself. This lesson covers the property graph model, how to design one, and enough Cypher to read and write it.

Watch

Three short videos from Neo4j's own channel. The first two are lessons from the free Neo4j Fundamentals course on GraphAcademy, and the third is a hands-on Cypher walkthrough.

The opening lesson of Neo4j Fundamentals: what Neo4j is and what a graph database does.

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

The second lesson of Neo4j Fundamentals, on how to think about data as nodes and relationships.

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

A hands-on look at Cypher, retrieving and creating data patterns in a Neo4j graph with a movie dataset.

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

The property graph model

A property graph has four building blocks:

  • Nodes: things. Each has one or more labels (Person, Company).
  • Relationships: directed, typed connections between two nodes (WORKS_AT).
  • Properties: key-value pairs on nodes or relationships (name, since).
  • Types and labels act as your lightweight schema.
CREATE (a:Person {name: 'Ada'})-[:WORKS_AT {since: 2021}]->(c:Company {name: 'Acme'})

Cypher in five patterns

Cypher draws the pattern you want with ASCII art: () is a node, -[]-> is a relationship.

// 1. Find
MATCH (p:Person)-[:WORKS_AT]->(c:Company {name: 'Acme'})
RETURN p.name

// 2. Create without duplicates
MERGE (c:Company {name: 'Acme'})

// 3. Multi-hop: colleagues of colleagues
MATCH (p:Person {name: 'Ada'})-[:WORKS_AT]->(:Company)<-[:WORKS_AT]-(colleague)
RETURN DISTINCT colleague.name

// 4. Aggregate
MATCH (p:Person)-[:WORKS_AT]->(c:Company)
RETURN c.name, count(p) AS employees
ORDER BY employees DESC

// 5. Variable-length path (up to 3 hops)
MATCH path = (:Person {name: 'Ada'})-[*1..3]-(other)
RETURN path LIMIT 25

MERGE is the one to remember: it matches an existing pattern or creates it, which is how you avoid duplicate entities when loading data.

Modeling advice that matters for RAG

  • Nodes are things, relationships are verbs. If you find yourself naming a node WorksAt, make it a relationship.
  • Keep the schema small at first. Five node labels you trust beat thirty the extractor invents.
  • Model for the questions you will ask. List ten real questions, then check each is answerable by a short path.
  • Keep the source text. In GraphRAG you usually also store Chunk or Document nodes linked to the entities extracted from them, so every fact can cite its source.

Resources

Free courseNeo4j GraphAcademy
Neo4j Fundamentals (opens in a new tab)

A short, free, hands-on introduction to graphs and Cypher.

Free courseNeo4j GraphAcademy
Cypher Fundamentals (opens in a new tab)

Free course of lessons, hands-on challenges and quizzes on reading and writing data with Cypher.

Free courseNeo4j GraphAcademy
Graph Data Modeling Fundamentals (opens in a new tab)

How to design a graph model from your questions.

Articlegraphrag.com
GraphRAG glossary (opens in a new tab)

Keep this open; the vocabulary comes fast in later lessons.

Check yourself

  1. Create a free Neo4j instance (the GraphAcademy courses give you a sandbox, or use a free AuraDB or a local install).
  2. Model something you know, such as the books you have read, with at least three node labels and three relationship types.
  3. Write a query that answers a two-hop question about it and another that aggregates.

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