RAG With Autoscaling: Better Performance With Lower Costs For pgvector
Neon's autoscaling lets a Postgres instance scale up temporarily for the heavy memory and CPU demands of pgvector HNSW index builds, then scale back down, instead of being permanently overprovisioned. On a 1M-row table, a sequential-scan similarity query took about 3 seconds, while an HNSW index cut it to about 1 ms. Building that index used 8 parallel workers and 8GB of maintenance_work_mem and produced a ~7.8GB index. Because maintenance_work_mem is allocated upfront, Neon backs it with disk swap so a small compute can accept an 8GB setting, swapping data back into memory as the autoscaler adds compute units.
Related posts
- pgvector: 30x Faster Index Build for your Vector Embeddings
Neon mediumAdept
pgvector 0.6.0 adds parallel builds for HNSW indexes, cutting build time by up to 30x in benchmarks on 10M 1,536-dimension vectors using a 64 vCPU, 512GB instance. Recall is essentially unchanged, with most results shifting slightly upward. Fast builds depend on giving the graph enough memory: raise maintenance_work_mem (for example to 8GB) so the graph fits, and raise max_parallel_maintenance_workers above the default of 2. On Neon, which currently supports pgvector 0.5.1 with 0.6.0 coming, compute can be scaled up for the build and back down afterward, avoiding permanent over-provisioning just for indexing.
- pgvector 0.6.0: 30x faster with parallel index builds
Supabase mediumAdeptpgvector 0.6.0 adds parallel HNSW index builds, cutting build time for 1M 1536-dimension vectors (dbpedia OpenAI dataset, m=16, ef_construction=200) from about 1h27m to 9.5 minutes. Benchmarks show 7-9x speedups on a 16-core instance and up to 13.5x on 64 cores, with no change in recall (0.963) or QPS. Scaling is not linear in core count, so max_parallel_maintenance_workers is best set to about CPU count / 2. Building on unlogged tables skips the non-parallelizable WAL write and pushes speedups to 23-31x, which suits embeddings that can be regenerated from source data.
- On-disk HNSW index for Postgres with pg_embedding
Neon mediumAdept
pg_embedding's new version builds its HNSW vector index on disk rather than in memory and adds cosine, Manhattan and Euclidean (L2) distance support. Benchmarks on an 8 vCPU / 32 GB machine show the in-memory index is roughly 2x faster, but persisting the index lets it work with Neon's autoscaling, scale-to-zero and read replicas for read-heavy similarity search. The post walks through enabling the extension, storing embeddings as real[] and tuning the index parameters dims, m, efConstruction and efSearch, where efSearch should be at least the query's LIMIT k. Neon has since discontinued pg_embedding and recommends pgvector instead.
- Hosting Postgres with pgvector: provider tradeoffs, migrations, indexes, and tuning
Railway mediumAdeptRunning pgvector well depends on hosting that allows extension and configuration control, migrations wired into the deploy pipeline, and the right index choice. Run migrations as pre-deploy steps, use idempotent CREATE EXTENSION, and build vector indexes with CREATE INDEX CONCURRENTLY outside a transaction so large tables stay writable. HNSW is recommended over IVFFlat for most workloads because recall and latency stay steadier, and tuning maintenance_work_mem, work_mem and effective_cache_size helps builds and queries. For traffic spikes, pair connection pooling, caching, precomputation and LIMIT queries with scalable infrastructure. Railway's container-based Postgres offers full extension control but lacks point-in-time recovery, automatic failover and built-in read replicas.
- 1 Year of Autoscaling Postgres: How it’s going, and what’s next
Neon hardMaster
Neon autoscales Postgres by running each instance as a VM in Kubernetes (NeonVM), with a per-node autoscaler-agent, a modified scheduler, and an in-VM vm-monitor that resizes the Local File Cache. Over the past year the team replaced cgroup memory.high event triggers with 100ms polling of memory usage for stability, and traced a 0-TPS stall to a kernel bug in ACPI memory hotplug that was fixed by upgrading the kernel. Next steps include sizing compute with a HyperLogLog estimate of working set from LFC page accesses, since a slightly larger cache can yield 10x gains. They are also adding swap, set up via mkswap/swapon on pre-created VMs, and disabling overcommit so up-front allocations like pgvector 0.6's parallel HNSW builds don't OOM.