From 6d8168b779bc00838b962a58ce502aea7c8a8799 Mon Sep 17 00:00:00 2001 From: "Chaunte W. Lacewell" Date: Mon, 14 Oct 2024 14:07:46 -0700 Subject: [PATCH] V2.10 hnswfix (#235) * Add HNSW to DescriptorSet Engine enum (#233) * Update enum in api_schema.json and add client test using hnsw * remove artifact --------- Signed-off-by: dependabot[bot] Co-authored-by: Michael Beale Co-authored-by: Ian Adams Co-authored-by: sys_vdms Co-authored-by: Rohit Verma Co-authored-by: Sameh Gobriel <75963591+s-gobriel@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- tests/unit_tests/client_descriptors.cc | 28 +++++++++++++++++++ tests/unit_tests/meta_data.cc | 37 ++++++++++++++++++++++++++ tests/unit_tests/meta_data_helper.h | 2 ++ utils/src/api_schema/api_schema.json | 2 +- 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/client_descriptors.cc b/tests/unit_tests/client_descriptors.cc index 5912247c..c9832f3c 100644 --- a/tests/unit_tests/client_descriptors.cc +++ b/tests/unit_tests/client_descriptors.cc @@ -56,6 +56,34 @@ TEST(CLIENT_CPP, add_flinng_descriptor) { EXPECT_EQ(status1, 0); } +TEST(CLIENT_CPP, add_hnsw_descriptor) { + std::vector fv_values; + srand((unsigned)time(NULL)); + for (int i = 0; i < 100; i++) + fv_values.push_back((float)rand() / RAND_MAX); + + std::vector blobs; + std::string *bytes_str = new std::string(); + bytes_str->resize(fv_values.size() * sizeof(float)); + std::memcpy((void *)bytes_str->data(), fv_values.data(), + fv_values.size() * sizeof(float)); + blobs.push_back(bytes_str); + + Meta_Data *meta_obj = new Meta_Data(); + meta_obj->_aclient.reset( + new VDMS::VDMSClient(meta_obj->get_server(), meta_obj->get_port())); + Json::Value tuple; + tuple = meta_obj->construct_hnsw_descriptor(); + + VDMS::Response response = + meta_obj->_aclient->query(meta_obj->_fastwriter.write(tuple), blobs); + Json::Value result; + meta_obj->_reader.parse(response.json.c_str(), result); + + int status1 = result[0]["AddDescriptor"]["status"].asInt(); + + EXPECT_EQ(status1, 0); +} TEST(CLIENT_CPP, find_descriptor) { diff --git a/tests/unit_tests/meta_data.cc b/tests/unit_tests/meta_data.cc index 240997af..7a98ac00 100644 --- a/tests/unit_tests/meta_data.cc +++ b/tests/unit_tests/meta_data.cc @@ -45,6 +45,43 @@ Json::Value Meta_Data::construct_flinng_descriptor() { return tuple; } +Json::Value Meta_Data::construct_hnsw_Set(std::string &name, int &dim) { + + Json::Value descriptor_set; + Json::Value set_query; + Json::Value tuple; + descriptor_set["name"] = name; + descriptor_set["dimensions"] = dim; + descriptor_set["metric"] = "L2"; + descriptor_set["engine"] = "FaissHNSWFlat"; + set_query["AddDescriptorSet"] = descriptor_set; + + return set_query; +} + +Json::Value Meta_Data::construct_hnsw_descriptor() { + Json::Value tuple; + std::shared_ptr test_aclient; + std::string name = "hnsw_test_2060"; + int dim = 100; + tuple.append(construct_hnsw_Set(name, dim)); + test_aclient.reset(new VDMS::VDMSClient(get_server(), get_port())); + VDMS::Response response = test_aclient->query(_fastwriter.write(tuple)); + Json::Value result; + _reader.parse(response.json.c_str(), result); + Json::Value AddDesc; + Json::Value Desc; + + Desc["set"] = "hnsw_test_2060"; + Desc["label"] = "Person"; + Desc["_ref"] = 1; + Desc["properties"]["id"] = 123; + Desc["properties"]["name"] = "Jane Doe"; + AddDesc["AddDescriptor"] = Desc; + tuple.append(AddDesc); + return tuple; +} + Json::Value Meta_Data::construct_descriptor() { Json::Value descriptor_set; Json::Value set_query; diff --git a/tests/unit_tests/meta_data_helper.h b/tests/unit_tests/meta_data_helper.h index bb9369d7..a3e6b825 100644 --- a/tests/unit_tests/meta_data_helper.h +++ b/tests/unit_tests/meta_data_helper.h @@ -55,6 +55,8 @@ class Meta_Data { Json::Value construct_flinng_descriptor(); Json::Value construct_find_flinng_descriptor(); Json::Value construct_Flinng_Set(std::string &, int &); + Json::Value construct_hnsw_descriptor(); + Json::Value construct_hnsw_Set(std::string &, int &); std::string get_server() { return _server_name; } int get_port() { return _port; } }; diff --git a/utils/src/api_schema/api_schema.json b/utils/src/api_schema/api_schema.json index 5b337e78..31fa384f 100644 --- a/utils/src/api_schema/api_schema.json +++ b/utils/src/api_schema/api_schema.json @@ -130,7 +130,7 @@ "engineFormatString": { "type": "string", - "enum": ["FaissFlat", "FaissIVFFlat", "TileDBDense", "TileDBSparse", "Flinng"] + "enum": ["FaissFlat", "FaissHNSWFlat", "FaissIVFFlat", "TileDBDense", "TileDBSparse", "Flinng"] }, "vidCodecString": {