Hi all,
I'm trying to run an exact kNN search.
I've created the following index with the mappings:
await client.indices.create({
index: "semantic-stuff",
mappings: {
properties: {
data: { type: "text", index: false },
embeddings: { type: "dense_vector", index: false, dims: 1536 },
orgId: { type: "text" },
},
},
});
Let me start by noting that when I fetch the mapping for this index, the embeddings
property has type float
rather than dense_vector
, is this expected? I hope so.
But then when running the following query (from Script score query | Elasticsearch Guide [8.6] | Elastic):
query: {
script_score: {
query: {
match: {
orgId: {
query: "a50ff874-2cf4-4058-a0e1-aa47f27eaef7",
},
},
},
script: {
source:
"cosineSimilarity(params.queryVector, 'embeddings') + 1.0",
params: {
queryVector: emeddingsIReceiveFromOpenAiHERE,
},
},
},
},
the embeddings I'm passing to the query are computed in the same exact way as the ones I've used to populate ES.
But I always get the following error:
'class org.elasticsearch.script.field.FloatDocValuesField cannot be cast to class org.elasticsearch.script.field.vectors.DenseVectorDocValuesField (org.elasticsearch.script.field.FloatDocValuesField and org.elasticsearch.script.field.vectors.DenseVectorDocValuesField are in module org.elasticsearch.server@8.6.2 of loader 'app')'
with also
Does anyone know what I'm doing wrong here?
EDIT: reloading data I've noticed the mapping now shows dense_vector
as embedding field type and the search works as expected.
I have changed nothing in my code though, which is a bit concerning, does anyone know if it can happen automatic casting from dense_vector to float on bulk import or something?