pgmem
Reference

SQL layer & schema

The Postgres schema and migration contract.

pgmem's SQL layer lives entirely in the pgmem Postgres schema namespace — tables, indexes, and functions installed by versioned migrations. There's no graph database and no separate service; it's plain PostgreSQL plus pgvector. This page is an overview; DESIGN.md and sql/migrations/README.md in the repo are the full spec.

Shape

  • Namespace: everything is under the pgmem schema.
  • Vectors: pgvector with HNSW indexes; embedding dimension fixed at 1536.
  • Bi-temporal: facts carry validity bounds as generated tstzrange columns — see The bi-temporal model.
  • Full-text: generated tsvector columns with GIN indexes (English regconfig); an optional BM25 backend is used when present.

Main tables

TableTierHolds
entities4Semantic graph nodes.
entity_edges4Relationships, bi-temporally bounded.
episodes / episodic_edges4Source episodes and their mentions.
communities / community_nodes4Community detection output.
sessions0Session rows (group, user, MAGE pointers).
session_turns1Per-turn buffer.
session_state_nodes2The MAGE execution tree.
session_compactions2Compaction audit trail + validation verdicts.
memory_claims / memory_evidence3Authoritative scoped claims and immutable provenance.
memory_claim_indexes / vectors / graph edges4Rebuildable lexical, vector, and graph claim projections.
sagas / saga edges5Narrative threads and their session/episode links.
promotion_jobsThe async Tier 3 → Tier 4 promotion queue.

Session child tables (session_turns, session_state_nodes, session_compactions) deliberately carry no group_id — tenant isolation is transitive through the session handle. See Multi-tenancy.

Migrations

The schema evolves through immutable, append-only migrations in sql/migrations/:

RangeWhat it adds
001006Core graph schema, indexes, functions, HNSW tuning.
007024Sessions, claim ledger/evidence, narratives, projection queues, claim projections, and scope-isolation indexes.

The current schema version is recorded in pgmem.control (0.20.0), decoupled from the app version. Apply the schema with the plain-SQL installer (psql -f sql/migrations/install.sql); see which migrations are applied by querying pgmem.schema_migrations.

Migration files are immutable once released, and the packaged extension SQL (sql/extension/pgmem--*.sql) is generated from the migrations, never edited by hand. See Versioning & migrations.

On this page