elastic/elasticsearch · error · IllegalStateException

attempt to retrieve score correction for different ord {} th

Error message

attempt to retrieve score correction for different ord {} than the quantization was done for: {}

What it means

Thrown by QuantizedFloatVectorValues.getScoreCorrectionConstant() when called with an ordinal different from the one used in the most recent vectorValue() call. This class lazily quantizes vectors: vectorValue(ord) sets lastOrd = ord and computes the offset/score correction, then getScoreCorrectionConstant(ord) must be called with the same ord. Calling getScoreCorrectionConstant with a different ord means the caller is out of sync with the quantization state.

Source

Thrown at libs/gpu-codec/src/main/java/org/elasticsearch/gpu/codec/MergedQuantizedVectorValues.java:238

        private final FloatVectorValues values;
        private final ScalarQuantizer quantizer;
        private final byte[] quantizedVector;
        private int lastOrd = -1;
        private float offsetValue = 0f;

        private final VectorSimilarityFunction vectorSimilarityFunction;

        QuantizedFloatVectorValues(FloatVectorValues values, VectorSimilarityFunction vectorSimilarityFunction, ScalarQuantizer quantizer) {
            this.values = values;
            this.quantizer = quantizer;
            this.quantizedVector = new byte[values.dimension()];
            this.vectorSimilarityFunction = vectorSimilarityFunction;
        }

        @Override
        public float getScoreCorrectionConstant(int ord) {
            if (ord != lastOrd) {
                throw new IllegalStateException(
                    "attempt to retrieve score correction for different ord " + ord + " than the quantization was done for: " + lastOrd
                );
            }
            return offsetValue;
        }

        @Override
        public int dimension() {
            return values.dimension();
        }

        @Override
        public int size() {
            return values.size();
        }

        @Override
        public byte[] vectorValue(int ord) throws IOException {

View on GitHub (pinned to db6a809a66)

Solutions

  1. Always call vectorValue(ord) before getScoreCorrectionConstant(ord) with the same ord.
  2. Do not share a QuantizedFloatVectorValues instance across threads — create a new instance per thread.
  3. Check that the ord passed to getScoreCorrectionConstant matches the ord from the last vectorValue call.
  4. If this occurs during segment merge, verify that the merge code follows the correct quantize-then-score protocol.

Example fix

// before — calling score correction before vectorValue
byte[] quantized = values.vectorValue(5);
float correction = values.getScoreCorrectionConstant(6); // wrong ord

// after — same ord for both calls
byte[] quantized = values.vectorValue(5);
float correction = values.getScoreCorrectionConstant(5); // matches
Defensive patterns

Strategy: validation

Validate before calling

// Always call vectorValue before getScoreCorrectionConstant with the same ord
byte[] quantized = values.vectorValue(ord);
// use quantized for scoring...
float correction = values.getScoreCorrectionConstant(ord); // must match the ord above

Prevention

When it happens

Trigger: Calling getScoreCorrectionConstant(ord) before calling vectorValue(ord), or calling them with mismatched ordinals. This class is used during merging of quantized vectors where the scoring path expects the score correction constant to match the vector that was just quantized. The error indicates a protocol violation in the caller: vectorValue must be called first, then getScoreCorrectionConstant with the same ord.

Common situations: Bug in the merge/scoring code that calls getScoreCorrectionConstant before or without calling vectorValue for the same ordinal; concurrent access to the same QuantizedFloatVectorValues instance from multiple threads (not thread-safe); caller using a stale ord value after the iterator advanced.

Related errors


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