Fix vector query format validation error messages (#2063)

* fix: correct vector query format validation error message

- Fix parser to properly detect missing colon in vector query format
- Remove redundant condition check for colon validation
- Ensure format `fieldname:([values])` is strictly enforced
- Update test cases to match expected error messages

* fix(vector-search): make missing colon error more descriptive

* chore: update comments to reflect proper vector query formatting
This commit is contained in:
Fanis 2024-11-13 11:41:35 +02:00 committed by GitHub
parent a05b046d1d
commit 5705717987
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 8 deletions

View File

@ -8,18 +8,17 @@ Option<bool> VectorQueryOps::parse_vector_query_str(const std::string& vector_qu
const Collection* coll,
const bool allow_empty_query) {
// FORMAT:
// field_name([0.34, 0.66, 0.12, 0.68], exact: false, k: 10)
// field_name:([0.34, 0.66, 0.12, 0.68], k: 10)
size_t i = 0;
while(i < vector_query_str.size()) {
if(vector_query_str[i] == '(' || vector_query_str[i] == '[') {
// If we hit a bracket before a colon, it's a missing colon error
return Option<bool>(400, "Malformed vector query string: `:` is missing after the vector field name.");
}
if(vector_query_str[i] != ':') {
vector_query.field_name += vector_query_str[i];
i++;
} else {
if(vector_query_str[i] != ':') {
// missing ":"
return Option<bool>(400, "Malformed vector query string: `:` is missing.");
}
// field name is done
i++;
@ -265,5 +264,6 @@ Option<bool> VectorQueryOps::parse_vector_query_str(const std::string& vector_qu
}
}
return Option<bool>(400, "Malformed vector query string.");
// We hit the end of the string without finding a colon
return Option<bool>(400, "Malformed vector query string: `:` is missing.");
}

View File

@ -72,5 +72,10 @@ TEST_F(VectorQueryOpsTest, ParseVectorQueryString) {
vector_query._reset();
parsed = VectorQueryOps::parse_vector_query_str("vec([0.34, 0.66, 0.12, 0.68])", vector_query, false, nullptr, false);
ASSERT_FALSE(parsed.ok());
ASSERT_EQ("Malformed vector query string.", parsed.error());
ASSERT_EQ("Malformed vector query string: `:` is missing after the vector field name.", parsed.error());
vector_query._reset();
parsed = VectorQueryOps::parse_vector_query_str("vec([0.34, 0.66, 0.12, 0.68], k: 10)", vector_query, false, nullptr, false);
ASSERT_FALSE(parsed.ok());
ASSERT_EQ("Malformed vector query string: `:` is missing after the vector field name.", parsed.error());
}