Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
Signed-off-by: jinjiabao.jjb <[email protected]>
  • Loading branch information
jinjiabao.jjb committed Jan 15, 2025
1 parent bfc0d4d commit 90e07bb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
28 changes: 0 additions & 28 deletions src/index/hnsw_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(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}}},
};
Expand All @@ -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]") {
Expand Down
40 changes: 36 additions & 4 deletions tests/test_hnsw_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -48,19 +48,20 @@ TestDatasetPool HNSWTestIndex::pool{};
std::vector<int> 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",
"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
Expand Down Expand Up @@ -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]") {
Expand Down

0 comments on commit 90e07bb

Please sign in to comment.