Skip to main content

Module pg

Module pg 

Source
Expand description

PostgreSQL GraphBackend (feature graph-pg). PostgreSQL GraphBackend (graph-pg feature).

PgGraph mirrors the bundled SQLite backend over a single mutex-guarded synchronous postgres::Client. Every GraphBackend method matches the SQLite semantics — the composite smart_recall reuses super::recall’s weights and compute_recency for zero drift across backends. Full-text search uses ILIKE substring matching (no PostgreSQL extension required, so the backend runs on any vanilla install), and schema versioning flows through the trait’s current_version / migrate.

§Performance note

ILIKE with a leading wildcard ('%term%') is a sequential scan — the BTREE indexes cannot serve it. This is intentional: keeping the backend extension-free preserves portability (the same rationale as the CJK feature). For very large graphs, callers may opt into indexed substring search by enabling pg_trgm out-of-band (CREATE EXTENSION pg_trgm; CREATE INDEX nodes_trgm ON nodes USING gin ((title || ' ' || body || ' ' || tags) gin_trgm_ops)); the ILIKE queries then use it transparently. (With a non-empty PgGraph table prefix, substitute the prefixed table name in that out-of-band DDL.)

§TLS (graph-pg-tls feature)

PgGraph::connect / PgGraph::connect_config always use postgres::NoTls — servers requiring sslmode=require or stricter reject that handshake. Enabling graph-pg-tls adds PgGraph::connect_native_tls (system trust store, one call) plus PgGraph::connect_tls / PgGraph::connect_config_tls for a caller-supplied postgres::tls::MakeTlsConnect implementor.

§Table prefix

Every constructor has a *_with_prefix variant that namespaces the backing nodes / edges / _meta tables — and every index name — under a caller-chosen prefix, so several graphs (or a graph and unrelated service tables) can coexist in one database. The default empty prefix preserves the original nodes / edges / _meta names exactly: existing databases and tests are unaffected. Because the prefix is interpolated into DDL/DML as a bare identifier (PostgreSQL does not accept bind parameters for identifiers), it is validated by is_identifier_safe before any SQL is emitted, keeping the interpolation injection-safe.

Structs§

PgGraph
PostgreSQL-backed GraphBackend over one mutex-guarded connection.