Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Railway 9 min read How-to mediumAdept

Hosting Postgres with pgvector: provider tradeoffs, migrations, indexes, and tuning

Running 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.

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.

  • RAG With Autoscaling: Better Performance With Lower Costs For pgvector

    Neon mediumAdept

    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.

  • pgvector 0.4.0 performance

    Supabase mediumAdept

    With tuned settings, pgvector 0.4.0's IVFFlat index handles 1M OpenAI embeddings (1536 dimensions, dbpedia dataset) at about 1800 QPS with 0.91 accuracy@10 on a 64-core, 256 GB instance, or about 670 QPS at 0.98 accuracy. Using the ANN Benchmarks methodology, the tests reproduce a default-config pgvector vs Qdrant comparison. Pre-warming RAM, using inner-product distance, raising lists to 2000 and increasing probes makes pgvector competitive, and throughput scales predictably with instance size. Practical guidance: raise lists above the recommended rows/1000 for faster queries at the cost of longer index builds and more maintenance_work_mem, prefer inner product for normalized embeddings, and benchmark with real rather than random vectors before right-sizing RAM.

  • pgvector 0.6.0: 30x faster with parallel index builds

    Supabase mediumAdept

    pgvector 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.

  • 20x faster than pgvector: introducing pg_embedding extension for vector search in Postgres and LangChain

    Neon mediumAdept

    pg_embedding brought HNSW graph-based approximate nearest neighbor indexing to Postgres. On the GIST-960 dataset (1M 960-dim vectors, k=100, 4 vCPU/16 GB), it ran 5–30x faster than pgvector's IVFFlat at equal recall. IVFFlat needs more probes to raise recall and drifts toward a sequential scan, while HNSW's layered graph gives roughly logarithmic search. HNSW trades higher memory use, slower index builds (driven by efConstruction) and L2-only distance for that speed. Neon has since deprecated pg_embedding in favor of pgvector, which now supports HNSW natively.

The quest for software engineering knowledge.

Look:
Layout: