pg_agentmem
alohadb · AlohaDB versioned agent memory with scoped hybrid recall
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102461 | pg_agentmem | alohadb | 1.2 | RAG | MIT | SQL |
PostgreSQL · 18
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
pg_agentmem 1.2 stores versioned long-term agent memories and entity relationships, with hybrid recall using vector, keyword, graph, recency and importance scores.
These are preview modules of AlohaDB 21.7.0, a PostgreSQL 18 fork. Compatibility with stock PostgreSQL is not established.
Store and Recall
The SQL/PLpgSQL extension uses the AlohaDB core vector type; a separate vector extension is not a declared dependency. Its control sets superuser=false, but does not mark it trusted: the installer still needs the permissions required by its objects and language. No preload or restart is required.
agentmem_update creates a new version; agentmem_history reads version history. agentmem_forget normally soft-forgets a memory, while hard=true deletes its history. agentmem_context formats recalled content under an approximate prompt-token budget; it is not an exact model tokenizer.
Scope and Security
Version 1.2 adds role-to-tenant binding and RLS through agentmem_grant(role, tenant_id, read_only). A bound role reads its own tenant and global NULL-tenant rows, writes only its own tenant, and has its tenant filled in by the APIs; requests for another tenant fail with SQLSTATE 42501. Unbound roles and table owners remain unrestricted. User, agent and session arguments are still caller-selected filters, not authentication. Review role memberships and inherited scope before serving untrusted tenants. agentmem_revoke(role) removes grants and the binding.
Recall normally updates access counters; set read_only=true for a read-only transaction. Optional pg_embeddings supplies embeddings and pg_graph supplies graph integration; manual embeddings and keyword recall do not require these optional modules. Keep embedding dimensions/model consistent. Hybrid ranking is heuristic, and retrieved text remains untrusted application input.
Ingestion, Queue and Upgrade
agentmem_ingest() converts text or messages into proposed memory changes through optional pg_nl2sql or a custom extractor with signature (text,jsonb) RETURNS jsonb. Proposed modifications are checked against the supplied scope and execute with caller privileges; model output is still untrusted, and sending text to an external model can disclose it. Review changes with dry_run before applying sensitive workloads.
agentmem_enqueue() records work and agentmem_process_queue() processes each item in its own subtransaction with bounded retries. Inspect failures and queue statistics. agentmem_schedule() needs optional pg_cronjobs; an external scheduler can invoke processing instead. agentmem_enqueue_from_traces() additionally needs pg_agenttrace. These optional integrations are not required for basic memory storage.
Back up memory and role bindings, install matching SQL files, then use the supplied 1.0-to-1.1-to-1.2 chain with ALTER EXTENSION pg_agentmem UPDATE TO '1.2'. Bind each service role explicitly and check cross-tenant denial; simply upgrading does not restrict existing unbound roles.