{"record":{"id":"bd3a632f8c11e57f","repo":"elastic/elasticsearch","slug":"negative-vector-dims","errorCode":null,"errorMessage":"negative vector dims: {}","messagePattern":"negative vector dims: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/gpu-codec/src/main/java/org/elasticsearch/gpu/codec/DatasetUtilsImpl.java","lineNumber":70,"sourceCode":"        final int byteSize = dataType == CuVSMatrix.DataType.FLOAT ? Float.BYTES : Byte.BYTES;\n        if (((long) numVectors * dims * byteSize) > input.byteSize()) {\n            throwIllegalArgumentException(input, numVectors, dims);\n        }\n        return fromMemorySegment(input, numVectors, dims, dataType);\n    }\n\n    static void throwIllegalArgumentException(MemorySegment ms, int numVectors, int dims) {\n        var s = \"segment of size [\" + ms.byteSize() + \"] too small for expected \" + numVectors + \" float vectors of \" + dims + \" dims\";\n        throw new IllegalArgumentException(s);\n    }\n\n    static void throwIllegalArgumentException(int numVectors, int dims) {\n        String s;\n        if (numVectors < 0) {\n            s = \"negative number of vectors: \" + numVectors;\n        } else {\n            s = \"negative vector dims: \" + dims;\n        }\n        throw new IllegalArgumentException(s);\n    }\n}\n","sourceCodeStart":52,"sourceCodeEnd":74,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/gpu-codec/src/main/java/org/elasticsearch/gpu/codec/DatasetUtilsImpl.java#L52-L74","documentation":"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).","triggerScenarios":"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.","commonSituations":"FieldInfo with no vector dimension set (returning a default/sentinel); corrupted segment where the dimension field is damaged; unit test with a malformed FieldInfo.","solutions":["Verify fieldInfo.getVectorDimension() returns a positive value before calling fromInput.","Check that the dense_vector mapping has a valid dims parameter in the index mapping.","Run CheckIndex to detect segment corruption."],"exampleFix":"// before\nint dims = fieldInfo.getVectorDimension();\nCuVSMatrix m = DatasetUtils.getInstance().fromInput(seg, numVectors, dims, type);\n\n// after\nint dims = fieldInfo.getVectorDimension();\nif (dims <= 0) {\n    throw new IllegalStateException(\"Invalid vector dimension \" + dims + \" for field \" + fieldInfo.name);\n}\nCuVSMatrix m = DatasetUtils.getInstance().fromInput(seg, numVectors, dims, type);","handlingStrategy":"validation","validationCode":"if (dims <= 0) {\n    throw new IllegalStateException(\"dims must be positive, got: \" + dims);\n}\nCuVSMatrix m = DatasetUtils.getInstance().fromInput(segment, numVectors, dims, dataType);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify fieldInfo.getVectorDimension() returns a positive value before using it as dims.","Ensure the dense_vector index mapping has a valid dims parameter.","Validate dims at the point where FieldInfo is created or loaded."],"tags":["gpu-codec","vector-search","validation","cuvs"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}