{"record":{"id":"7c5065a583f03302","repo":"apache/cassandra","slug":"unable-to-create-a-vector-selector-of-type-s-from","errorCode":null,"errorMessage":"Unable to create a vector selector of type %s from %d elements","messagePattern":"Unable to create a vector selector of type (.+?) from (.+?) elements","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/selection/Selectable.java","lineNumber":944,"sourceCode":"\n        @Override\n        public Factory newSelectorFactory(TableMetadata cfm,\n                                          AbstractType<?> expectedType,\n                                          List<ColumnMetadata> defs,\n                                          VariableSpecifications boundNames)\n        {\n            AbstractType<?> type = getExactTypeIfKnown(cfm.keyspace);\n            if (type == null)\n            {\n                type = expectedType;\n                if (type == null)\n                    throw invalidRequest(\"Cannot infer type for term %s in selection clause (try using a cast to force a type)\",\n                                         this);\n            }\n\n            VectorType<?> vectorType = (VectorType<?>) type;\n            if (vectorType.dimension != selectables.size())\n                throw invalidRequest(\"Unable to create a vector selector of type %s from %d elements\", vectorType.asCQL3Type(), selectables.size());\n\n            List<AbstractType<?>> expectedTypes = new ArrayList<>(selectables.size());\n            for (int i = 0, m = selectables.size(); i < m; i++)\n                expectedTypes.add(vectorType.getElementsType());\n\n            SelectorFactories factories = createFactoriesAndCollectColumnDefinitions(selectables,\n                                                                                     expectedTypes,\n                                                                                     cfm,\n                                                                                     defs,\n                                                                                     boundNames);\n            return VectorSelector.newFactory(type, factories);\n        }\n\n        @Override\n        public AbstractType<?> getExactTypeIfKnown(String keyspace)\n        {\n            return Vectors.getExactVectorTypeIfKnown(selectables, p -> p.getExactTypeIfKnown(keyspace));\n        }","sourceCodeStart":926,"sourceCodeEnd":962,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/selection/Selectable.java#L926-L962","documentation":"Cassandra throws this when a vector literal in a SELECT clause has a different number of elements than the dimension of the vector type it must match. Vector types in Cassandra are fixed-dimension; a term like [1,2,3] cannot be used where a vector of dimension 4 is expected. The request is rejected at statement-prepare time as an invalid request.","triggerScenarios":"SELECTing a vector term whose element count differs from the column/target vector type's declared dimension, e.g. `SELECT [1,2] FROM t` where the inferred vector type has dimension 3; also when selecting a literal intended for an ANN/similarity usage where element count mismatches the schema vector column.","commonSituations":"Schema changed (vector dimension resized) but queries not updated; hand-written literals with wrong arity; copy-pasted examples from docs with different dimensions; driver/app code generating vector literals from variable-length embeddings.","solutions":["Count the elements in the vector literal and make it exactly equal to the vector type's dimension (check with DESCRIBE TYPE / schema).","Re-generate embeddings with the model/dimension matching the column's declared vector dimension.","If the intent is a non-vector collection, use list/set/map syntax or cast the term to the correct collection type instead.","Update stored queries/prepared statements after any vector dimension change."],"exampleFix":"// before\nSELECT [0.1, 0.2] FROM vectors; -- column embedding is vector<float, 3>\n// after\nSELECT [0.1, 0.2, 0.3] FROM vectors;","handlingStrategy":"validation","validationCode":"int dim = vectorType.getDimension(); if (elements.size() != dim) throw new IllegalArgumentException(\"expected vector dimension \" + dim + \", got \" + elements.size());","typeGuard":null,"tryCatchPattern":"try { session.execute(select); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"vector selector\")) { /* fix literal arity or re-embed */ } else throw e; }","preventionTips":["Derive vector literals from the column's declared dimension, not from raw model output.","Centralize embedding generation so dimension changes propagate to queries.","Add a unit check comparing embedding length to schema dimension before executing queries."],"tags":["cql","vector","type-mismatch","invalid-request"],"backgroundTag":"invalid-argument-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}