{"record":{"id":"3090dd07ac14fbe8","repo":"apache/cassandra","slug":"function-name-doesn-t-support-all-zero-vectors","errorCode":null,"errorMessage":"Function ${name} doesn't support all-zero vectors.","messagePattern":"Function (.+?) doesn't support all-zero vectors\\.","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/VectorFcts.java","lineNumber":91,"sourceCode":"            {\n                return new FunctionArguments(context,\n                                             (v, b) -> type.composeAsFloat(b),\n                                             (v, b) -> type.composeAsFloat(b));\n            }\n\n            @Override\n            public ByteBuffer execute(Arguments arguments) throws InvalidRequestException\n            {\n                if (arguments.containsNulls())\n                    return null;\n\n                float[] v1 = arguments.get(0);\n                float[] v2 = arguments.get(1);\n\n                if (!supportsZeroVectors)\n                {\n                    if (isAllZero(v1) || isAllZero(v2))\n                        throw new InvalidRequestException(\"Function \" + name + \" doesn't support all-zero vectors.\");\n                }\n\n                return FloatType.instance.decompose(f.compare(v1, v2));\n            }\n\n            private boolean isAllZero(float[] v)\n            {\n                for (float f : v)\n                    if (f != 0)\n                        return false;\n                return true;\n            }\n        };\n    }\n}\n","sourceCodeStart":73,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/VectorFcts.java#L73-L107","documentation":"The similarity function implementation executes the comparison after checking each float[] argument for all-zero content. Because an all-zero vector makes cosine similarity mathematically undefined (division by zero), when supportsZeroVectors is false the execute method rejects such inputs with this InvalidRequestException.","triggerScenarios":"Calling similarity_cosine (which disallows zero vectors) with an argument whose every float is 0.0, either as a literal vector[0.0, 0.0, ...] or read from a column holding a zero vector.","commonSituations":"Rows where a default/uninitialized embedding of all zeros was inserted; failed embedding generation producing empty vectors; users testing similarity functions with zero placeholders.","solutions":["Ensure vectors are populated with real (non-all-zero) embeddings before comparing","Filter out rows with zero vectors in application code before issuing the query","Use similarity_dot_product or similarity_euclidean if a zero-vector operand is legitimate for your use case"],"exampleFix":"// before\nSELECT similarity_cosine(embedding, vector[0.0, 0.0, 0.0]) FROM items; // all-zero query vector\n// after\nSELECT similarity_cosine(embedding, vector[0.12, -0.4, 0.9]) FROM items;","handlingStrategy":"validation","validationCode":"static boolean isAllZero(float[] v) {\n    for (float f : v) if (f != 0.0f) return false;\n    return true;\n}\nif (isAllZero(queryVector)) throw new IllegalArgumentException(\"zero vector not allowed for similarity_cosine\");","typeGuard":null,"tryCatchPattern":"try {\n    ResultSet rs = session.execute(similarityQuery);\n} catch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"doesn't support all-zero vectors\")) {\n        // fall back to dot product or skip the row\n    }\n}","preventionTips":["Reject all-zero embeddings at ingestion time with an application-side check","Choose similarity_euclidean or similarity_dot_product when zero vectors are legitimate","Regenerate embeddings that failed and defaulted to zero arrays"],"tags":["cassandra","vector-search","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-14T16:17:12.679Z"}