The store contract
GraphStore is a Protocol with these operations: apply(contribution) (atomic), drop_unit, versions, pinned, known_types, registry, search and export.
InMemoryStore is the reference implementation. LadybugStore (an embedded graph database) and a networked variant implement the same contract, and the same contract tests run against each. open_index opens an index.
An index is one
.lbdb file.
Tables
Depth and tree edges are not stored as tables. Depth is derived from the
parent chain, and a concept names its context in a column. Timestamps are ISO text so the time zone survives.
Relations: the rows are the truth, the edges are derived
A relation is kept as a row inRelation, and a RELATES edge is kept for each row whose target exists. Edges alone would not be enough, for three reasons measured on the embedded database (version 0.15.3):
- A relation may name a concept that does not exist yet. Creating an edge to a missing node is accepted and creates nothing, with no error.
- Rewriting a concept with
DETACH DELETEremoves every edge of the node, including edges that other concepts own and that point at it. In the test, 11 edges became 0 while the rows still held every fact. - The merge rules work on relation records: their unit, their evidence, and “remove when all evidence goes”.
check_edges says whether edges equal rows, and rebuild_edges repairs them, so edges are never the only copy. Opening a version 1 database, which has no edges, builds them from the rows.
How a save stays safe
A save is one explicit transaction, the version marker included. A half-written save that moved the marker would never be repaired, because the next update trusts the marker. Measured on the embedded database:- A statement sent without
BEGINcommits alone. - A failed statement aborts the transaction.
- A process killed before
COMMITleaves nothing. - Only one write transaction runs at a time, and a second is refused at once.
- One process owns the database file.
Export
The index can be exported as a bundle of markdown files, one per concept, in a folder per context.relations front-matter key and as plain links in the body. A moved concept or context leaves a stub at the old path, with type: Redirect.
Implementation rules
These rules were measured on LadybugDB 0.21.2, embedded, with 768-dimension vectors.Flight server
Build and run the server that other machines use to read and save.