@@ -1086,6 +1086,58 @@ TestIndex::TestSerializeReaderSet(const IndexPtr& index_from,
10861086 }
10871087}
10881088
1089+ void
1090+ TestIndex::TestSerializeWriteFunc (const IndexPtr& index_from,
1091+ const IndexPtr& index_to,
1092+ const TestDatasetPtr& dataset,
1093+ const std::string& search_param,
1094+ bool expected_success) {
1095+ if (not index_from->CheckFeature (vsag::SUPPORT_SERIALIZE_WRITE_FUNC)) {
1096+ return ;
1097+ }
1098+ auto dir = fixtures::TempDir (" serialize" );
1099+ auto path = dir.GenerateRandomFile ();
1100+ std::ofstream outfile (path, std::ios::out | std::ios::binary);
1101+ vsag::WriteFuncType write_func =
1102+ [&outfile](vsag::OffsetType offset, vsag::SizeType size, const void * data) -> void {
1103+ outfile.seekp (offset);
1104+ outfile.write (reinterpret_cast <const char *>(data), size);
1105+ };
1106+ auto serialize_index = index_from->Serialize (write_func);
1107+ REQUIRE (serialize_index.has_value () == expected_success);
1108+ outfile.close ();
1109+
1110+ std::ifstream infile (path, std::ios::in | std::ios::binary);
1111+ auto deserialize_index = index_to->Deserialize (infile);
1112+ REQUIRE (deserialize_index.has_value () == expected_success);
1113+ infile.close ();
1114+ if (index_to->GetNumElements () == 0 ) {
1115+ return ;
1116+ }
1117+
1118+ const auto & queries = dataset->query_ ;
1119+ auto query_count = queries->GetNumElements ();
1120+ auto dim = queries->GetDim ();
1121+ auto topk = 10 ;
1122+ for (auto i = 0 ; i < query_count; ++i) {
1123+ auto query = vsag::Dataset::Make ();
1124+ query->NumElements (1 )
1125+ ->Dim (dim)
1126+ ->Paths (queries->GetPaths () + i)
1127+ ->SparseVectors (queries->GetSparseVectors () + i)
1128+ ->Float32Vectors (queries->GetFloat32Vectors () + i * dim)
1129+ ->Owner (false );
1130+ auto res_from = index_from->KnnSearch (query, topk, search_param);
1131+ auto res_to = index_to->KnnSearch (query, topk, search_param);
1132+ REQUIRE (res_from.has_value ());
1133+ REQUIRE (res_to.has_value ());
1134+ REQUIRE (res_from.value ()->GetDim () == res_to.value ()->GetDim ());
1135+ for (auto j = 0 ; j < topk; ++j) {
1136+ REQUIRE (res_to.value ()->GetIds ()[j] == res_from.value ()->GetIds ()[j]);
1137+ }
1138+ }
1139+ }
1140+
10891141void
10901142TestIndex::TestConcurrentAddSearch (const TestIndex::IndexPtr& index,
10911143 const TestDatasetPtr& dataset,
0 commit comments