graphlava

Chapter 8

The meta-model

The last metagraph kind is the model itself, stored as data. In graphlava the schema, the hyperedge types, the shapes and the rules are statements in one graph, read by the planner and checked on write.

Why store the schema as statements

Chapter 3 called a system homoiconic when data, schema and rules share one representation. Three practical things follow:

The price is validation. A write to the schema can make existing data invalid, so schema writes get checked harder than data writes.

The system graph

graphlava's spec puts every meta-model statement in the system graph, a graph with a fixed ID that is created with the file, next to the default graph. Its IRIs use a reserved namespace; the recommended choice is a URN namespace such as urn:meta-core: (renamed with the project), and the decision is still open.

Three parts of the engine read it:

Meta-model entryDeclaresRead by
predicate declarationmulti or functional flag, value index, on-demand orderings, datatypewrite path, planner
hyperedge typearity, role names, role ranges, fixed width; literal attributes, stored as inline properties of the hyperedgewrite path, planner
class and labelclass IRIs used as Cypher labelsCypher front end (v1)
shapeconstraints checked at commit (optional)write path
ruleDatalog rule text, @materialized or @on_demandrule engine
index declarationvalue indexes, on-demand orderings, vector indexesplanner, write path

The running example's schema

The spec fixes what each entry declares. It does not yet fix how the statements are spelled. The sketch below shows the content, not final syntax:

# sketch, syntax not final: system namespace written as sys:
GRAPH sys:system {
  :worksAt    a sys:Predicate ; sys:functional true .   # one employer: set keeps the ID
  :met        a sys:Predicate ; sys:multi true .        # chapter 6: several meetings
  :confidence a sys:Predicate ; sys:datatype xsd:decimal .

  :Meeting a sys:HyperedgeType ;
    sys:role [ sys:iri :agent  ; sys:card "one" ; sys:index 0 ] ,
             [ sys:iri :target ; sys:card "one" ; sys:index 1 ] ,
             [ sys:iri :topic  ; sys:card "one" ; sys:index 2 ] ;
    sys:attribute [ sys:iri :when ; sys:datatype xsd:date ] .   # a property of e, not a role

  :colleague a sys:Rule ; sys:mode "on_demand" ;
    sys:text "colleague(?x, ?y) :- :worksAt(?x, ?o), :worksAt(?y, ?o), ?x != ?y ." .
}

Whatever the final spelling, each line is a statement and each statement has an ID. So the meta-model can carry annotations too: who added the :Meeting type, and why.

Validation before commit

A write to the system graph is validated before commit, against both the rest of the schema and the data. The spec lists the rejecting cases:

ChangeRejected when
Make a predicate multia hyperedge type or rule depends on it being single
Make a predicate functionalany subject already has two objects for it
Shrink a hyperedge type's arityrecords of that type exist
Add or change a rulethe program fails stratification (negation or aggregation inside a recursive cycle)

Some changes are allowed but expensive. Switching a predicate between single and multi rewrites its ordering entries, because the two use different key shapes. Removing a role from a hyperedge type, or changing its cardinality, rewrites all records of that type as an online migration. Adding an optional role rewrites nothing: missing slots read as null.

Like every write, a failed validation aborts the whole transaction and leaves no partial state.

Shapes, and what is not in v0

A shape is a constraint checked at commit, such as "every :worksAt object is an :Organization". The spec keeps shapes to a small checked subset in v0. A full SHACL or OWL engine is a non-goal; reasoning profiles come as Datalog rule sets instead. RDFS and an OWL-RL subset are designed to ship as built-in rule sets, compiled ahead of time, under the same rules as user rules.

Shapes as holon boundaries. In a nested memory, a shape on a graph acts as a contract at the container's edge: what may enter :session7, what :aliceMemory promises to hold. Metagraph for AI Agents treats SHACL in exactly this role. In graphlava's v0, the contract is a small subset, checked on every commit.

Rules live in the meta-model too

A Datalog program sent with a query keeps its rules for that query only. To keep rules, define stores them in the meta-model under their head IRIs. After that, SPARQL can call them through SERVICE <meta:datalog>, and later Datalog programs can use them by name. A stored rule is again a statement, so the question "which rules depend on :worksAt?" can be answered with a query, and the validator uses the same information to refuse a change that would break a rule.

Chapter 9 covers the rules themselves.

What the meta-model buys in queries

The planner reads the meta-model to pick a plan before it reads data:

In graphlava. The meta-model is a set of statements in the system graph: predicate declarations, hyperedge types, classes, shapes, rules and index declarations. Writes to it are validated against the data before commit. Its exact vocabulary and namespace are not final in the spec yet.

Takeaways

Contents