Filtering and Hybrid Search
15. Why do metadata filters hurt recall, and what are the strategies?
An ANN index is built on vector proximity, not on your filter. Three strategies exist:
- Post-filtering: search the index, then drop rows that fail the filter. Simple, and it returns too few results when the filter is selective. pgvector works this way by default.
- Pre-filtering: find matching IDs first, then search only among them. Exact for selective filters and slow for broad ones.
- Filter-aware graph search: traverse the graph while checking the filter, with extra links or fallbacks so the walk does not get stuck in regions where no node matches. Qdrant's filterable HNSW and ACORN, and similar features in other engines, take this route.
Most engines switch strategy based on estimated filter cardinality, using payload index statistics.
A strong candidate asks how selective the production filters are (one tenant out of 10,000, or "language = en" matching 80%) before picking a design, and measures recall with those filters applied.
16. How do pgvector's iterative index scans work?
Added in pgvector 0.8.0, iterative scans keep scanning more of the index when filtering leaves too few results, until enough rows are found or a limit is hit.
SET hnsw.iterative_scan = strict_order; -- results stay exactly ordered by distance
SET hnsw.iterative_scan = relaxed_order; -- better recall, slight reordering allowed
SET hnsw.max_scan_tuples = 20000; -- default ceiling on tuples visited
SELECT id FROM items
WHERE category_id = 123
ORDER BY embedding <-> $1
LIMIT 10;
With relaxed_order, the README recommends a materialized CTE to restore strict ordering, and on Postgres 17 and later the outer sort needs distance + 0:
WITH relaxed AS MATERIALIZED (
SELECT id, embedding <-> $1 AS distance
FROM items WHERE category_id = 123
ORDER BY distance LIMIT 10
)
SELECT * FROM relaxed ORDER BY distance + 0;
Other pgvector options a strong candidate names: a B-tree index on the filter column for highly selective filters (exact search over few rows), a partial HNSW index per hot category, or table partitioning by tenant.
17. How do you make filtered search fast in Qdrant?
Create payload indexes on every field you filter by.
Qdrant uses them both to evaluate filters and to plan the query: for a very selective filter it can skip the graph and score matching points directly, and for broader filters it uses filter-aware HNSW traversal.
Without a payload index, filters fall back to scanning payloads.
Features from recent releases that a candidate working on Qdrant should know:
- ACORN (1.16): a search method that stays accurate over many filtered points at some cost in speed.
- Prefix match in keyword filters (1.19) and a full-scan-only substring condition (1.20).
- Per-element indexes for arrays of objects (1.20) for nested filters.
- Tenant indexes: a keyword payload index marked
is_tenant: true co-locates each tenant's data for faster per-tenant search.
A weak candidate filters in application code after retrieving the top 100, which drops recall the same way post-filtering does.
18. How does hybrid search work, and how do you fuse the two result lists?
Hybrid search runs a keyword retriever (BM25 or a learned sparse model such as SPLADE) and a dense vector retriever, then merges the results.
Keyword search catches exact terms, product codes and names that embeddings blur; dense search catches paraphrases.
Reciprocal rank fusion (RRF) is the common merge: each document scores the sum of 1 / (k + rank) across the lists it appears in, so only rank positions matter. In Qdrant, hybrid search is a Query API call with prefetches:
client.query_points(
collection_name="docs",
prefetch=[
models.Prefetch(query=models.SparseVector(indices=[1, 42], values=[0.22, 0.8]), using="sparse", limit=20),
models.Prefetch(query=dense_vector, using="dense", limit=20),
],
query=models.RrfQuery(rrf=models.Rrf()),
limit=10,
)
Per the Qdrant hybrid query docs, the k constant became configurable in 1.16 and weighted RRF arrived in 1.17.
Weaviate's hybrid query uses alpha (1 is pure vector, 0 is pure keyword), and its hybrid search docs state relative score fusion has been the default since 1.24.
19. Find the bug in this hybrid merge.
def hybrid(query: str, k: int = 10):
dense = vector_search(embed(query), limit=50) # [(doc_id, cosine_similarity)]
sparse = bm25_search(query, limit=50) # [(doc_id, bm25_score)]
scores = {}
for doc_id, s in dense + sparse:
scores[doc_id] = scores.get(doc_id, 0) + s
return sorted(scores, key=scores.get, reverse=True)[:k]
Bug: it adds raw scores on different scales. Cosine similarity sits between -1 and 1, while BM25 scores are unbounded and often range from 5 to 30 depending on query length and corpus statistics.
BM25 dominates every result, so the dense retriever barely affects ranking, and the balance changes from query to query.
Fix: use rank-based fusion (RRF), or normalize each list (min-max or relative score fusion, as Weaviate does) before weighting. Then tune the weight on a labeled evaluation set.
A follow-up for senior candidates: documents that appear in only one list get no contribution from the other, so the candidate limit per retriever (50 here) affects results and belongs in the evaluation.
20. When do you add a reranker, and how many candidates do you give it?
Add a cross-encoder reranker when first-stage retrieval finds the right documents but ranks them poorly, which shows up as good recall@50 and weak precision@5.
A cross-encoder reads the query and each candidate together, so it scores relevance much better than vector distance, at a cost of one model call per candidate.
Typical shape: retrieve 50 to 200 candidates with hybrid search, rerank, keep the top 5 to 10 for the LLM context. The candidate count is a latency budget question.
Doubling it doubles reranker cost and helps only if relevant documents sit beyond the current cutoff, which you check with recall@k at several values of k. Engines are absorbing this step: Milvus 3.0 added a Function Chain API for model-based reranking inside the search request.
A strong candidate also caches reranker results for repeated queries and remembers question 8, since a pgvector ef_search of 40 caps the candidate pool silently.