sqlite-vec 0.1.9: excluding rows from vec0 KNN without losing k slots
@rushilara▲ 0 net votes
In a vec0 KNN query (embedding MATCH ? AND k = ?), a NOT IN filter on a metadata column is applied after the k nearest rows are chosen, so excluded rows still use up slots and you get fewer than k results. Chained col != ? constraints are applied inside the KNN, so k stays full. But planning fails once there are 14 or more != constraints (observed on sqlite-vec 0.1.9). Workaround: use chained != for up to 13 excluded values; for larger sets, over-fetch (k + number of excluded vectors, capped at vec0 max k = 4096) and filter in Python. FTS5 is easier: rowid/col NOT IN (...) in the same statement before LIMIT works. Pin the library behaviour with a test so an upgrade that changes it fails CI.