elastic/elasticsearch · error · IllegalArgumentException

negative vector dims: {}

Error message

negative vector dims: {}

What it means

Thrown by DatasetUtilsImpl.fromInput() when dims is negative and numVectors is non-negative. The method checks both parameters upfront; this branch fires only when dims < 0 (since the numVectors < 0 case is checked first and produces a different message).

Source

Thrown at libs/gpu-codec/src/main/java/org/elasticsearch/gpu/codec/DatasetUtilsImpl.java:70

        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

  1. Verify fieldInfo.getVectorDimension() returns a positive value before calling fromInput.
  2. Check that the dense_vector mapping has a valid dims parameter in the index mapping.
  3. Run CheckIndex to detect segment corruption.

Example fix

// before
int dims = fieldInfo.getVectorDimension();
CuVSMatrix m = DatasetUtils.getInstance().fromInput(seg, numVectors, dims, type);

// after
int dims = fieldInfo.getVectorDimension();
if (dims <= 0) {
    throw new IllegalStateException("Invalid vector dimension " + dims + " for field " + fieldInfo.name);
}
CuVSMatrix m = DatasetUtils.getInstance().fromInput(seg, numVectors, dims, type);
Defensive patterns

Strategy: validation

Validate before calling

if (dims <= 0) {
    throw new IllegalStateException("dims must be positive, got: " + dims);
}
CuVSMatrix m = DatasetUtils.getInstance().fromInput(segment, numVectors, dims, dataType);

Prevention

When it happens

Trigger: Calling DatasetUtils.getInstance().fromInput(segment, numVectors, dims, dataType) with dims < 0 and numVectors >= 0. This occurs when the vector dimensionality source returns a negative value — typically from fieldInfo.getVectorDimension() on a misconfigured or corrupted FieldInfo.

Common situations: FieldInfo with no vector dimension set (returning a default/sentinel); corrupted segment where the dimension field is damaged; unit test with a malformed FieldInfo.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/bd3a632f8c11e57f. Report an issue: GitHub.