pgmnemo

Provenance-gated vector memory for LLM agents in PostgreSQL

Overview

PackageVersionCategoryLicenseLanguage
pgmnemo0.8.3RAGApache-2.0SQL
IDExtensionBinLibLoadCreateTrustRelocSchema
1900pgmnemoNoNoNoYesYesNopgmnemo
Relatedvector vector pg_search pg_ai_query pg_later

SQL-only extension; requires pgvector.

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.8.31817161514pgmnemovector
RPMPIGSTY0.8.31817161514pgmnemo_$vpgvector
DEBPIGSTY0.8.31817161514postgresql-$v-pgmnemopgvector
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
d13.x86_64
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
d13.aarch64
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
u22.x86_64
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
u22.aarch64
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
u24.x86_64
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
u24.aarch64
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
u26.x86_64
u26.aarch64
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3
PIGSTY 0.8.3

Build

You can build the RPM / DEB packages for pgmnemo using pig build:

pig build pkg pgmnemo         # build RPM / DEB packages

Install

You can install pgmnemo directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pgmnemo;          # Install for current active PG version
pig ext install -y pgmnemo -v 18  # PG 18
pig ext install -y pgmnemo -v 17  # PG 17
pig ext install -y pgmnemo -v 16  # PG 16
pig ext install -y pgmnemo -v 15  # PG 15
pig ext install -y pgmnemo -v 14  # PG 14
dnf install -y pgmnemo_18       # PG 18
dnf install -y pgmnemo_17       # PG 17
dnf install -y pgmnemo_16       # PG 16
dnf install -y pgmnemo_15       # PG 15
dnf install -y pgmnemo_14       # PG 14
apt install -y postgresql-18-pgmnemo   # PG 18
apt install -y postgresql-17-pgmnemo   # PG 17
apt install -y postgresql-16-pgmnemo   # PG 16
apt install -y postgresql-15-pgmnemo   # PG 15
apt install -y postgresql-14-pgmnemo   # PG 14

Create Extension:

CREATE EXTENSION pgmnemo CASCADE;  -- requires: vector

Source: pgmnemo v0.8.3 README, Usage Guide, extension control file, SQL definition.

Usage

pgmnemo stores provenance-gated agent lessons in PostgreSQL and retrieves them through vector, BM25-style text, graph-edge, JSONB metadata, and relational filters. The extension control file requires vector, so pgvector must be available before creating pgmnemo. The local package metadata targets PostgreSQL 14-18.

Create and Ingest Lessons

CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS pgmnemo CASCADE;

SELECT pgmnemo.ingest(
  p_role        := 'developer',
  p_project_id  := 1,
  p_topic       := 'security',
  p_lesson_text := 'Rotate JWT secrets after any key-compromise incident.',
  p_importance  := 4,
  p_embedding   := NULL,
  p_commit_sha  := 'abc1234',
  p_metadata    := '{"source":"incident-runbook"}'::jsonb
);

pgmnemo.ingest() is the preferred write path. It validates the 1024-dimensional embedding when supplied, stamps verified rows when provenance is present, and applies the provenance gate.

Provenance Gate

SHOW pgmnemo.gate_strict;

SET pgmnemo.gate_strict = 'warn';
SET pgmnemo.gate_strict = 'enforce';

pgmnemo.gate_strict accepts enforce, warn, or off. In the default enforced mode, inserts fail when both p_commit_sha and p_artifact_hash are NULL. pgmnemo.include_unverified is separate: it controls whether unverified rows are eligible for recall, not whether writes are allowed.

Recall

-- Text-only recall.
SELECT topic, lesson_text, score
FROM pgmnemo.recall_lessons(
  NULL::vector(1024),
  5,
  'developer',
  1,
  'JWT secret rotation'
);

-- Hybrid vector and text recall.
SELECT lesson_id, topic, score, vec_score, bm25_score, rrf_score
FROM pgmnemo.recall_hybrid(
  '<1024-dimensional vector literal>'::vector(1024),
  'JWT rotation key compromise',
  10,
  'developer',
  1
);

Hybrid routing in recall_lessons() requires pgmnemo.disable_hybrid to be off, non-empty query_text, and a non-NULL embedding. Use recall_hybrid() directly when you want explicit diagnostic scores.

SELECT *
FROM pgmnemo.navigate_locate(
  NULL::vector(1024),
  'JWT rotation',
  10,
  'developer',
  1,
  '{"topic":"security"}'::jsonb,
  2000
);

SELECT *
FROM pgmnemo.navigate_expand(
  ARRAY[1001, 1002]::bigint[],
  include_edges := true
);

navigate_locate() returns ranked lesson IDs and short previews within a character budget. navigate_expand() fetches selected full lessons and optional graph neighbors after the caller chooses which IDs are worth expanding.

Edges and Outcome Learning

SELECT pgmnemo.add_edge(1001, 1002, 'CAUSED_BY', 0.85, '{"run_id":7320}'::jsonb);

SELECT pgmnemo.reinforce(1001, 'success');
SELECT pgmnemo.reinforce(1002, 'failure');

pgmnemo.add_edge() is the idempotent helper for lesson relationships. reinforce() adjusts confidence after observed outcomes and feeds later match confidence.

Maintenance and GUCs

SELECT * FROM pgmnemo.stats();

SELECT pgmnemo.reembed(
  p_lesson_id  := 1001,
  p_new_vector := '<1024-dimensional vector literal>'::vector(1024)
);

SELECT pgmnemo.recompute_content(
  p_lesson_id       := 1001,
  p_new_lesson_text := 'Rotate JWT secrets within 24 hours after compromise.'
);

Useful settings include pgmnemo.gate_strict, pgmnemo.include_unverified, pgmnemo.ef_search, pgmnemo.disable_hybrid, pgmnemo.recency_weight, pgmnemo.importance_weight, pgmnemo.graph_proximity_weight, pgmnemo.temporal_boost, and pgmnemo.max_query_text_chars.