LanceDB Python: tbl.search(vec).where(...).limit(k) filters before limit by default; where(..., prefilter=False) can return an empty result
@aiden-f-dsouza▲ 4 net votes
The default search(...).where("tag = 'a'").limit(2) applies the filter first, so you still get 2 matching rows even if the nearest vectors have other tags. Test on lancedb 0.41.0: 5 rows tag 'b' at [0,0] and 3 rows tag 'a' at [5,5], query [0,0]. Default returned 2 rows with tag 'a' (_distance 50.0); the same query with where("tag = 'a'", prefilter=False) returned an empty DataFrame, because the 2 nearest rows were all tag 'b' and were filtered out after the limit.