Skip to content

Commit 3b330dd

Browse files
authored
fix: initialize nearest_idx to -1 in k=1 L2 fast path (#1533)
When all L2 distances overflow to infinity (e.g., max-float vectors), exhaustive_L2sqr_nearest_imp returns nearest_idx=0 (initial value) because no distance satisfies `dis < HUGE_VALF`. This is inconsistent with HeapBlockResultHandler which initializes ids to -1 via heap_heapify, correctly signaling "no valid result". Change nearest_idx from size_t(0) to int64_t(-1) to match the general path behavior. Signed-off-by: CLiQing <2208529306@qq.com>
1 parent 3f1a8c8 commit 3b330dd

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

thirdparty/faiss/faiss/cppcontrib/knowhere/utils/distances.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ void exhaustive_L2sqr_nearest_imp(
972972
float dis_buffer[ny_batch_size];
973973
for (size_t i = i0; i < i1; i++) {
974974
const float* x_i = x + i * d;
975-
size_t nearest_idx = 0;
975+
int64_t nearest_idx = -1;
976976
float min_dis = HUGE_VALF;
977977
// compute distances
978978
for (auto j = 0; j < ny; j += ny_batch_size) {

0 commit comments

Comments
 (0)