apache/cassandra · error · InvalidRequestException

Invalid vector literal for %s: value %s is not of type %s

Error message

Invalid vector literal for %s: value %s is not of type %s

What it means

Thrown in Vectors.Literal.prepare when an individual element of a vector literal is not assignable to the vector's declared element type. Each element's testAssignment is checked against a receiver specification of the component type.

Source

Thrown at src/java/org/apache/cassandra/cql3/terms/Vectors.java:132

        @Override
        public Term prepare(String keyspace, ColumnSpecification receiver) throws InvalidRequestException
        {
            AbstractType<?> unwrapped = receiver.type.unwrap();

            if (!unwrapped.isVector())
                throw new InvalidRequestException(String.format("Invalid vector literal for %s of type %s", receiver.name, receiver.type.asCQL3Type()));
            VectorType<?> type = (VectorType<?>) unwrapped;
            if (elements.size() != type.dimension)
                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()));

            ColumnSpecification valueSpec = valueSpecOf(receiver);
            List<Term> values = new ArrayList<>(elements.size());
            boolean allTerminal = true;
            for (Term.Raw rt : elements)
            {
                if (!rt.testAssignment(keyspace, valueSpec).isAssignable())
                    throw new InvalidRequestException(String.format("Invalid vector literal for %s: value %s is not of type %s", receiver.name, rt, valueSpec.type.asCQL3Type()));

                Term t = rt.prepare(keyspace, valueSpec);

                if (t instanceof Term.NonTerminal)
                    allTerminal = false;

                values.add(t);
            }
            MultiElements.DelayedValue value = new MultiElements.DelayedValue(type, values);
            return allTerminal ? value.bind(FunctionContext.NONE) : value;
        }

        @Override
        public String getText()
        {
            return Lists.listToString(elements, Term.Raw::getText);
        }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Make every element a literal/term of the declared component type (e.g. float for vector<float, N>).
  2. Cast values in the generating application before building the literal.
  3. Sanitize upstream data to remove nulls or non-numeric entries.

Example fix

// before
INSERT INTO t (embedding) VALUES ([0.1, '0.2', 0.3]); // string element in vector<float,3>
// after
INSERT INTO t (embedding) VALUES ([0.1, 0.2, 0.3]);
Defensive patterns

Strategy: validation

Validate before calling

for (Object el : elements)
    if (!(el instanceof Float)) throw new IllegalArgumentException("Vector element not float: " + el);

Type guard

boolean allFloats(List<Object> xs) { return xs.stream().allMatch(x -> x instanceof Number); }

Try / catch

try { session.execute(stmt); } catch (InvalidRequestException e) { if (e.getMessage().contains("is not of type")) sanitizeElements(); else throw e; }

Prevention

When it happens

Trigger: `[0.1, 'a', 3]` for vector<float, 3> — a string or int element that cannot be coerced to the declared component type; nested collections or UDT literals inside a vector literal.

Common situations: Mixing numeric types inconsistently (int literals into float vectors are generally fine, but strings/nulls are not); generated queries embedding non-numeric values from upstream data.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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