Postgres is sometimes not using hnsw index, and returning the wrong values. Fix this.
Query:
CREATE TABLE sift_base10k_1 (
id SERIAL PRIMARY KEY,
v real[128]
);
\copy sift_base10k_1 (v) FROM '/tmp/lanterndb/vector_datasets/siftsmall_base_arrays_smaller.csv' with csv;
CREATE INDEX hnsw_idx ON sift_base10k_1 USING hnsw (v dist_l2sq_ops) WITH (M=5, ef_construction=10, ef=100, dims=128);
-- \copy sift_base10k_1 (v) FROM '/tmp/lanterndb/vector_datasets/siftsmall_base_arrays_smaller.csv' with csv;
-- SELECT V AS v4444 FROM sift_base10k_1 WHERE id = 4444 \gset
EXPLAIN ANALYZE SELECT * FROM sift_base10k_1 order by v <-> '{120,15,0,0,0,8,8,10,34,0,0,0,1,120,89,25,16,0,0,1,3,39,120,120,26,0,0,11,70,7,19,26,111,16,0,0,0,105,49,16,3,0,0,0,1,120,83,8,120,2,0,0,0,20,55,98,120,1,4,10,55,39,13,46,16,0,0,0,8,87,31,8,8,0,0,0,0,36,34,14,120,89,6,6,11,7,12,31,64,24,4,6,26,54,117,25,0,0,0,2,16,7,1,0,11,0,0,2,2,0,0,2,120,26,2,4,25,28,19,69,3,6,1,4,57,52,24,12}'
LIMIT 5;
-- should be 5100
SELECT id, l2sq_dist(v, '{120,15,0,0,0,8,8,10,34,0,0,0,1,120,89,25,16,0,0,1,3,39,120,120,26,0,0,11,70,7,19,26,111,16,0,0,0,105,49,16,3,0,0,0,1,120,83,8,120,2,0,0,0,20,55,98,120,1,4,10,55,39,13,46,16,0,0,0,8,87,31,8,8,0,0,0,0,36,34,14,120,89,6,6,11,7,12,31,64,24,4,6,26,54,117,25,0,0,0,2,16,7,1,0,11,0,0,2,2,0,0,2,120,26,2,4,25,28,19,69,3,6,1,4,57,52,24,12}'), v FROM sift_base10k_1 order by v <-> '{120,15,0,0,0,8,8,10,34,0,0,0,1,120,89,25,16,0,0,1,3,39,120,120,26,0,0,11,70,7,19,26,111,16,0,0,0,105,49,16,3,0,0,0,1,120,83,8,120,2,0,0,0,20,55,98,120,1,4,10,55,39,13,46,16,0,0,0,8,87,31,8,8,0,0,0,0,36,34,14,120,89,6,6,11,7,12,31,64,24,4,6,26,54,117,25,0,0,0,2,16,7,1,0,11,0,0,2,2,0,0,2,120,26,2,4,25,28,19,69,3,6,1,4,57,52,24,12}'
LIMIT 5;
Postgres is sometimes not using hnsw index, and returning the wrong values. Fix this.
Query:
Data: