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
| Rung | Climb to it when | Stay below it when |
|---|---|---|
| Binary graph | always the start | never: every model starts here |
| Hypergraph | a relation has three or more parts that must stay together | extra parts are just qualifiers of one binary fact |
| Metagraph | you must say things about relations, link relations, or group facts into named wholes | relations are never talked about |
| Recursive metagraph | layers on layers: provenance of provenance, episodes in memories in agents | one level of annotation or grouping is enough |
Need → structure → graphlava
| You need | Structure | In graphlava | Cost (spec) | Chapter |
|---|---|---|---|---|
| A plain fact | binary statement | insert(s, p, o) | 4 writes (node object) or 1 (literal) | 4 |
| A value that changes often | inline property | literal object, stored in the property record | 1 write per overwrite | 6 |
| A single-valued link that changes, keeping its annotations | functional binary statement | functional predicate: set updates in place | 7 writes per change; ID and annotations kept | 6, 8 |
| How sure, where from | annotation | {| :confidence 0.9 ; :source :chat12 |} | as any statement; promotes the target if virtual | 6 |
| Who checked the source | annotation of an annotation | nested {| … {| … |} |} | one more statement and one more join | 6 |
| The same fact several times | parallel statements | multi predicate | wider keys for that predicate only | 6, 8 |
| A relation with fixed roles | role-labelled hyperedge | hyperedge type and record | 1 record + 1 incidence key per node filler | 5 |
| A literal value of a relation, such as a meeting's date | attribute of the hyperedge | literal attribute: inline property of e, never a role | 1 write; a value index to search by it | 5 |
| A relation whose roles vary | n-ary node + role statements | ordinary statements | 4 writes per node-valued role | 5 |
| A remark on one role | reified role | annotate the role triple (promotion) | 1 statement ID + hedge_promo key | 5, 6 |
| A relation between relations | edge as vertex | statement or hyperedge ID as subject or object | 1 statement | 4 |
| A group of facts | container | named graph | 0 bytes for home membership | 7 |
| A fact in two groups | extra membership | INSERT the triple into the second graph: same statement, one more gmem entry | 2 keys | 7 |
| Metadata per group (which episode said it, how sure) | annotated membership | annotate << X :in g >> (promotion) | 1 statement ID in gmem | 7 |
| Groups in groups | nesting DAG | (child, :in, parent), transitive GRAPH | closure update proportional to descendants × ancestors | 7 |
| An edge that holds a subgraph | edge as container | a graph linked to the edge | 1 link statement; lifetime managed by you | 7 |
| A summary over existing parts | fold | nest graphs under a new graph | 1 nesting statement per part; nothing copied | 9 |
| Facts that follow from facts | rule | Datalog, on demand (v0) or materialized (v1) | per query, or at commit under a budget | 9 |
| Rules about the schema | meta-model | statements in the system graph | validated before commit | 8 |
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:
- Relations are binary, or have a small fixed set of extra values.
- Edge properties are values, never links to other nodes or edges.
- Nobody asks "who said so?" or "how sure are we?" about an edge.
- The data has one perspective: no episodes, sources or agents that disagree.
You need a metagraph when any of these holds:
- Relationships have relationships ("the meeting led to the price change").
- The same fact is held with different confidence by different sources.
- Knowledge is grouped into episodes, documents or projects that are themselves described.
- Rules or the schema must be queried and changed like data.
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 need | Choose |
|---|---|
| Current state only, many value overwrites, small fast transactions | graphlava |
| Native hyperedge records with typed roles | graphlava |
| Nested graphs with transitive scope | graphlava |
| "What did I believe last Tuesday?", corrections that keep the old version, nothing ever deleted | tiramemsu |
| Valid time as well as transaction time | tiramemsu |
| Something you can install today | tiramemsu (graphlava is at the design stage) |
Five rules of thumb
- 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.
- Give a relation a type when its roles are fixed. The store can then check it and read it as one record.
- Annotate instead of encoding. A confidence belongs on the statement, not in a compound predicate or a side table.
- 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. - Group with graphs, not with properties. A
:contextvalue 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
- Pick the lowest rung that holds the problem; graphlava charges for higher rungs only where they are used.
- Fixed roles: hyperedge type. Remarks: annotation. Groups: graphs. Conclusions: rules. Schema: the system graph.
- Choose tiramemsu when the memory must remember its own past.