@@ -489,44 +489,43 @@ TYPED_TEST(SVSTieredIndexTest, KNNSearch) {
489
489
// Memory usage should not change.
490
490
ASSERT_EQ (allocator->getAllocationSize (), cur_memory_usage);
491
491
492
- // TODO: add timeouts support to SVS index and test it here.
493
- // // // // // // // // // // // // //
494
- // // Check behavior upon timeout. //
495
- // // // // // // // // // // // // //
496
-
497
- // VecSimQueryReply *res;
498
- // // Add a vector to the SVS index so there will be a reason to query it.
499
- // GenerateAndAddVector<TEST_DATA_T>(svs_index, dim, n, n);
500
-
501
- // // Set timeout callback to always return 1 (will fail while querying the flat buffer).
502
- // VecSim_SetTimeoutCallbackFunction([](void *ctx) { return 1; }); // Always times out
503
-
504
- // res = VecSimIndex_TopKQuery(tiered_index, query_0, k, nullptr, BY_SCORE);
505
- // ASSERT_TRUE(res->results.empty());
506
- // ASSERT_EQ(VecSimQueryReply_GetCode(res), VecSim_QueryReply_TimedOut);
507
- // VecSimQueryReply_Free(res);
508
-
509
- // // Set timeout callback to return 1 after n checks (will fail while querying the SVS index).
510
- // // Brute-force index checks for timeout after each vector.
511
- // size_t checks_in_flat = flat_index->indexSize();
512
- // VecSimQueryParams qparams = {.timeoutCtx = &checks_in_flat};
513
- // VecSim_SetTimeoutCallbackFunction([](void *ctx) {
514
- // auto count = static_cast<size_t *>(ctx);
515
- // if (*count == 0) {
516
- // return 1;
517
- // }
518
- // (*count)--;
519
- // return 0;
520
- // });
521
- // res = VecSimIndex_TopKQuery(tiered_index, query_0, k, &qparams, BY_SCORE);
522
- // ASSERT_TRUE(res->results.empty());
523
- // ASSERT_EQ(VecSimQueryReply_GetCode(res), VecSim_QueryReply_TimedOut);
524
- // VecSimQueryReply_Free(res);
525
- // // Make sure we didn't get the timeout in the flat index.
526
- // checks_in_flat = flat_index->indexSize(); // Reset the counter.
527
- // res = VecSimIndex_TopKQuery(flat_index, query_0, k, &qparams, BY_SCORE);
528
- // ASSERT_EQ(VecSimQueryReply_GetCode(res), VecSim_QueryReply_OK);
529
- // VecSimQueryReply_Free(res);
492
+ // // // // // // // // // // // //
493
+ // Check behavior upon timeout. //
494
+ // // // // // // // // // // // //
495
+
496
+ VecSimQueryReply *res;
497
+ // Add a vector to the SVS index so there will be a reason to query it.
498
+ GenerateAndAddVector<TEST_DATA_T>(svs_index, dim, n, n);
499
+
500
+ // Set timeout callback to always return 1 (will fail while querying the flat buffer).
501
+ VecSim_SetTimeoutCallbackFunction ([](void *ctx) { return 1 ; }); // Always times out
502
+
503
+ res = VecSimIndex_TopKQuery (tiered_index, query_0, k, nullptr , BY_SCORE);
504
+ ASSERT_TRUE (res->results .empty ());
505
+ ASSERT_EQ (VecSimQueryReply_GetCode (res), VecSim_QueryReply_TimedOut);
506
+ VecSimQueryReply_Free (res);
507
+
508
+ // Set timeout callback to return 1 after n checks (will fail while querying the SVS index).
509
+ // Brute-force index checks for timeout after each vector.
510
+ size_t checks_in_flat = flat_index->indexSize ();
511
+ VecSimQueryParams qparams = {.timeoutCtx = &checks_in_flat};
512
+ VecSim_SetTimeoutCallbackFunction ([](void *ctx) {
513
+ auto count = static_cast <size_t *>(ctx);
514
+ if (*count == 0 ) {
515
+ return 1 ;
516
+ }
517
+ (*count)--;
518
+ return 0 ;
519
+ });
520
+ res = VecSimIndex_TopKQuery (tiered_index, query_0, k, &qparams, BY_SCORE);
521
+ ASSERT_TRUE (res->results .empty ());
522
+ ASSERT_EQ (VecSimQueryReply_GetCode (res), VecSim_QueryReply_TimedOut);
523
+ VecSimQueryReply_Free (res);
524
+ // Make sure we didn't get the timeout in the flat index.
525
+ checks_in_flat = flat_index->indexSize (); // Reset the counter.
526
+ res = VecSimIndex_TopKQuery (flat_index, query_0, k, &qparams, BY_SCORE);
527
+ ASSERT_EQ (VecSimQueryReply_GetCode (res), VecSim_QueryReply_OK);
528
+ VecSimQueryReply_Free (res);
530
529
531
530
// Clean up.
532
531
VecSim_SetTimeoutCallbackFunction ([](void *ctx) { return 0 ; });
0 commit comments