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:

  1. Operations: who hosts it, backs it up, upgrades it, monitors it?
  2. Filtering: combining vectors and metadata (customer, category, date, permissions) without losing recall (lesson 2.3).
  3. Hybrid search: can the database do lexical search and fuse both?
  4. Multi-tenancy: isolating each customer's data.
  5. Quantization: reducing memory at scale (lesson 2.4).
  6. Consistency with your data: do your documents, their permissions and their metadata already live somewhere?

Five options compared

pgvectorQdrantWeaviatePineconeMilvus
NaturePostgreSQL extensionDedicated database (Rust)Dedicated database (Go)Managed service onlyDedicated, distributed database
HostingAnywhere Postgres runs (including Supabase, RDS, Neon…)Self-hosted, embedded or cloudSelf-hosted or cloudCloudSelf-hosted (Zilliz for managed)
IndexesHNSW, IVFFlatHNSWHNSW, flat, dynamicProprietaryMany (HNSW, IVF, disk, GPU)
Lexical / hybridPostgres full text + fusion in SQLSparse vectors + built-in fusionBM25 + built-in fusionSparse + dense vectorsBuilt-in BM25 in recent versions
Multi-tenancyColumn + Row Level SecurityPayload-based partitioningNative tenantsNamespacesPartition key
Quantizationhalfvec, binaryScalar, binary, PQSeveral (PQ, binary, scalar…)Managed by the serviceSeveral

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

  1. Load sql/pgvector.sql into a PostgreSQL with pgvector (or Supabase) and insert Prism's passages.
  2. Run the dense query with EXPLAIN ANALYZE, then replace <=> with <->: is the index still used?
  3. For your project, fill in the criteria table and justify your choice of database in three sentences.

Resources