@@ -1015,6 +1015,7 @@ BOOST_AUTO_TEST_CASE(CacheTest)
10151015
10161016 std::cout << " =================No Cache===================" << std::endl;
10171017 std::string prevPath = " original_index" ;
1018+ float recall = 0.0 ;
10181019 for (int iter = 0 ; iter < iterations; iter++)
10191020 {
10201021 std::string clone_path = " clone_index_" + std::to_string (iter);
@@ -1032,7 +1033,9 @@ BOOST_AUTO_TEST_CASE(CacheTest)
10321033 static_cast <SPANN::Index<int8_t > *>(prevIndex.get ())->GetDBStat ();
10331034
10341035 auto cloneIndex = prevIndex->Clone (clone_path);
1035-
1036+ prevIndex = nullptr ;
1037+ BOOST_REQUIRE (cloneIndex->Check () == ErrorCode::Success);
1038+
10361039 auto t1 = std::chrono::high_resolution_clock::now ();
10371040 InsertVectors<int8_t >(static_cast <SPANN::Index<int8_t > *>(cloneIndex.get ()), 1 , insertBatchSize, addvecset,
10381041 metaset, iter * insertBatchSize);
@@ -1051,26 +1054,26 @@ BOOST_AUTO_TEST_CASE(CacheTest)
10511054 prevPath = clone_path;
10521055 }
10531056
1054- std::shared_ptr<VectorIndex> prevIndex ;
1055- BOOST_REQUIRE (VectorIndex::LoadIndex (prevPath, prevIndex ) == ErrorCode::Success);
1056- BOOST_REQUIRE (prevIndex != nullptr );
1057- auto t0 = std::chrono::high_resolution_clock::now ();
1058- BOOST_REQUIRE (prevIndex ->Check () == ErrorCode::Success);
1057+ std::shared_ptr<VectorIndex> finalIndex ;
1058+ BOOST_REQUIRE (VectorIndex::LoadIndex (prevPath, finalIndex ) == ErrorCode::Success);
1059+ BOOST_REQUIRE (finalIndex != nullptr );
1060+ auto t = std::chrono::high_resolution_clock::now ();
1061+ BOOST_REQUIRE (finalIndex ->Check () == ErrorCode::Success);
10591062 std::cout << " [INFO] Check time for iteration " << iterations << " : "
1060- << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now () - t0 ).count ()
1063+ << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now () - t ).count ()
10611064 << " ms" << std::endl;
10621065
1063- recall = Search<int8_t >(prevIndex , queryset, vecset, addvecset, K, truth, N, iterations);
1066+ recall = Search<int8_t >(finalIndex , queryset, vecset, addvecset, K, truth, N, iterations);
10641067 std::cout << " [INFO] After Save and Load:" << " recall@5=" << recall << std::endl;
1065- static_cast <SPANN::Index<int8_t > *>(prevIndex .get ())->GetDBStat ();
1066- prevIndex = nullptr ;
1067- for (int iter = 0 ; iter < insertIterations ; iter++)
1068+ static_cast <SPANN::Index<int8_t > *>(finalIndex .get ())->GetDBStat ();
1069+ finalIndex = nullptr ;
1070+ for (int iter = 0 ; iter < iterations ; iter++)
10681071 {
10691072 std::filesystem::remove_all (" clone_index_" + std::to_string (iter));
10701073 }
10711074
10721075 std::cout << " =================Enable Cache===================" << std::endl;
1073- std::string prevPath = " original_index" ;
1076+ prevPath = " original_index" ;
10741077 for (int iter = 0 ; iter < iterations; iter++)
10751078 {
10761079 std::string clone_path = " clone_index_" + std::to_string (iter);
@@ -1110,21 +1113,20 @@ BOOST_AUTO_TEST_CASE(CacheTest)
11101113 cloneIndex = nullptr ;
11111114 prevPath = clone_path;
11121115 }
1113- std::shared_ptr<VectorIndex> prevIndex;
1114- BOOST_REQUIRE (VectorIndex::LoadIndex (prevPath, prevIndex) == ErrorCode::Success);
1115- BOOST_REQUIRE (prevIndex != nullptr );
1116- auto t0 = std::chrono::high_resolution_clock::now ();
1117- BOOST_REQUIRE (prevIndex->Check () == ErrorCode::Success);
1116+ BOOST_REQUIRE (VectorIndex::LoadIndex (prevPath, finalIndex) == ErrorCode::Success);
1117+ BOOST_REQUIRE (finalIndex != nullptr );
1118+ t = std::chrono::high_resolution_clock::now ();
1119+ BOOST_REQUIRE (finalIndex->Check () == ErrorCode::Success);
11181120 std::cout << " [INFO] Check time for iteration " << iterations << " : "
1119- << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now () - t0 ).count ()
1121+ << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now () - t ).count ()
11201122 << " ms" << std::endl;
11211123
1122- recall = Search<int8_t >(prevIndex , queryset, vecset, addvecset, K, truth, N, iterations);
1124+ recall = Search<int8_t >(finalIndex , queryset, vecset, addvecset, K, truth, N, iterations);
11231125 std::cout << " [INFO] After Save and Load:" << " recall@5=" << recall << std::endl;
1124- static_cast <SPANN::Index<int8_t > *>(prevIndex .get ())->GetDBStat ();
1125- prevIndex = nullptr ;
1126+ static_cast <SPANN::Index<int8_t > *>(finalIndex .get ())->GetDBStat ();
1127+ finalIndex = nullptr ;
11261128
1127- for (int iter = 0 ; iter < insertIterations ; iter++)
1129+ for (int iter = 0 ; iter < iterations ; iter++)
11281130 {
11291131 std::filesystem::remove_all (" clone_index_" + std::to_string (iter));
11301132 }
0 commit comments