Özer Cem KELAHMETKELAHMET
Articles · Vector databases

Filtered vector search for RAG: post-filtering, allow lists, ACORN and iterative scans

Most RAG queries carry a filter: one tenant, one product, documents newer than a date. Filters and approximate vector indexes fight each other. This guide measures the failure in Python and explains the fixes in pgvector, Qdrant, Weaviate and Elasticsearch.

Download Markdown
At a glance
Reading time
19 min
Sections
9
Code examples
2
Tables
5
Sources
9
Published
25 Nov 2026
In 30 seconds
What changed
pgvector 0.8.0 adds iterative index scans
Why it matters
Filtered retrieval is a recall problem first and a speed problem second.
What to do
Measure filter selectivity

A RAG system almost never searches the whole corpus. A support bot searches one customer's tickets. A legal assistant searches contracts signed after a certain date. A shop assistant searches products that are in stock. Each of these is a vector search plus a metadata filter, and that combination is where many production systems quietly lose recall.

Approximate nearest neighbour indexes such as HNSW know nothing about tenants, dates or stock levels. Add a filter and you either throw away most of what the index found, or force it to walk through regions full of points it may not return.

Every major vector store has now shipped an answer. If you are new to the index types themselves, start with vector databases explained. This article explains the four basic strategies, measures each one on 100,000 vectors with a script you can run, and then maps the results to the settings you actually change.

What happened

pgvector 0.8.0 adds iterative index scans (30 October 2024)

The pgvector 0.8.0 changelog is dated 30 October 2024, and the PostgreSQL announcement followed on 11 November 2024. The release added iterative index scans, described as a way to prevent "overfiltering", which means returning fewer rows than the query asked for. If the first index scan does not satisfy the query, pgvector keeps scanning until it hits a threshold set by hnsw.max_scan_tuples or ivfflat.max_probes. The feature is opt-in. The current pgvector install instructions point to version 0.8.7.

Weaviate makes ACORN the default filter strategy (11 November 2025)

Weaviate added ACORN as an alternative to its older sweeping strategy in version 1.27. In version 1.34, released on 11 November 2025, ACORN became the default filter strategy for new collections. Weaviate's current documentation lists a third strategy, pathseer, added in version 1.40.

Elasticsearch 9.1 uses ACORN-1 for filtered kNN (29 July 2025)

Elastic's post on Elasticsearch 9.1 says filtered kNN search now uses ACORN-1, so that "only nodes that are accepted by the filter are evaluated". It also checks second-level neighbours that pass the filter. Elastic claims "typical speedups of 5x", with larger gains for very selective filters. No configuration is needed.

Qdrant benchmarks ACORN against filterable HNSW (7 August 2026)

Qdrant published a benchmark on one million points, measured on Qdrant v1.18.2. It compares a plain HNSW graph, the same graph with ACORN switched on per query, and Qdrant's filterable HNSW, which adds extra graph edges for indexed payload values. We use its numbers below.

Qdrant 1.20 adds per-element payload indexes (22 October 2026)

Qdrant 1.20.0 added a nested parameter to every payload index type. When all conditions in a nested filter use per-element indexes on the same array, Qdrant answers the filter without reading payloads. Qdrant reports this was 7 to 38 times faster than regular indexes with payload reads on a 100,000-point benchmark.

Think of an HNSW graph as a city's road network (the HNSW simulation lets you watch a search walk one). Every point is a house, and each house has roads to its nearest neighbours. A query starts at an entry point and walks greedily toward the target, always stepping to the neighbour that is closest. The ef parameter sets how many candidate houses the search keeps in its notebook while walking. With pgvector's default hnsw.ef_search of 40, the search ends with about 40 good candidates.

Now add a filter: "only houses painted blue". There are two naive ways to handle it.

Post-filtering. Walk the graph as usual, collect 40 candidates, then drop the ones that are not blue. If 10% of houses are blue, you expect 40 × 0.1 = 4 survivors. You asked for 10. This is exactly the example in the pgvector README: with a condition matching 10% of rows and the default ef_search of 40, only about 4 rows match on average. The chance of at least 10 blue houses out of 40 is the binomial tail P(X ≥ 10) for n = 40 and p = 0.1, which is 0.005.

Pre-filtering with in-graph checks (an allow list). First build the set of blue houses from a normal database index, then walk the graph but only admit blue houses into the results. Weaviate documents this allow-list approach. Recall stays high, but the walk can get long. When only 0.1% of houses are blue, most steps land on houses you cannot keep, and the search wanders.

There is also a third failure that neither approach sees coming: correlation. If the filter keeps points that sit far from the query in vector space (anti-correlated), the nearest 40 candidates may contain none of them at all. If the filter keeps points near the query (correlated), even post-filtering works fine.

The fourth option is the oldest: pre-filter, then scan exactly. Use a normal index to fetch the matching rows and compute every distance. It returns 100% recall by construction. Its cost grows with the number of matching rows, so it is cheap exactly when the graph approaches are expensive: when the filter is very selective.

Measuring the four strategies

The script below builds 100,000 normalised 64-dimensional vectors in 50 clusters, indexes them with hnswlib (M = 16, ef_construction = 200), and gives every vector a uniform random attribute. A filter tenant < s keeps a share s of the collection. For 200 queries it compares post-filtering at ef = 40, hnswlib's built-in filter callback (an allow-list walk) and an exact scan over the matching rows, against exact ground truth.

# pip install hnswlib numpy
import time, numpy as np, hnswlib

rng = np.random.default_rng(0)
N, D, K, Q = 100_000, 64, 10, 200
centers = rng.normal(size=(50, D)).astype(np.float32)
cluster = rng.integers(0, 50, N)
X = (centers[cluster] + 0.6 * rng.normal(size=(N, D))).astype(np.float32)
X /= np.linalg.norm(X, axis=1, keepdims=True)
qc = rng.integers(0, 50, Q)
Qv = (centers[qc] + 0.6 * rng.normal(size=(Q, D))).astype(np.float32)
Qv /= np.linalg.norm(Qv, axis=1, keepdims=True)

index = hnswlib.Index(space="ip", dim=D)
index.init_index(max_elements=N, M=16, ef_construction=200, random_seed=1)
index.add_items(X, np.arange(N))
tenant = rng.random(N)   # filter "tenant < s" keeps share s

def truth(q, mask):
    ids = np.flatnonzero(mask)
    return set(ids[np.argsort(-(X[ids] @ q))[:K]])

def run(sel, ef=40):
    mask = tenant < sel
    r_post = r_in = r_flat = n_post = 0.0
    for q in Qv:
        gt = truth(q, mask)
        index.set_ef(ef)                                  # 1) post-filter
        lab, _ = index.knn_query(q, k=ef)
        kept = [i for i in lab[0] if mask[i]][:K]
        n_post += len(kept); r_post += len(gt & set(kept)) / K
        index.set_ef(max(ef, K))                          # 2) allow-list walk
        lab, _ = index.knn_query(q, k=K, filter=lambda i: bool(mask[i]))
        r_in += len(gt & set(lab[0])) / K
        ids = np.flatnonzero(mask); s = X[ids] @ q        # 3) exact scan
        top = ids[np.argpartition(-s, min(K, len(ids) - 1))[:K]]
        r_flat += len(gt & set(top)) / K
    return sel, round(n_post / Q, 1), round(r_post / Q, 3), round(r_in / Q, 3), round(r_flat / Q, 3)

for sel in [0.5, 0.2, 0.1, 0.01, 0.001]:
    print(run(sel))

The full version, which also times each strategy, printed these results on a single CPU core. Recall can move by about 0.003 between runs, because hnswlib builds the graph with several threads:

Table 1. Measuring the four strategies
Filter keeps Matching rows Post-filter rows returned Post-filter recall@10 Allow-list recall@10 Exact scan recall@10 Post-filter ms Allow-list ms Exact scan ms
50% 50,037 10.0 0.919 0.984 1.000 0.09 0.14 2.18
20% 19,819 7.6 0.733 1.000 1.000 0.09 0.28 0.99
10% 9,961 3.9 0.388 1.000 1.000 0.09 0.44 0.53
1% 955 0.4 0.041 1.000 1.000 0.05 2.29 0.09
0.1% 109 0.0 0.003 1.000 1.000 0.05 18.15 0.04

Three things stand out.

First, the post-filter row count matches the arithmetic. At 10% selectivity it returned 3.9 rows on average, against the predicted 4. Its latency never moves, because it always does the same unfiltered walk, but its recall collapses from 0.92 to almost zero.

Second, the allow-list walk keeps recall at 1.0 but gets slower as the filter gets stricter: 0.14 ms at 50%, 2.29 ms at 1% and 18.15 ms at 0.1%, a 130-fold increase. The walk has to visit many non-matching nodes to find ten matching ones. Part of this is hnswlib's per-node Python callback, but the shape of the curve is the point.

Third, the exact scan gets cheaper as the filter tightens, because there are fewer rows to score. Between 10% and 1% the two lines cross. Below that point, brute force is both exact and faster.

Recall@10 by filter selectivity (100,000 vectors, ef = 40)
post-filterallow-list walkexact scan of matches
00.20.40.60.8150%20%10%1%0.1%post-filter · 50%: 0.919post-filter · 20%: 0.733post-filter · 10%: 0.388post-filter · 1%: 0.041post-filter · 0.1%: 0.003allow-list walk · 50%: 0.984allow-list walk · 20%: 1allow-list walk · 10%: 1allow-list walk · 1%: 1allow-list walk · 0.1%: 1exact scan of matches · 50%: 1exact scan of matches · 20%: 1exact scan of matches · 10%: 1exact scan of matches · 1%: 1exact scan of matches · 0.1%: 1share of collection that passes the filterrecall@10
Figure 1. Computed with the hnswlib script in this article, 200 queries
Latency per query by filter selectivity
allow-list walkexact scan of matches
0 ms5 ms10 ms15 ms20 ms50%20%10%1%0.1%allow-list walk · 50%: 0.14 msallow-list walk · 20%: 0.28 msallow-list walk · 10%: 0.44 msallow-list walk · 1%: 2.29 msallow-list walk · 0.1%: 18.1 msexact scan of matches · 50%: 2.18 msexact scan of matches · 20%: 0.99 msexact scan of matches · 10%: 0.53 msexact scan of matches · 1%: 0.09 msexact scan of matches · 0.1%: 0.04 msshare of collection that passes the filtermilliseconds per query
Figure 2. Computed with the hnswlib script in this article on one CPU core; absolute times depend on hardware

Iterative scanning: post-filtering that keeps going

pgvector's iterative scan fixes post-filtering by not stopping at the first batch. We can imitate it: start at ef = 40, and if fewer than 10 rows pass the filter, double ef and search again, up to a cap of 20,000 (pgvector's default hnsw.max_scan_tuples is also 20,000, though it counts visited tuples rather than ef).

Table 2. Iterative scanning: post-filtering that keeps going
Filter keeps Recall@10 Mean final ef Latency
10% 0.990 150 0.18 ms
1% 1.000 1,483 1.27 ms
0.1% 0.986 11,469 10.88 ms

The mean final ef tracks the estimate "rows needed divided by selectivity": 10 / 0.01 = 1,000 and 10 / 0.001 = 10,000, with some overshoot from doubling. At 0.1%, the graph checks about ten thousand candidates to find ten rows, while the exact scan touches 109.

Correlation can break everything

The last experiment keeps the share fixed at 10% but changes which points pass. The filter keeps five of the 50 clusters. When the query's own cluster is one of the five, post-filtering at ef = 40 reaches recall 0.936. When the query's cluster is excluded, recall is 0.0: none of the 40 nearest candidates passes. Selectivity alone does not tell you how hard a filter is. Qdrant's benchmark shows the same effect at scale: on a plain graph, a correlated 10% filter reached 88.4% recall while the one-keyword 10% filter reached 20.6%.

How ACORN and filterable graphs fix the walk

The allow-list walk fails when matching points are sparse. There are two families of fixes, plus a planner.

ACORN changes the walk. ACORN, by Liana Patel, Peter Kraft, Carlos Guestrin and Matei Zaharia (arXiv, March 2024), is "predicate-agnostic": it works with any filter expression, not just ones known at build time. The full ACORN-γ builds a denser graph so that matching points stay connected under any filter. The lighter ACORN-1 keeps the normal graph and expands the search at query time: when a node's direct neighbours fail the filter, it looks at the neighbours of those neighbours, and only nodes that pass the filter are scored. The paper reports 2 to 1,000 times higher throughput than prior methods at fixed recall. Qdrant and Elasticsearch describe their implementations as ACORN-1, and Weaviate's filter strategy is also built on ACORN.

Filterable HNSW changes the graph. Qdrant's approach adds extra edges at index time for indexed payload values, so that the sub-graph of points sharing a value stays connected. It only helps filters on fields indexed before the build. In Qdrant's benchmark, building the index took 116 seconds without the extra edges and 507 to 652 seconds with them, 4.4 to 5.6 times longer.

A query planner chooses per query. Systems estimate how many points match and switch to an exact scan when the number is small. Weaviate documents a cut-off of about 15% of the dataset size, set per collection, below which it uses brute force over the matching subset. Qdrant's planner combines payload-index cardinality estimates with ACORN.

Qdrant's published numbers (one million points, recall@10 at mean server-side latency, hnsw_ef = 64) show where each wins:

Table 3. How ACORN and filterable graphs fix the walk
Filter (share kept) Plain graph Plain graph + ACORN Filterable HNSW
One keyword (20%) 62.9% at 1.6 ms 98.9% at 4.4 ms 94.8% at 1.2 ms
One keyword (10%) 20.6% at 1.7 ms 98.1% at 4.3 ms 99.0% at 1.1 ms
One keyword (1%) 0.1% at 1.6 ms 67.7% at 4.7 ms 99.8% at 1.0 ms
Correlated (10%) 88.4% at 1.7 ms 98.6% at 3.5 ms 99.0% at 1.2 ms

Filterable HNSW wins on single indexed keywords. The picture flips for combined filters, because the extra edges were built per value, not per combination:

Table 4. How ACORN and filterable graphs fix the walk
Two keywords, AND (share kept) Plain graph + ACORN Filterable HNSW Planner + ACORN
4% 95.2% at 7.7 ms 63.7% at 1.2 ms 99.9% at 13.9 ms
1% 72.7% at 6.8 ms 70.8% at 1.5 ms 100% at 3.7 ms
0.012% 0.6% at 2.6 ms 1.8% at 2.6 ms 100% at 1.3 ms
Qdrant benchmark: recall@10 for two-keyword AND filters
plain graph + ACORNfilterable HNSWplanner + ACORN
0%20%40%60%80%100%4%1%0.012%plain graph + ACORN · 4%: 95.2%95.2%plain graph + ACORN · 1%: 72.7%72.7%plain graph + ACORN · 0.012%: 0.6%0.6%filterable HNSW · 4%: 63.7%63.7%filterable HNSW · 1%: 70.8%70.8%filterable HNSW · 0.012%: 1.8%1.8%planner + ACORN · 4%: 99.9%99.9%planner + ACORN · 1%: 100%100%planner + ACORN · 0.012%: 100%100%share of collection that passes the filterrecall@10
Figure 3. Source: Qdrant, Filtered vector search with ACORN, 7 August 2026, one million points, hnsw_ef 64

At 0.012% the planner reaches 100% at 1.3 ms because it stops using the graph and scans the few matching points, the same crossover our small experiment showed.

Settings in the main systems

Table 5. Settings in the main systems
System Default behaviour What to change Watch out for
pgvector 0.8.x Filter applied after the index scan; iterative scan is opt-in SET hnsw.iterative_scan = relaxed_order (or strict_order); raise hnsw.max_scan_tuples (default 20,000) and hnsw.scan_mem_multiplier (default 1) if recall is low Relaxed order can return slightly misordered rows; re-sort in an outer query over a MATERIALIZED CTE
Qdrant Filterable HNSW for indexed payload fields; planner picks exact search for small cardinalities Create payload indexes before building; enable acorn.enable per query for multi-field filters; max_selectivity defaults to 0.4 Extra edges multiply build time; ACORN adds latency
Weaviate ACORN default for new collections since 1.34 Choose sweeping, acorn or pathseer per collection; flat-search cut-off near 15% of the dataset Collections created before 1.34 keep their old strategy
Elasticsearch 9.1 ACORN-1 for filtered kNN, automatic Nothing to enable Very selective filters still benefit from exact search on the filtered set

For pgvector, the README also offers two structural fixes that avoid the problem entirely. If you filter by a few distinct values, build a partial index per value, for example CREATE INDEX ON items USING hnsw (embedding vector_l2_ops) WHERE (category_id = 123). If you filter by many values, partition the table so each partition has its own index. The 0.8.0 announcement adds a reminder worth keeping: "If you can achieve the same query performance without using an ANN index, this is usually preferable as it lets you achieve 100% recall."

Use cases and examples

Multi-tenant support bot. A SaaS company stores 20 million ticket chunks for 2,000 customers in one pgvector table. The largest customer owns 5% of the rows and the median customer 0.02%. With post-filtering at ef_search 40, the median customer expects 40 × 0.0002 = 0.008 rows per query: effectively nothing. The team adds a B-tree index on tenant_id. For a median tenant that is 20,000,000 × 0.0002 = 4,000 rows, so an exact scan scores only 4,000 vectors and returns perfect recall; they confirm with EXPLAIN that PostgreSQL picks the B-tree path for small tenants. For the largest tenant (1 million rows), they enable hnsw.iterative_scan = relaxed_order.

Product catalogue with stacked filters. A shop filters by in_stock AND brand AND price band. Each condition keeps 10 to 40%, but the combination often keeps under 1%. Given Qdrant's 63.7% recall for filterable HNSW on a 4% two-keyword filter, the team enables ACORN for this path and accepts a few extra milliseconds.

Access-controlled enterprise search. Each chunk carries a list of group IDs. A user belongs to three groups that together see 0.5% of the corpus, and the groups cluster by department, so the filter is often anti-correlated with general queries. The team routes any query whose estimated match count is under 50,000 rows to an exact scan,.

What it means in practice

Filtered retrieval is a recall problem first and a speed problem second. The failure is silent: the system returns three chunks instead of ten, the model answers from thin evidence, and nothing errors.

The right strategy depends on how many rows pass, not on which database you use. Broad filters (above about 20%) work with almost anything, narrow ones (below about 1%) suit an exact scan, and the middle is where ACORN, filterable graphs and iterative scans earn their keep. The same logic applies to hybrid search: a BM25 leg and a dense leg must both honour the filter before fusion.

What to do now

  1. Measure filter selectivity. Log the share of rows each production filter keeps and bucket queries into above 20%, 1 to 20% and below 1%.
  2. Add filtered queries to your evaluation set. Report recall@10 per selectivity bucket and per tenant size, not just one global number; the RAG evaluation guide shows how to compute it.
  3. Check the rows returned. Alert when a filtered query returns fewer than k rows; it is the cheapest overfiltering detector there is.
  4. Turn on iterative scans in pgvector. Use relaxed_order for RAG, where exact ordering matters less than a full page, and tune hnsw.max_scan_tuples.
  5. Index the filter columns. A B-tree or payload index lets the planner count matches and choose an exact scan for narrow filters.
  6. Use partial indexes or partitions for big tenants. Give each large tenant its own index so its searches never compete with other tenants' points; production RAG covers the wider access-control design.
  7. Enable ACORN for combined filters. In Qdrant, switch it on per query path for AND filters; in Weaviate, keep the 1.34 default on new collections.

Risks and open questions

Planner estimates can be wrong. If the cardinality estimate for a filter is off, the system may pick the graph when an exact scan was needed, or the reverse.

ACORN costs latency. In Qdrant's benchmark, ACORN raised latency from about 1.6 ms to about 4.4 ms on single filters. That is close to a threefold cost.

Filterable graphs cost build time and only cover indexed fields. Qdrant measured 4.4 to 5.6 times longer builds. Fields added later, or filters on unindexed fields, fall back to slower paths.

Relaxed ordering changes results. pgvector's relaxed_order can return rows slightly out of distance order.

Watch next: how Weaviate's pathseer strategy compares with ACORN on combined filters, whether pgvector adds in-graph filtering beyond iterative scans, and whether Qdrant's per-element payload indexes change the planner's choices for array fields such as access-control lists.

Frequently asked questions

Why does my pgvector query return fewer rows than LIMIT?

With approximate indexes, pgvector applies the WHERE clause after the index scan. With the default hnsw.ef_search of 40 and a filter that keeps 10% of rows, you get about 4 rows on average. Enable hnsw.iterative_scan, raise ef_search, or let the planner use a normal index for narrow filters.

Is pre-filtering always better than post-filtering?

No. Pre-filtering with an allow list keeps recall high, but in our test its latency rose from 0.14 ms to 18 ms as the filter tightened from 50% to 0.1%. For very narrow filters an exact scan of the matching rows is both faster and exact.

What is ACORN in one sentence?

ACORN is a method from a 2024 paper that keeps HNSW search connected under arbitrary filters, and its light variant, ACORN-1, does this by checking neighbours of neighbours when direct neighbours fail the filter. Qdrant and Elasticsearch implement ACORN-1.

When should I skip the vector index entirely?

When the filter leaves few enough rows that scoring all of them is cheap. In our 100,000-vector test that point fell between 10% and 1%; Weaviate's default cut-off is about 15% of the dataset. Exact scans also give 100% recall.

Does filtering affect hybrid search and reranking?

Yes. Each retrieval leg must apply the same filter before fusion, or the fused list can contain rows the user may not see. A reranker cannot recover documents that the filtered retrieval never returned.

Summary

Metadata filters clash with approximate vector indexes. Post-filtering keeps latency flat but loses recall as filters tighten: in our test recall@10 fell from 0.92 to 0.003, with 3.9 rows returned instead of 10 at 10% selectivity, as the pgvector README predicts. Allow-list walks keep recall but slow down for narrow filters, where an exact scan becomes faster and perfect. ACORN and Qdrant's filterable HNSW fix the middle range in different ways, and a planner that switches strategies reached 99.9 to 100% recall on combined filters in Qdrant's benchmark. Measure selectivity, test filtered queries separately, and let the planner choose.

Sources

Cite this article

Kelahmet, Ö. C. (2026, November 25). Filtered vector search for RAG: post-filtering, allow lists, ACORN and iterative scans. Özer Cem KELAHMET. https://www.ozercemkelahmet.com/articles/filtered-vector-search-acorn-iterative-scans

BibTeX
@online{kelahmet2026filtered,
  author = {Kelahmet, {\"O}zer Cem},
  title  = {{Filtered vector search for RAG: post-filtering, allow lists, ACORN and iterative scans}},
  year   = {2026},
  month  = {nov},
  url    = {https://www.ozercemkelahmet.com/articles/filtered-vector-search-acorn-iterative-scans}
}
Version historyfirst version
  1. Published

Factual corrections are listed here with what changed. Wording and formatting edits are not listed.

Last updated Nov 25, 2026
Type to search.
    ↑↓ navigate↵ open