Build your own knowledge graph database
The Bacon machine·14 min

Capstone: Bacon's co-stars

0 / 1
# grade this stage (from your course directory)
npx theinference test --stage bacon-costars --watch

The screenshot moment. Run the famous query through your own database, end to end on the real graph. Nothing new to implement — this assembles the whole path (anchor on a real name, DISTINCT across shared movies, ORDER BY on real strings) and catches integration bugs the unit fixtures missed.

Your task

Run the co-star query

kgdb query must print the exact co-star table the reference engine prints. The capstone query returns each co-star with the movie they shared, ordered by name then movie:

bash
your_program.sh query {fixture}/fixtures/data/nodes.json {fixture}/fixtures/data/relationships.json "MATCH (bacon:Person {name:'Kevin Bacon'})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coStar) WHERE coStar.name <> 'Kevin Bacon' RETURN DISTINCT coStar.name AS name, m.title AS via ORDER BY name, via"
The answer (15 co-stars across three Bacon films)
name                 | via
---------------------+----------------
Bill Paxton          | Apollo 13
Christopher Guest    | A Few Good Men
Cuba Gooding Jr.     | A Few Good Men
Demi Moore           | A Few Good Men
Ed Harris            | Apollo 13
Gary Sinise          | Apollo 13
... (Jack Nicholson, Tom Cruise, Tom Hanks, Sam Rockwell via Frost/Nixon, ...)
If the row set is off

If a co-star is missing or duplicated, check three things: the anchor found exactly one Kevin Bacon; isomorphism stops the same ACTED_IN being reused (so Bacon isn't his own co-star); and DISTINCT collapses duplicates. The <> predicate is the last guard against self-matches.

How it's graded

Process mode, stdout_json_match against the canonicalized result (ordered, since the query has ORDER BY name, via). This is the same engine that just passed every unit step — now proven end to end on the real graph.