Repository navigation
Make the exception obvious when caused by knn dimensions mismatch #1333
Copy link
Copy link
Closed
Description
Description
Elasticsearch client, 9.5.x
When there's a knn query, and the number dimensions of query embedding doesn't match what's in the index, the exception is not obvious to understand. It would help, if it could be obvious.
Example request:
SearchResponse<CatalogueItem> response = esClient.search(s -> s
.index(indexName)
.knn(knn -> knn
.field("embedding")
.queryVector(queryVector)
.k(k)
.numCandidates(numCandidates)
)
// Also set the size of the search response to k
.size(k)
.source(src -> src.filter(f -> f.includes("filename", "full-path", "price"))),
CatalogueItem.class);The actual exception:
Caused by: co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/search] failed: [search_phase_execution_exception] all shards failed
at co.elastic.clients.transport.ElasticsearchTransportBase.getApiResponse(ElasticsearchTransportBase.java:421)
at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:204)
at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:5207)
at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:5250)
When debugging and examining the error in ElasticsearchTransportBase:419, one can easily see:
{
"error": {
"phase": "dfs",
"failed_shards": [
{
"shard": 0,
"index": "catalogue",
"node": "geWMIwPdScSqIlebJP7eCw",
"reason": {
"type": "query_shard_exception",
"reason": "failed to create query: The query vector has a different number of dimensions [100] than the document vectors [768].",
"index_uuid": "h9wJXp-ES6WE3ihk-qsKIQ",
"index": "catalogue",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "The query vector has a different number of dimensions [100] than the document vectors [768]."
}
}
}
],
"grouped": true,
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"root_cause": [
{
"index_uuid": "h9wJXp-ES6WE3ihk-qsKIQ",
"index": "catalogue",
"type": "query_shard_exception",
"reason": "failed to create query: The query vector has a different number of dimensions [100] than the document vectors [768]."
}
]
},
"status": 400
}IMHO it would help a great deal if the exception had the root_cause too.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
l-trotta commentedon Sep 4, 2026
Thanks for making me aware of this! I've added all nested root causes to the main error message in #1335, it will be in the next patch. A failing Knn query such at this one will output: