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:
- One transaction. Adding a role to a hyperedge type and writing the first hyperedge that uses it can commit together.
- One query language. "Which predicates are multi?" and "which rules read
:worksAt?" are ordinary queries. - One set of tools. Export, backup and inspection treat the schema like any other data.
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 entry | Declares | Read by |
|---|---|---|
| predicate declaration | multi or functional flag, value index, on-demand orderings, datatype | write path, planner |
| hyperedge type | arity, role names, role ranges, fixed width; literal attributes, stored as inline properties of the hyperedge | write path, planner |
| class and label | class IRIs used as Cypher labels | Cypher front end (v1) |
| shape | constraints checked at commit (optional) | write path |
| rule | Datalog rule text, @materialized or @on_demand | rule engine |
| index declaration | value indexes, on-demand orderings, vector indexes | planner, 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:
| Change | Rejected when |
|---|---|
Make a predicate multi | a hyperedge type or rule depends on it being single |
Make a predicate functional | any subject already has two objects for it |
| Shrink a hyperedge type's arity | records of that type exist |
| Add or change a rule | the 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:
- A pattern on a predicate known to be node-valued reads only the orderings; one known to be literal-valued reads only property records. Without that knowledge it must read both.
- A star of role patterns on a fixed-arity hyperedge type can become one record scan (from v2).
- A predicate with a declared value index can be looked up by value. That is also how meetings are found by their
:whendate, since literal attributes are not in the incidence index. - A
functionalpredicate makes(s, p)a key, so the planner knows a pattern with both bound returns at most one row. - A rule's mode tells the planner whether to read a derived table or evaluate on demand.
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
- Storing the schema as statements gives one transaction, one query language and one toolset for schema and data.
- The cost is validation: schema writes are checked against existing data and rules.
- Declarations are not decoration: the planner uses them to read fewer sources and pick cheaper plans.