To choose a vector database, start from your constraints rather than a product list: how many vectors you will store, how much you rely on metadata filtering and keyword search, what infrastructure your team already runs, and how much operational work you can absorb. For many applications, adding vector search to a database you already operate is enough; dedicated vector databases earn their place at larger scale or with demanding filtering and hybrid search needs. This vector database comparison walks through the categories and the criteria that actually decide the choice.
What is a vector database?
A vector database stores embeddings, which are arrays of numbers that represent the meaning of text, images, or other data, and finds the stored vectors closest to a query vector. That nearest-neighbor search powers semantic search, recommendations, deduplication, and the retrieval step in retrieval-augmented generation. If embeddings are new to you, read embeddings explained first.
Exact nearest-neighbor search compares the query with every vector, which gets slow as data grows. So most systems use approximate nearest neighbor (ANN) indexes that trade a small amount of recall for large speedups.
How do vector indexes work? HNSW vs IVF
Almost every option below uses one of a few index families. Understanding them helps you read documentation and tune settings.
HNSW (hierarchical navigable small world)
HNSW builds a layered graph where each vector links to its near neighbors. A search starts at a sparse top layer and greedily walks toward the query, descending into denser layers. It offers strong recall and low latency, supports incremental inserts well, and is the default in many systems. The trade-off is memory: the graph links add overhead on top of the vectors themselves, and builds can be slow for very large datasets.
IVF (inverted file index)
IVF clusters vectors into partitions around centroids. At query time it searches only the few partitions closest to the query. It uses less memory than HNSW and builds faster, but recall depends on how many partitions you probe, and it may need retraining as the data distribution shifts. IVF is often combined with product quantization (PQ), which compresses vectors to fit more in memory at some cost to accuracy.
Flat (brute force)
For small collections, exact search is simple, perfectly accurate, and often fast enough. Do not reach for an ANN index before you need one. The same indexing trade-offs you know from database indexes apply: faster reads in exchange for memory, build time, and write overhead.
Vector database comparison: the four categories
1. Dedicated vector databases
Purpose-built systems such as Pinecone, Weaviate, Qdrant, Milvus, and similar products focus on vector search as the primary workload. They typically offer multiple index types, metadata filtering integrated with ANN search, hybrid search, horizontal scaling, and managed cloud options. They are a good fit when vectors are central to the product and scale or query patterns outgrow a general-purpose database. The cost is another system to operate, secure, and keep in sync with your source of truth.
2. Postgres with pgvector
The pgvector extension adds a vector column type, distance operators, and HNSW and IVF indexes to PostgreSQL. You get transactions, joins, backups, access control, and familiar tooling, and your embeddings live next to the rows they describe. This is often the simplest path for teams already on Postgres.
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE doc_chunks (
id bigserial PRIMARY KEY,
tenant_id bigint NOT NULL,
content text NOT NULL,
embedding vector(1024) NOT NULL
);
CREATE INDEX doc_chunks_embedding_hnsw
ON doc_chunks USING hnsw (embedding vector_cosine_ops);
CREATE INDEX doc_chunks_tenant ON doc_chunks (tenant_id);
-- $1 = query embedding, $2 = tenant id
SELECT id, content, 1 - (embedding <=> $1) AS similarity
FROM doc_chunks
WHERE tenant_id = $2
ORDER BY embedding <=> $1
LIMIT 10;
The main caveats are that very large vector collections compete with your transactional workload for memory and CPU, and combining selective filters with ANN indexes needs care to avoid returning too few results.
3. Search engines with vector support
Search engines such as Elasticsearch, OpenSearch, and other Lucene-based or similar systems now support dense vector fields alongside full-text search. If you already run one for keyword search, adding vectors gives you hybrid search, rich filtering, aggregations, and mature operational tooling in one place. They are heavier to run than a library and may require tuning for vector-heavy workloads.
4. In-process libraries
Libraries such as FAISS, hnswlib, Annoy, and embedded databases run inside your application process. There is no server to operate, and they are excellent for prototypes, offline batch jobs, edge deployments, and read-mostly datasets that fit in memory. You take on persistence, updates, replication, and filtering yourself.
How to choose a vector database: the criteria
| Criterion | Dedicated vector DB | Postgres + pgvector | Search engine | In-process library |
|---|---|---|---|---|
| Scale ceiling | High, built to scale out | Moderate, bounded by the Postgres node | High, scales out | Bounded by one machine's memory |
| Metadata filtering | Strong, integrated with ANN | Full SQL, needs tuning with ANN | Strong | Mostly do-it-yourself |
| Hybrid keyword + vector | Often built in | Possible with full-text search | Native strength | Do-it-yourself |
| Transactions and joins | Limited | Full | Limited | None |
| Operational burden | New system, or managed service | Low if you already run Postgres | Medium to high | Very low |
| Best fit | Vector-first products at scale | Apps already on Postgres | Search-heavy apps | Prototypes, batch, edge |
Beyond the table, work through these questions:
- How many vectors, and how fast is it growing? Thousands to low millions is comfortable territory for most options. Far beyond that, memory and sharding strategy start to dominate; see sharding.
- How selective are your filters? Multi-tenant apps and permission-aware retrieval depend on filtering that stays accurate when combined with ANN search. Test with your real filter patterns.
- Do you need hybrid search? If users search for exact identifiers, product codes, or names, you need keyword search alongside vectors.
- What is your update pattern? Frequent upserts and deletes stress some indexes more than others. Check how deletes are handled and whether indexes need periodic rebuilds.
- What does your team already operate? Fewer systems means fewer failure modes, fewer backups, and simpler security reviews.
- What will it cost? Consider memory footprint (dimensions times vector count, plus index overhead), managed-service pricing models, and engineering time. Smaller embedding dimensions or quantization can cut memory significantly.
A practical decision path
- Prototype with an in-process library or pgvector using your real data and queries.
- Build a small evaluation set and measure recall at k and latency with realistic filters.
- If you already run Postgres and results meet your targets, stay there.
- If you already run a search engine and need hybrid search, extend it.
- Move to a dedicated vector database when scale, filtering, or throughput requirements exceed what your existing stack handles comfortably.
Keep your embedding pipeline independent of the storage choice so switching later is a re-index, not a rewrite.
Key takeaways
- Choose based on scale, filtering, hybrid search needs, and existing operations, not hype.
- HNSW favors recall and low latency at higher memory cost; IVF favors memory and build speed.
- Postgres with pgvector is a strong default for teams already on Postgres.
- Search engines are a natural choice when keyword and vector search must work together.
- Dedicated vector databases pay off when vectors are core and scale is large.
- Benchmark on your own data and filters before committing.
Frequently asked questions
Do I need a dedicated vector database?
Not always. If your collection is modest and you already run Postgres or a search engine, adding vector support there is often simpler. Dedicated systems make sense when vector search is central and scale or filtering requirements grow beyond your existing stack.
What is the difference between HNSW and IVF?
HNSW is a graph-based index that delivers high recall and low latency but uses more memory. IVF partitions vectors into clusters and searches only nearby clusters, using less memory and building faster, with recall that depends on how many clusters you probe.
Is pgvector good enough for production?
For many production workloads, yes, particularly when data sits comfortably on a single Postgres node and you benefit from transactions and joins. Test with realistic filters and data volumes, and watch memory usage as the collection grows.
How does a vector database fit into RAG?
It stores embeddings of your document chunks and returns the most similar chunks for a user's question. Those chunks become the context the language model uses to answer; see what is RAG for the overall flow.