From b29e6870fac6b5b993e4e9236ecde42508495dc2 Mon Sep 17 00:00:00 2001 From: Dawid Pawlik Date: Thu, 24 Jul 2025 13:28:19 +0200 Subject: [PATCH] vector_index: make parameter names case insensitive The custom index class name 'vector_index' and it's similarity function options should be case insensitive. Before the patch the similarity functions had to be written in SCREAMING_SNAKE_CASE which was not commonly and intuitively used. Furthermore the Cassandra translated tests used the options written in snake_case and as we wanted to translate them exactly, we had to be able to use lower case option. --- index/secondary_index_manager.cc | 4 +++- index/vector_index.cc | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/index/secondary_index_manager.cc b/index/secondary_index_manager.cc index b21b7ee0a1..e57c9096ff 100644 --- a/index/secondary_index_manager.cc +++ b/index/secondary_index_manager.cc @@ -362,12 +362,14 @@ std::optional secondary_index_manager::custom_index_class(const schema& // This function returns a factory, as the custom index class should be lightweight, preferably not holding any state. // We prefer this over a static custom index class instance, as it allows us to avoid any issues with thread safety. std::optional()>> secondary_index_manager::get_custom_class_factory(const sstring& class_name) { + sstring lower_class_name = class_name; + std::transform(lower_class_name.begin(), lower_class_name.end(), lower_class_name.begin(), ::tolower); const static std::unordered_map()>> classes = { {"vector_index", vector_index_factory}, }; - if (auto class_it = classes.find(class_name); class_it != classes.end()) { + if (auto class_it = classes.find(lower_class_name); class_it != classes.end()) { return class_it->second; } else { return std::nullopt; diff --git a/index/vector_index.cc b/index/vector_index.cc index d5ed937cab..22bf63da1f 100644 --- a/index/vector_index.cc +++ b/index/vector_index.cc @@ -38,7 +38,9 @@ static void validate_unsigned_option(const sstring& value) { } static void validate_similarity_function(const sstring& value) { - if (value != "COSINE" && value != "EUCLIDEAN" && value != "DOT_PRODUCT") { + sstring similarity_function = value; + std::transform(similarity_function.begin(), similarity_function.end(), similarity_function.begin(), ::tolower); + if (similarity_function != "cosine" && similarity_function != "euclidean" && similarity_function != "dot_product") { throw exceptions::invalid_request_exception(format("Unsupported similarity function: {}", value)); } }