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

  1. Check the upstream source of numVectors — if it comes from FloatVectorValues.size(), verify the index is not corrupted.
  2. Add a guard before calling fromInput: if (numVectors < 0) throw early with context about where the negative value originated.
  3. 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

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


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