{"record":{"id":"a37954d403b5ac8d","repo":"apache/cassandra","slug":"similarity-function-s-was-not-recognized-for-inde","errorCode":null,"errorMessage":"Similarity function %s was not recognized for index %s. Valid values are: %s","messagePattern":"Similarity function (.+?) was not recognized for index (.+?)\\. Valid values are: (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/index/sai/disk/v1/IndexWriterConfig.java","lineNumber":163,"sourceCode":"                }\n                catch (NumberFormatException e)\n                {\n                    throw new InvalidRequestException(String.format(\"Construction beam width %s is not a valid integer for index %s\",\n                                                                    options.get(CONSTRUCTION_BEAM_WIDTH), indexName));\n                }\n                if (queueSize <= 0 || queueSize > MAXIMUM_CONSTRUCTION_BEAM_WIDTH)\n                    throw new InvalidRequestException(String.format(\"Construction beam width for index %s cannot be <= 0 or > %s, was %s\", indexName, MAXIMUM_CONSTRUCTION_BEAM_WIDTH, queueSize));\n            }\n            if (options.containsKey(SIMILARITY_FUNCTION))\n            {\n                String option = toUpperCaseLocalized(options.get(SIMILARITY_FUNCTION));\n                try\n                {\n                    similarityFunction = VectorSimilarityFunction.valueOf(option);\n                }\n                catch (IllegalArgumentException e)\n                {\n                    throw new InvalidRequestException(String.format(\"Similarity function %s was not recognized for index %s. Valid values are: %s\",\n                                                                    option, indexName, validSimilarityFunctions));\n                }\n            }\n            if (options.containsKey(OPTIMIZE_FOR))\n            {\n                String option = toUpperCaseLocalized(options.get(OPTIMIZE_FOR));\n                try\n                {\n                    optimizeFor = OptimizeFor.valueOf(option);\n                }\n                catch (IllegalArgumentException e)\n                {\n                    throw new InvalidRequestException(String.format(\"optimize_for '%s' was not recognized for index %s. Valid values are: %s\",\n                                                                    option, indexName, validOptimizeFor));\n                }\n            }\n        }\n        return new IndexWriterConfig(maximumNodeConnections, queueSize, similarityFunction, optimizeFor);","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/index/sai/disk/v1/IndexWriterConfig.java#L145-L181","documentation":"Thrown by IndexWriterConfig.fromOptions when the 'similarity_function' option value does not match any org.apache.lucene.util.VectorSimilarityFunction enum constant (comparison is on the upper-cased value). Only the Lucene-supported functions (e.g. EUCLIDEAN, COSINE, DOT_PRODUCT) are accepted.","triggerScenarios":"CREATE CUSTOM INDEX on a vector column WITH OPTIONS = {'similarity_function': 'cosine_similarity'} or 'L2' — any name that is not a VectorSimilarityFunction enum constant when upper-cased.","commonSituations":"Using similarity names from other systems (pgvector 'cosine', 'l2', 'inner_product'); lowercase handled fine, but abbreviations are not; typo like 'EUCLIDEAN_DISTANCE'.","solutions":["Use one of the valid values printed in the message (validSimilarityFunctions): EUCLIDEAN, COSINE, DOT_PRODUCT","Map your domain term to the Lucene name (e.g. L2 -> EUCLIDEAN, inner_product -> DOT_PRODUCT)","Omit the option to use the default similarity function","Validate against VectorSimilarityFunction.valueOf(upper(value)) before issuing the DDL"],"exampleFix":"// before\nWITH OPTIONS = {'similarity_function': 'L2'}\n// after\nWITH OPTIONS = {'similarity_function': 'EUCLIDEAN'}","handlingStrategy":"validation","validationCode":"String v = opts.get(\"similarity_function\");\nif (v != null)\n    org.apache.lucene.util.VectorSimilarityFunction.valueOf(v.trim().toUpperCase(java.util.Locale.ROOT)); // throws IllegalArgumentException if invalid","typeGuard":null,"tryCatchPattern":"try { session.execute(createIndexCql); }\ncatch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"was not recognized\") && e.getMessage().contains(\"Similarity function\")) { /* map to a valid enum name and retry */ }\n    else throw e;\n}","preventionTips":["Only use enum names accepted by VectorSimilarityFunction (EUCLIDEAN, COSINE, DOT_PRODUCT)","Map cross-database similarity names to Lucene names in your tooling","Parse the 'Valid values are:' list from the error message to discover accepted names"],"tags":["cassandra","sai","vector-index","enum","index-options"],"backgroundTag":"invalid-enum-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}