pgvector vs Chroma vs Qdrant vs Milvus vs Redis Compared
Introduction
Every RAG systemClick to read tutorial: RAG Architecture Explained: Chunking, Embeddings, Retrieval and every semantic search needs somewhere to keep its embeddingsClick to read tutorial: LLM Tokens, Context Windows, Embeddings and Hallucinations and to search them quickly - a vector store. There are dozens to choose from, and five come up in almost every Java project: pgvector, Chroma, Qdrant, Milvus and Redis. All five are supported by both Spring AI and LangChain4j, so the choice is not about which framework you use, but about how you run your data. This post compares them with diagrams: what a vector store does, how approximate indexes trade accuracy for speed - measured with a Java program - why filtering is harder than it looks, each of the five stores, a comparison table, and a guide to choosing.(Note - The products change quickly. This comparison describes them as of late 2026; check the current documentation for exact limits and versions before you decide.)
What a vector store does
A vector store keeps records of a vector together with the text it came from and metadata about it, and answers one main question: which stored vectors are most similar to this one? -The data model and operations which all five stores share.
Approximate search: trading recall for speed
Finding the exact nearest vectors means comparing the query with every stored vector, using the measure the index was created with (see cosine similarity vs dot productClick to read tutorial: Cosine Similarity vs Dot Product for Embeddings). That is fine for ten thousand chunks, but too slow for ten million. Vector stores therefore build an approximate nearest neighbour (ANN) index, which looks at only a small part of the data and usually, but not always, finds the true nearest vectors. Two index families dominate -The two common ANN index families, drawn in two dimensions.
- IVF (inverted file) groups the vectors into clusters with k-means. A search compares the query with the cluster centres, and then only with the vectors in the
nprobenearest clusters. It builds fast and uses little memory, but recall drops when the true neighbours sit in a neighbouring cluster. - HNSW (Hierarchical Navigable Small World) links every vector to some of its neighbours in a graph with several layers. A search enters at the sparse top layer, walks greedily towards the query, and drops down layer by layer. It gives high recall at low latency, but the graph needs more memory and is slower to build. It is the default in most vector stores.
nprobe for IVF, ef_search for HNSW. The program below builds a small IVF index over 20,000 synthetic, normalized embeddings, and measures the trade-off against exact search: recall@10 is the share of the true 10 nearest vectors which the index found.
Exact search versus an IVF index, measured
//AnnIndexDemo.java
import java.util.*;
public class AnnIndexDemo {
static final int DIM = 32, N = 20_000, QUERIES = 100, K = 10, LISTS = 100;
static final Random RANDOM = new Random(42); // fixed seed, so the output is repeatable
static float[] normalize(float[] v) {
double norm = 0;
for (float x : v) norm += x * x;
norm = Math.sqrt(norm);
for (int i = 0; i < v.length; i++) v[i] /= norm;
return v;
}
static double dot(float[] a, float[] b) {
double s = 0;
for (int i = 0; i < a.length; i++) s += a[i] * b[i];
return s;
}
// Synthetic "embeddings": points scattered around 200 topic centres, normalized like real embeddings
static float[][] centres = new float[200][];
static float[] randomEmbedding() {
if (centres[0] == null)
for (int c = 0; c < centres.length; c++) {
centres[c] = new float[DIM];
for (int i = 0; i < DIM; i++) centres[c][i] = (float) RANDOM.nextGaussian();
}
float[] centre = centres[RANDOM.nextInt(centres.length)], v = new float[DIM];
for (int i = 0; i < DIM; i++) v[i] = centre[i] + 1.2f * (float) RANDOM.nextGaussian();
return normalize(v);
}
// Exact search: compare the query with every vector
static Set<Integer> exactTopK(float[][] data, float[] q) {
PriorityQueue<double[]> heap = new PriorityQueue<>(Comparator.comparingDouble(e -> e[0]));
for (int i = 0; i < data.length; i++) {
heap.add(new double[] {dot(data[i], q), i});
if (heap.size() > K) heap.poll();
}
Set<Integer> ids = new HashSet<>();
for (double[] e : heap) ids.add((int) e[1]);
return ids;
}
public static void main(String[] args) {
float[][] data = new float[N][];
for (int i = 0; i < N; i++) data[i] = randomEmbedding();
float[][] queries = new float[QUERIES][];
for (int i = 0; i < QUERIES; i++) queries[i] = randomEmbedding();
// Build an IVF index: k-means into LISTS clusters; each vector is stored in the list of its nearest centroid
float[][] centroids = new float[LISTS][];
for (int c = 0; c < LISTS; c++) centroids[c] = data[RANDOM.nextInt(N)].clone();
int[] assign = new int[N];
for (int iteration = 0; iteration < 10; iteration++) {
for (int i = 0; i < N; i++) assign[i] = nearest(centroids, data[i], 1)[0];
float[][] sums = new float[LISTS][DIM];
int[] counts = new int[LISTS];
for (int i = 0; i < N; i++) {
counts[assign[i]]++;
for (int d = 0; d < DIM; d++) sums[assign[i]][d] += data[i][d];
}
for (int c = 0; c < LISTS; c++) if (counts[c] > 0) centroids[c] = normalize(sums[c]);
}
List<List<Integer>> lists = new ArrayList<>();
for (int c = 0; c < LISTS; c++) lists.add(new ArrayList<>());
for (int i = 0; i < N; i++) lists.get(assign[i]).add(i);
System.out.printf("%,d vectors of %d dimensions, %d queries, top %d results each%n%n", N, DIM, QUERIES, K);
System.out.printf("%-26s %-12s %s%n", "Search", "Recall@10", "Vectors compared per query");
System.out.printf("%-26s %-12s %,d%n", "Exact (every vector)", "100.0%", N);
for (int nprobe : new int[] {1, 4, 16}) {
int found = 0;
long compared = 0;
for (float[] q : queries) {
Set<Integer> truth = exactTopK(data, q);
PriorityQueue<double[]> heap = new PriorityQueue<>(Comparator.comparingDouble(e -> e[0]));
compared += LISTS; // the query is compared with every centroid
for (int c : nearest(centroids, q, nprobe)) // then only the vectors in the nprobe nearest lists
for (int i : lists.get(c)) {
compared++;
heap.add(new double[] {dot(data[i], q), i});
if (heap.size() > K) heap.poll();
}
for (double[] e : heap) if (truth.contains((int) e[1])) found++;
}
System.out.printf("%-26s %-12s %,d%n", "IVF, nprobe = " + nprobe,
String.format("%.1f%%", 100.0 * found / (QUERIES * K)), compared / QUERIES);
}
}
// Indexes of the `count` centroids most similar to v
static int[] nearest(float[][] centroids, float[] v, int count) {
Integer[] idx = new Integer[centroids.length];
for (int i = 0; i < idx.length; i++) idx[i] = i;
Arrays.sort(idx, (a, b) -> Double.compare(dot(centroids[b], v), dot(centroids[a], v)));
int[] out = new int[count];
for (int i = 0; i < count; i++) out[i] = idx[i];
return out;
}
}
20,000 vectors of 32 dimensions, 100 queries, top 10 results each Search Recall@10 Vectors compared per query Exact (every vector) 100.0% 20,000 IVF, nprobe = 1 53.4% 309 IVF, nprobe = 4 75.7% 910 IVF, nprobe = 16 92.9% 3,337
Explanation of the code
- The index is built once: ten rounds of k-means put every vector into one of 100 lists, each with a centroid. In a vector store, this is the slow part of building an index, done ahead of time.
- With
nprobe = 1, a search compared about 309 vectors instead of 20,000 - roughly 65 times less work - but found only 53.4% of the true top 10. Many true neighbours were in the next cluster. - Searching 4 and then 16 lists raised recall to 75.7% and 92.9%, while still comparing only about 900 and 3,300 vectors. This is the dial every vector store exposes: more work per query buys higher recall.
- The synthetic topics overlap on purpose. With clearly separated topics, recall at
nprobe = 1was over 98% in a test run - how well an index works depends on the data, which is why it is worth measuring recall on your own embeddings.
Filtering: the hard part
Real searches almost always carry a filter - only this tenant's documents, only the HR department, only documents the user may read. Combining a filter with an ANN index is harder than it looks. The diagram shows the three approaches for a search for the top 3 chunks with the filterdept = "HR", where only one chunk in five belongs to HR -
Three ways to combine a metadata filter with a nearest-neighbour search.
- Post-filtering runs the ANN search for the top k, then removes the results which fail the filter. If the filter is selective, few or none of the top k survive, and the query returns fewer results than asked for.
- Pre-filtering first selects the matching records and then searches only them. That is exact, but with a broad filter it can fall back to comparing many vectors one by one.
- Filter-aware indexes apply the filter while walking the index, so that the search keeps going until it has k matching results.
The five stores
The five differ first in how they are run - inside a database you already have, inside your process, or as a separate system -How each of the five stores is deployed next to a Java application.
vector column type, distance operators and HNSW and IVFFlat indexes. Vectors live in ordinary tables, next to the rest of the application's data, so a single SQL query can join, filter and search, inside the same transactions and backups. Since version 0.8, iterative index scans keep scanning an index until a filtered query has enough rows. Full-precision vectors can be indexed up to 2,000 dimensions; half-precision (halfvec) and binary types reduce memory. It is available in most managed PostgreSQL services, and uses the permissive PostgreSQL licence. It is the natural first choice for a Java application which already runs on PostgreSQL, up to a few tens of millions of vectors on one server.Chroma is an open-source (Apache 2.0) embedding database built for developer convenience: it runs embedded in a Python process or as a server, and starts with one command. Its core was rewritten in Rust in 2025. Java applications reach it through its HTTP API, for example via the Spring AI and LangChain4j integrations. It is a quick way to start a prototype; for large production systems, teams more often move to one of the others.
Qdrant is an open-source (Apache 2.0) vector database written in Rust, with an official Java client using gRPC. Its HNSW index is filter-aware: with payload indexes created before the data is loaded, it adds graph links between records sharing a payload value, so filtered searches stay fast and complete. It offers scalar and binary quantization - storing each number of a vector in fewer bits - to cut memory, runs as one container or a distributed cluster, and is also sold as a managed cloud service. It is a strong default for a dedicated vector database with heavy filtering.
Milvus is an open-source (Apache 2.0) vector database built for very large scale, with storage and compute separated into services which scale on their own. It offers the widest choice of indexes - HNSW, IVF variants with product quantization, GPU indexes and DiskANN, which keeps most of the index on SSD instead of in RAM - and an official Java SDK. That power comes with more parts to operate; Zilliz Cloud offers it as a managed service, and Milvus Lite runs it embedded for development. It is the choice for hundreds of millions to billions of vectors.
Redis includes vector search in its query engine - HNSW and flat indexes over vectors stored in hashes or JSON documents, with filters on other fields - and, since Redis 8, a new vector set data type. Everything is held in memory, which gives very low latency, but makes large collections expensive. Redis 8 can be used under the AGPLv3 licence, as well as its earlier source-available licences. It fits applications which already use Redis, need the fastest responses, and have a collection that fits comfortably in memory - for example, caching LLM answers by the similarity of questions.
Side by side
| pgvector | Chroma | Qdrant | Milvus | Redis | |
|---|---|---|---|---|---|
| What it is | PostgreSQL extension | Embedding database | Vector database | Distributed vector database | In-memory store with vector search |
| Indexes | HNSW, IVFFlat | HNSW | HNSW (filter-aware) | HNSW, IVF, PQ, DiskANN, GPU | HNSW, flat |
| Filtering | SQL; iterative scans | Metadata filters | Payload filters inside HNSW | Scalar filters | Query engine filters |
| Typical scale | Up to tens of millions | Prototypes, small apps | Millions to billions | Hundreds of millions to billions | What fits in RAM |
| Java access | JDBC | HTTP API | Official client | Official SDK | Redis clients (Jedis, Lettuce) |
| Licence | PostgreSQL | Apache 2.0 | Apache 2.0 | Apache 2.0 | AGPLv3 or source-available |
| Best when | You already run PostgreSQL | You want to start in minutes | You need a dedicated store with heavy filtering | You have very large collections | You already run Redis and need speed |
VectorStore implementation in Spring AI and an EmbeddingStore in LangChain4j, so application code written against those interfaces can switch stores with a configuration change - the embeddings, though, must be re-loaded into the new store.
Choosing one
A starting point for choosing a vector store. Ask the questions in order.
Summary
In this post we compared five vector stores for Java applications. We saw that all of them store vectors with text and metadata and answer nearest-neighbour searches, and that they rely on approximate indexes - IVF and HNSW - which trade recall for speed, a trade-off we measured in Java: from 53% to 93% recall while still comparing only a fraction of the vectors. We looked at why filtering is hard for ANN indexes, and then at each store: pgvector inside PostgreSQL, Chroma for a quick start, Qdrant with filter-aware HNSW, Milvus for very large collections, and Redis for in-memory speed. Lastly, we put them side by side and went through a guide to choosing. How the vector store fits into the whole pipeline is explained in RAG architecture explainedClick to read tutorial: RAG Architecture Explained: Chunking, Embeddings, Retrieval.Continue Reading: AI and LLM Papers Explained
Prompt Engineering Techniques Explained with ExamplesClick to read tutorial: Prompt Engineering Techniques Explained with Examples RAG Architecture Explained: Chunking, Embeddings, RetrievalClick to read tutorial: RAG Architecture Explained: Chunking, Embeddings, Retrieval Attention Is All You Need: The Transformer Paper ExplainedClick to read tutorial: Attention Is All You Need: The Transformer Paper Explained BERT Paper Explained: Bidirectional TransformersClick to read tutorial: BERT Paper Explained: Bidirectional Transformers Scaling Laws for Language Models (and Chinchilla) ExplainedClick to read tutorial: Scaling Laws for Language Models (and Chinchilla) Explained GPT-3 Paper Explained: Language Models Are Few-Shot LearnersClick to read tutorial: GPT-3 Paper Explained: Language Models Are Few-Shot Learners RAG Paper Explained: Retrieval-Augmented GenerationClick to read tutorial: RAG Paper Explained: Retrieval-Augmented Generation LoRA Paper Explained: Low-Rank Adaptation of LLMsClick to read tutorial: LoRA Paper Explained: Low-Rank Adaptation of LLMs Chain-of-Thought Prompting Paper ExplainedClick to read tutorial: Chain-of-Thought Prompting Paper Explained
Prompt Engineering Techniques Explained with ExamplesClick to read tutorial: Prompt Engineering Techniques Explained with Examples RAG Architecture Explained: Chunking, Embeddings, RetrievalClick to read tutorial: RAG Architecture Explained: Chunking, Embeddings, Retrieval Attention Is All You Need: The Transformer Paper ExplainedClick to read tutorial: Attention Is All You Need: The Transformer Paper Explained BERT Paper Explained: Bidirectional TransformersClick to read tutorial: BERT Paper Explained: Bidirectional Transformers Scaling Laws for Language Models (and Chinchilla) ExplainedClick to read tutorial: Scaling Laws for Language Models (and Chinchilla) Explained GPT-3 Paper Explained: Language Models Are Few-Shot LearnersClick to read tutorial: GPT-3 Paper Explained: Language Models Are Few-Shot Learners RAG Paper Explained: Retrieval-Augmented GenerationClick to read tutorial: RAG Paper Explained: Retrieval-Augmented Generation LoRA Paper Explained: Low-Rank Adaptation of LLMsClick to read tutorial: LoRA Paper Explained: Low-Rank Adaptation of LLMs Chain-of-Thought Prompting Paper ExplainedClick to read tutorial: Chain-of-Thought Prompting Paper Explained