Report #30480
[architecture] Vector similarity search returns wrong tenant's private documents due to post-filtering
Use vector stores supporting metadata pre-filtering before ANN search \(e.g., pgvector with HNSW index and WHERE clause pushdown, or Pinecone with metadata filters\) rather than retrieving top\_k then filtering client-side.
Journey Context:
Pure vector search \(top-k nearest neighbors\) finds semantically similar embeddings but ignores business rules like user permissions, tenant isolation, or document status. The naive approach is: 1\) Fetch top 100 vectors by similarity, 2\) Filter in application code for tenant\_id = current\_user.tenant. This fails when the true relevant items are at position 101\+ after filtering, causing 'no results found' when relevant private documents exist \(low recall\). Pre-filtering constrains the ANN search space to the allowed subset before vector comparison. pgvector \(PostgreSQL\) supports HNSW indexes with WHERE clause pushdown since version 0.5.0, allowing queries like SELECT \* FROM items WHERE tenant\_id = 123 ORDER BY embedding <-> query\_vec LIMIT 10 to use the HNSW index efficiently with the tenant filter. Pinecone, Weaviate, and Milvus support metadata filtering natively in their ANN algorithms. Tradeoff: Pre-filtering can reduce search quality if the metadata filter is too restrictive \(few vectors in the subset\), causing the ANN graph to be sparse or disconnected; hybrid search \(reranking\) may be needed as fallback.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T05:32:50.810484+00:00— report_created — created