Compare exact and quantized vector order¶
Use a small dataset to compare an exact distance sort with an IVFFLAT index quantized to float16. Keep lists=2 and the query fixed. The existing IVF health tutorial covers index inspection.
SET experimental_ivf_index=1;
CREATE DATABASE cookbook_quant;
CREATE TABLE cookbook_quant.items(id INT PRIMARY KEY, v VECF32(4));
INSERT INTO cookbook_quant.items VALUES
(1,'[1,1,1,1]'),(2,'[3,3,3,3]'),(3,'[5,5,5,5]'),
(4,'[50,50,50,50]'),(5,'[52,52,52,52]'),(6,'[54,54,54,54]');
SELECT id FROM cookbook_quant.items
ORDER BY L2_DISTANCE(v,'[1,1,1,1]') LIMIT 3;
CREATE INDEX quant_f16 USING IVFFLAT ON cookbook_quant.items(v)
LISTS=2 OP_TYPE 'vector_l2_ops' QUANTIZATION 'float16';
SELECT id FROM cookbook_quant.items
ORDER BY L2_DISTANCE(v,'[1,1,1,1]') LIMIT 3;
DROP DATABASE cookbook_quant;
Both queries should return 1,2,3 on these separated clusters. This checks correctness for the fixture, not recall or memory savings on production data. Compare an exact baseline and inspect index health before choosing quantization. See the v4.2.4 source test.