Build your own knowledge graph database
Index-free adjacency and a Cypher-lite engine, from scratch.
What you'll build
You'll build a labeled property-graph database from scratch in TypeScript — record store, index-free adjacency, label and property indexes, graph traversals, and a Cypher-lite query engine that tokenizes, parses, plans, and executes real queries. It runs against the canonical Neo4j Movies graph (38 movies, 133 people, 253 relationships), and the capstone answers "who are Kevin Bacon's co-stars?" returning the exact, sorted row set real Neo4j returns. Database internals, not ML — every step graded against ground truth from real Neo4j.
- An in-memory property-graph store with index-free adjacency — per-node relationship chains that make a hop an O(1) pointer-follow instead of an index probe
- Label and property indexes that find a query's anchor node in O(1), plus BFS, DFS, shortest path, and variable-length matching with relationship isomorphism enforced
- A Cypher-lite query engine end to end — tokenizer, recursive-descent parser to a typed AST, a planner that anchors on the most-constrained node, and an executor that binds, filters, and projects rows
- A kgdb CLI that runs real Cypher against the Neo4j Movies graph and prints a result table byte-identical to Neo4j's, verified by the grader
What you'll learn
- Why a graph database beats a SQL self-join on multi-hop queries — and the index-free adjacency data structure that makes each hop cost proportional to the answer, not the database size
- How a query language is built end to end — tokenize, parse, plan, execute — the same shape as a SQL engine, a regex engine, or a language interpreter
- Graph algorithms as code you wrote: BFS for shortest paths, cycle detection, and variable-length traversal with the relationship-isomorphism rule that keeps it from looping forever
- How a query planner chooses where to start, why results are unordered sets without ORDER BY, and how the property-graph model compares to RDF triples for knowledge graphs and GraphRAG
Prerequisites
- Comfortable reading and running TypeScript
- Familiarity with basic data structures — arrays, maps, queues (we build the graph-specific structures from scratch)
- No database or graph-theory background required
Get started
Everything runs locally — no GPU, no API keys. Clear stage 1 in under ten minutes.
# 1. log in (approve in your browser — required) npx theinference login # 2. scaffold the course npx theinference course start knowledge-graph-db ./knowledge-graph-db # 3. install dependencies cd knowledge-graph-db && npm install # 4. grade the first stage npx theinference test --stage run-the-grader --watch
Each lesson shows the exact --stage command for that stage — passing it marks the stage complete here automatically.