Skip to content

Commit

Permalink
Update enum in api_schema.json and add client test using hnsw
Browse files Browse the repository at this point in the history
  • Loading branch information
cwlacewe committed Oct 14, 2024
1 parent fe0dfac commit fcc9178
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 1 deletion.
28 changes: 28 additions & 0 deletions tests/unit_tests/client_descriptors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ TEST(CLIENT_CPP, add_flinng_descriptor) {

EXPECT_EQ(status1, 0);
}
TEST(CLIENT_CPP, add_hnsw_descriptor) {
std::vector<float> fv_values;
srand((unsigned)time(NULL));
for (int i = 0; i < 100; i++)
fv_values.push_back((float)rand() / RAND_MAX);

std::vector<std::string *> 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) {

Expand Down
143 changes: 143 additions & 0 deletions tests/unit_tests/meta_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<VDMS::VDMSClient> 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;
Expand Down Expand Up @@ -330,6 +367,112 @@ Json::Value Meta_Data::construct_find_video_with_dynamic_metadata() {
return tuple;
}

Json::Value Meta_Data::construct_find_video_withop(Json::Value operations) {
Json::Value tuple;

Json::Value results;
results["blob"] = true;
results["limit"] = 1;

Json::Value video;
video["results"] = results;
video["operations"].append(operations);

Json::Value find_video;
find_video["FindVideo"] = video;

tuple.append(find_video);
return tuple;
}

Json::Value Meta_Data::construct_find_image_with_dynamic_metadata() {
Json::Value tuple;

Json::Value cons;
cons["category"][0] = "==";
cons["category"][1] = "image_dynamic_metadata";

Json::Value metacons;
metacons["objectID"][0] = "==";
metacons["objectID"][1] = "face";

Json::Value results;
results["blob"] = true;

Json::Value link_image;
link_image["ref"] = 1;

Json::Value image;
image["constraints"] = cons;
image["_ref"] = 1;

Json::Value find_image;
find_image["FindImage"] = image;

tuple.append(find_image);

Json::Value bimage;
bimage["metaconstraints"] = metacons;
bimage["link"] = link_image;

Json::Value find_image_bbox;
find_image_bbox["FindImage"] = bimage;

tuple.append(find_image_bbox);

return tuple;
}

Json::Value Meta_Data::construct_find_video_with_dynamic_metadata() {
Json::Value tuple;

Json::Value cons;
cons["category"][0] = "==";
cons["category"][1] = "dynamic_metadata";

Json::Value metacons;
metacons["objectID"][0] = "==";
metacons["objectID"][1] = "face";

Json::Value results;
results["blob"] = true;

Json::Value link_video;
link_video["ref"] = 1;
Json::Value link_frame;
link_frame["ref"] = 2;

Json::Value video;
video["constraints"] = cons;
video["_ref"] = 1;

Json::Value find_video;
find_video["FindVideo"] = video;

tuple.append(find_video);

Json::Value fvideo;
fvideo["frameconstraints"] = false;
fvideo["_ref"] = 2;
fvideo["link"] = link_video;

Json::Value find_video_frame;
find_video_frame["FindVideo"] = fvideo;

tuple.append(find_video_frame);

Json::Value bvideo;
bvideo["metaconstraints"] = metacons;
bvideo["link"] = link_frame;

Json::Value find_video_bbox;
find_video_bbox["FindVideo"] = bvideo;

tuple.append(find_video_bbox);

return tuple;
}

std::string *Meta_Data::read_blob(std::string &fname) {
std::string video;
std::ifstream video_file(fname,
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_tests/meta_data_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};
2 changes: 1 addition & 1 deletion utils/src/api_schema/api_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@

"engineFormatString": {
"type": "string",
"enum": ["FaissFlat", "FaissIVFFlat", "TileDBDense", "TileDBSparse", "Flinng"]
"enum": ["FaissFlat", "FaissHNSWFlat", "FaissIVFFlat", "TileDBDense", "TileDBSparse", "Flinng"]
},

"vidCodecString": {
Expand Down

0 comments on commit fcc9178

Please sign in to comment.