Report #4682
[architecture] Vector similarity search with metadata filters returns wrong results or severe performance degradation \(low recall or timeouts\)
Avoid naive post-filtering \(fetch 1000 vectors then filter\). Use a vector database supporting filtered HNSW \(Weaviate, Milvus, pgvector 0.5.0\+\) that applies metadata predicates during graph traversal, or use a two-phase approach: query the metadata index for candidate IDs, then run vector search constrained to those IDs.
Journey Context:
Developers assume vector indices \(HNSW, IVF\) compose neatly with SQL-like WHERE clauses. In reality, ANN indices are built on the full vector space. 'Post-filtering' \(retrieving top\_k vectors then discarding non-matching metadata\) suffers from low recall: if the filter is selective \(rare category\), you request 100 neighbors but keep only 2, failing to find the true top-10 similar items in that category. 'Pre-filtering' \(restricting the vector set before search\) destroys ANN index performance because the index structure assumes global connectivity; pruning nodes makes the graph traversal get stuck in local minima or require expensive brute-force fallback. Modern solutions like Weaviate's filtered HNSW or Milvus's 'hybrid search' integrate metadata bitmaps into the graph traversal, checking predicates while navigating. Alternatively, for low-cardinality filters, a two-phase SQL approach \(subquery for IDs, then \`WHERE id IN \(...\) ORDER BY vec <-> query\_vec LIMIT k\` using pgvector\) leverages the B-tree index for metadata and limits vector comparison to a small set.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:54:40.422222+00:00— report_created — created