Repository navigation
Conversation
A quantized IVF column keeps each vector's int8 or binary form in its cell and the vector as it was inserted in _ivf_vectors, but ivf_get_vector_data() returned the cell's bytes for every column. A point query then read the column's float32 elements past the end of the quantized vector, and a full scan or a KNN query returned the quantized bytes as the column's value. A quantized column's vectors are now read from _ivf_vectors.
vec0Filter_knn() collects the rowids a KNN query's `rowid in (...)` constraint names, and xBestIndex tells SQLite to omit the constraint, but the IVF dispatch never passed them to ivf_query_knn(), so a filtered query on an IVF column returned the unfiltered k nearest rows. ivf_query_knn() now takes them and ranks the rows they name by their exact distances, read through ivf_get_vector_data(), skipping a rowid the table does not have; the cell scan and the oversample re-rank run only without a filter.
This was referenced Oct 23, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A KNN query on an IVF column ignores a
rowid in (...)filter and returns the unfiltered k nearest rows.vec0Filter_knn()collects the rowids the filter names, andvec0BestIndex()tells SQLite to omit the constraint, but the IVF dispatch never passed them toivf_query_knn(). It now does, and a filter's rows are ranked by their exact distances, read throughivf_get_vector_data(), skipping a rowid the table does not have. The cell scan and the oversample re-rank run only without a filter: the probed cells hold the rows near the query, which the filter may not name, so a filter applied to them alone would miss the named rows in other cells (above, row 2 is in a cell thatnprobe=1does not probe).This builds on #349 and carries its commit, since on main
ivf_get_vector_data()returns a quantized column's quantized bytes rather than its vectors.Test:
test_ivf_knn_rowid_inin test-ivf.py compares rowids and distances with a flat column built from the same vectors, before and aftercompute-centroids, for filters that name rows outside the probed cell and a rowid the table does not have, parametrized over no quantizer, int8 and binary. All three fail on main and on #349 and pass here. The Python suite passes (with-DSQLITE_VEC_EXPERIMENTAL_IVF_ENABLE=1, 306 passed, 4 skipped; without it, 239 passed, 71 skipped), under ASan and UBSan as well, and both builds' warnings are main's.The distance half is #316, which applies
distanceconstraints in every backend. The two merge cleanly, and together a distance constraint applies to the k rows the filter ranked, as it does to the probed cells' results, sorowid in (...) and distance > xcan return fewer than k of the named rows where a flat column returns k. This also merges cleanly with every open PR that touches the IVF code, #313, #343 and #347 included.Origin. Found in the IVF port to photostructure/sqlite-vec, photostructure#12 (65817f4), whose
ivf_knn()takes the rowid filter and distance constraints of the rescore index's KNN; the change and its test are written here for asg017's main. No open or closed PR or issue here makes the same change.