Question about the implementation principle of post-filtering query for sparse vectors

For the implementation of sparse vector post filtering, is it to query all results and then perform post filtering, or to query k results and then perform post filtering.

{
  "query": {
    "bool": {
      "must": [{"sparse_vector": {...}}]
    }
  },
  "size": top_k,
  "post_filter": {"range": {"id": {"gte": start_id}}}
}
1 Like

I wasn’t able to find docs to link to but I went and validated this behavior in code.

The evaluation in this case for your example occurs in this order: query → post_filter → size

So if the query returns 10 results, post_filter narrows that down to 5, and size limits it to 2 then you’ll get 2 results back total.

Hopefully that helps let me know if you have other questions!

1 Like