k-NN query inside bool query with filter compared to FAISS efficient filter

@Alireza Thanks for reaching out. Please find my ans below.

There is a big difference between both the queries. In the first query what will happen is, docs from filter and docs from knn query will be intersected and final intersected results will be returned. Think of it like a post filter. This has the potential to return less than K number of documents.

In the second query what will happen while doing vector search we will select those documents only which evaluate to true on the filter provided. Think of this as Filter while Search. This will ensure that if K documents are there for filters then K documents are returned.

I hope this clarifies.

Documentation : k-NN search with filters - OpenSearch documentation

The first Query is Post Filter and second query is Efficient Filters.

2 Likes