Tutorials and Examples

Hands-on learning paths with executable examples and expected outputs.

Getting Started Tutorials

1. MATCH Basics (10 minutes)

Learn fundamental pattern matching:

Create sample data:

CREATE GRAPH SocialNetwork;
USE SocialNetwork;

CREATE
  (:Person {name: "Alice", age: 30}),
  (:Person {name: "Bob", age: 25}),
  (:Person {name: "Charlie", age: 35});

MATCH (a:Person {name: "Alice"}), (b:Person {name: "Bob"})
CREATE (a)-[:KNOWS {since: 2020}]->(b);

Basic queries:

-- Match all people
MATCH (p:Person)
RETURN p.name, p.age;

-- Match with predicate
MATCH (p:Person)
WHERE p.age > 26
RETURN p.name;

-- Match relationship
MATCH (a:Person)-[k:KNOWS]->(b:Person)
RETURN a.name, b.name, k.since;

Expected output:

name     | age
---------|----
Alice    | 30
Bob      | 25
Charlie  | 35

See GQL Guide for complete syntax.

2. Indexing and Query Optimization (15 minutes)

Learn to create indexes and use EXPLAIN/PROFILE:

Step 1: Identify slow query

PROFILE
MATCH (p:Person)
WHERE p.age > 25
RETURN p.name;

Output shows SeqScan (sequential scan) → slow for large datasets.

Step 2: Create index

CREATE INDEX person_age_idx ON Person(age) USING btree;

Step 3: Verify index usage

EXPLAIN
MATCH (p:Person)
WHERE p.age > 25
RETURN p.name;

Now shows IndexScan [person_age_idx] → fast!

Step 4: Compare performance

PROFILE
MATCH (p:Person)
WHERE p.age > 25
RETURN p.name;

See execution time improvement with indexes.

See Indexing and Optimization for details.

3. Graph Algorithms Quickstart (20 minutes)

Run PageRank on social network:

Setup:

-- Use social network from Tutorial 1
USE SocialNetwork;

-- Add more connections
MATCH (b:Person {name: "Bob"}), (c:Person {name: "Charlie"})
CREATE (b)-[:KNOWS]->(c);

Run PageRank:

CALL graph.pageRank('SocialNetwork', {
  relationship_type: 'KNOWS',
  iterations: 20
})
YIELD node, score
RETURN node.name AS person, score
ORDER BY score DESC;

Expected output:

person   | score
---------|-------
Bob      | 0.385
Charlie  | 0.315
Alice    | 0.300

Bob has highest PageRank (receives 2 connections).

See Graph Algorithms for more algorithms.

4. Vector Similarity Search (25 minutes)

Generate embeddings and find similar items:

Create item graph:

CREATE GRAPH ProductCatalog;
USE ProductCatalog;

CREATE
  (:Product {id: 1, name: "Laptop"}),
  (:Product {id: 2, name: "Mouse"}),
  (:Product {id: 3, name: "Keyboard"}),
  (:Product {id: 4, name: "Monitor"});

-- Co-purchase relationships
MATCH (laptop:Product {name: "Laptop"}), (mouse:Product {name: "Mouse"})
CREATE (laptop)-[:CO_PURCHASED]->(mouse);

MATCH (laptop:Product {name: "Laptop"}), (monitor:Product {name: "Monitor"})
CREATE (laptop)-[:CO_PURCHASED]->(monitor);

Generate embeddings:

CALL graph.node2vec('ProductCatalog', {
  relationship_type: 'CO_PURCHASED',
  dimensions: 128,
  walk_length: 80,
  num_walks: 10
})
YIELD node, embedding
WITH node, embedding
MATCH (p:Product)
WHERE p.id = node.id
SET p.embedding = embedding;

Create vector index:

CREATE INDEX product_embedding_idx ON Product(embedding) USING vector;

Find similar products:

MATCH (laptop:Product {name: "Laptop"})
MATCH (similar:Product)
WHERE similar.id <> laptop.id
  AND vector_distance_cosine(similar.embedding, laptop.embedding) < 0.5
RETURN similar.name, vector_distance_cosine(similar.embedding, laptop.embedding) AS similarity
ORDER BY similarity ASC;

Expected output: Mouse and Monitor (co-purchased with Laptop) have low distance.

See Data Model and Types for vector types.

5. Backup and Restore Workflow (10 minutes)

Protect your data with backups:

Local backup:

# Create backup
./geode backup --output /backups/social-network-$(date +%Y%m%d).tar.gz

# Verify backup
ls -lh /backups/

S3 backup (requires AWS credentials):

export AWS_ACCESS_KEY_ID="..."
export AWS_SECRET_ACCESS_KEY="..."

# Backup to S3
./geode backup --dest s3://my-bucket/geode-backups/backup-$(date +%Y%m%d).tar.gz

Restore:

# Restore from local backup
./geode restore \
  --input /backups/social-network-20240115.tar.gz \
  --data-dir /var/lib/geode

# Restore from S3
./geode restore \
  --source s3://my-bucket/geode-backups/backup-20240115.tar.gz \
  --data-dir /var/lib/geode

See Deployment Guide for automation.

Advanced Tutorials

Transaction Isolation with Savepoints

Learn MVCC and SSI with practical examples:

START TRANSACTION;

CREATE (:Account {id: 1, balance: 1000});
SAVEPOINT sp1;

CREATE (:Account {id: 2, balance: 500});
SAVEPOINT sp2;

-- Transfer $100
MATCH (a1:Account {id: 1})
SET a1.balance = a1.balance - 100;

MATCH (a2:Account {id: 2})
SET a2.balance = a2.balance + 100;

-- Verify
MATCH (a:Account)
RETURN a.id, a.balance;

COMMIT;

See Transactions Overview for ACID semantics.

Full-Text Search with BM25 Ranking

Build a document search engine:

CREATE GRAPH DocumentSearch;
USE DocumentSearch;

CREATE
  (:Document {id: 1, title: "Graph Databases Explained", content: "Graph databases store data as nodes and relationships..."}),
  (:Document {id: 2, title: "Introduction to GQL", content: "GQL is the ISO standard query language for graph databases..."});

-- Create full-text index
CREATE INDEX doc_content_idx ON Document(content) USING fulltext;

-- Search with BM25 ranking
MATCH (d:Document)
WHERE fulltext_match(d.content, "graph database")
RETURN d.title, bm25_score(d.content, "graph database") AS relevance
ORDER BY relevance DESC;

See Indexing and Optimization for BM25 details.

Next Steps