Skip to content

Commit

Permalink
tweaks, returning error for knn with _ref
Browse files Browse the repository at this point in the history
  • Loading branch information
ifadams committed Sep 25, 2024
1 parent 612d69c commit c59eab9
Showing 1 changed file with 66 additions and 9 deletions.
75 changes: 66 additions & 9 deletions src/DescriptorsCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ int AddDescriptorSet::construct_protobuf(PMGDQuery &query,
}

//create a new index based on the descriptor set name
printf("HERE\n\n");
try{
std::string idx_prop = VDMS_DESC_ID_PROP + std::string("_") + set_name;
query.AddIntNodeIndexImmediate(VDMS_DESC_TAG, (char *)idx_prop.c_str());
Expand Down Expand Up @@ -892,10 +891,18 @@ int FindDescriptor::construct_protobuf(PMGDQuery &query,
}
// Case (3), Just want the descriptor by value, we only need the set
else {
Json::Value link_null; // null

Json::Value link_null; // null
if (cmd.isMember("_ref")) {
cp_result["status"] = RSCommand::Error;
cp_result["info"] = "_ref is not supported for KNN search";
return -1;
}
const int k_neighbors = get_value<int>(cmd, "k_neighbors", 0);

//This set query is a little weird and may be optimized away in the future
// as we no longer explicitly need the set links, however subsequent logic
//uses this to look up the path (again) in construct response
int ref_set = query.get_available_reference();

// Query for the set and detect if exist during transaction.
Expand Down Expand Up @@ -950,9 +957,35 @@ int FindDescriptor::construct_protobuf(PMGDQuery &query,

Json::Value node_constraints = constraints;
cp_result["ids_array"] = ids_array;
//TODO QUERY REFACTOR MODS-Still queries for link_to_set
for (int i = 0; i < ids.size(); ++i){
printf("IDS!\n");
Json::Value k_node_constraints;

// Create a vector with a string and an integer
std::vector<Json::Value> values;
values.push_back("==");
values.push_back(ids[i]);

// Add the vector to the JSON object with a key
Json::Value jsonArray(Json::arrayValue);
for (const auto& value : values) {
jsonArray.append(value);
}
k_node_constraints[desc_id_prop_name] = jsonArray;

results["limit"] = 1;
//TODO UPDATE TO IGNORE LINK TO SET
//query.QueryNode(get_value<int>(cmd, "_ref", -1), VDMS_DESC_TAG,
// link_to_set, k_node_constraints, results, false);

query.QueryNode(get_value<int>(cmd, "_ref", -1), VDMS_DESC_TAG,
Json::nullValue, k_node_constraints, results, false);
}
//TODO END MODS

query.QueryNode(get_value<int>(cmd, "_ref", -1), VDMS_DESC_TAG,
link_to_set, node_constraints, results, false);
/*query.QueryNode(get_value<int>(cmd, "_ref", -1), VDMS_DESC_TAG,
link_to_set, node_constraints, results, false);*/

} catch (VCL::Exception e) {
print_exception(e);
Expand Down Expand Up @@ -1033,7 +1066,7 @@ Json::Value FindDescriptor::construct_responses(
Json::Value ret;

bool flag_error = false;

const std::string set_name = cmd["set"].asString();
std::string desc_id_prop_name = VDMS_DESC_ID_PROP + std::string("_") + set_name;

Expand Down Expand Up @@ -1127,8 +1160,8 @@ Json::Value FindDescriptor::construct_responses(
}
// Case (3)
else {

assert(json_responses.size() == 2);
//TODO POSSIBLE REMOVE
//assert(json_responses.size() == 2);

// Get Set info.
const Json::Value &set_response = json_responses[0];
Expand Down Expand Up @@ -1184,8 +1217,32 @@ Json::Value FindDescriptor::construct_responses(
IDDistancePair *pair = _cache_map[cache_obj_id];
ids = &(pair->first);
distances = &(pair->second);

findDesc = json_responses[1];
//TODO BEGIN MODS
Json::Value combined_tx_constraints;
Json::Value set_values;
Json::Value ent_values;
for (int i = 0; i < json_responses.size(); ++i){

// Create a vector with a string and an integer
if (i==0)
continue;
else{
Json::Value desc_data;
for (auto ent : json_responses[i]["entities"])
desc_data = ent;
ent_values.append(desc_data);
}
// Add the vector to the JSON object with a key
}
set_values["status"] = 0;
set_values["returned"] = json_responses.size() - 1;
set_values["entities"] = ent_values;
//combined_tx_constraints.append(set_values);

//std::cout<<"modified pmgd output"<<set_values<<std::endl;
findDesc = set_values;
// TODO END MODS
//findDesc = json_responses[1];

if (findDesc["status"] != 0 || !findDesc.isMember("entities")) {

Expand Down

0 comments on commit c59eab9

Please sign in to comment.