Commit d8bcfeb
committed
libsql-sqlite3: Break vector search distance ties by rowid deterministically
The DiskANN top-k buffer ordered candidates by distance using a strict
less-than comparison (distanceBufferInsertIdx), so when two vectors are
exactly equidistant from the query their relative order in the result fell
out of the search/visit order. That visit order depends on float rounding in
the distance computation, which varies with compiler/build flags -- e.g. the
same sources built as testfixture vs the sqlite3 shell resolved such ties
differently, and the Makefile.in changes in the 3.47.0 merge were enough to
flip the testfixture build's result for vector-index-v2-query-4 (query vector
[-1,1,1,1] is exactly equidistant from rows 'b' and 'c').
Add topCandidateInsertIdx(), which breaks exact-distance ties in the top
candidates buffer by rowid (ascending). Equidistant results now come back in
a stable, reproducible order independent of build flags or how the search
happened to reach them. Non-tied results are unaffected (the distance
comparison still decides first).
Update vector-index-v2-query-4 to assert the deterministic ordering ({d a b},
'b' being the smaller rowid of the tied pair) instead of the build-dependent
value it previously hard-coded.1 parent ebd1563 commit d8bcfeb
2 files changed
Lines changed: 39 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
923 | 923 | | |
924 | 924 | | |
925 | 925 | | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
926 | 958 | | |
927 | 959 | | |
928 | 960 | | |
| |||
1100 | 1132 | | |
1101 | 1133 | | |
1102 | 1134 | | |
1103 | | - | |
| 1135 | + | |
1104 | 1136 | | |
1105 | 1137 | | |
1106 | 1138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
562 | 562 | | |
563 | 563 | | |
564 | 564 | | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
565 | 570 | | |
566 | 571 | | |
567 | | - | |
| 572 | + | |
0 commit comments