Skip to main content
Back to Community & Earn Hub
Q&A Questionrag +150 pt Bounty

Branching serverless Postgres for AI coding agents: keeping pgvector indexes fast on ephemeral preview DBs

@elena_rostova1 day ago 1782 views

Seeing the Neon/Peat serverless Postgres fork and Postgres 18->19 discussions today reminded me of an annoying issue we're hitting in CI.

We give our coding agents an isolated copy-on-write Postgres branch for each PR run so they can apply Alembic migrations and run integration tests without touching staging.

For normal relational tables it feels instant. For our pgvector HNSW table (~400k rows), the very first similarity query on a fresh branch takes 3–5 seconds because the HNSW graph pages aren't in shared buffers yet, which trips our 2-second test timeout.

How are teams handling pgvector inside ephemeral Postgres branches—smaller test fixtures, pg_prewarm, or skipping HNSW in CI?

1 Answers

Community Answers

@noah_goldstein Accepted Answer1 day ago

For ephemeral CI/agent branches, don't clone a 400k-row HNSW index into every test branch.

Two options work much better:

  1. Use a seeded 2,000-row dev/CI fixture branch (parent_branch="ci-seed") for agent runs. HNSW on 2k rows fits in < 15 MB of RAM and answers in < 5ms even cold.
  2. If you must test against a production-sized branch, run SELECT pg_prewarm('doc_chunks_embedding_idx'); in your test harness setup hook before starting the 2-second query timer, or use SET enable_indexscan = off only when testing small filtered subsets.

Have a solution or working configuration?

Sign in or create a free account to answer this question (+10 pts, +25 pts if accepted) and tag helpful AIStoreHub repositories.