apache/cassandra · error · InvalidRequestException

Unable to create a vector selector of type %s from %d elemen

Error message

Unable to create a vector selector of type %s from %d elements

What it means

Cassandra throws this when a vector literal in a SELECT clause has a different number of elements than the dimension of the vector type it must match. Vector types in Cassandra are fixed-dimension; a term like [1,2,3] cannot be used where a vector of dimension 4 is expected. The request is rejected at statement-prepare time as an invalid request.

Source

Thrown at src/java/org/apache/cassandra/cql3/selection/Selectable.java:944

        @Override
        public Factory newSelectorFactory(TableMetadata cfm,
                                          AbstractType<?> expectedType,
                                          List<ColumnMetadata> defs,
                                          VariableSpecifications boundNames)
        {
            AbstractType<?> type = getExactTypeIfKnown(cfm.keyspace);
            if (type == null)
            {
                type = expectedType;
                if (type == null)
                    throw invalidRequest("Cannot infer type for term %s in selection clause (try using a cast to force a type)",
                                         this);
            }

            VectorType<?> vectorType = (VectorType<?>) type;
            if (vectorType.dimension != selectables.size())
                throw invalidRequest("Unable to create a vector selector of type %s from %d elements", vectorType.asCQL3Type(), selectables.size());

            List<AbstractType<?>> expectedTypes = new ArrayList<>(selectables.size());
            for (int i = 0, m = selectables.size(); i < m; i++)
                expectedTypes.add(vectorType.getElementsType());

            SelectorFactories factories = createFactoriesAndCollectColumnDefinitions(selectables,
                                                                                     expectedTypes,
                                                                                     cfm,
                                                                                     defs,
                                                                                     boundNames);
            return VectorSelector.newFactory(type, factories);
        }

        @Override
        public AbstractType<?> getExactTypeIfKnown(String keyspace)
        {
            return Vectors.getExactVectorTypeIfKnown(selectables, p -> p.getExactTypeIfKnown(keyspace));
        }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Count the elements in the vector literal and make it exactly equal to the vector type's dimension (check with DESCRIBE TYPE / schema).
  2. Re-generate embeddings with the model/dimension matching the column's declared vector dimension.
  3. If the intent is a non-vector collection, use list/set/map syntax or cast the term to the correct collection type instead.
  4. Update stored queries/prepared statements after any vector dimension change.

Example fix

// before
SELECT [0.1, 0.2] FROM vectors; -- column embedding is vector<float, 3>
// after
SELECT [0.1, 0.2, 0.3] FROM vectors;
Defensive patterns

Strategy: validation

Validate before calling

int dim = vectorType.getDimension(); if (elements.size() != dim) throw new IllegalArgumentException("expected vector dimension " + dim + ", got " + elements.size());

Try / catch

try { session.execute(select); } catch (InvalidRequestException e) { if (e.getMessage().contains("vector selector")) { /* fix literal arity or re-embed */ } else throw e; }

Prevention

When it happens

Trigger: SELECTing a vector term whose element count differs from the column/target vector type's declared dimension, e.g. `SELECT [1,2] FROM t` where the inferred vector type has dimension 3; also when selecting a literal intended for an ANN/similarity usage where element count mismatches the schema vector column.

Common situations: Schema changed (vector dimension resized) but queries not updated; hand-written literals with wrong arity; copy-pasted examples from docs with different dimensions; driver/app code generating vector literals from variable-length embeddings.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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