Skip to content

Commit

Permalink
Give a meaningful error when a bad vector field is given in vector qu…
Browse files Browse the repository at this point in the history
…ery during sorting.
  • Loading branch information
kishorenc committed Oct 11, 2024
1 parent c34fdda commit bda539d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/vector_query_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ Option<bool> VectorQueryOps::parse_vector_query_str(const std::string& vector_qu
auto search_schema = const_cast<Collection*>(coll)->get_schema();
auto vector_field_it = search_schema.find(vector_query.field_name);

if(vector_field_it == search_schema.end()) {
return Option<bool>(400, "Malformed vector query string: could not find a field named "
"`" + vector_query.field_name + "`.");
}

if(!StringUtils::is_float(param_kv[1])) {
return Option<bool>(400, "Malformed vector query string: "
"`distance_threshold` parameter must be a float.");
Expand Down
15 changes: 15 additions & 0 deletions test/collection_vector_search_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5009,6 +5009,21 @@ TEST_F(CollectionVectorTest, TestDistanceThresholdWithIP) {
ASSERT_EQ(18, res["hits"][4]["document"]["rank_score"].get<size_t>());
ASSERT_EQ(3.4028232635611926e+38, res["hits"][4]["vector_distance"].get<float>());

// with missing field name
req_params = {
{"collection", "products"},
{"q", "document"},
{"query_by", "name"},
{"sort_by", "_text_match:desc,"
"_vector_query(embeddingx:([0.11731103425347378, -0.6694758317235057, -0.6211945774857595, -0.27966758971688255, -0.4683744007950299],"
"distance_threshold:1)):asc,"
"rank_score:desc"},
{"exclude_fields", "embedding"}
};
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);

ASSERT_FALSE(search_op.ok());
ASSERT_EQ("Malformed vector query string: could not find a field named `embeddingx`.", search_op.error());

//inner product distances should work when distance_threshold is not given
req_params = {
Expand Down

0 comments on commit bda539d

Please sign in to comment.