{"record":{"id":"9ee4fa4a3172f697","repo":"elastic/elasticsearch","slug":"vector-query-dimension-differs-from-field-dime","errorCode":null,"errorMessage":"vector query dimension: {} differs from field dimension: {}","messagePattern":"vector query dimension: (.+?) differs from field dimension: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/simdvec/src/main/java/org/elasticsearch/simdvec/internal/BFloat16VectorScorer.java","lineNumber":233,"sourceCode":"                numNodes,\n                addrsScratch::get,\n                addrs -> DISTANCE_FUNCS.dotProductDBF16QF32BulkSparse(addrs, query, dimensions, numNodes, MemorySegment.ofArray(scores))\n            );\n            if (resolved) {\n                float max = Float.NEGATIVE_INFINITY;\n                for (int i = 0; i < numNodes; ++i) {\n                    scores[i] = VectorUtil.scaleMaxInnerProductScore(scores[i]);\n                    max = Math.max(max, scores[i]);\n                }\n                return max;\n            }\n            return super.bulkScore(nodes, scores, numNodes);\n        }\n    }\n\n    static void checkDimensions(int queryLen, int fieldLen) {\n        if (queryLen != fieldLen) {\n            throw new IllegalArgumentException(\"vector query dimension: \" + queryLen + \" differs from field dimension: \" + fieldLen);\n        }\n    }\n}\n","sourceCodeStart":215,"sourceCodeEnd":237,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/simdvec/src/main/java/org/elasticsearch/simdvec/internal/BFloat16VectorScorer.java#L215-L237","documentation":"Thrown by BFloat16VectorScorer.checkDimensions when the query vector length does not equal the indexed field's vector dimension. This scorer handles bfloat16 (brain float) vectors. The check is invoked from the static create() method before constructing a scorer, so it fires at scorer-creation time, not per-document.","triggerScenarios":"Calling BFloat16VectorScorer.create(sim, values, queryVector) where queryVector.length != values.dimension(). The create() method is called by the scorer-provider pipeline when resolving a kNN query against bfloat16 fields.","commonSituations":"Indexing a dense_vector field at one dimension (e.g. dims: 768) then querying with a vector of a different size (e.g. 384). Also occurs after changing the mapping dims without reindexing, or passing a model embedding from a different model than the one used for indexing.","solutions":["Match the query vector dimension to the field's configured dims (check the index mapping: PUT index/_mapping or GET index/_mapping).","If the embedding model changed, reindex all documents with the new model before querying.","Validate the query vector length against the mapping before sending the kNN query."],"exampleFix":"// before\nGET my-index/_search\n{ \"knn\": { \"query_vector\": [0.1, 0.2, ... /* 384 dims */], ... } }\n\n// after — field is mapped as dims:768, so supply a 768-dim vector\nGET my-index/_search\n{ \"knn\": { \"query_vector\": [/* 768 dims from the same model */], ... } }","handlingStrategy":"validation","validationCode":"if (queryVector.length != values.dimension()) {\n    throw new IllegalArgumentException(\"query dims \" + queryVector.length + \" != field dims \" + values.dimension());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check the index mapping (GET index/_mapping) for the dense_vector dims before querying.","Use the same embedding model for indexing and querying.","Reindex when the model or dimension changes."],"tags":["vector-search","knn","dimension-mismatch","bfloat16","scorer","elasticsearch"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}