Applications should connect through a bounded database adapter that owns pooling, pgvector type registration, parameterized SQL, transactions, timeouts, and result mapping. Python's psycopg and TypeScript's node-postgres can both issue the same reviewed SQL. Keep tenant identity server-derived, validate vector dimensions, and never let framework convenience obscure transaction or query-plan behavior.
Add psycopg_pool to dependencies. In a real adapter, derive the model ID and expected dimensions, set role or session identity for RLS, map results to typed objects, and emit safe metrics.
With pg, vectors can be passed in the textual form supported by pgvector or through a library codec. Keep conversion in one function and validate finite numbers and length.
The example is intentionally SQL-forward. Adapt column names to the canonical schema and use transactions when setting local policy context.
Test missing DATABASE_URL, wrong dimensions, NaN/Infinity, connection failure, timeout, cross-tenant fixtures, rollback, and pool exhaustion. Compare adapter output with the same SQL in psql. Log query fingerprints and duration—not vectors, raw prompts, credentials, or sensitive content.
Review this database adapter [paste]. Check pool lifecycle, parameterization, pgvector encoding, transaction boundaries, statement timeouts, tenant provenance, retries, typed results, and sensitive logging. Produce tests before refactoring code.
Verification contract: Run the adapter against the same deterministic fixture as psql; assert ordered IDs, denial behavior, rollback, timeouts, and no leaked connections.