Postgres Adapter
For team sharing and production deployments. Uses PostgreSQL with database-level triggers for outcome propagation,LISTEN/NOTIFY for real-time watch, native full-text search via tsvector/GIN, and vector similarity search via pgvector.
Installation
psycopg3. For vector search, install the pgvector extension (included in the pgvector/pgvector Docker image).
Configuration
YAML
Environment Variable
Programmatic
Schema
The adapter auto-creates three tables and associated triggers:amfs_memory_entries
amfs_outcomes
amfs_knowledge_graph
A unique constraint on
(namespace, branch, source_entity, relation, target_entity) ensures idempotent upserts — repeated writes increment evidence_count and update last_seen rather than creating duplicates.
The knowledge graph is populated automatically by the SDK’s materializers: write() with pattern_refs, commit_outcome(), and read_from() all create edges without extra code. See API Reference for the full model.
Graph Methods
How It Works
Write
SELECT ... FOR UPDATElocks the current version rowUPDATEsetssuperseded_aton the old rowINSERTcreates the new version
Outcome Propagation
AnAFTER INSERT trigger on amfs_outcomes automatically:
- Reads the causal entry keys
- Supersedes the current version of each
- Inserts a new version with updated confidence (
old × multiplier)
Watch (LISTEN/NOTIFY)
AnAFTER INSERT trigger on amfs_memory_entries calls pg_notify('amfs_write', ...). The adapter listens on this channel and dispatches to your callbacks.
Docker Quick Start
Search
Full-Text Search
The adapter automatically maintains asearch_tsv column (GIN-indexed) that combines the key, entity_path, and value fields. When SearchQuery.query is set, the adapter uses plainto_tsquery with the @@ operator for efficient in-database filtering. When sort_by is "confidence" and a query is present, results are ordered by ts_rank(search_tsv, ...) first, then by confidence — so textually relevant results float to the top.
Vector Similarity Search (pgvector)
When an embedder is configured, the adapter stores vector embeddings in aVECTOR(384) column with an HNSW index. The semantic_search() method uses cosine similarity directly in SQL via pgvector’s <=> operator.
To use pgvector, install the extension in your database:
Tier Indexes
Two partial indexes accelerate progressive retrieval queries:idx_entries_hot—WHERE tier = 1 AND superseded_at IS NULLidx_entries_warm—WHERE tier <= 2 AND superseded_at IS NULL
depth=1, the query uses the hot index; depth=2 uses the warm index.
Connection Pooling
The adapter usespsycopg_pool.ConnectionPool for efficient connection management. The pool size is configurable and defaults to sensible limits for most deployments.
When to Use
- Team environments (multiple developers/agents sharing memory)
- Production deployments with full-text and vector search
- When you need database-level consistency guarantees
- When you want memory to survive machine restarts
- When you need efficient search across large memory stores
Next Steps
- S3 Adapter — cloud-native storage for distributed teams
- HTTP API Server — expose SenseLab over REST
- Docker & Kubernetes — deploy SenseLab + Postgres in containers
