From 5e4c557f931a5103e21ba6a29197a9e475927790 Mon Sep 17 00:00:00 2001 From: Alex Garcia Date: Tue, 31 Mar 2026 14:35:55 -0700 Subject: [PATCH] Initialize rescore distance variable to FLT_MAX The `dist` variable in rescore KNN quantized distance computation was uninitialized. If the switch on quantizer_type or distance_metric didn't match any case, the uninitialized value would propagate into the top-k heap, potentially returning garbage results. Co-Authored-By: Claude Opus 4.6 (1M context) --- sqlite-vec-rescore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlite-vec-rescore.c b/sqlite-vec-rescore.c index ef0a35c..1cf67bf 100644 --- a/sqlite-vec-rescore.c +++ b/sqlite-vec-rescore.c @@ -465,7 +465,7 @@ static int rescore_knn(vec0_vtab *p, vec0_cursor *pCur, for (int j = 0; j < p->chunk_size; j++) { if (!bitmap_get(b, j)) continue; - f32 dist; + f32 dist = FLT_MAX; switch (vector_column->rescore.quantizer_type) { case VEC0_RESCORE_QUANTIZER_BIT: { const u8 *base_j = ((u8 *)baseVectors) + (j * (qdim / CHAR_BIT));