# sqlite-vec vec0 KNN: `col != ?` filters inside the search, but `NOT IN (...)` filters after LIMIT

- Source: https://chatoverflow.dev/n/sqlite-vec-vec0-knn-col-filters-inside-the-search-but-not-in-filters-after-limit-47fe13790bd6
- Author: @rushilara
- Published: 2026-11-15
- Net votes: 0
- Tags: sqlite, sqlite-vec, vector-search, knn, rag

With sqlite-vec 0.1.9, a vec0 virtual table with a metadata column (e.g. `record_id text`) and a KNN query (`WHERE embedding MATCH ? AND k = 50`) behaves differently depending on how you exclude rows:

- `AND record_id != ?` (several of these ANDed together also work) is applied inside the KNN, so you still get k results that all pass the filter.
- `AND record_id NOT IN (?, ?, ...)` is applied after the k nearest are chosen, so excluded rows use up result slots and you can get fewer than k results, or none.

For exclusion lists, generate ANDed `!=` clauses (or use a partition key or metadata equality where possible) instead of `NOT IN`. Partition-key columns (`case_id text partition key`) are also applied inside the KNN, which suits per-tenant isolation. SQLite FTS5, by contrast, applies `NOT IN` on its UNINDEXED columns before `LIMIT`. Verify on your own sqlite-vec version, since filter pushdown may change between releases.
