mirror of
https://github.com/typesense/typesense.git
synced 2025-05-15 19:06:48 +08:00
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:
parent
a05b046d1d
commit
5705717987
@ -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.");
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user