apache/cassandra · error · InvalidRequestException
vectors may only have positive dimensions; given
Error message
vectors may only have positive dimensions; given %d
What it means
VectorType requires a strictly positive dimension when a vector type is constructed. The constructor validates the dimension parameter and throws InvalidRequestException if it is <= 0, because a vector with zero or negative elements is meaningless in CQL.
Solutions
- Pass a positive dimension (>= 1) when constructing the vector type
- Fix the CQL schema to declare vector<elementType, N> with N > 0
- If dimension comes from a variable/config, validate it is > 0 before calling VectorType.getInstance
Example fix
// before AbstractType<?> t = VectorType.getInstance(Int32Type.instance, 0); // after AbstractType<?> t = VectorType.getInstance(Int32Type.instance, 3);
Defensive patterns
Strategy: validation
Validate before calling
if (dimension <= 0) throw new IllegalArgumentException("dimension must be > 0, got " + dimension);
AbstractType<?> t = VectorType.getInstance(elementType, dimension); Try / catch
try { VectorType.getInstance(et, dim); } catch (InvalidRequestException e) { /* log and fail schema setup */ } Prevention
- Validate dimension > 0 before constructing vector types
- Never hardcode dimensions from unchecked config values
When it happens
Trigger: Calling VectorType.getInstance(elementType, dimension) with dimension = 0 or a negative number, or declaring a CQL type like vector<int, 0> which resolves to a VectorType construction with an invalid dimension.
Common situations: Typo or computed dimension passed as 0 (e.g. a config value or variable that defaulted to 0), schema generation code building vector types programmatically, or user-supplied DDL with vector<..., 0>.
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
- ACCESS TO DATACENTERS operations not supported by…
- ALREADY_EXISTS
- Already exists
- Attempted to add float vector of dimension
- Because of this name
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/a7a4eb475457ec77.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/db/marshal/VectorType.java:91
@Override
public int hashCode()
{
return Objects.hash(type, dimension);
}
}
@SuppressWarnings("rawtypes")
private static final ConcurrentHashMap<Key, VectorType> instances = new ConcurrentHashMap<>();
public final AbstractType<T> elementType;
public final int dimension;
private final TypeSerializer<T> elementSerializer;
private final VectorSerializer serializer;
private VectorType(AbstractType<T> elementType, int dimension)
{
super(ComparisonType.CUSTOM, valueLengthIfFixed(elementType, dimension));
if (dimension <= 0)
throw new InvalidRequestException(String.format("vectors may only have positive dimensions; given %d", dimension));
this.elementType = elementType;
this.dimension = dimension;
this.elementSerializer = elementType.getSerializer();
this.serializer = elementType.isValueLengthFixed() ?
new FixedLengthSerializer() :
new VariableLengthSerializer();
}
@SuppressWarnings("unchecked")
public static <T> VectorType<T> getInstance(AbstractType<T> elements, int dimension)
{
Key key = new Key(elements, dimension);
return instances.computeIfAbsent(key, Key::create);
}
public static VectorType<?> getInstance(TypeParser parser)
{
TypeParser.Vector v = parser.getVectorParameters();View on GitHub (pinned to 88fd0f6a0e)