apache/cassandra · error · InvalidRequestException

All arguments must have the same vector dimensions

Error message

All arguments must have the same vector dimensions

What it means

Cassandra's vector similarity functions (similarity_cosine, similarity_dot_product, similarity_euclidean) require all arguments to be vectors of identical dimensions. In doGetOrCreateFunction, the first argument's dimension is captured and every argument type is checked against it; any mismatch throws this InvalidRequestException at function-resolution time.

Source

Thrown at src/java/org/apache/cassandra/cql3/functions/VectorFcts.java:58

    }

    private static FunctionFactory createSimilarityFunctionFactory(String name,
                                                                   VectorSimilarityFunction vectorSimilarityFunction,
                                                                   boolean supportsZeroVectors)
    {
        return new FunctionFactory(name,
                                   FunctionParameter.sameAs(1, false, FunctionParameter.vector(CQL3Type.Native.FLOAT)),
                                   FunctionParameter.sameAs(0, false, FunctionParameter.vector(CQL3Type.Native.FLOAT)))
        {
            @Override
            @SuppressWarnings("unchecked")
            protected NativeFunction doGetOrCreateFunction(List<AbstractType<?>> argTypes, AbstractType<?> receiverType)
            {
                // check that all arguments have the same vector dimensions
                VectorType<Float> firstArgType = (VectorType<Float>) argTypes.get(0);
                int dimensions = firstArgType.dimension;
                if (!argTypes.stream().allMatch(t -> ((VectorType<?>) t).dimension == dimensions))
                    throw new InvalidRequestException("All arguments must have the same vector dimensions");
                return createSimilarityFunction(name.name, firstArgType, vectorSimilarityFunction, supportsZeroVectors);
            }
        };
    }

    private static NativeFunction createSimilarityFunction(String name,
                                                           VectorType<Float> type,
                                                           VectorSimilarityFunction f,
                                                           boolean supportsZeroVectors)
    {
        return new NativeScalarFunction(name, FloatType.instance, type, type)
        {
            @Override
            public Arguments newArguments(FunctionContext context)
            {
                return new FunctionArguments(context,
                                             (v, b) -> type.composeAsFloat(b),
                                             (v, b) -> type.composeAsFloat(b));

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Alter or recreate the involved columns/indexes so both vectors use the same dimension count
  2. Cast or rebuild the data (e.g. truncate/pad vectors) so all arguments share one dimension
  3. Verify the column definitions with DESCRIBE TABLE / system_schema to confirm dimensions before querying

Example fix

// before
SELECT similarity_cosine(embedding, vector[1.0, 2.0]) FROM items; -- embedding is vector<float,5>
// after
SELECT similarity_cosine(embedding, vector[1.0, 2.0, 0.0, 0.0, 0.0]) FROM items;
Defensive patterns

Strategy: validation

Validate before calling

boolean dimsMatch = argTypes.stream().allMatch(t -> ((VectorType<?>) t).dimension == ((VectorType<?>) argTypes.get(0)).dimension);
if (!dimsMatch) throw new IllegalArgumentException("similarity function args must have equal vector dimensions");

Type guard

boolean isCompatibleVectorPair(AbstractType<?> a, AbstractType<?> b) {
    return a instanceof VectorType && b instanceof VectorType
        && ((VectorType<?>) a).dimension == ((VectorType<?>) b).dimension;
}

Try / catch

try {
    session.execute(query);
} catch (InvalidRequestException e) {
    if (e.getMessage().contains("same vector dimensions")) {
        // correct schema or query and retry
    }
}

Prevention

When it happens

Trigger: Calling a vector similarity function in CQL with vector<float, N> arguments whose dimension values differ, e.g. similarity_cosine(v3, v5) where v3 is vector<float,3> and v5 is vector<float,5>.

Common situations: Comparing vectors stored in different tables or columns that were created with different dimension counts; schema drift after changing ANN index dimensions; passing a literal vector with a different number of floats than the column.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/dbc092b5b9f3f4e1. Report an issue: GitHub.