{"record":{"id":"445576943485f957","repo":"apache/cassandra","slug":"optimize-for-s-was-not-recognized-for-index-s","errorCode":null,"errorMessage":"optimize_for '%s' was not recognized for index %s. Valid values are: %s","messagePattern":"optimize_for '(.+?)' 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":176,"sourceCode":"                {\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);\n    }\n\n    public static IndexWriterConfig emptyConfig()\n    {\n        return EMPTY_CONFIG;\n    }\n\n    @Override\n    public String toString()\n    {\n        return String.format(\"IndexWriterConfig{%s=%d, %s=%d, %s=%s, %s=%s}\",\n                             MAXIMUM_NODE_CONNECTIONS, maximumNodeConnections,\n                             CONSTRUCTION_BEAM_WIDTH, constructionBeamWidth,","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/index/sai/disk/v1/IndexWriterConfig.java#L158-L194","documentation":"SAI (Storage-Attached Index) per-index option 'optimize_for' was given a value that is not one of the recognized enum constants of OptimizeFor. fromOptions parses CREATE CUSTOM INDEX OPTIONS and converts the value with OptimizeFor.valueOf, which throws IllegalArgumentException; it is rethrown as an InvalidRequestException listing the valid values. This protects against silently misconfigured index build options.","triggerScenarios":"CREATE CUSTOM INDEX ... WITH OPTIONS = {'optimize_for': 'xyz'} where 'xyz' is not an OptimizeFor enum constant (valid values are e.g. BALANCED / LATENCY / RECALL, case-sensitive).","commonSituations":"Typo in the option value (e.g. 'latency' lowercase instead of 'LATENCY'), copying an option from docs for an older Cassandra version, or tools generating DDL with stale option names.","solutions":["Use one of the valid values exactly as listed in the error message (case-sensitive enum constant).","Check the OptimizeFor enum in src/java/org/apache/cassandra/index/sai/disk/v1/IndexWriterConfig.java for the constants your version supports.","Remove the optimize_for option entirely to accept the default."],"exampleFix":"// before\nCREATE CUSTOM INDEX ON t (c) USING 'StorageAttachedIndex' WITH OPTIONS = {'optimize_for': 'latency'};\n// after\nCREATE CUSTOM INDEX ON t (c) USING 'StorageAttachedIndex' WITH OPTIONS = {'optimize_for': 'LATENCY'};","handlingStrategy":"validation","validationCode":"const VALID_OPTIMIZE_FOR = ['BALANCED','LATENCY','RECALL']; // confirm against your version\nif (options.optimize_for && !VALID_OPTIMIZE_FOR.includes(options.optimize_for)) {\n  throw new Error(`optimize_for '${options.optimize_for}' invalid; valid: ${VALID_OPTIMIZE_FOR.join(', ')}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy option values from the docs of the exact Cassandra version in use.","Keep enum values uppercase and verify case sensitivity.","Test CREATE INDEX DDL in a dev cluster before production."],"tags":["cassandra","sai","invalid-option-value","ddl"],"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"}