Choosing a vector database when every query carries a filter
Vendor benchmarks measure unfiltered search on someone else's data. If every real query has a tenant filter, that filter decides the choice.
TL;DRthe 30-second version
- Pick a vector database for your own workload: your vector count, your dimensions and, above all, your filter pattern.
- When the filter is a tenant boundary, it has to be correct as well as fast. Keeping it in the same statement as the search means no copied metadata that can drift.
- pgvector applies filters after the index scan. With default settings, a filter matching 10% of rows returns about 4 of the 10 results you asked for.
- Iterative scans (pgvector 0.8.0+), partial indexes and per-tenant partitions fix most of it. Benchmark the filtered case on your own data before deciding.
Every vector database benchmark you’ll read was run on someone else’s data: their vector count, their dimensions, their query pattern, their idea of “fast”. None of it tells you how the thing behaves on your workload, and the gap between the vendor’s benchmark and your production traffic is where the unpleasant surprises live.
The decision I faced was whether to pull our vectors out of the database they already lived in. We’d started with pgvector, embeddings stored in Postgres next to everything else, and the received wisdom said that’s a prototype choice you graduate from. Real scale means a dedicated vector store. So before committing to a migration I asked what, specifically, a dedicated store would buy us on our data. The more I looked at our actual queries, the less obvious the upgrade became.
The candidates were the usual set: pgvector, Qdrant, Milvus, Weaviate and Pinecone. The question was never which is best in the abstract. It was which is best for this shape of data and this access pattern, which is the only version of the question that has an answer.
The workload shape
This part decides everything, and generic benchmarks can’t capture it. Our corpus is code, tickets and docs, chunked and embedded with a code-specialised model at 1,024 dimensions, cosine distance, behind an HNSW index. The number that shapes the decision isn’t the vector count. It’s that every real query carries a metadata filter. We never run a pure nearest-neighbour search. We run “nearest neighbour among the repositories this agent is allowed to see”, because the system is multi-tenant and scope is non-negotiable.
Filtered search is a different and harder problem from plain nearest-neighbour search, and systems handle it very differently. If your real queries always carry filters, a benchmark that measures unfiltered search is measuring a workload you don’t have. Ours always do, and the filter is a security boundary, which raises the bar from “filtering should be fast” to “filtering must be correct, and enforced in the same query as the search”.
What the filter does to your results
Here’s the part I underestimated at first, and it cuts against pgvector. Its README is explicit: with approximate indexes, filtering is applied after the index is scanned. The HNSW search collects its candidates first (40 by default, set by hnsw.ef_search), then the WHERE clause throws out the ones the tenant can’t see. If a tenant can see 10% of rows, about 4 of those 40 candidates survive. You asked for 10 results and got 4.
Drag the slider down to a small tenant’s share of the corpus:
How many of your top 10 come back once the tenant filter applies
k = 10For a multi-tenant system that matters more than raw latency, because small tenants are the norm. pgvector’s documented fixes:
- Iterative index scans (pgvector 0.8.0 and later):
SET hnsw.iterative_scan = strict_order;(orrelaxed_order) keeps scanning until enough rows match, up tohnsw.max_scan_tuples(20,000 by default). - Partial indexes when you filter on a few distinct values.
- Partitioning when you filter on many, such as one partition per tenant or group of tenants.
- Exact search when the filter is very selective, where scanning a small partition beats an approximate index.
A store that applies the filter during the graph search doesn’t have this failure mode, which is the honest case for the dedicated databases. What it trades away is the single statement: the scope metadata now lives in a second system.
What to measure on your own data
Under the hood, most of these systems use the same approximate-nearest-neighbour index families, and each choice is a trade. HNSW gives strong recall at low latency and pays for it in memory and build time. IVF is lighter on memory and trades recall for speed through its tuning. No setting is fast, accurate, cheap and memory-light at once. We ended up running both: HNSW at m = 16, ef_construction = 200, with ef_search set per query, for the high-traffic code index, and a lighter IVF index for the bulk document store, where build cost mattered more than the last point of recall.
Measure the things that map to user experience and cost, on your corpus and your filtered query mix:
- Results returned and recall@k, filtered and unfiltered. They will differ, and the filtered number is the one your users see.
- p95 latency under load, at your real QPS, with the filter applied.
- Filtered latency against unfiltered, across your smallest and largest tenants.
- Total cost at your scale, including the people and infrastructure a dedicated system needs, not only compute.
Why we stayed in Postgres
We kept pgvector, and the reason wasn’t speed. The filter is a plain SQL WHERE clause on the same table as the vectors, so “search within this scope” is one statement. Nothing has to sync a copy of the scope tables into a second system and keep it correct.
The bigger factor was operational. Every dedicated vector store is one more system to run, scale, back up, secure and reason about, and a second source of truth that can drift from the database the rest of the application trusts. Staying in Postgres meant the vectors inherited what the database already gave us: the same backups, the same access control, the same transactional consistency, and the same home as the tenant-scope tables. The filter caveat above was real, and iterative scans and partitioning were the price of keeping one system. For us that was a good trade. For a corpus dominated by tiny tenants and huge query volume, it might not be.
The takeaway
The right vector database depends on your workload, not the leaderboard. Benchmark on your own vector count, dimensions and filter pattern, including your smallest tenants, because that’s where systems separate. Weight operational cost and filtered behaviour at least as heavily as raw latency. The fastest option on someone else’s data is a number about someone else’s problem.
References
- pgvector README: filtering, iterative index scans, partial indexes and partitioning (checked 14 Nov 2026).
- Malkov & Yashunin. Efficient and robust approximate nearest neighbor search using hierarchical navigable small world graphs. arXiv 2016; IEEE TPAMI 2018.
- ANN-Benchmarks: useful for intuition about index methods; run the filtered case yourself.