Skip to content

LangGraph Store on pgdorm — 1-RTT Fused abatch Long-Term Memory#

LangGraph's BaseStore persists long-term agent memories across threads (PutOp, GetOp, SearchOp, ListNamespacesOp). Upstream's AsyncPostgresStore dispatches each operation group with hand-written SQL strings and multiple round trips. PgdormStore fuses the entire abatch into 1 wire RTT.

Before vs. After#

Dimension Upstream AsyncPostgresStore PgdormStore (pgdorm)
Multi-op abatch (3x PutOp + GetOp + SearchOp + ListNamespacesOp) Separate round trips per op group 1 wire RTT (pool.pipeline())
Bulk PutOp upsert Hand-built VALUES / per-row SQL Constant-shape UNNEST ... ON CONFLICT (prefix, key) DO UPDATE
Schema & typing Raw DDL strings + psycopg dicts Slot-backed StoreEntry(pg.Table) with typed Jsonb
tests/cases/langgraph_store/store.py — 1-RTT fused abatch
async with self._pool.pipeline() as pipe:
    if upsert_rows:
        pipe.add(
            pg.insert_many(StoreEntry, upsert_rows).on_conflict_do_update(
                StoreEntry.prefix,
                StoreEntry.key,
                value=pg.excluded(StoreEntry.value),
                updated_at=pg.excluded(StoreEntry.updated_at),
                expires_at=pg.excluded(StoreEntry.expires_at),
                ttl_minutes=pg.excluded(StoreEntry.ttl_minutes),
            )
        )
    for prefix, key in delete_keys:
        pipe.add(
            pg.delete(StoreEntry).where(
                (StoreEntry.prefix == prefix) & (StoreEntry.key == key)
            )
        )
    for idx, op in enumerate(op_list):
        if isinstance(op, GetOp):
            prefix = _ns_to_prefix(op.namespace)
            h = pipe.add(
                pg.select(StoreEntry).where(
                    (StoreEntry.prefix == prefix) & (StoreEntry.key == op.key)
                )
            )
            handles[idx] = ("get", h)
        elif isinstance(op, SearchOp):
            prefix = _ns_to_prefix(op.namespace_prefix)
            stmt = pg.select(StoreEntry)
            if prefix:
                stmt = stmt.where(
                    (StoreEntry.prefix == prefix) | StoreEntry.prefix.like(f"{prefix}.%")
                )
            stmt = stmt.order_by(StoreEntry.prefix.asc(), StoreEntry.key.asc())
            handles[idx] = ("search", pipe.add(stmt))
        elif isinstance(op, ListNamespacesOp):
            h = pipe.add(pg.select(StoreEntry).order_by(StoreEntry.prefix.asc()))
            handles[idx] = ("list_ns", h)

Adoption Ladder (Live PostgreSQL)#

Status Rung Today Blocked by
✅ Audit the live schema 2 tables; left untouched: nothing —
✅ Bind models to the live schema, zero DDL 0 planned DDL operations —
✅ Build a fresh database from the models alone 2 DDL ops applied cleanly —
✅ Assimilate the upstream schema into idiomatic pgdorm 6 assimilation ops applied cleanly, 0 blockers, 0 residual ops —
✅ Run core BaseStore operations (put, get, search, list_namespaces, delete) 5 of 5 named queries, each graded upstream —
✅ Run real LangGraph StateGraph with BaseStore long-term memory on pgdorm 1-RTT fused abatch (UNNEST PutOp + GetOp + SearchOp + ListNamespacesOp) inside live StateGraph —

Source & Tests#