Regulated domains such as clinical research, drug safety, finance and medical devices do not ask only "what is true?". They ask who asserted it, on what evidence, under which rule version, when it was true, when we learned it, and what else depended on it. A plain graph stores the first answer well and the rest badly. This article argues that a metagraph built on a statement graph, with Elpi (higher-order λProlog) as the rule layer, models those questions directly. It uses two of my own projects as the working examples: tiramemsu as the store and lean-elpi as the reasoning engine.
The problem
Three properties recur in every regulated workflow:
Many-to-one derivations. A conclusion rests on a set of inputs together, not on a single edge. A safety assessment is derived from lab results, a dosage record and a protocol version jointly.
Statements about statements. Confidence, source, reviewer sign-off, correction and retraction are all claims about other claims. An auditor needs them as first-class data, not as comments.
Two clocks. What was valid in the world and what the system knew at the time are different questions, and an inspection asks both.
A system that cannot represent these natively pushes them into application code, where they are hard to audit and easy to get wrong.
Where simple graphs stop
A triple or property-graph edge links one source to one target. The metagraph, as defined by Basu and Blanning, is instead a collection of directed set-to-set mappings over a generating set of elements. That one change matches how regulated reasoning works: a conclusion is a set of premises mapped to a set of consequences, and the set is the unit of evidence.
The graph community has felt the gap from the other side. The authors of the Meta-Property Graph proposal describe the ISO property graph model as lacking metadata awareness and reification, and extend it for governance tasks that current systems make difficult. On the RDF side, RDF-star and RDF 1.2 were introduced because classic reification is clumsy, and they now let metadata such as provenance, confidence and temporal validity attach to individual assertions. Work on RDF-star and named graphs concludes that a meta-level is the cleanest way to model provenance.
So the field agrees on the need. The three approaches differ in what they leave out:
Property graph: edges carry properties, but an edge cannot be the endpoint of another edge, and an edge has one source and one target.
RDF-star: statements can be quoted and annotated, but there is no native set-valued edge. A many-to-one derivation needs an auxiliary node.
Metagraph on a statement graph: statements have ids and can be endpoints, and edge ends may be sets. Both gaps close in one model.
The model: a metagraph on a statement graph
tiramemsu is an embedded graph database for agent memory that keeps everything in one file on SQLite or redb. Its core move is that each fact is a statement with its own id, so other statements can point at it. Confidence, source, belief and correction are layers built this way, and retracting a fact retracts its layers. Edges can also be nodes that hold subgraphs, which is the metagraph part, and named graphs work as tags. Every fact carries transaction time and valid time.
The design reduces to one statement shape and three kinds of term:
kind id, term type.
type node string -> term. % an entity
type set list term -> term. % a vertex set (canonically ordered)
type ref id -> term. % a statement used as a term
type stmt id -> term -> term -> term -> prop. % id, subject, predicate, object
% a metagraph edge: {lab_result, dose_record} --supports--> {assessment}
stmt e1 (set [node lab_42, node dose_7]) (node supports) (set [node assess_9]).
% statements about that edge
stmt e2 (ref e1) (node assertedBy) (node reviewer_ana).
stmt e3 (ref e1) (node ruleVersion) (node "sop-14.3").Three consequences follow from this shape:
A many-to-one derivation is one statement, so its premises cannot be separated from its conclusion by accident.
Provenance, confidence, sign-off and correction are statements whose subject is a
ref. They need no separate audit table and they nest to any depth.A context (an inspection snapshot, a competing belief set, a what-if branch) is a named graph or a bitemporal view. It is a scoped assumption, not a copy of the data.
One safeguard is needed. Statements about statements can refer to themselves. A simple rule avoids that: a ref may only point at an earlier id.
Worked example: a safety signal and a protocol change
The scenario is illustrative, not taken from a real trial. A sponsor sees a possible liver-enzyme signal and must justify tightening the monitoring schedule. Four facts matter to an inspector.
- 1.
The derivation is joint. The assessment rests on a lab result, a dose record and the protocol version together.
- 2.
The assessment is reviewed. A named reviewer signs it under a specific SOP version.
- 3.
It is later corrected. A re-read of the lab result changes the value after the decision was made.
- 4.
The inspector asks a time-travel question. "What did the sponsor know on 3 March, and what did it decide on that basis?"
In the statement graph this is a handful of rows:
% joint derivation (set-to-set edge)
stmt d1 (set [node lab_42, node dose_7, node protocol_v3]) (node supports) (set [node signal_9]).
% layers on the derivation: who, under what rule, how sure
stmt d2 (ref d1) (node reviewedBy) (node reviewer_ana).
stmt d3 (ref d1) (node underSOP) (node "sop-14.3").
stmt d4 (ref d1) (node confidence) (node 0.8).
% the decision depends on the derivation, not on the raw inputs
stmt d5 (node signal_9) (node triggers) (node tighten_monitoring).
stmt d6 (ref d5) (node basedOn) (ref d1).
% later: the lab value is corrected; the old statement is superseded, not deleted
stmt d7 (node lab_42) (node supersededBy) (node lab_42_v2).The store contributes two behaviours here. First, tiramemsu describes forgetting as a retraction that stays visible in history, and says deletes and rewrites are refused. That is the property an audit trail needs. Second, its bitemporal views let a query run against the current state, an as-of transaction, or a valid-at point, so the same question returns the same answer next year.
The graph does three things that a plain property graph would handle with workarounds. It keeps the three inputs as one inseparable premise set. It lets the reviewer, SOP and confidence attach to the derivation itself. It lets the correction in step 3 propagate: because the decision points at the derivation, and the derivation points at the superseded value, a rule can flag every decision whose basis has changed. The next section shows that rule.
Elpi against OWL and Cypher
The rule that flags decisions whose basis changed is short in Elpi:
superseded T :- stmt _ T (node supersededBy) _.
inputs_of Der L :- stmt Der (set L) (node supports) _.
decision_stale Dec :-
stmt _ (ref Dec) (node basedOn) (ref Der),
inputs_of Der L,
std.mem L T, superseded T.
% property characteristics are data, so one rule serves every transitive predicate
holds S P O :- stmt _ S P O.
holds S P O :- stmt _ P (node type) (node transitive),
holds S P M, holds M P O.
% what-if with no trace: assume a correction locally, then ask
what_if D :- (stmt dx (node dose_7) (node supersededBy) (node dose_7_v2)) => decision_stale D.The closing rule uses a construct that λProlog adds to Prolog: scoped assumptions with =>. λProlog also brings higher-order quantification and higher-order unification, and Elpi in particular offers native handling of variable binding through HOAS. tiramemsu's speculative with blocks give the store-side equivalent.
Against OWL
OWL reasons under the open-world assumption. Research on integrity constraints in OWL notes that what triggers a violation in a closed-world system leads to new inferences in a standard OWL system. In a regulated setting that is the wrong default: a missing sign-off must be an error, not a hint that a sign-off exists somewhere.
The usual fix is to add SHACL, which assumes complete data. Combining the two is hard. A 2025 study of SHACL validation with ontologies shows that even very simple ontologies make the problem ExpTime-complete, and PTime-complete in data complexity. In practice a team then maintains an OWL ontology, a SHACL shapes graph and a bridge between them.
Elpi keeps one language for all three jobs. Inference rules, negation-as-failure checks and commit-time validators are all clauses. You choose open or closed reading per predicate, explicitly, in code you can read. OWL still wins for shared vocabularies and interoperability, and you should export to it.
Against Cypher
Cypher is a query language. It matches patterns and returns rows, but it has no rule or inference mechanism of its own. A derived fact such as "this decision is stale" must be recomputed by every client query or materialised by application code. Recursion over arbitrary predicates, binders and hypothetical assumptions are outside its scope.
Elpi complements Cypher instead of replacing it. In tiramemsu, Elpi goals are callable from SPARQL or Cypher, so analysts keep their query language and the rules live in one place.
lean-elpi: conclusions an auditor can re-check
lean-elpi is a native Lean 4 implementation of Elpi. It runs as a metaprogramming tool inside Lean, as a pure library, as a standalone binary, and through bindings for Python, Node.js and Rust. The engine supports typed clauses, higher-order pattern unification, modes, constraints and CHR. Lean terms can be quoted inside Elpi code, and deriving Elpi shares Lean types with Elpi programs. An opt-in LF layer adds dependently typed signatures, recorded proof terms and kernel-checked certificates.
The last feature is what matters for regulated work. The following use is a design I am proposing, not something I have verified end to end:
- 1.
An Elpi query such as
decision_stale Druns over statements loaded from the store. - 2.
The engine returns the answer together with a recorded proof term whose leaves are statement ids.
- 3.
The Lean kernel checks that term against the rule set. An inspector can repeat that check without trusting the Elpi engine, the database or the vendor.
The result is a stronger audit claim than "the query returned this row". It becomes "this derivation is valid under rules R, using exactly these statements". tiramemsu already points in this direction on its own side: its N3 rules produce conclusions with proofs built from statement ids, and conclusions are retracted when their premises change. The two projects are separate, so the integration above is a design, not an existing feature.
There is a second benefit. The same Lean file can hold the rules and the theorems about them, for example that the staleness rule is monotone in the set of superseded inputs. In a regulated setting you can then show that a rule change cannot silently un-flag a decision.
Honest limits
The case for metagraphs here is structural. I found no head-to-head empirical study comparing metagraphs with property graphs or OWL stacks in a regulated deployment, so no performance or error-rate claim is made. The argument is that the model fits the shape of the problem and removes workarounds.
The tools are young, and their own pages say so:
lean-elpi is at version 0.3. It is about 2.4 times slower than ELPI 1.18 by geometric mean on its benchmark set, passes 52 of 114 applicable upstream tests, and one benchmark reaches 1.4 GB of memory. It is a reasoning engine, not a bulk store.
tiramemsu reports that writes are much slower than a plain triple store, that redb files are about three times larger, and that there is no network server.
The model itself needs decisions that are not yet made: how to canonicalise vertex sets (Elpi has no set unification, so sorted lists or reified set nodes are the options), how to stratify
refto forbid cycles, and where to apply open-world and closed-world readings.
A sensible next step is a thin vertical slice: load one real derivation chain from a regulated process, run the staleness rule, export the proof, and have a Lean kernel check it. If that works, the article's claim has evidence behind it.