Database / LanceDB Interview questions
What is prefiltering vs postfiltering in LanceDB queries?
When a query combines vector search with a metadata filter, there are two possible orders to apply them in, and LanceDB supports both, with different performance and correctness trade-offs depending on how selective the filter is.
| Prefiltering (default) | Postfiltering |
| Filter applied to narrow the candidate set before vector scoring. | Filter applied after ranking the top-k vector search results. |
| Benefits from scalar indexes on the filtered columns. | Doesn't require a scalar index; runs the filter on already-ranked results. |
| Guarantees full top-k results even with a highly selective filter. | Can return fewer than k results if the filter is very selective. |
| Generally the better default for most workloads. | Can be faster when the filter is non-selective or unindexed. |
The core risk with postfiltering is easy to miss until it happens in practice: if you ask for the top 10 vector matches and then filter down by a condition afterward, you might end up with only 2 or 3 results if most of the top 10 don't happen to match the filter — prefiltering avoids this by narrowing the candidate pool before scoring, so the vector search itself only ever ranks candidates that already satisfy the filter.
More Related questions...