diff --git a/src/index/hnsw_test.cpp b/src/index/hnsw_test.cpp index 7f745bc3..cdd0ce60 100644 --- a/src/index/hnsw_test.cpp +++ b/src/index/hnsw_test.cpp @@ -418,20 +418,6 @@ TEST_CASE("static hnsw", "[ut][hnsw]") { REQUIRE_FALSE(result.has_value()); REQUIRE(result.error().type == ErrorType::UNSUPPORTED_INDEX_OPERATION); - SECTION("serialize to binaryset") { - auto binary_set = index->Serialize(); - REQUIRE(binary_set.has_value()); - - auto voidresult = index->Deserialize(binary_set.value()); - REQUIRE_FALSE(voidresult.has_value()); - REQUIRE(voidresult.error().type == ErrorType::INDEX_NOT_EMPTY); - auto another_index = std::make_shared(hnsw_obj, commom_param); - another_index->InitMemorySpace(); - auto deserialize_result = another_index->Deserialize(binary_set.value()); - REQUIRE(deserialize_result.has_value()); - index = another_index; - } - JsonType params{ {"hnsw", {{"ef_search", 100}}}, }; @@ -458,20 +444,6 @@ TEST_CASE("static hnsw", "[ut][hnsw]") { auto remove_result = index->Remove(ids[0]); REQUIRE_FALSE(remove_result.has_value()); REQUIRE(remove_result.error().type == ErrorType::UNSUPPORTED_INDEX_OPERATION); - - SECTION("serialize to fstream") { - fixtures::TempDir dir("hnsw_test_deserialize_on_not_empty_index"); - std::fstream out_stream(dir.path + "index.bin", std::ios::out | std::ios::binary); - auto serialize_result = index->Serialize(out_stream); - REQUIRE(serialize_result.has_value()); - out_stream.close(); - - std::fstream in_stream(dir.path + "index.bin", std::ios::in | std::ios::binary); - auto voidresult = index->Deserialize(in_stream); - REQUIRE_FALSE(voidresult.has_value()); - REQUIRE(voidresult.error().type == ErrorType::INDEX_NOT_EMPTY); - in_stream.close(); - } } TEST_CASE("hnsw add vector with duplicated id", "[ut][hnsw]") { diff --git a/tests/test_hnsw_new.cpp b/tests/test_hnsw_new.cpp index 1f5f18ce..dce947d4 100644 --- a/tests/test_hnsw_new.cpp +++ b/tests/test_hnsw_new.cpp @@ -28,7 +28,7 @@ namespace fixtures { class HNSWTestIndex : public fixtures::TestIndex { public: static std::string - GenerateHNSWBuildParametersString(const std::string& metric_type, int64_t dim); + GenerateHNSWBuildParametersString(const std::string& metric_type, int64_t dim, bool use_static=false); static TestDatasetPool pool; @@ -48,7 +48,7 @@ TestDatasetPool HNSWTestIndex::pool{}; std::vector HNSWTestIndex::dims = fixtures::get_common_used_dims(2, RandomValue(0, 999)); std::string -HNSWTestIndex::GenerateHNSWBuildParametersString(const std::string& metric_type, int64_t dim) { +HNSWTestIndex::GenerateHNSWBuildParametersString(const std::string& metric_type, int64_t dim, bool use_static) { constexpr auto parameter_temp = R"( {{ "dtype": "float32", @@ -56,11 +56,12 @@ HNSWTestIndex::GenerateHNSWBuildParametersString(const std::string& metric_type, "dim": {}, "hnsw": {{ "max_degree": 64, - "ef_construction": 500 + "ef_construction": 500, + "use_static": {} }} }} )"; - auto build_parameters_str = fmt::format(parameter_temp, metric_type, dim); + auto build_parameters_str = fmt::format(parameter_temp, metric_type, dim, use_static); return build_parameters_str; } } // namespace fixtures @@ -340,6 +341,37 @@ TEST_CASE_PERSISTENT_FIXTURE(fixtures::HNSWTestIndex, "HNSW Serialize File", "[f vsag::Options::Instance().set_block_size_limit(origin_size); } +TEST_CASE_PERSISTENT_FIXTURE(fixtures::HNSWTestIndex, "static HNSW Serialize File", "[ft][hnsw]") { + auto origin_size = vsag::Options::Instance().block_size_limit(); + auto size = GENERATE(1024 * 1024 * 2); + auto metric_type = "l2"; + const std::string name = "hnsw"; + auto search_param = fmt::format(search_param_tmp, 100); + auto dim = 128; + vsag::Options::Instance().set_block_size_limit(size); + auto param = GenerateHNSWBuildParametersString(metric_type, dim, true); + auto index = TestFactory(name, param, true); + + auto dataset = pool.GetDatasetAndCreate(dim, base_count, metric_type); + TestBuildIndex(index, dataset, true); + if (index->CheckFeature(vsag::SUPPORT_SERIALIZE_FILE) and + index->CheckFeature(vsag::SUPPORT_DESERIALIZE_FILE)) { + auto index2 = TestFactory(name, param, true); + TestSerializeFile(index, index2, dataset, search_param, true); + } + if (index->CheckFeature(vsag::SUPPORT_SERIALIZE_BINARY_SET) and + index->CheckFeature(vsag::SUPPORT_DESERIALIZE_BINARY_SET)) { + auto index2 = TestFactory(name, param, true); + TestSerializeBinarySet(index, index2, dataset, search_param, true); + } + if (index->CheckFeature(vsag::SUPPORT_SERIALIZE_FILE) and + index->CheckFeature(vsag::SUPPORT_DESERIALIZE_READER_SET)) { + auto index2 = TestFactory(name, param, true); + TestSerializeReaderSet(index, index2, dataset, search_param, name, true); + } + vsag::Options::Instance().set_block_size_limit(origin_size); +} + TEST_CASE_PERSISTENT_FIXTURE(fixtures::HNSWTestIndex, "HNSW Build & ContinueAdd Test With Random Allocator", "[ft][hnsw]") {