PostgreSQL with pgvector vs Dedicated Vector Databases: Indexing, ACID Transactions, and Scaling Billions of Vectors
Adding vector search to an application forces an immediate infrastructure choice: enable the open-source `pgvector` extension inside your existing PostgreSQL database, or deploy a dedicated vector database alongside Postgres. Thanks to HNSW indexing, `halfvec` (FP16) and binary quantization, iterative filtered index scans, and DiskANN extensions, PostgreSQL now comfortably serves 5 million to 50+ million vectors at single-digit millisecond latency with full ACID transactional integrity—reserving standalone vector clusters for massive 100M-to-multi-billion-vector workloads.
Key Highlights
- Eliminating 'dual-write drift' is pgvector’s biggest superpower: when a user deletes a document or revokes team permissions in Postgres, the vector embedding disappears or updates inside the exact same ACID transaction.
- Modern `pgvector` (0.7 / 0.8+) fixed the classic 'filtered HNSW hole' via iterative index scans—automatically continuing graph traversal until enough rows matching your SQL `WHERE` clause are found.
- Switching `vector(1536)` (6 KB/row) to `halfvec(1536)` (3 KB/row in FP16) halves RAM usage and doubles index build speed in PostgreSQL with virtually zero retrieval recall loss.
- Dedicated vector databases (Qdrant, Milvus, Weaviate, Pinecone, Turbopuffer) pull ahead when vectors cross 100M–5B+ rows, need independent memory/compute sharding away from OLTP checkout traffic, or use object-storage-native cold/warm tiering.
2. Essential Production Tuning for PostgreSQL + pgvector
Default PostgreSQL settings (`shared_buffers = 128MB`, `maintenance_work_mem = 64MB`) will make HNSW index creation crawl! Apply four proven configurations whenever deploying `pgvector` in production:
- Use `halfvec` by default: Define columns as `halfvec(1024)` or `halfvec(1536)` with `halfvec_cosine_ops` to cut index memory by 50% cleanly.
- Raise `maintenance_work_mem` during index builds: Set `SET maintenance_work_mem = ‘4GB’` (or higher) and `max_parallel_maintenance_workers = 7` so HNSW graph construction finishes in minutes in RAM rather than thrashing disk.
- Partition multi-tenant tables: If each enterprise customer only ever searches their own workspace, declarative PostgreSQL list/hash partitioning by `tenant_id` keeps per-partition HNSW graphs tiny, fast, and hot in cache.
- Enable Iterative Scans (`SET hnsw.iterative_scan = relaxed_order;`): Guarantees full top-K results even when strict SQL `WHERE` filters match only 2% of rows.
3. When You Truly Outgrow pgvector
Migrate embeddings to a dedicated vector engine (or object-storage-backed vector store) when any of three concrete thresholds arrive: (1) your vector count crosses 100 million+ embeddings where holding HNSW graphs in primary Postgres RAM costs thousands of dollars monthly; (2) write-heavy streaming ingestion (5,000+ vector upserts per second) contends with sensitive OLTP locks; or (3) you have thousands of cold customer namespaces that rarely query simultaneously and benefit from S3/NVMe serverless cold storage.
FAQs
Should I run pgvector on the exact same Postgres instance as high-TPS financial payments?
Up to moderate load, yes; as vector QPS grows, route read-only RAG similarity queries to a dedicated PostgreSQL Read Replica (using streaming physical replication) so vector CPU/RAM usage never touches your primary transactional writer.
Can PostgreSQL do Hybrid BM25 + Vector Search natively without Elasticsearch?
Yes! Combine PostgreSQL’s native `tsvector` GIN full-text index (or the `pg_search` BM25 extension) with a `pgvector` HNSW query inside a single SQL Common Table Expression (`WITH semantic AS (...), lexical AS (...)`) joined via Reciprocal Rank Fusion in under 15 milliseconds.
Which index should I pick in pgvector: IVFFlat or HNSW?
Choose HNSW almost every time. Unlike IVFFlat—which requires existing data to train k-means centroids and degrades as data drifts without periodic `REINDEX`—HNSW can be created on an empty table, handles live inserts gracefully, and delivers markedly superior speed-recall curves.
References & Sources
- Kane, A. & Contributors — pgvector: Open-Source Vector Similarity Search for Postgres (HNSW, halfvec, sparsevec & Iterative Scans).
- PostgreSQL Global Development Group — PostgreSQL 17/18 Documentation: Index Access Methods & Parallel Maintenance.
- Pan, J. J.; Wang, J.; Li, G. — Survey of Vector Database Management Systems, The VLDB Journal.