b1tb0x

EntityStore v3 · the doublets data model

Everything is a GUID in one of three tables. The table an id lives in says what it is: a word is its text; an entity is just an id, described by the doublets that point at it; a doublet is a pair. A fact is two doublets.

schema

EntityStore v3 schema: words, entities and doublets tables, with a worked example of a fact as two doublets. words id TEXT · PK value TEXT UNIQUE · not empty found or created entities id TEXT · PK an id and nothing else described by the doublets pointing at it doublets id TEXT · PK left TEXT · not null right TEXT · not null UNIQUE(left,right) · index(right) left and right hold a GUID → any row in words, entities, or another doublet. plain ids, no foreign keys. self-ref a fact = two doublets  ((subject, predicate), object) Me is-a (Me, is-a) shared doublet left right human alien fact ① ( •, human ) fact ② ( •, alien ) left left right right (Me, is-a) is stored once and shared; each object just adds one outer doublet. Me → human, alien. entity doublet table

columns

words.id
GUID, primary key.
words.value
the text; UNIQUE, never empty. Case-sensitive, found or created.
entities.id
GUID, primary key — the whole row. Meaning comes from its doublets.
doublets.id
GUID, primary key.
doublets.left
a GUID referencing any row in words, entities or doublets.
doublets.right
likewise. UNIQUE(left, right) so a pair exists once; indexed on right.

built on top

A fact is two doublets: ((subject, predicate), object). The inner (subject, predicate) is shared by every object.
Text is a chain of positions: each position an entity, with (pos, of) → word and (pos, next) → pos.
Built-in entities (fixed GUIDs, named like anything else): a · name · of · next · word separator.