Description
Description
Currently, if the number of dimensions in a dense vector field doesn't match the input vector, an error is thrown. It would be helpful to support automatic dimension shrinking for models trained with Matryoshka (which allows dimension flexibility), without requiring this to be done offline. This feature would be particularly useful in scenarios like inference API usage, where models, such as those provided by OpenAI, offer flexible dimensions for indexing.
For example, if a model outputs 1024 dimensions, users could define a mapping like this:
PUT my-index
{
"mappings": {
"properties": {
"emb_short": {
"type": "dense_vector",
// using the first 384 dimensions
"dims": 384,
"copy_to": "emb_full"
},
"emb_full" : {
"type" : "dense_vector",
"dims": 1024,
"index_options": {
"type": "int8_hnsw"
}
}
}
}
}
Then at query time, the emb_short
field can be used for approximate nearest neighbour search through the HNSW index and rescore the results using the emb_full
field to increase the recall.
The downside is that it would now be impossible to determine if the number of dimensions was misconfigured for the emb_short
field in this example. However we could continue to throw an error if the input vector has less dimensions that the value configured in the mapping.
At query time, the emb_full field can be used for approximate nearest neighbor search through the HNSW index, and the results can be rescored using the emb_full field to improve recall.
The potential downside is that it would no longer be possible to detect if the number of dimensions was misconfigured for the emb_short
field in this scenario. However, we could still throw an error if the input vector has fewer dimensions than the value configured in the mapping.