graphlava

Chapter 11

Choosing an encoding

A cheat sheet for the whole book: which rung of the ladder a problem needs, which structure holds it, what graphlava offers for it, and what it costs.

The ladder, with exits

Binary graph  ⊂  Hypergraph  ⊂  Metagraph  ⊂  Recursive metagraph
RungClimb to it whenStay below it when
Binary graphalways the startnever: every model starts here
Hypergrapha relation has three or more parts that must stay togetherextra parts are just qualifiers of one binary fact
Metagraphyou must say things about relations, link relations, or group facts into named wholesrelations are never talked about
Recursive metagraphlayers on layers: provenance of provenance, episodes in memories in agentsone level of annotation or grouping is enough

Need → structure → graphlava

You needStructureIn graphlavaCost (spec)Chapter
A plain factbinary statementinsert(s, p, o)4 writes (node object) or 1 (literal)4
A value that changes ofteninline propertyliteral object, stored in the property record1 write per overwrite6
A single-valued link that changes, keeping its annotationsfunctional binary statementfunctional predicate: set updates in place7 writes per change; ID and annotations kept6, 8
How sure, where fromannotation{| :confidence 0.9 ; :source :chat12 |}as any statement; promotes the target if virtual6
Who checked the sourceannotation of an annotationnested {| … {| … |} |}one more statement and one more join6
The same fact several timesparallel statementsmulti predicatewider keys for that predicate only6, 8
A relation with fixed rolesrole-labelled hyperedgehyperedge type and record1 record + 1 incidence key per node filler5
A literal value of a relation, such as a meeting's dateattribute of the hyperedgeliteral attribute: inline property of e, never a role1 write; a value index to search by it5
A relation whose roles varyn-ary node + role statementsordinary statements4 writes per node-valued role5
A remark on one rolereified roleannotate the role triple (promotion)1 statement ID + hedge_promo key5, 6
A relation between relationsedge as vertexstatement or hyperedge ID as subject or object1 statement4
A group of factscontainernamed graph0 bytes for home membership7
A fact in two groupsextra membershipINSERT the triple into the second graph: same statement, one more gmem entry2 keys7
Metadata per group (which episode said it, how sure)annotated membershipannotate << X :in g >> (promotion)1 statement ID in gmem7
Groups in groupsnesting DAG(child, :in, parent), transitive GRAPHclosure update proportional to descendants × ancestors7
An edge that holds a subgraphedge as containera graph linked to the edge1 link statement; lifetime managed by you7
A summary over existing partsfoldnest graphs under a new graph1 nesting statement per part; nothing copied9
Facts that follow from factsruleDatalog, on demand (v0) or materialized (v1)per query, or at commit under a budget9
Rules about the schemameta-modelstatements in the system graphvalidated before commit8

Write counts are base-table operations from the data model spec. Times are still to be measured.

Is a property graph enough?

Many projects reach for a metagraph too early. A labelled property graph is enough when all of these hold:

You need a metagraph when any of these holds:

Agent memory usually meets the second list on the first day: every remembered fact has a source and a confidence.

graphlava or tiramemsu

Both are statement stores from the same idea. The choice is about time.

If you needChoose
Current state only, many value overwrites, small fast transactionsgraphlava
Native hyperedge records with typed rolesgraphlava
Nested graphs with transitive scopegraphlava
"What did I believe last Tuesday?", corrections that keep the old version, nothing ever deletedtiramemsu
Valid time as well as transaction timetiramemsu
Something you can install todaytiramemsu (graphlava is at the design stage)

Five rules of thumb

  1. Climb only as far as the problem needs. A binary fact that is never annotated costs the least, and graphlava is designed so that it pays for nothing else.
  2. Give a relation a type when its roles are fixed. The store can then check it and read it as one record.
  3. Annotate instead of encoding. A confidence belongs on the statement, not in a compound predicate or a side table.
  4. Point dependencies the way deletes flow. Annotations follow their subject into deletion. A reference from the object position does not cascade; the recommended option makes it block the delete unless DETACH.
  5. Group with graphs, not with properties. A :context value on every fact cannot be nested, scoped or described. A graph can.

Closing

The book started with a meeting that binary edges could not hold, and ended with a memory where a fact, its source, the source's checker, the meeting, its outcome, the episode and the rule that reads them all are statements in one ID space. Nothing in between needed a second data model. That is the case for statement graphs as the ground floor of a metagraph store: give every statement an identity, let identities stand where nodes stand, and the higher rungs of the ladder become ordinary writes.

graphlava is designed around that idea, with the physical choices that agent memory asks for: IDs given lazily, overwrites that cost one write, hyperedges stored once, and scopes that cost in proportion to the graph. The specs are in the repository.

In graphlava. Every row of the table above maps to a part of the spec: statements and promotion (data model), hyperedge records (hyperedges), membership and scope (graphs), the system graph (meta-model) and Datalog (rules). One query core, SPARQL 1.2 and Datalog in v0, reads all of it.

Takeaways