Repository navigation
Description
Self Graph cannot read data that already lives in Postgres tables. Today a user with people, companies, and an employment table has to copy the rows out and insert them as text or facts. The copy goes stale on the next write.
pg_hydradb already keeps an index of the links between registered tables, updated by triggers in the writer's transaction. It answers "what is one hop from this row" in one SQL call. Self Graph can read through it without owning the data.
Proposal
Add a read-only store, PgHydraDBStore, behind a new selfgraph[postgres] extra.
- A row of a registered vertex table is an entity (
person:1). A row of an edge table is a current relation with one version (relation:works_at:10). Types come from the labels, asSchema.from_tablesnames a table (personisPerson,works_atisWORKS_AT).draft_schema()returns them as a schema. - The store implements the read primitives that
retrieve,neighbors,find_path,entities.get,entities.find, andrelations.getuse. Each hop is onehydradb.reachable_edgescall. - Every write primitive raises a coded
read_only_storeerror. A read that lists or counts every row, or runs Cypher, raisesunsupported_read. A graph that is missing, paused, or unreadable failsinitializewithgraph_unavailable. - Seeding:
retrievetoday scans every entity page. A store can now supply seed candidates through an optionalseed_candidates(ns, terms)read. The Postgres store runs a fixedWHERE <name> ILIKE $1 LIMIT $2per table and query word, and BM25 ranks the hits as today._opsstays backend-unaware. - Partial reads: a store that hits an engine limit calls
mark_partial(). Theretrieve,neighbors, andfind_pathresult then hastruncated: true.
Database access contract
- Every connection starts with
default_transaction_read_only=onand astatement_timeout. The pool runs no reset statement. - Only fixed, parameterised statements: registry reads,
hydradb.reachable_edges,SELECT <cols> FROM <registered table> WHERE <key> = ANY(...), and the ILIKE lookup. - Identifiers come only from the pg_hydradb registry and are quoted. Values are always bound. No DDL, no writes, no LLM- or user-written SQL. No password or URI in any error.
Plan
One stack of PRs, each under 1,000 changed lines:
- Store read hooks and the three error codes, in both SDKs.
- The Python store, its tests, and the docs.
- The TypeScript store.
store=postgresin the runtime, CLI, and MCP server of both SDKs.
Out of scope
Writes, fact history, and contradiction handling over Postgres (the tables are the source of truth). Postgres as Self Graph's own storage is a separate, larger change.
Decisions
The maintainers decided the open questions on 2026-12-05:
- CI: #729 adds the CI job
postgres. It builds pg_hydradb from a pinned hydradb commit, caches the build, and runs the gated tests of both SDKs on Postgres 16 and 17. No image goes to a registry. - Drivers: asyncpg (
asyncpg>=0.30) for Python, node-postgrespg(optional peer dependency) for TypeScript. check_answerablestays refused on this store withunsupported_read; the docs page states this limit.- AGENTS.md: a schema draft may read a store's own catalog and registry, never user rows.
Activity
adityamishra-hydradb commentedon Dec 4, 2026
/approved
github-actions commentedon Dec 4, 2026
Approved by @adityamishra-hydradb. @adityamishra-hydradb or an assignee of this issue can now open a PR that links it with
Closes #706(max 10 open PRs at a time). Anyone else can comment/takeon this issue to be assigned.