Suppose an agent tells you which Mexican airports have no direct flight to Mexico City but would still get there in two flights through
at least two different hubs. The answer is a short list. The graph behind it has 57,645 relationships, and the query used
count(), collect() and a NOT EXISTS, so the paths were gone by the time I saw the rows.
You can trust the list or re-derive it. I wanted a third option: a graph small enough to read that still gives the same answer.
Repo: https://github.com/edycutjong/witness · Live: https://witness.edycu.dev · Video (1:55): https://youtu.be/GYbci7TseJw
The idea: delete until nothing else can go
Witness takes a read-only Cypher query and its answer. It deletes relationships and re-runs the query. If the answer is
unchanged the deletion stays; if not, it is undone. When no single remaining relationship can be removed without changing the
answer, what is left is a witness.
Every trial is a transaction that never commits. That is the part Relate makes cheap: an embedded
engine, a single-file store, and begin / rollback in the same process as the reducer. This is the trial, from
src/witness/store.py:
self.db.begin_transaction()
try:
dr, dn = self._delete(rel_ids, node_ids)
results = []
for q, p in statements:
res = self.db.execute(q, p or {})
results.append((res.data, res.columns))
finally:
if self.db.transaction_active():
self.db.rollback_transaction()
After each rollback Witness checks that the node and relationship counts are back. That check is a tripwire for rollback
residue. It is not the proof.
The number
The query is queries/two-hub.cypher. It uses aggregation, an OPTIONAL MATCH and a NOT EXISTS, which is the kind of query
where the matched path is not the explanation.
MATCH (a:Airport)-[:IN_COUNTRY]->(:Country {code: $country})
WHERE a.iata <> $dest
AND NOT EXISTS { MATCH (a)-[:HAS_ROUTE]->(:Airport {iata: $dest}) }
MATCH (a)-[:HAS_ROUTE]->(hub:Airport)-[:HAS_ROUTE]->(:Airport {iata: $dest})
OPTIONAL MATCH (hub)-[:IN_COUNTRY]->(hc:Country)
WITH a, count(DISTINCT hub) AS hubs, coll.sort(collect(DISTINCT hc.code)) AS hub_countries
WHERE hubs >= 2
RETURN a.iata AS airport, hub_countries
ORDER BY airport
On the air-routes graph (Kelvin Lawrence, Apache-2.0: 3,748 nodes, 57,645 relationships) with MX and MEX, Witness reduces
57,645 relationships to 22 (12 nodes) in 371 trials and 1.1 s, on an M1 Max. Then it proves the claim one relationship
at a time: for each of the 22, a fresh copy of the witness without that one relationship gives a different answer.
22 of 22 change the answer
I run that on the Python API and on the plain Relate CLI, so the second check does not go through relate-db. The witness
is one .rl file. Anyone can re-run it:
relate query --database witnesses/two-hub.rl --read-only \
--param country=MX --param dest=MEX < queries/two-hub.cypher
What "minimal" means here
I do not claim "smallest". I claim deletion-minimal: no single remaining relationship can be removed without changing the
answer. A different, smaller subgraph might also work. This is the 1-minimality guarantee from delta debugging, and it is the
one thing I can check exhaustively.
Two more honest limits:
- A query can be non-monotone (
NOT EXISTSand aggregation can change the answer when relationships are added), so a witness proves its own answer on its own file. It does not prove that every superset gives the same answer. -
NOT EXISTSdepends on facts that are absent, and a drawn subgraph cannot show absence. Inwitness demo, absence is checked on the full graph with a companion query and printed in its own block;witness whydoes not do this yet.
It also refuses what it cannot judge: writes, procedures, LOAD CSV, clocks, randomness and storage-order dependence (a heuristic check) exit 2.
The comparison, and the label I got wrong
I wanted to know whether Relate's in-process rollback was any faster than a server, so I ran the same loop on Neo4j 2026.10.2
in Docker over Bolt: begin, delete one relationship, run the headline query, fetch every row, roll back, check the counts.
Same 1,000 relationships in the same order, 100 warm-up trials discarded, median of 3 runs.
| Relate 1.0.1, in-process | Neo4j 2026.10.2, Docker, Bolt | |
|---|---|---|
| trials per second (median) | 366.8 | 90.2 |
| trial ms p50, begin to rollback | 2.54 | 6.48 |
| counts restored after rollback | 3000 / 3000 | 3000 / 3000 |
The answers matched on all 3,000 trials. Only 2 of 1,000 random relationships change this answer, so I also ran the 68
relationships the query actually binds: 20 change it on Relate and the same 20 on Neo4j.
My first write-up said the Relate side ran on a :memory: copy. It did not: it ran on a file-backed scratch copy in a temp
dir, the same path the reducer uses. An automated review pass caught it. The number did not move, but I corrected the label and the
evidence file in the repo, because a benchmark whose description is wrong is a benchmark nobody should reuse.
Read the gap for what it is. One machine, one query, one graph. It compares an embedded engine with a Dockerised server that
pays a network round trip per statement. It says nothing about Neo4j's query engine, and Neo4j was still speeding up across
its three runs (76.9, 90.2, 102.2 trials/s). Neo4j runs rollback trials fine and returned the same answers.
For agents
Witness ships an MCP server with two tools, why and check. An agent that answers through Relate's own read_cypher can call
why on the same statement and attach the witness to its reply. Its own rows are passed in, so a mismatch is refused instead of
attached. A person then accepts or disputes the witness with witness review, and the ledger, itself a Relate graph, keeps both.
Try it
git clone https://github.com/edycutjong/witness && cd witness
uv run witness demo
That copies the committed source graph (never modified), reduces the answer, re-proves it, and writes the witness. The suite is
557 tests passing at 100% line and branch coverage. Every number above is in the repo under evidence/.
I built this for the Relate by Neo4j hackathon with Claude Code as the coding agent, under my direction. If you point it at a
query whose answer confused you, I would like to hear what it gets wrong.
Top comments (1)
This is a beautiful idea, Edy — and the honesty about its limits is what makes it convincing. "Delete until nothing else can go" is such a clean framing, and using a transaction that never commits as the trial mechanism is the elegant part: the rollback is not just cleanup, it is the whole experiment, and the counts-restored check after every trial keeps it honest.
Two things stood out to me. First, calling it deletion-minimal instead of smallest — that distinction matters, and most write-ups would have blurred it. Second, correcting the :memory: label even though the numbers did not move. A benchmark whose description is wrong is a benchmark nobody should trust, and fixing it publicly is exactly why I trust the 366.8 vs 90.2 trials/s comparison more, not less.
The NOT EXISTS limit is the interesting edge for me, since absence is exactly what a drawn subgraph cannot show. Which kind of query would you most like someone to try next — one where the absence itself is the whole answer, or one where aggregation makes the witness non-monotone?