All posts

28 Oct 2026 · Postgres & pgvector

Production RAG in PostgreSQL, pgvector vs Pinecone and Qdrant

When a vector column next to Auth.js is enough, what managed vector DBs actually cost, and how Next.js 15 talks to pgvector through Prisma.

Pinecone is a good product. It is also a second vendor, a second bill, and a second network hop between your Next.js app and the chunks that belong to the same user row in Postgres.

AgenticPacks OSS is Postgres plus Prisma, no vectors: Agentic-Packs/agenticpacks-oss. Pro keeps embeddings in pgvector (1536-dim, cosine <=>) next to Auth.js and Stripe customer ids. The SQL details are in Prisma pgvector migrations.

What you pay for

Figures are order-of-magnitude, USD per month, not a quote.

SetupAt 10k docsAt 1M chunksExtra moving parts
pgvector on the same VPS as the appincluded in the 5 euro nodestill on that disk until you vertical scaleextension, raw SQL
Pinecone serverlesstens of dollarsusage + storageAPI keys, another region
Qdrant Cloudsimilar bandsimilar bandanother cluster
Self-hosted Qdrantanother containerRAM for HNSWsecond healthcheck

The self-hosting cost post already argued that serverless glue is the line item you notice. A managed vector DB is the same shape: cheap at hackathon size, loud at SaaS size.

You still pay the embeddings API. pgvector does not make OpenAI free. It removes the retrieval vendor.

When Pinecone still wins

  • You have hundreds of millions of vectors and a dedicated search team.
  • You need hybrid search features you do not want to build.
  • Your Postgres is a tiny managed instance you refuse to grow.

For an AI SaaS with per-tenant docs in the low millions of chunks, Postgres is the boring answer. Filters are WHERE "organizationId" = $1 instead of metadata syntax in a second product.

Next.js shape

  1. Upload or crawl.
  2. Chunk ~500 tokens (Pro's chunker).
  3. Embed in batches. Respect rate limits. See ingestion.
  4. $executeRaw insert as vector(1536).
  5. At query time, embed the question, ORDER BY embedding <=> $q LIMIT k.
  6. Pass chunks into the model. Optionally into LangGraph. See LangGraph streaming.

Authz is a SQL WHERE, not a hope that the vector index is tenant-scoped. Same IDOR lesson as Server Actions.

Ops

The Docker image must be pgvector/pgvector:pg16 (or equivalent). Stock postgres:16 will reject vector. Backups are pg_dump like everything else. Restore includes the extension.

HNSW vs IVFFlat is an index choice, not a reason to leave Postgres. Start IVFFlat after you have data. Rebuild in a maintenance window.

Tired of a $70 vector bill next to a $25 Postgres bill?

AgenticPacks OSS is the relational baseline: Agentic-Packs/agenticpacks-oss.

Pro ships pgvector RAG in the same Compose file. See self-hosted pgvector RAG in Pro.

Decision

If your RAG corpus is tenant documents and your source of truth is already Postgres, add a column. If you are building a standalone search company, buy a search company product.


Where to Go From Here

You do not have to stand up a second database to ship contextual chat.

Option A: Free open-source baseline (MIT)


Option B: Ship with AgenticPacks Pro ($149 one-time)

If retrieval should live next to users and invoices:

  • Automated Hetzner provisioning: Terraform, Caddy, Compose, pgvector image.
  • Production multi-agent core: Chunking, cosine search, LangGraph, Redis.
  • Usage & Unit Economics: Stripe and a token ledger.