Open Ontology Data Model

Open Ontology is a digital twin platform that unifies disparate business data sources into a queryable knowledge graph. This document provides a formal specification of the data model, query language, and core concepts.

Table of Contents

  1. Fundamental Concepts
  2. Triple Store
  3. Value Types
  4. Datalog Query Language
  5. Namespaces
  6. Object Types
  7. Link Types
  8. Time Travel
  9. Transactions

Fundamental Concepts

The Triple Model

Open Ontology stores all data as triples—atomic facts in the form:

This is also known as the Entity-Attribute-Value (EAV) model. Every piece of information in the system is represented as a statement about some entity.

Example facts about an employee:

Why Triples?

The triple model provides several advantages over traditional relational tables:

AspectTraditional TablesTriple Store
Schema changesRequire migrationsAdd attributes freely
Sparse dataNULL columns everywhereStore only what exists
RelationshipsForeign keys, join tablesFirst-class references
HistoryManual audit tablesBuilt-in timestamps
FlexibilityFixed columnsAny attribute on any entity

Design Principles

  1. Schema emerges from data — The schema describes what exists, not what must exist
  2. Every fact is timestamped — Full audit trail without extra work
  3. Relationships are first-class — Not foreign keys, but actual graph edges
  4. Time travel is built-in — Query any historical state

Triple Store

Triple Structure

Each triple in the database contains the following fields:

FieldTypeDescription
idstringUnique identifier for this triple
entityIdstringThe entity this fact describes
attributestringThe property name (conventionally prefixed with :)
valueTripleValueThe fact's value (typed)
createdAtnumberUnix timestamp (milliseconds) when created
createdBystring?Optional: who created this fact
retractedAtnumber?Unix timestamp when soft-deleted (null = active)
entityTypestring?Optional classification (e.g., "Employee")
txIdstring?Transaction ID this triple belongs to

Conventions

Entity IDs should be namespaced to avoid collisions across data sources:

Attributes conventionally start with : (colon):

Operations

Assert — Add a new fact:

Retract — Soft-delete a fact (sets retractedAt):

Query — Retrieve facts by pattern:


Value Types

Open Ontology supports six primitive value types:

String

Text values of any length.

Number

Numeric values (integers or floating-point).

Boolean

True or false values.

Datetime

Timestamps stored as Unix milliseconds.

Reference

A pointer to another entity. This creates a graph edge.

JSON

Arbitrary JSON data for complex, nested structures.

Value Storage

Values are stored in typed columns in SQLite:

TypeSQL Column
stringvalue_string
numbervalue_number
booleanvalue_boolean
datetimevalue_datetime
refvalue_string
jsonvalue_json

The value_type column discriminates which column contains the actual value.


Datalog Query Language

Datalog is a declarative query language that makes complex relational queries feel like pattern matching. Open Ontology uses a JSON-based syntax.

Query Structure

Variables and Attributes

Variables begin with ? and represent unknown values to be bound:

Attributes begin with : and identify properties:

Pattern Clauses

A pattern clause matches triples in the database:

This matches any triple where:

  • The entity is bound to ?person
  • The attribute is :employee:name
  • The value is bound to ?name

Shared variables create implicit joins:

This query joins people to their departments because ?person and ?dept appear in multiple patterns.

Predicate Clauses

Filter results with comparison operators:

Supported operators: >, >=, <, <=, =, !=

Negation

Find entities that don't match a pattern:

This matches people who do not have :terminated set to true.

Disjunction (OR)

Match any of several patterns:

Complete Example

Find high-earning employees in the engineering department who haven't been terminated:

Aggregation

Group and aggregate results:

Supported aggregation operators: count, sum, avg, min, max


Namespaces

Namespaces provide isolation for multi-tenant deployments and multi-source data federation.

Purpose

  • Data isolation — Each namespace has its own SQLite database
  • Source organization — Group data by origin (salesforce, stripe, internal)
  • Multi-tenancy — Separate customer data cleanly

Operations

Cross-Namespace References

Entities in different namespaces can reference each other using the :same-as attribute:

This enables unified queries across data sources.


Object Types

Object Types define the expected structure of entities, enabling validation and documentation.

Definition

Validation

Object types enable conformance checking:

Schema Evolution

Object types are versioned. When the schema changes, create a new version rather than modifying the existing one. This preserves historical validation semantics.


Link Types

Link Types define typed, validated relationships between entities.

Definition

Usage

Querying Links

Use the link clause in Datalog queries:


Time Travel

Every fact in Open Ontology is timestamped, enabling queries against historical state.

How It Works

  • createdAt — When the fact was asserted
  • retractedAt — When the fact was retracted (null if still active)

A fact is active at time T if:

Query Historical State

Get Full History

Use Cases

  • Audit trails — What was the state before a change?
  • Debugging — Why does this data look wrong?
  • Compliance — What was our posture on a specific date?
  • Recovery — Restore previous values after an error

Transactions

Group related assertions into atomic units with shared metadata.

Creating Transactions

Transaction Benefits

  • Atomicity — All facts in a transaction share the same txId
  • Provenance — Track which process/user created the data
  • Rollback — Retract all facts in a transaction at once
  • Audit — Query "what changed in this transaction?"

Querying by Transaction


API Reference

HTTP Endpoints

MethodPathDescription
POST/namespacesCreate namespace
GET/namespacesList namespaces
GET/namespaces/:nsGet namespace metadata
DELETE/namespaces/:nsDelete namespace
POST/namespaces/:ns/triplesAssert triples
DELETE/namespaces/:ns/triples/:idRetract triple
GET/namespaces/:ns/entities/:idGet entity triples
GET/namespaces/:ns/entities/:id/historyGet entity history
POST/namespaces/:ns/queryPattern query
POST/namespaces/:ns/query/as-ofTime-travel query
POST/namespaces/:ns/datalogDatalog query

Effect Services

All operations are wrapped in Effect for composability:


Glossary

TermDefinition
TripleAn atomic fact: [entity, attribute, value]
EntitySomething that facts can describe; identified by a string ID
AttributeA property name, conventionally prefixed with :
ValueA typed datum (string, number, boolean, datetime, ref, or json)
NamespaceAn isolated database for grouping related data
Object TypeA schema definition for entity validation
Link TypeA typed relationship definition between entities
RetractionSoft-deletion by setting retractedAt timestamp
TransactionA group of facts created atomically with shared metadata
DatalogA declarative query language based on pattern matching
VariableA query placeholder, prefixed with ?

Further Reading

  • HANDOFF.md [blocked] — Project status and architecture overview
  • PLAN-API.md [blocked] — HTTP API specifications
  • PLAN-AI.md [blocked] — AI integration roadmap
  • PLAN-UI.md [blocked] — Debug UI design
  • PLAN-SCALE.md [blocked] — Storage scaling strategies