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.
| Setup | At 10k docs | At 1M chunks | Extra moving parts |
|---|---|---|---|
| pgvector on the same VPS as the app | included in the 5 euro node | still on that disk until you vertical scale | extension, raw SQL |
| Pinecone serverless | tens of dollars | usage + storage | API keys, another region |
| Qdrant Cloud | similar band | similar band | another cluster |
| Self-hosted Qdrant | another container | RAM for HNSW | second 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
- Upload or crawl.
- Chunk ~500 tokens (Pro's chunker).
- Embed in batches. Respect rate limits. See ingestion.
$executeRawinsert asvector(1536).- At query time, embed the question,
ORDER BY embedding <=> $q LIMIT k. - 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)
- GitHub: github.com/Agentic-Packs/agenticpacks-oss
- What is included: Next.js 15, Compose, PostgreSQL 16, Prisma, Auth.js v5, streaming chat, single-plan Stripe. No pgvector.
- Cost: free, 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.
