pgvector vs Dedicated Vector DBs
Read a little, play a little. No scary maths, and no rush.
Last reviewed: October 2026 · report an issue
The one-line verdict
- Data already in Postgres? pgvector — vectors as a column, similarity in SQL, one backup to manage.
- Outgrowing it? Qdrant / Pinecone / Chroma (see our vector-DB showdown) — purpose-built scale and filtering.
Official homes: pgvector · Supabase AI guide · Qdrant.
pgvector in 5 lines
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE docs (
id bigserial PRIMARY KEY,
content text,
embedding vector(1536)
);
CREATE INDEX ON docs USING hnsw (embedding vector_cosine_ops);
SELECT content FROM docs ORDER BY embedding <=> '[0.1, 0.2, ...]' LIMIT 4;
A worked example: a multi-tenant help assistant
A SaaS product stores each customer's help articles in Postgres, with a tenant_id column and an embedding column on the chunks table. One query does everything:
SELECT content
FROM chunks
WHERE tenant_id = $1
ORDER BY embedding <=> $2
LIMIT 4;
Row-level security on chunks guarantees the tenant filter even if application code forgets it. When an article is edited, one transaction updates the text and its embedding together, so they can never disagree. Backups, permissions, and monitoring are the ones the team already runs.
Choosing an index
pgvector offers two approximate index types:
- HNSW: fast queries and high recall, at the cost of more memory and slower index builds. The usual default.
- IVFFlat: builds faster and uses less memory, but should be created after the table has data, and typically gives lower recall at the same speed.
For small tables, a plain scan with no index is exact and often fast enough.
A filtering gotcha
With an approximate index, Postgres may find the nearest vectors first and apply your WHERE filter afterwards. If the filter is very selective, such as a small tenant in a large table, a query asking for 4 results can come back with fewer. Recent pgvector versions added options to keep searching until enough rows pass the filter. Check the pgvector documentation for your version before relying on filtered approximate search.
Storage math
A 1536-dimension embedding stored as 4-byte floats is about 6 KB. A million chunks is therefore about 6 GB of vectors before index overhead, which is very manageable for one Postgres server, and a useful number to have when someone asks whether you have outgrown it.
Keeping it healthy under load
Vector search is heavy on CPU and memory, and it competes with your normal transactional queries on the same server. A few habits keep both happy:
- Send vector reads to a read replica, so similarity search cannot slow down checkouts or sign-ups on the primary.
- Give index builds enough memory. Building an HNSW index on a large table is much faster when Postgres is allowed more working memory for the build.
- Watch p95 and p99 search latency, not just averages, and track them separately from other queries.
- Vacuum after large re-embedding jobs, since updating many rows leaves dead rows behind that slow later queries.
When dedicated wins
- Billions of vectors or strict p99 latency budgets.
- Metadata filtering at a scale where a single Postgres box sweats.
- You want managed uptime someone else wakes up for.
Until then, pgvector plus the chunking and eval discipline from our RAG chapters beats a fancier database with sloppy retrieval.
Migration is a one-weekend project
Because embeddings are portable (vectors are just arrays), moving later is mechanical: export vectors + metadata, bulk-import into the new store, dual-read during cutover, compare recall on your eval set, flip the switch. Choosing pgvector today never traps you — it just defers the ops bill until scale demands it.
Check your understanding
5 questions · first-try answers earn the most XP
My notes
Saved in this browser. Highlight a line above and save it, or write it in your own words.
Nothing saved yet. Your highlights will live here.
References
Finished reading?
Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.
Related chapters
Spotted a mistake or want a topic covered? Report an issue