elastic/elasticsearch · error · IllegalArgumentException
vector dimensions differ: {}!={}
Error message
vector dimensions differ: {}!={} What it means
Thrown by ESVectorUtil.andBitCount when the two signed-byte vectors differ in length. andBitCount computes the bitwise AND population count, which requires identical byte arrays. The guard runs before invoking the method-handle kernel that assumes equal lengths.
Source
Thrown at libs/simdvec/src/main/java/org/elasticsearch/simdvec/ESVectorUtil.java:421
* @return the inner product of the two vectors
*/
public static float ipFloatByte(float[] q, byte[] d) {
if (q.length != d.length) {
throw new IllegalArgumentException("vector dimensions incompatible: " + q.length + "!= " + d.length);
}
return IMPL.ipFloatByte(q, d);
}
/**
* AND bit count computed over signed bytes.
* Copied from Lucene's XOR implementation
* @param a bytes containing a vector
* @param b bytes containing another vector, of the same dimension
* @return the value of the AND bit count of the two vectors
*/
public static int andBitCount(byte[] a, byte[] b) {
if (a.length != b.length) {
throw new IllegalArgumentException("vector dimensions differ: " + a.length + "!=" + b.length);
}
try {
return (int) BIT_COUNT_MH.invokeExact(a, b);
} catch (Throwable e) {
if (e instanceof Error err) {
throw err;
} else if (e instanceof RuntimeException re) {
throw re;
} else {
throw new RuntimeException(e);
}
}
}
/**
* Hamming similarity between two equal-length bit vectors, matching Lucene's
* {@code FlatBitVectorsScorer}: {@code (numBits - xorBitCount) / numBits}.
*/View on GitHub (pinned to db6a809a66)
Solutions
- Ensure both byte arrays have identical length before calling.
- Validate that both vectors share the same logical dimension and element_type.
- Pad the shorter vector with zeros or reject the mismatch upstream rather than at the scorer.
Example fix
// before
int andCount = ESVectorUtil.andBitCount(a, b);
// after
if (a.length != b.length) {
throw new IllegalArgumentException("bit vectors differ: " + a.length + " vs " + b.length);
}
int andCount = ESVectorUtil.andBitCount(a, b); Defensive patterns
Strategy: validation
Validate before calling
if (a.length != b.length) {
throw new IllegalArgumentException("bit vectors differ: " + a.length + " vs " + b.length);
}
int andCount = ESVectorUtil.andBitCount(a, b); Type guard
static boolean sameLength(byte[] a, byte[] b) {
return a != null && b != null && a.length == b.length;
} Prevention
- Index bit vectors with a single canonical encoder to guarantee identical packed lengths.
- Reject mismatched-length bit vectors at the scorer dispatcher rather than at the SIMD boundary.
- Add length assertions in unit tests for any new bit-vector similarity.
When it happens
Trigger: Calling ESVectorUtil.andBitCount(byte[] a, byte[] b) with a.length != b.length. Occurs in scoring paths that compare two bit-packed vectors (e.g., hamming/and-based similarity) where the query and document bit encodings disagree on packed length.
Common situations: Two bit vectors indexed with different dims; one vector was truncated or zero-padded during ingestion; quantization/encoding path produced inconsistent byte counts; query and document came from different element_type=bit mappings.
Related errors
- Pitch needs to be at least {}
- vector dimensions incompatible
- distances array must have length >= 4, but was: {}
- distancesOffset must be between 0 and distances.length - 4
- distances array must have length 4, but was: {}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/525989953bf67153.
Report an issue: GitHub.