Module 2 · Vector databases
pgvector, Qdrant, Weaviate, Pinecone, Milvus compared
5 min read
Do you need a dedicated vector database? The market offers dozens, and every vendor publishes benchmarks that put it on top. This lesson compares five representative options — pgvector, Qdrant, Weaviate, Pinecone and Milvus — on the criteria that really matter for RAG, then shows pgvector in detail, tested end to end with Prism's corpus.
The criteria that matter
Raw performance is rarely the limiting factor: under a few tens of millions of vectors, all these solutions answer in a few milliseconds with a well-tuned HNSW index. The real criteria are elsewhere:
- Operations: who hosts it, backs it up, upgrades it, monitors it?
- Filtering: combining vectors and metadata (customer, category, date, permissions) without losing recall (lesson 2.3).
- Hybrid search: can the database do lexical search and fuse both?
- Multi-tenancy: isolating each customer's data.
- Quantization: reducing memory at scale (lesson 2.4).
- Consistency with your data: do your documents, their permissions and their metadata already live somewhere?
Five options compared
| pgvector | Qdrant | Weaviate | Pinecone | Milvus | |
|---|---|---|---|---|---|
| Nature | PostgreSQL extension | Dedicated database (Rust) | Dedicated database (Go) | Managed service only | Dedicated, distributed database |
| Hosting | Anywhere Postgres runs (including Supabase, RDS, Neon…) | Self-hosted, embedded or cloud | Self-hosted or cloud | Cloud | Self-hosted (Zilliz for managed) |
| Indexes | HNSW, IVFFlat | HNSW | HNSW, flat, dynamic | Proprietary | Many (HNSW, IVF, disk, GPU) |
| Lexical / hybrid | Postgres full text + fusion in SQL | Sparse vectors + built-in fusion | BM25 + built-in fusion | Sparse + dense vectors | Built-in BM25 in recent versions |
| Multi-tenancy | Column + Row Level Security | Payload-based partitioning | Native tenants | Namespaces | Partition key |
| Quantization | halfvec, binary | Scalar, binary, PQ | Several (PQ, binary, scalar…) | Managed by the service | Several |
These products evolve quickly: check every point in the documentation of the version you deploy.
How to choose
- You already have PostgreSQL and fewer than a few tens of millions of vectors: pgvector. One database, transactions, joins with your business tables, row-level security, your existing backups. It is the most reasonable default for most projects.
- You want a dedicated, self-hostable database with excellent filtering: Qdrant (which also has a handy embedded mode for development, used in the LlamaIndex course).
- You want built-in hybrid search and multi-tenancy, with vectorization modules: Weaviate.
- You want to operate nothing: Pinecone, accepting dependence on a service and usage-based pricing.
- You are targeting hundreds of millions or billions of vectors, with a team to run it: Milvus.
Be wary of vendor benchmarks: each picks the dataset, parameters and hardware that favor it. Only a measurement on your data and your queries, with controlled recall, allows a comparison.
pgvector in practice
Prism provides a complete pgvector schema, tested with embedded PostgreSQL (PGlite) and pgvector 0.8 on the course corpus: the results are identical, passage for passage, to those of the Python implementation.
CREATE TABLE chunks (
id text PRIMARY KEY,
tenant_id text NOT NULL, -- multi-tenant : chaque client ne voit que ses données
article_id text NOT NULL,
category text NOT NULL,
content text NOT NULL,
embedding vector(384) NOT NULL,
-- recherche lexicale
content_tsv tsvector GENERATED ALWAYS AS (to_tsvector('french', content)) STORED
);
-- m : voisins par nœud (16 par défaut) ; ef_construction : effort de construction (64 par défaut)
CREATE INDEX chunks_embedding_hnsw ON chunks USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);
(The SQL comments are those of the companion code: tenant_id isolates each customer's data, content_tsv powers lexical search, m and ef_construction default to 16 and 64.)
Three distance operators, to match with the index's operator class: <=> (cosine, vector_cosine_ops), <-> (Euclidean, vector_l2_ops), <#> (negative inner product, vector_ip_ops). If the query's operator does not match the index, PostgreSQL does not use it and performs an exact search — correct, but slow. Check with EXPLAIN.
The search:
SET hnsw.ef_search = 100; -- candidats explorés : plus = meilleur rappel, plus lent
SELECT id, article_id, 1 - (embedding <=> $1) AS similarity
FROM chunks
ORDER BY embedding <=> $1
LIMIT 5;
hnsw.ef_search (40 by default) plays the role of efSearch from the previous lesson. It also limits the number of results the index can return: a LIMIT 200 query with ef_search = 40 may return fewer rows than requested.
Two pgvector pitfalls
Build the index after loading. Building an HNSW index on an already-filled table is much faster than maintaining it through millions of inserts. For an initial load, insert first, index afterwards, raising maintenance_work_mem so the graph fits in memory during the build.
Memory. HNSW performs well when the index fits in RAM. Compute its size (vectors + graph, lesson 2.1) and compare it with your instance's memory: an index that spills to disk becomes slow. Quantization (lesson 2.4) is often the answer.
Key takeaways
- Under a few tens of millions of vectors, every database is fast enough: choose on operations, filtering, hybrid search, multi-tenancy.
- pgvector is the default choice if you have PostgreSQL: one database, transactions, joins, RLS.
- Qdrant, Weaviate, Pinecone, Milvus: dedicated, more built-in features, more operations (or a paid service).
- Match the distance operator to the index's operator class, and check with
EXPLAIN.- Index after the initial load and make sure the index fits in memory.
Practice
- Load
sql/pgvector.sqlinto a PostgreSQL with pgvector (or Supabase) and insert Prism's passages. - Run the dense query with
EXPLAIN ANALYZE, then replace<=>with<->: is the index still used? - For your project, fill in the criteria table and justify your choice of database in three sentences.