Contents Start here
Start here
Before you start: Neo4j running in five minutes in Docker, on a small cloud machine or on AuraDB Free
The Python this course assumes, three ways to get a Neo4j database, a self-check that ends with your database answering, and a model key with a spending limit.
Free lesson Code zip with this lesson
About 18 minutes to read, and about 20 minutes for the hands-on lab.
Your progress0 of 9 checks answered right
It fills only when a prediction matches the measured result. Reading a page does not move it. It is kept in this browser.
Every lab in this course talks to a Neo4j database, so before anything else you need one that answers. This lesson gets you there in one of two ways: Neo4j AuraDB Free, the free tier of Neo4j's managed service, or Neo4j Community Edition in Docker, on a small cloud machine of your own or on your own computer. It then runs a short self-check that prints the database's version, measures how long one tiny query takes there and back, writes one node and deletes it, and ends with SETUP OK. Everything shown in this lesson is from our own run on 6 December 2026, on an AWS EC2 t2.small in us-east-1.
After this lesson you will be able to:
- say which skills the course assumes, and which ones it teaches from zero;
- choose between AuraDB Free and Neo4j in Docker, and say what each one costs you;
- start Neo4j 2026.10.2 in Docker with a password and a memory limit that fit a 2 GB machine;
- connect to it with the official Python driver and run the self-check until it prints
SETUP OK; - delete a cloud lab machine completely, and prove that nothing is left running.
What you need first: a terminal, Python 3.10 or newer, and either a free Neo4j Aura account or an AWS account with the AWS command line tool set up.
Time: about 20 minutes, most of it waiting for a machine to start.
What it costs: nothing on AuraDB Free. On AWS, a t2.small costs $0.023 an hour, so a lab session of an hour or two costs a few cents, including its disk and public address.
Code: the start-up script and the self-check are in the code for this lesson, with a START-HERE note.
The problem: every later lesson assumes a database that answers
From the next part onwards, every lesson loads Ferncliff Robotics' data into Neo4j, queries it and measures the result. If your database is not running, or your password is wrong, or your Python cannot reach it, you find out in the middle of a lesson about something else, and the error message is about networking, not about graphs. So we settle all of that once, here, with a check that either prints SETUP OK or tells you exactly which step failed.
What this course assumes you already know
- Python. You can read and change a 200-line program, install a package with
pip, and use a virtual environment. - The terminal. You can run a command, read its output, and set an environment variable.
- Basic HTTP and JSON. You know that a program calls an API and gets JSON back.
What the course teaches from zero: graphs, Neo4j, the Cypher query language, embeddings, retrieval, GraphRAG and agent memory. If you have never written a database query of any kind, you can still follow, because Part 1 starts with the very first MATCH, in the lesson "Your first Cypher".
The idea: two places your database can live
Neo4j is a database server. It runs on an ordinary CPU and needs no GPU. Your Python programs talk to it over Bolt, Neo4j's own network protocol, which listens on port 7687 by default. Neo4j also serves a web page, the Neo4j Browser, on port 7474, where you can type queries by hand. You can run the server in two places:
| AuraDB Free | Neo4j Community Edition in Docker | |
|---|---|---|
| Who runs it | Neo4j, as a managed service | you, on a cloud machine or your own computer |
| What it costs | $0, and Neo4j's pricing page says no credit card is needed | free software; you pay for the machine, if it is in the cloud |
| Limits | Neo4j says the free plan "places limits on the number of nodes and relationships"; Ferncliff's graph is small | whatever the machine can hold |
| Address you connect to | neo4j+s://<your instance>.databases.neo4j.io | bolt://localhost:7687 |
| Good for | the quickest start, no machine to look after | the labs on memory, loading and production in Part 7, which need settings Aura does not expose |
Most lessons work on either. The lessons in Part 7 that tune memory or use the offline import tool say so at the top and use Docker.

Read the figure as the table above, drawn as places. The left frame is a database someone else runs for you, at no cost. The right frame is a machine you rent and look after yourself, with Neo4j running inside Docker on it. Your program is the same in both cases; only the address in NEO4J_URI changes.
Neo4j numbers its versions by the calendar since January 2025: 2026.10.2 means the October 2026 release, patch 2. The older numbering ended with 5.26, which Neo4j's driver manual lists as a long-term-support version. This course is written against 2026.10.2, the newest version on Docker Hub on 14 November 2026.
Option A: Neo4j AuraDB Free
- Go to https://console.neo4j.io and sign up, or sign in.
- Create a new instance and choose the free tier.
- When the instance is created, the console shows its connection address and a generated password. Save them at once, in a password manager or a file only you can read. Treat the password like any other secret: never paste it into a chat, a ticket or a Git commit.
- Wait until the console shows the instance as running, then go to the self-check below and use these values:
export NEO4J_URI="neo4j+s://<your instance id>.databases.neo4j.io"
export NEO4J_USER="neo4j"
export NEO4J_PASSWORD="<the password the console showed you>"
Watch out: the console's screens change from time to time, so the steps above describe what you do rather than which button to press. If a screen looks different from these words, the idea is the same: create a free instance, and keep the address and the password it gives you.
Option B: Neo4j in Docker on a small cloud machine
This is the route we measured. It builds one small Ubuntu machine on AWS, installs Docker, starts Neo4j with a strong random password and a memory budget that fits a 2 GB machine, and lets you reach it only through SSH from your own address. If you would rather run Docker on your own laptop for these early pages, the same docker run command works there too; the course's measurements are from the cloud machine.
Step 1: the machine's start-up script
When an AWS machine starts for the first time, it can run a script you give it, called user data. Ours installs Docker and Python, makes a random password, and starts Neo4j. Save it as user-data.sh:
#!/bin/bash
# Cloud lab machine for "Hands-On Context Engineering with Neo4j" (Ubuntu 24.04 on EC2, us-east-1).
# Installs Docker and Python, then starts Neo4j Community in Docker with a small memory budget that fits a
# 2 GB machine. The password comes from the instance's own random generator and is written to a root-only file.
set -euo pipefail
exec > /var/log/lab-setup.log 2>&1
apt-get update -y
apt-get install -y docker.io python3-venv python3-pip
systemctl enable --now docker
PW=$(openssl rand -hex 16)
echo "$PW" > /root/neo4j-password && chmod 600 /root/neo4j-password
cp /root/neo4j-password /home/ubuntu/neo4j-password && chown ubuntu:ubuntu /home/ubuntu/neo4j-password && chmod 600 /home/ubuntu/neo4j-password
date +%s.%N > /home/ubuntu/neo4j-start-time
docker run -d --name neo4j --restart unless-stopped \
-p 127.0.0.1:7474:7474 -p 127.0.0.1:7687:7687 \
-e NEO4J_AUTH="neo4j/$PW" \
-e NEO4J_server_memory_heap_initial__size=512m -e NEO4J_server_memory_heap_max__size=512m \
-e NEO4J_server_memory_pagecache_size=256m \
-v neo4jdata:/data \
neo4j:2026.10.2-community
until docker exec neo4j cypher-shell -u neo4j -p "$PW" "RETURN 1" >/dev/null 2>&1; do sleep 1; done
date +%s.%N > /home/ubuntu/neo4j-ready-time
sudo -u ubuntu python3 -m venv /home/ubuntu/venv
sudo -u ubuntu /home/ubuntu/venv/bin/pip install -q "neo4j==6.4.1"
touch /home/ubuntu/lab-ready
Four lines in it matter most.
-p 127.0.0.1:7687:7687publishes Neo4j's ports on the machine's own loopback address only. Nothing on the internet can reach the database directly; you reach it through SSH. A database with a public port and a password is the most common way a lab database gets broken into.NEO4J_AUTH="neo4j/$PW"sets the password of the userneo4j. Neo4j's Docker guide says the first user name cannot be changed fromneo4j, and that the setting is ignored if the data volume already holds a database, so a rerun keeps the first password.- The memory settings follow the image's naming rule: start with
NEO4J_, write each dot as one underscore, and write each underscore in the setting's own name as two. Soserver.memory.heap.max_sizebecomesNEO4J_server_memory_heap_max__size. A 512 MB heap and a 256 MB page cache leave room for the operating system on a 2 GB machine. Part 7 explains what each of the two does. set -euo pipefailstops the script at the first error. Our very first run usedset -xas well, which prints every command as it runs. That printed the generated password into the setup log. The machine was deleted the same hour, so no harm was done, but it is exactly how real passwords leak into logs, and the copy above no longer does it.
Step 2: start the machine
These are the commands we ran, in order. Each one is plain AWS command line, so you can read what it does before you run it. Replace nothing except the region, if you want a different one.
# the latest Ubuntu 24.04 image, from Canonical's public parameter
AMI=$(aws ssm get-parameter --region us-east-1 \
--name /aws/service/canonical/ubuntu/server/24.04/stable/current/amd64/hvm/ebs-gp3/ami-id \
--query Parameter.Value --output text)
# a key pair for SSH, saved where only you can read it
aws ec2 create-key-pair --region us-east-1 --key-name neo4j-course-lab \
--query KeyMaterial --output text > lab-key.pem && chmod 600 lab-key.pem
# a firewall that lets in SSH from your own address and nothing else
MYIP=$(curl -s https://checkip.amazonaws.com)
SG=$(aws ec2 create-security-group --region us-east-1 --group-name neo4j-course-lab \
--description "Neo4j course lab, SSH from one IP" --query GroupId --output text)
aws ec2 authorize-security-group-ingress --region us-east-1 --group-id "$SG" \
--protocol tcp --port 22 --cidr "$MYIP/32"
# the machine: a t2.small, a 16 GB disk that is deleted with it, and our start-up script
aws ec2 run-instances --region us-east-1 --image-id "$AMI" --instance-type t2.small \
--key-name neo4j-course-lab --security-group-ids "$SG" --user-data file://user-data.sh \
--block-device-mappings "DeviceName=/dev/sda1,Ebs={VolumeSize=16,VolumeType=gp3,DeleteOnTermination=true}" \
--tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=neo4j-course-lab}]" \
--query "Instances[0].InstanceId" --output text
We chose a t2.small because it has 2 GB of memory, enough for Neo4j with the settings above, and because some new AWS accounts may only start machines with one virtual CPU at first. On 14 November 2026 the AWS Price List API gave $0.023 an hour for it in us-east-1, plus $0.08 a month for each GB of gp3 disk and $0.005 an hour for its public address while it runs.

Read the figure from the outside in. The yellow frame is the firewall rule from Step 2, the green frame is the machine, and the grey box is the database with the two ports from Step 1. The only arrow that crosses the yellow frame is your own SSH connection. The database is reached by a program on the same machine, and the red cross marks every other way in.
Step 3: wait for Neo4j, and see how long it took
The script writes a file called lab-ready when everything is installed, and two timestamps: one just before docker run, one at Neo4j's first answer. Find the machine's address with aws ec2 describe-instances, then log in and look. This is exactly what our machine printed, before we copied any lab files over:
$ ssh -i lab-key.pem ubuntu@<address> 'ls ~; test -f ~/lab-ready && echo READY; echo "startup seconds: $(echo "$(cat ~/neo4j-ready-time) - $(cat ~/neo4j-start-time)" | bc)"; free -m | head -2; nproc; uname -r; lsb_release -ds; docker --version'
lab-ready
neo4j-password
neo4j-ready-time
neo4j-start-time
venv
READY
startup seconds: 62.899222252
total used free shared buff/cache available
Mem: 1959 1323 240 1 582 635
1
7.0.0-1021-aws
Ubuntu 24.04.5 LTS
Docker version 29.1.3, build 29.1.3-0ubuntu3~24.04.2
From the docker run to Neo4j's first answer took 62.9 seconds on our machine. That includes downloading the 1.05 GB image. We then restarted the container to see how long a start takes when the image is already there: 59.0 seconds from the restart to the first answer. Neo4j is a Java program, and on one small virtual CPU most of that minute is the Java runtime starting up. On a bigger machine it is much quicker. While idle, the running container used 817.9 MiB of memory, measured with sudo docker stats --no-stream.
The self-check: does your database answer?
The same check works for both options. Install the driver in a virtual environment and save this as check_setup.py:
python3 -m venv venv && . venv/bin/activate
pip install "neo4j==6.4.1"
"""Before you start: the five-minute self-check that your Neo4j answers.
Run: python check_setup.py
Reads NEO4J_URI, NEO4J_USER and NEO4J_PASSWORD from the environment.
Prints the server's name, version and edition, the driver version, and how long one tiny query
takes there and back (the median of 20), then writes and deletes one test node.
"""
import os
import statistics
import time
import neo4j
from neo4j import GraphDatabase
uri = os.environ.get("NEO4J_URI", "bolt://localhost:7687")
auth = (os.environ.get("NEO4J_USER", "neo4j"), os.environ["NEO4J_PASSWORD"])
with GraphDatabase.driver(uri, auth=auth) as driver:
driver.verify_connectivity()
rows, _, _ = driver.execute_query("CALL dbms.components() YIELD name, versions, edition RETURN name, versions[0] AS version, edition")
for r in rows:
if r["name"] == "Neo4j Kernel":
print(f"server: {r['name']} {r['version']} ({r['edition']} edition)")
print(f"driver: neo4j Python driver {neo4j.__version__}")
times = []
for _ in range(20):
t = time.perf_counter()
driver.execute_query("RETURN 1 AS ok")
times.append((time.perf_counter() - t) * 1000)
print(f"round trip for RETURN 1: median {statistics.median(times):.2f} ms over 20 runs")
driver.execute_query("CREATE (:SelfCheck {at: datetime()})")
n = driver.execute_query("MATCH (c:SelfCheck) RETURN count(c) AS n").records[0]["n"]
driver.execute_query("MATCH (c:SelfCheck) DELETE c")
left = driver.execute_query("MATCH (c:SelfCheck) RETURN count(c) AS n").records[0]["n"]
print(f"write test: created {n} node, deleted it, {left} left")
print("SETUP OK" if n == 1 and left == 0 else "SETUP PROBLEM")
What each part does:
verify_connectivity()fails at once, with a clear message, if the address, the port or the password is wrong. The driver manual recommends calling it before anything else.execute_query()is the driver's simplest way to run a query: it opens a session, runs the query in a transaction, retries if the database asks it to, and returns the rows. The manual's rule, which this whole course follows: never build a query by joining strings; pass values as parameters.CALL dbms.components()asks the server what it is. It is the quickest proof you are talking to the version you think you are.- The 20 timed
RETURN 1queries measure the round trip: the time for a query to reach the database and for the answer to come back, with almost no work in between. Every later query costs at least this much.
Predict, then measure
The self-check times 20 tiny RETURN 1 queries on a t2.small, with Python and Neo4j on the same machine. What median round trip do you expect?
The measured result appears once you lock in. Only your first answer counts toward your progress.
On the cloud machine the database is on the same machine as Python, so the address is the loopback one. Written down? Then run it:
$ export NEO4J_PASSWORD=$(cat ~/neo4j-password)
$ ~/venv/bin/python ~/check_setup.py
server: Neo4j Kernel 2026.10.2 (community edition)
driver: neo4j Python driver 6.4.1
round trip for RETURN 1: median 11.08 ms over 20 runs
write test: created 1 node, deleted it, 0 left
SETUP OK
That is a working setup: the server is 2026.10.2 Community Edition, the driver is 6.4.1, one tiny query takes a median of 11.08 ms there and back on this small machine, and the database accepts a write and a delete. If you are on AuraDB Free, your round trip will be larger, because each query crosses the internet to Neo4j's data centre and back.
If you see something else:
ServiceUnavailableor a connection refused: the database is not running yet, or the address or port is wrong. On the cloud machine, wait forlab-ready.AuthError: the password is wrong. On AuraDB, use the password the console showed when the instance was created.KeyError: 'NEO4J_PASSWORD': you have not set the environment variable in this terminal.
Before you leave: delete the cloud machine, and prove it
A lab machine left running is a bill that keeps growing and a door that stays open. So every cloud lab in this course ends the same way: delete it, then check that nothing is left. These are the commands we ran at the end of our session:
aws ec2 terminate-instances --region us-east-1 --instance-ids <instance id>
aws ec2 wait instance-terminated --region us-east-1 --instance-ids <instance id>
aws ec2 delete-security-group --region us-east-1 --group-id "$SG"
aws ec2 delete-key-pair --region us-east-1 --key-name neo4j-course-lab && rm lab-key.pem
And the check, with what it printed for us at 08:06:04 UTC. Our run used the names neo4j-ctx-1206 for the security group and the key pair; yours will be neo4j-course-lab:
$ aws ec2 describe-instances --region us-east-1 --instance-ids <instance id> \
--query "Reservations[0].Instances[0].[State.Name,StateTransitionReason]" --output text
terminated User initiated (2026-12-06 08:05:27 GMT)
$ aws ec2 describe-volumes --region us-east-1 --filters Name=attachment.instance-id,Values=<instance id> \
--query "Volumes[].VolumeId" --output text
$ aws ec2 describe-security-groups --region us-east-1 --filters Name=group-name,Values=neo4j-course-lab \
--query "SecurityGroups[].GroupId" --output text
$ aws ec2 describe-key-pairs --region us-east-1 --filters Name=key-name,Values=neo4j-course-lab \
--query "KeyPairs[].KeyName" --output text
The machine is terminated, its disk went with it because we set DeleteOnTermination=true, and the firewall rule and the key are gone. Empty output is the answer you want. Our machine ran from 07:31:38 to 08:05:27 UTC, about 34 minutes, for the labs of Part 0 and the first four lessons of Part 1. At $0.023 an hour for the t2.small, $0.08 a GB-month for the 16 GB disk and $0.005 an hour for the public address, that came to about 2 cents.

Read the figure as a checklist of three questions you ask AWS after every cloud lab. Each section names the command you run and shows what ours printed. A green chip means the answer you want, and two of the three good answers are empty output, because there was nothing left to list.
Your model key
From Part 1 onwards, some lessons call a language model. Create an API key with your provider, set a monthly spending limit on it in the provider's dashboard before you use it, and put the key in an environment variable, never in a file you commit:
export OPENAI_API_KEY="<your key>"
The course's own runs use OpenAI's gpt-5.4-mini, a cheap current model: one answer built from the graph in the first lab cost between $0.00079 and $0.00091, and the most expensive answer in that lab, with every document pasted in, cost $0.00773. OpenAI's pricing page listed gpt-5.4-mini at $0.75 per million input tokens and $4.50 per million output tokens, and text-embedding-3-small at $0.02 per million tokens, on 6 December 2026. Each lab lesson states what its own run cost.
Questions people ask
- Is Neo4j free to use for this course?
Yes. Neo4j's pricing page lists AuraDB Free at $0, with no credit card needed, and Neo4j Community Edition is free software you can run in Docker. If you run it on a cloud machine, you pay only for the machine: an AWS EC2 t2.small costs $0.023 an hour.
- Can I run Neo4j in Docker on my own computer instead?
Yes. Install Docker Desktop, then run the same
docker runline from Step 1, with your own password in place of$PW. Every lab in Parts 1 to 6 works there. The ports are published on 127.0.0.1 only, so nothing outside your computer can reach the database. The course's own measurements come from the cloud machine described in this lesson, so your times will differ.- Why is only SSH open on the cloud machine?
Because a database with a public port and a password is the easiest thing on the internet to break into. In this lesson Neo4j listens only on the machine's own loopback address, and the firewall lets in SSH from your one address and nothing else.
Knowledge check
Tap an answer to see straight away whether it is right, and why. You can try the whole check again at the end.
- Question 1
You want to set Neo4j's setting
server.memory.heap.max_sizethrough an environment variable in Docker. Which name do you use? - Question 2
Why does the
docker runcommand publish the ports as127.0.0.1:7687:7687? - Question 3
You run the start-up script a second time on a machine whose data volume already holds a database, with a new password in
NEO4J_AUTH. What happens? - Question 4
On our t2.small, with Python and Neo4j on the same machine, what median round trip did the self-check measure for
RETURN 1? - Question 5
How do you prove a cloud lab is really gone?
0 of 5 right so far, 0 of 5 answered.
Words from this lesson
| Word | What it means |
|---|---|
| AuraDB Free | the free tier of Neo4j's managed database service |
| Community Edition | the free, open-source edition of the Neo4j server |
| Bolt | Neo4j's network protocol; port 7687 by default |
| Neo4j Browser | the web page, on port 7474, where you can type queries by hand |
| driver | the library your program uses to talk to the database; here, the neo4j Python driver |
| round trip | the time for a request to reach the server and its answer to come back |
| heap, page cache | the two parts of memory Neo4j uses: one for running queries, one for holding the graph's data in memory |
| user data | a script an AWS machine runs the first time it starts |
| loopback address | 127.0.0.1, the address a machine uses to talk to itself; nothing outside can reach it |
What to keep
You now have a Neo4j database that answers, on AuraDB Free or in Docker on a small cloud machine. The self-check printed the server's version, a median round trip of 11.08 ms on our t2.small, and SETUP OK. The cloud machine's ports were open only to SSH from one address, the database only to the machine itself, and at the end everything was deleted and checked. Keep check_setup.py: run it again at the start of any session, and it tells you in a few seconds whether the database is ready.
The next lesson, "What context engineering is", uses this database for the first real lab of the course.
Sources
- Our own lab run of 6 December 2026, from 07:31:38 to 08:06:04 UTC, on an AWS EC2 t2.small in us-east-1: the run files
2026-12-06-before-check.txtand2026-12-06-teardown.txtin the course's lab folder. - Neo4j Operations Manual, "Docker: introduction", https://neo4j.com/docs/operations-manual/current/docker/introduction/, read on 14 November 2026: publishing ports 7474 and 7687,
NEO4J_AUTH=neo4j/your_password, "there is currently no way to change the initial username from neo4j", and thatNEO4J_AUTHdoes not override an existing database's authentication. - Neo4j Operations Manual, "Docker: configuration", https://neo4j.com/docs/operations-manual/current/docker/configuration/, read on 14 November 2026: the
NEO4J_prefix, a period written as one underscore and an underscore written as two. - Neo4j Operations Manual, "Introduction", https://neo4j.com/docs/operations-manual/current/introduction/, read on 14 November 2026: calendar versioning from 2025.01.0, in the form YYYY.MM.Patch.
- Neo4j Python Driver Manual, https://neo4j.com/docs/python-manual/current/ and its installation page, read on 14 November 2026:
pip install neo4j, Python 3.10 or newer, the 6.x driver's support for Neo4j 4.4, 5.x, 2025.x and 2026.x,execute_query(), parameters instead of joined strings,verify_connectivity(), Bolt on port 7687, and "Neo4j 4.4 and 5.26 are LTS versions". - Neo4j pricing page, https://neo4j.com/pricing/, read on 14 November 2026: AuraDB Free at $0, "No credit card or other payment method required", and "The free plan places limits on the number of nodes and relationships".
- Docker Hub, the official
neo4jimage, https://hub.docker.com/_/neo4j, read on 14 November 2026 and again on 6 December 2026, when 2026.10.2 was still the newest calendar release: the tag2026.10.2-community. - The AWS Price List API for us-east-1, read on 14 November 2026, and the t2.small price read again on 6 December 2026: t2.small $0.023 an hour, gp3 storage $0.08 a GB-month, a public IPv4 address $0.005 an hour.