Every RAG project hits the same early question: do we add a vector database, or
put embeddings in the Postgres we already run? The honest answer for most
teams starting out is that pgvector vs a dedicated vector database is not
a performance contest yet. It is an operations and risk decision, and the
performance question only becomes real at a scale most products reach later
than they expect.
This post lays out what pgvector actually gives you, where its documented
limits are, and the signals that justify moving to a dedicated engine. Facts
about pgvector come from its official README.
Where I describe vendor benchmarks, I do not quote their numbers, because they
are run on specific hardware by parties who sell one side of the comparison.
What does pgvector give you out of the box?
pgvector adds vector types and nearest-neighbour search to Postgres. Per its
README it supports two approximate index types, HNSW and IVFFlat, and several
vector types:
| Type | Max dimensions you can index | Use |
|---|
vector | 2,000 | Standard float32 embeddings |
halfvec | 4,000 | Half precision, smaller index |
bit | 64,000 | Binary quantization |
sparsevec | 1,000 non-zero elements (HNSW only) | Sparse embeddings |
Vectors can be stored up to 16,000 dimensions, but only the sizes above can be
indexed. Most mainstream embedding models fall well inside that, though you
should check the dimension of the model you choose.
The practical benefit is not speed. It is that your embeddings sit in the same
database as the rows they describe. One backup, one set of credentials, one
migration tool, and a write that updates a document and its embedding in one
transaction. For a team without dedicated infrastructure staff, that removes a
whole system from the pager rotation.
Where does pgvector get hard?
Filtered search
This is the limit that surprises people most. The README states that with
approximate indexes, filtering is applied after the index is scanned. Its own
example: if your WHERE clause matches 10% of rows, HNSW with the default
hnsw.ef_search of 40 returns about 4 matching rows on average, not 40.
That matters enormously for multi-tenant products, where every query is
filtered by customer. Version 0.8.0 added iterative index scans, which keep
scanning until enough results are found or a cap is hit (hnsw.max_scan_tuples
defaults to 20,000). The README also suggests partial indexes for filters with
few distinct values and partitioning for many. If your filters are highly
selective, test this on real data first. Our post on
multi-tenant RAG data isolation
covers the isolation side of the same problem.
Memory and index builds
HNSW indexes perform best when they fit in memory, so index size and
shared_buffers become capacity-planning inputs. Quantized types (halfvec,
binary with re-ranking against the original vectors, as the README
recommends) reduce size at some cost in recall. None of this is exotic, but
it is Postgres tuning, so someone has to own it.
Everything shares one database
Heavy vector queries compete with your transactional workload for CPU, memory
and I/O. A read replica dedicated to retrieval is the usual answer, and it is
also the point where you are already running a second database system, just a
familiar one.
What does a dedicated vector database add?
Dedicated engines such as Pinecone, Qdrant, Weaviate or Milvus are built
around the vector workload, so they typically offer:
- Filtering designed into the index rather than applied afterwards
- Horizontal scaling and sharding for very large collections
- Managed operation, if you choose a hosted product
- Built-in features such as sparse-plus-dense hybrid retrieval
The costs are real too: another system to deploy, secure and monitor; data
duplicated from your source of truth, with sync logic that can drift; and, for
proprietary managed services, a migration project if you ever leave.
How should you decide?
| Situation | Lean towards |
|---|
| Already on Postgres, early product, modest corpus | pgvector |
| Small team, no one to run another datastore | pgvector or a fully managed service |
| Strict per-tenant filters on every query, large corpus | Test pgvector with iterative scans; consider a dedicated engine if recall suffers |
| Corpus growing past what one Postgres node serves comfortably | Dedicated engine or sharded setup |
| Need vector search to scale independently of your app database | Dedicated engine or a retrieval read replica |
| Strong data-residency or self-hosting requirement | pgvector or a self-hosted engine such as Qdrant |
The deciding evidence is always a measurement on your own data. Build a set of
representative queries with known relevant documents (the same evaluation set
you need for hybrid search and reranking),
then record recall and latency under the filters your product really uses.
A vendor chart tells you about the vendor's dataset.
How do you avoid getting locked in either way?
Three habits keep the decision reversible:
- Keep source text and embeddings in your own storage. Treat the vector
index as a rebuildable cache, not the system of record.
- Put retrieval behind one interface in your code:
search(query, filters, k). Swapping the backend then touches one module.
- Record the embedding model and version with every vector. When you
change models you must re-embed everything, regardless of which database
you use. The same discipline applies to generation models, as covered in
planning an LLM model migration.
What to do next
Start with pgvector if you already run Postgres, and write down the trigger
that would make you move: for example, filtered recall below a target you set,
p95 retrieval latency above your budget, or index size that no longer fits your
memory plan. Having that trigger written down turns a vague worry into a
measurable condition.
If you are choosing a retrieval architecture for an AI product and want a
second opinion before committing, see how we approach
AI SaaS development and get in touch.