{"record":{"id":"d813d828d7a14ab9","repo":"apache/cassandra","slug":"invalid-vector-literal-for-s-of-type-s","errorCode":null,"errorMessage":"Invalid vector literal for %s of type %s","messagePattern":"Invalid vector literal for (.+?) of type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/terms/Vectors.java","lineNumber":121,"sourceCode":"        @Override\n        public TestResult testAssignment(String keyspace, ColumnSpecification receiver)\n        {\n            if (!receiver.type.isVector())\n                return AssignmentTestable.TestResult.NOT_ASSIGNABLE;\n            VectorType<?> type = (VectorType<?>) receiver.type;\n            if (elements.size() != type.dimension)\n                return AssignmentTestable.TestResult.NOT_ASSIGNABLE;\n            ColumnSpecification valueSpec = valueSpecOf(receiver);\n            return AssignmentTestable.TestResult.testAll(receiver.ksName, valueSpec, elements);\n        }\n\n        @Override\n        public Term prepare(String keyspace, ColumnSpecification receiver) throws InvalidRequestException\n        {\n            AbstractType<?> unwrapped = receiver.type.unwrap();\n\n            if (!unwrapped.isVector())\n                throw new InvalidRequestException(String.format(\"Invalid vector literal for %s of type %s\", receiver.name, receiver.type.asCQL3Type()));\n            VectorType<?> type = (VectorType<?>) unwrapped;\n            if (elements.size() != type.dimension)\n                throw new InvalidRequestException(String.format(\"Invalid vector literal for %s of type %s; expected %d elements, but given %d\", receiver.name, receiver.type.asCQL3Type(), type.dimension, elements.size()));\n\n            ColumnSpecification valueSpec = valueSpecOf(receiver);\n            List<Term> values = new ArrayList<>(elements.size());\n            boolean allTerminal = true;\n            for (Term.Raw rt : elements)\n            {\n                if (!rt.testAssignment(keyspace, valueSpec).isAssignable())\n                    throw new InvalidRequestException(String.format(\"Invalid vector literal for %s: value %s is not of type %s\", receiver.name, rt, valueSpec.type.asCQL3Type()));\n\n                Term t = rt.prepare(keyspace, valueSpec);\n\n                if (t instanceof Term.NonTerminal)\n                    allTerminal = false;\n\n                values.add(t);","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/terms/Vectors.java#L103-L139","documentation":"Cassandra throws this InvalidRequestException in Vectors.Literal.prepare when a vector literal `[a, b, c]` is assigned to a receiver whose type is not a vector type. Vector literals are only valid for columns declared as vector<type, n>.","triggerScenarios":"Using `[1,2,3]` for a list column, a set, or any non-vector receiver; schema changed the column from vector to list; misconfigured SAI/vector workload targeting the wrong column.","commonSituations":"Vector-search migrations where columns were expected to be vector<t, dim> but are lists; copy-paste between tables where one column is vector and the other is list.","solutions":["Confirm the column type is vector<K, N>; alter the schema or the statement.","Use a list literal `json`-style or bind parameters for non-vector collections.","If migrating, recreate the column as vector with the intended dimension."],"exampleFix":"// before\nCREATE TABLE t(id int PRIMARY KEY, embedding list<float>);\nINSERT INTO t (id, embedding) VALUES (1, [0.1, 0.2]); // fails: not a vector\n// after\nALTER TABLE t ADD embedding vector<float, 2>;\nINSERT INTO t (id, embedding) VALUES (1, [0.1, 0.2]);","handlingStrategy":"validation","validationCode":"if (!column.getType().unwrap().isVector())\n    throw new IllegalArgumentException(\"Column \" + column.getName() + \" is not vector type; use proper literal\");","typeGuard":"boolean isVectorColumn(ColumnSpecification c) { return c.type.unwrap().isVector(); }","tryCatchPattern":"try { session.execute(stmt); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"Invalid vector literal\")) fixLiteralSyntax(); else throw e; }","preventionTips":["Verify column is vector<t,N> before using [..] vector literal syntax","Keep vector workloads' schema and code in sync","Avoid copy-pasting literals between tables with differing column types"],"tags":["cql","vector","type-mismatch"],"backgroundTag":"type-mismatch","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"}