Skip to content
Skip to content
CHIMBUK.

Try flutter, ai, pricing or sudoku

[Engineering Insights]AI

Postgres with pgvector vs. dedicated vector databases: benchmarks and TCO at 10M embeddings

Before committing to a $1,500/month dedicated vector database, benchmark Postgres with HNSW indexing. Real-world latency numbers, recall trade-offs, and why one database for relational data and vectors simplifies production.

Chimbuk Engineering Studio11 min readPeer Reviewed

Every team building an AI-powered application arrives at the vector database fork in the road: do you pay for a specialized hosted vector service (Pinecone, Qdrant, Milvus), or do you enable pgvector on your existing PostgreSQL instance? The vendor marketing insists that general-purpose databases cannot handle vector workloads at scale. We ran empirical benchmarks at 1M, 5M, and 10M 1536-dimensional embeddings (OpenAI text-embedding-3-small) to measure real p95 latency, recall, and infrastructure cost.

Benchmark methodology and test environment

  • Dataset: 10,000,000 vectors with 1,536 dimensions, generated from technical documentation corpora.
  • PostgreSQL instance: AWS RDS db.r6g.2xlarge (8 vCPU, 64 GB RAM, 500 GB gp3 SSD with 3,000 IOPS baseline).
  • Dedicated vector instance: Pinecone standard pod / Qdrant Cloud 4-node cluster with equivalent memory.
  • Index parameters: pgvector HNSW with m=16, ef_construction=64, and runtime hnsw.ef_search=40.
  • Query workload: 1,000 concurrent vector searches filtered by tenant_id (multi-tenant query pattern).

Latency and recall results

At 10M embeddings with HNSW indexing, pgvector delivered an average p95 latency of 14.2ms with 98.4% recall@10 compared to exact k-NN. The dedicated vector database clocked in at 11.8ms p95 with 99.1% recall. While the dedicated engine was ~2.4ms faster in isolation, pgvector won decisively once relational joins were required.

sql
-- Production pgvector setup with HNSW index
CREATE EXTENSION IF NOT EXISTS vector;

CREATE TABLE document_embeddings (
  id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  tenant_id   UUID NOT NULL,
  doc_id      TEXT NOT NULL,
  content     TEXT NOT NULL,
  embedding   vector(1536) NOT NULL,
  created_at  TIMESTAMPTZ DEFAULT clock_timestamp()
);

-- HNSW index using cosine similarity operator
CREATE INDEX idx_embeddings_hnsw 
  ON document_embeddings 
  USING hnsw (embedding vector_cosine_ops)
  WITH (m = 16, ef_construction = 64);

-- Query execution with runtime tuning
SET LOCAL hnsw.ef_search = 40;

SELECT id, doc_id, content, 1 - (embedding <=> $1) AS similarity
FROM document_embeddings
WHERE tenant_id = $2
ORDER BY embedding <=> $1
LIMIT 10;

The relational join advantage

In real applications, you almost never search raw vectors in a vacuum. You search vectors belonging to a specific workspace, filtered by user permissions, filtered by publication date, and joined with author metadata. With a dedicated vector DB, you either sync relational IDs into vector metadata (dual-write consistency headache) or do a two-step query: query vector DB, take 100 IDs, query Postgres to filter permissions. In Postgres, that is a single atomic SQL query with ACID guarantees.

Cost comparison: total cost of ownership

For 10M 1536-dimensional vectors with index memory overhead (~65GB RAM): a dedicated vector cloud provider averages $1,200 to $1,800/month. Expanding an existing AWS RDS Postgres instance from r6g.xlarge to r6g.2xlarge adds ~$240/month. The operational savings of not maintaining a second data store, sync pipeline, backup policy, and VPC peering connection are even larger.

Rule of thumb: unless you are surpassing 50 million vectors or require microsecond sub-5ms SLAs at 10,000 QPS, pgvector inside PostgreSQL is simpler, cheaper, and eliminates distributed transaction bugs.

CK
Chimbuk Engineering StudioVerified Engineering

Field notes authored by the core engineering and systems team at Chimbuk. We build and maintain production Flutter mobile applications, Next.js web architectures, and cloud backends. No recycled marketing theory — only architecture decisions, code patterns, and performance budgets from real production deployments.

Share:
★★★★★4.9 Clutch & Google Reviews

We architect and build the systems we write about.

From vector search pipelines to high-concurrency payment gateways — schedule a technical discovery call.