elastic/elasticsearch · error · IllegalArgumentException
negative number of vectors: {}
Error message
negative number of vectors: {} What it means
Thrown by DatasetUtilsImpl.fromInput() when the numVectors parameter is negative. This is a pre-condition check: the method validates that both numVectors and dims are non-negative before computing the required byte size. When numVectors is negative, this specific message is produced.
Source
Thrown at libs/gpu-codec/src/main/java/org/elasticsearch/gpu/codec/DatasetUtilsImpl.java:68
throwIllegalArgumentException(numVectors, dims);
}
final int byteSize = dataType == CuVSMatrix.DataType.FLOAT ? Float.BYTES : Byte.BYTES;
if (((long) numVectors * dims * byteSize) > input.byteSize()) {
throwIllegalArgumentException(input, numVectors, dims);
}
return fromMemorySegment(input, numVectors, dims, dataType);
}
static void throwIllegalArgumentException(MemorySegment ms, int numVectors, int dims) {
var s = "segment of size [" + ms.byteSize() + "] too small for expected " + numVectors + " float vectors of " + dims + " dims";
throw new IllegalArgumentException(s);
}
static void throwIllegalArgumentException(int numVectors, int dims) {
String s;
if (numVectors < 0) {
s = "negative number of vectors: " + numVectors;
} else {
s = "negative vector dims: " + dims;
}
throw new IllegalArgumentException(s);
}
}
View on GitHub (pinned to db6a809a66)
Solutions
- Check the upstream source of numVectors — if it comes from FloatVectorValues.size(), verify the index is not corrupted.
- Add a guard before calling fromInput: if (numVectors < 0) throw early with context about where the negative value originated.
- Run lucene CheckIndex on the affected shard to detect corruption.
Example fix
// before
int numVectors = floatVectorValues.size(); // could be negative if corrupted
CuVSMatrix m = DatasetUtils.getInstance().fromInput(seg, numVectors, dims, type);
// after
int numVectors = floatVectorValues.size();
if (numVectors < 0) {
throw new IllegalStateException("Unexpected negative vector count " + numVectors + " for field " + fieldName);
}
CuVSMatrix m = DatasetUtils.getInstance().fromInput(seg, numVectors, dims, type); Defensive patterns
Strategy: validation
Validate before calling
if (numVectors < 0) {
throw new IllegalStateException("numVectors must be non-negative, got: " + numVectors);
}
CuVSMatrix m = DatasetUtils.getInstance().fromInput(segment, numVectors, dims, dataType); Prevention
- Always validate numVectors >= 0 before calling fromInput.
- If numVectors comes from FloatVectorValues.size(), check the return value — a corrupted index can return negative sentinels.
- Use defensive checks at API boundaries where external data feeds into vector count parameters.
When it happens
Trigger: Calling DatasetUtils.getInstance().fromInput(segment, numVectors, dims, dataType) with numVectors < 0. In practice this can happen if FloatVectorValues.size() returns a negative value due to a corrupted index, or if an arithmetic overflow/underflow produces a negative count upstream.
Common situations: Corrupted segment metadata causing size() to return -1 or another sentinel negative value; integer underflow when computing numVectors from a subtraction; unit test passing invalid synthetic values.
Related errors
- segment of size [{}] too small for expected {} float vectors
- negative vector dims: {}
- maxConn must be positive and less than or equal to 512; maxC
- beamWidth must be positive and less than or equal to 3200; b
- Field [{}] must have FLOAT32 encoding, got: {}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/8134ed10e6c0feb6.
Report an issue: GitHub.