If you already run PostgreSQL, start with the pgvector extension. It keeps vectors in the same tables as the rest of your data, with ordinary SQL filters, transactions and backups. Move to a dedicated vector database only when you have measured a specific limit: an index that will not fit in memory even after compression, filters that pgvector handles badly at your scale, or search load that should not share a server with your transactional work.
Key takeaways
- pgvector does exact search by default and offers two approximate index types, HNSW and IVFFlat. Exact search is often enough for a small corpus.
- Its documented limits are about what can be indexed: up to 2,000 dimensions for the
vectortype and 4,000 forhalfvec. - With an approximate index, pgvector applies
WHEREfilters after the index scan. Iterative scans, partial indexes and partitioning exist to deal with that. - Dedicated databases offer more index types and filtering built into the index. The price is a second system to run, secure and keep in sync.
- Decide on three things you can measure: scale, filtering and operations. Ignore vendor benchmarks you cannot reproduce on your own data.
This article is part of our complete guide to retrieval-augmented generation.
What does pgvector give you today?
pgvector is an open-source PostgreSQL extension. As of November 2026 the latest release in its changelog is 0.8.7, dated 1 October 2026. Its README lists exact and approximate nearest-neighbour search, four vector types (single-precision, half-precision, binary and sparse) and six distance measures including cosine. Because it lives inside Postgres, you keep transactions, point-in-time recovery, joins and replication.
A minimal setup, using only statements from the README:
CREATE EXTENSION vector;
CREATE TABLE chunks (
id bigserial PRIMARY KEY,
tenant_id int,
content text,
embedding vector(384)
);
-- exact search: no index needed, perfect recall
SELECT id, content FROM chunks
ORDER BY embedding <=> $1 LIMIT 5;
-- approximate search: add an index when exact search gets too slow
CREATE INDEX ON chunks USING hnsw (embedding vector_cosine_ops);
<=> is cosine distance. The README is direct about what an index does: by default pgvector performs exact nearest-neighbour search "which provides perfect recall", and an approximate index "trades some recall for speed". After you add one, the same query can return different results.
HNSW or IVFFlat?
| HNSW | IVFFlat | |
|---|---|---|
| How it works | A multilayer graph of vectors | Divides vectors into lists and searches the closest lists |
| Speed versus recall | Better query performance | Lower query performance |
| Build time and memory | Slower to build, uses more memory | Faster to build, uses less memory |
| Needs data first? | No. Can be created on an empty table | Yes. Create it after the table has data |
| Build options and defaults | m = 16, ef_construction = 64 | lists, which you choose |
| Query option and default | hnsw.ef_search = 40 | ivfflat.probes = 1 |
All of this is from the README. Most teams should begin with HNSW, because it has the better speed-recall trade-off and no training step. Choose IVFFlat when build time or memory is the tighter constraint. In both cases raising the query option (hnsw.ef_search or ivfflat.probes) buys recall at the cost of speed.
What are pgvector's current limits?
| Item | Limit stated in the README |
|---|---|
Indexable vector | Up to 2,000 dimensions |
Indexable halfvec (half precision) | Up to 4,000 dimensions |
Indexable bit (binary) | Up to 64,000 dimensions |
Indexable sparsevec | Up to 1,000 non-zero elements, HNSW only |
| Table size | A non-partitioned Postgres table is limited to 32 TB by default |
The dimension limit is the one people hit first. If your embedding model produces more than 2,000 dimensions, the README suggests half-precision vectors or half-precision indexing, binary quantisation, indexing a subvector for models that support it, or reducing dimensions.
Indexes do not have to fit in memory, but the README says you will probably see better performance when they do. HNSW indexes also build much faster when the graph fits in maintenance_work_mem.
How does filtering work, and why does it matter?
Nearly every RAG query has a filter: this tenant, this user's permissions, documents after a certain date. Filtering is where the designs differ most.
In pgvector, with an approximate index, "filtering is applied after the index is scanned". The README gives the consequence in numbers. If a condition matches 10% of rows, then with HNSW and the default hnsw.ef_search of 40 only 4 rows will match on average. You asked for the top 10 and received 4.
pgvector offers several remedies:
- Index the filter column. For a condition that matches few rows, a normal B-tree index lets Postgres find those rows and compare vectors exactly.
- Iterative index scans, available since version 0.8.0, keep scanning the index until enough rows pass the filter:
SET hnsw.iterative_scan = strict_order;. A cap applies.hnsw.max_scan_tuplesdefaults to 20,000. - Partial indexes suit a handful of filter values, such as one index for each large tenant.
- Partitioning suits many values. The README recommends list partitioning or separate tables for multi-tenant isolation, noting that a shared approximate index lets one tenant's vectors affect recall and speed for the others.
These work, but you have to design for them. Some dedicated databases build filtering into the index. Qdrant's documentation, for example, describes extending the HNSW graph with extra edges based on indexed payload values, so the search respects the filter while it walks the graph. If your queries combine several strict filters over a very large collection, that difference is worth testing.
What do dedicated vector databases add?
Going by their own documentation, not their marketing pages:
- More index types. Milvus documents a long list for dense vectors, including quantised variants such as IVF_PQ, the disk-based DISKANN and GPU indexes. It gives guidance on choosing by whether the data fits in memory. pgvector has two index types.
- Filter-aware indexes, as described above.
- Built-in keyword ranking. Qdrant documents a full-text index that can rank with BM25. PostgreSQL's built-in ranking functions are not BM25, as explained in hybrid search and reranking.
- Horizontal scaling as a designed-in feature. With Postgres you scale up one server, add read replicas, or shard with an extension such as Citus. The README lists these routes.
And what they cost you:
- A second system. Separate backups, upgrades, monitoring and access control.
- Synchronisation. Every insert, update and delete must reach both stores. When they drift apart you get answers citing deleted documents, or permissions that no longer match.
- No joins and no shared transaction. Metadata must be copied into the vector store to filter on it.
How should you decide?
| Question | Stay with pgvector if | Consider a dedicated database if |
|---|---|---|
| Scale. How many vectors, and does the index fit in memory? | The index fits in RAM on a server you are willing to pay for, perhaps after halfvec or binary quantisation | It does not fit even after compression, or you need disk-based or GPU indexes |
| Filtering. How selective, and how many distinct values? | Filters are simple, or map cleanly to partitions, partial indexes or iterative scans | Many strict, combined filters over a huge shared collection, and tests show poor recall or latency |
| Operations. Who runs it, and what shares the server? | Your team already runs Postgres, and search load is modest beside transactional load | Search load would starve your main database, or you need to scale search on its own |
Then test on your own data. Vendor benchmarks use other people's vectors, filters and hardware, which is why this article quotes none.
- Load a realistic sample and run your test questions with no index. That is exact search. Save the returned IDs as ground truth.
- Add the index and run the same queries. The share of ground-truth IDs that come back is your recall. Record latency too.
- Repeat with your strictest filter and with several queries running at once.
- Only if pgvector misses your targets after tuning, run the same test on a candidate database.
How to evaluate a RAG system covers the wider test set.
Common questions
Can I use pgvector on managed Postgres?
Many hosted Postgres services include it. The project keeps a list of providers, linked from its README. Check which pgvector version your provider runs, because features such as iterative scans need 0.8.0 or later.
My embedding model has more than 2,000 dimensions. Is pgvector ruled out?
No. You can index up to 4,000 dimensions with half precision, use binary quantisation, or index a subvector if the model supports shortened embeddings. Test recall after any of these.
Does the choice of store affect answer quality?
Much less than chunking, the embedding model and the search method do. Any store that returns the true nearest neighbours gives the same passages. Differences show up in speed, filtering behaviour and running costs.
Free download: The RAG field guide
Retrieval-augmented generation from ingestion to cited answers: chunking, hybrid search and reranking, evaluation metrics, and choosing between pgvector and a vector database. See what’s inside.



