The schema, table by table.

Every SQLite table ai-memory creates, every column, every index, every foreign key. Postgres mirror via the SAL adapter (--features sal). Schema version: v19 (Patch 1; ladder v15→v17→v18→v19 is automatic on first run).

9 tables 15+ indexes v19 schema SQLite + Postgres mirror
Table-relationship map

9 tables, 6 foreign keys.

Every relation flows from the central memories table. Foreign-key cascade-on-delete protects against orphan rows. memory_links is the KG primitive; pending_actions is the governance queue; sync_state is the federation cursor table.

memories id (PK) tier · namespace · title content · tags · priority created_at · expires_at metadata (JSON) memory_links source_id (FK) target_id (FK) relation valid_from / valid_until observed_by · signature archived_memories id (PK) [same shape as memories] archived_at entity_aliases entity_id (FK) alias (PK + idx) created_at pending_actions id (PK) action_type · ns requested_by approvals (JSON) decision namespace_meta namespace (PK) standard_id (FK) parent · created_at subscriptions id (PK) url · events secret_hash dispatch_count sync_state agent_id · peer_url (PK) last_pulled_at last_pushed_at _agents namespace (stored as memories in reserved namespace) no separate table schema_version version (currently 15) FK source_id → id FK target_id → id archive ← memories (data shape) aliases reference entity (memory id) FK standard_id → memories.id
Core tables

memories & memory_links · the heart.

memories ▸ CORE · ALL TIERS since v0.1
The primary memory store. One row per stored memory. tier determines lifecycle (short / mid / long / archived). FTS5 virtual table mirrors title+content for keyword search.
ColumnTypeNotes
PKidTEXTUUIDv4 stringified. Stable across federation.
tierTEXT NOT NULLOne of short · mid · long · archived. Drives TTL + visibility.
namespaceTEXT NOT NULLHierarchical path with / delimiter (v0.6.3 Stream A). Max depth 8 segments.
titleTEXT NOT NULLHuman-readable summary, ≤ 256 chars. FTS5-indexed.
contentTEXT NOT NULLBody text. Up to 1 MiB. FTS5-indexed.
tagsTEXTJSON array. Validator caps count at 32, length at 64 each.
priorityINTEGER1-10 scale. Drives auto-promote eligibility.
confidenceREAL0.0-1.0. Displayed as % when < 1.0.
sourceTEXTOrigin tag: user · claude · hook · api · import · cli · consolidation.
access_countINTEGERBumped on each recall hit. Triggers auto-promote at ≥ 5.
created_atTEXTRFC3339 UTC. Immutable.
updated_atTEXTRFC3339 UTC. Bumped on update.
last_accessed_atTEXT NULLRFC3339. Touched on recall. Drives recency-decay scoring.
expires_atTEXT NULLRFC3339. NULL = never. GC sweep purges past-due.
embeddingBLOB NULLf32 array, 768 dims (nomic-embed-text). Set if semantic+ tier.
metadataTEXTJSON. Holds agent_id, scope, governance policy, chunked_from.
▸ idx_memories_namespace · ▸ idx_memories_tier · ▸ idx_memories_priority_desc · ▸ idx_memories_expires_at · ▸ memories_fts (FTS5 virtual)
memory_links ▸ KNOWLEDGE GRAPH extended in v0.6.3 (4 new columns)
Typed directed links between memories. The KG primitive. v0.6.3 added NEW temporal-validity columns (valid_from, valid_until, observed_by, signature placeholder) for time-aware traversal.
ColumnTypeNotes
FKsource_idTEXT NOT NULLmemories(id) ON DELETE CASCADE
FKtarget_idTEXT NOT NULLmemories(id) ON DELETE CASCADE
relationTEXT NOT NULLOne of: related_to, supersedes, refines, contradicts, derived_from, superseded_duplicate, plus arbitrary user-defined.
created_atTEXT NOT NULLRFC3339 UTC.
NEWvalid_fromTIMESTAMP NULLv0.6.3: when the assertion became true. Backfilled to source's created_at on migration.
NEWvalid_untilTIMESTAMP NULLv0.6.3: when the assertion was superseded. NULL = still valid.
NEWobserved_byTEXT NULLv0.6.3: agent_id of the observer. Powers per-agent visibility filter.
NEWsignatureBLOB NULLv0.6.3 placeholder · v0.7 will populate with Ed25519 signature for attested provenance.
▸ idx_links_temporal_src (source_id, valid_from, valid_until) · ▸ idx_links_temporal_tgt · ▸ idx_links_relation
schema_version ▸ MIGRATION
Single-row table. Tracks current schema version. Daemon checks at startup; runs forward migrations idempotently. Current version: 15 (Stream B hierarchy + KG additions).
versionINTEGER NOT NULLCurrently 19 (Patch 1). Bumped only on additive migrations. Migration ladder v15→v17→v18→v19 runs automatically at daemon start.
Archive & metadata

Soft-delete + namespace policy.

archived_memories ▸ SOFT DELETE TIER
Same shape as memories table. Memories transition here on memory_delete or curator soft-delete. Excluded from default reads. Restorable.
Mirrors memories schema column-for-column, plus:
archived_atTEXT NOT NULLRFC3339 UTC. Drives archive purge --older-than N.
archived_reasonTEXT NULLFree-form (e.g. "user_deleted", "consolidation_supersede", "auto_curator_dedup").
namespace_meta ▸ POLICY
Per-namespace policy attached via a "standard memory" — a special memory whose JSON metadata holds the governance policy for that namespace and its descendants.
ColumnTypeNotes
PKnamespaceTEXTHierarchical path. Inheriting children walk up.
FKstandard_idTEXT NULLmemories(id). The memory holding the policy in metadata.
parentTEXT NULLAncestor namespace (computed for fast walk).
created_atTEXT NOT NULLRFC3339 UTC.
entity_aliases ▸ ENTITY REGISTRY v0.6.3 Stream B
Alias → canonical-entity resolution side table. Each entity is a memory (in any namespace); this table holds zero-or-more alternate names per entity.
ColumnTypeNotes
PKentity_idTEXT NOT NULLmemories(id) (the canonical entity memory).
PKaliasTEXT NOT NULLAlternate name. Composite PK (entity_id, alias).
created_atTEXT NOT NULLRFC3339 UTC.
▸ idx_entity_aliases_alias (alias) — fast reverse lookup
Governance & federation

pending_actions · sync_state · subscriptions.

pending_actions ▸ GOVERNANCE QUEUE
When governance policy says "Approve", the requested action lands here instead of executing immediately. Cleared on approve (executes the action) or reject.
ColumnTypeNotes
PKidTEXTUUIDv4 of the pending action.
action_typeTEXT NOT NULLOne of store · delete · promote (the GovernedAction enum).
namespaceTEXT NOT NULLTarget namespace (drives policy lookup).
requested_byTEXT NOT NULLagent_id of the caller.
requested_atTEXT NOT NULLRFC3339 UTC.
payloadTEXT NOT NULLJSON. The full memory + context to execute on approval.
approvalsTEXT NOT NULLJSON array of {agent_id, approved_at}. Consensus mode counts entries.
decisionTEXT NULLNULL = pending · "approved" · "rejected".
decided_atTEXT NULLRFC3339 UTC when decision finalized.
sync_state ▸ FEDERATION CURSOR
Per-(local-agent, peer-URL) sync cursors. Drives the catchup loop. last_pulled_at advances after successful /api/v1/sync/since pulls.
ColumnTypeNotes
PKagent_idTEXT NOT NULLLocal node's agent_id.
PKpeer_urlTEXT NOT NULLFederation peer's HTTPS URL.
last_pulled_atTEXT NULLRFC3339 UTC of last successful pull from this peer.
last_pushed_atTEXT NULLRFC3339 UTC of last push.
subscriptions ▸ WEBHOOKS
Outbound webhook subscriptions. Each row spawns a dispatch thread on matching event. HMAC-SHA256 signed bodies. Retry-on-5xx with bounded attempts.
ColumnTypeNotes
PKidTEXTUUIDv4.
urlTEXT NOT NULLWebhook endpoint. Validated against SSRF guard (validate_url_dns).
eventsTEXT NOT NULLComma-separated or *. e.g. store,delete,contradiction.
namespace_filterTEXT NULLGlob pattern. NULL = all namespaces.
agent_filterTEXT NULLFilter by metadata.agent_id. NULL = all agents.
secret_hashTEXT NULLSHA-256 of the plaintext shared secret. Plaintext returned once on subscribe.
created_byTEXT NULLagent_id of subscriber.
created_atTEXT NOT NULLRFC3339 UTC.
dispatch_countINTEGERSuccessful dispatches.
failure_countINTEGERFailed dispatches (non-2xx OR connect timeout).
Migrations

Schema is versioned. Migrations are idempotent.

Every schema change is a forward migration applied at daemon startup. Idempotent so re-runs are safe. v15 was the v0.6.3 Stream B addition (KG temporal-validity columns + entity_aliases). v0.6.3.1 added the v17/v18/v19 ladder: v17 adds governance.inherit backfill (`migrations/sqlite/0012_governance_inherit.sql`), v18 adds embedding_dim guard + archive lossless (`0011_v0631_data_integrity.sql`), v19 adds webhook event_types column + index (`0013_webhook_event_types.sql`). Older versions (≤ v14) remain inline in db.rs::migrate.

Version timeline
VersionReleaseChange
1-3v0.1-0.4memories table; basic CRUD; tier enum; FTS5 virtual.
4-7v0.4-0.5memory_links; tags JSON; expires_at; embedding BLOB.
8-10v0.5archived_memories; subscriptions; webhook dispatch_count.
11-13v0.6.0-0.6.1pending_actions; sync_state; namespace_meta; governance policy in metadata; agent_id resolution.
14v0.6.2SAL adapter prep; postgres_schema.sql; chunked_from metadata.
15v0.6.3Hierarchy + KG additions. 4 new memory_links columns; entity_aliases table; 3 temporal indexes. Migration file →