{"record":{"id":"686fa7521bc3ff38","repo":"apache/cassandra","slug":"function-s-requires-a-s-vector-argument-but-fou","errorCode":null,"errorMessage":"Function %s requires a %s vector argument, but found argument %s of type %s","messagePattern":"Function (.+?) requires a (.+?) vector argument, but found argument (.+?) of type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/FunctionParameter.java","lineNumber":392,"sourceCode":"            }\n\n            @Override\n            public void validateType(FunctionName name, AssignmentTestable arg, AbstractType<?> argType)\n            {\n                if (argType.isVector())\n                {\n                    VectorType<?> vectorType = (VectorType<?>) argType;\n                    if (vectorType.elementType.asCQL3Type() == type)\n                        return;\n                }\n                else if (argType instanceof ListType) // if it's terminal it will be a list\n                {\n                    ListType<?> listType = (ListType<?>) argType;\n                    if (listType.getElementsType().testAssignment(type.getType()) == NOT_ASSIGNABLE)\n                        return;\n                }\n\n                throw new InvalidRequestException(format(\"Function %s requires a %s vector argument, \" +\n                                                         \"but found argument %s of type %s\",\n                                                         name, type, arg, argType.asCQL3Type()));\n            }\n\n            @Override\n            public String toString()\n            {\n                return format(\"vector<%s, n>\", type);\n            }\n        };\n    }\n}\n","sourceCodeStart":374,"sourceCodeEnd":405,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/FunctionParameter.java#L374-L405","documentation":"Functions accepting vector arguments validate that the argument is a ListType whose element type is assignable to the expected vector element type. validateType() throws this InvalidRequestException when the argument is not such a list (wrong container type or wrong element type). It means a vector (list) argument of the required element type was expected.","triggerScenarios":"Calling a vector-parameter function (e.g. vector similarity/format functions) with a non-list type, or a list whose element type does not match the expected float/vector element type (testAssignment == NOT_ASSIGNABLE).","commonSituations":"Passing a vector<string> where vector<float> is required; passing a single scalar instead of a list; schema drift where the column's element type changed.","solutions":["Pass a list literal with the correct element type, e.g. [1.0, 2.0, 3.0] for vector<float>.","Verify the column/argument type matches the expected vector element type; recreate/ALTER if it drifted.","Check the function's signature (FunctionFactory description) for the exact expected vector type.","Cast via a UDF if a conversion is genuinely needed."],"exampleFix":"// before\nSELECT similarity(vec, ['a','b']) FROM t; -- vector<text> passed\n// after\nSELECT similarity(vec, [1.0, 2.0]) FROM t; -- vector<float> passed","handlingStrategy":"type-guard","validationCode":"if (!(t instanceof ListType)) throw new IllegalArgumentException(\"vector arg must be a list\");\nListType<?> lt = (ListType<?>) t;\nif (lt.getElementsType().testAssignment(expectedElementType) == AssignmentTestable.Result.NOT_ASSIGNABLE)\n    throw new IllegalArgumentException(\"element type \" + lt.getElementsType().asCQL3Type() + \" not assignable\");","typeGuard":"boolean isVectorArg(AbstractType<?> t, AbstractType<?> elem) { return t instanceof ListType && ((ListType<?>) t).getElementsType().testAssignment(elem) != AssignmentTestable.Result.NOT_ASSIGNABLE; }","tryCatchPattern":"try { session.execute(q); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"vector argument\")) { /* supply list with correct element type */ } else throw e; }","preventionTips":["Match the vector element type (e.g. vector<float, n>) exactly","Pass list literals with correctly typed elements","Verify column types after schema migrations"],"tags":["cql","type-mismatch","vector"],"backgroundTag":"type-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}