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.
The second lesson of Neo4j Fundamentals, on how to think about data as nodes and relationships.
A hands-on look at Cypher, retrieving and creating data patterns in a Neo4j graph with a movie dataset.
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
ChunkorDocumentnodes linked to the entities extracted from them, so every fact can cite its source.
Resources
A short, free, hands-on introduction to graphs and Cypher.
Free course of lessons, hands-on challenges and quizzes on reading and writing data with Cypher.
How to design a graph model from your questions.
Keep this open; the vocabulary comes fast in later lessons.
Check yourself
- Create a free Neo4j instance (the GraphAcademy courses give you a sandbox, or use a free AuraDB or a local install).
- Model something you know, such as the books you have read, with at least three node labels and three relationship types.
- Write a query that answers a two-hop question about it and another that aggregates.