I have the following query that should perform CosineSimilarity:
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"script_score": {
"script": {
"source": "cosineSimilarity (params.queryVector, doc['embedding') + 1.0",
"params": {
"queryVector": [-0.0011626648483797908,
0.005565074738115072,
...]
}
}
}
}
}
We use ElasticSearch 7.10.0. I can't pinpoint what the issue is in this test query. From what I know CosineSimilarity should be available in ES 7.10+. The error encountered was:
{
"error": {
"root_cause":[...]
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [...],
"script": "cosineSimilarity (params.queryVector, doc['embedding']) + 1.0",.. },
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Unknown call [cosineSimilarity] with [2] arguments."
}
}
}
}
],
"caused_by": {
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"cosineSimilarity (params. ...",
"^---- HERE"
],
"script": "cosineSimilarity (params.queryVector, doc['embedding']) + 1.0"...
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Unknown call [cosineSimilarity] with [2] arguments."
}
}
},
"status": 400 }
Here's the property mapping of the embedding in the index:
"embeddings": {
"type": "knn_vector",
"dimension": 1536
}...
I followed the documentation in ES for CosineSimilarity but still encountering this error.