Usecase: We have multiple dense vector fields (4-5) with which we compute a similarity score for each one of them and then be able to give different weightage for each of these scores in runtime.
Approach: Use scripted fields and populate scores for each feature vectors. Then sort/boost by them in some order defined by the query in runtime.
Problem:
Query:
GET test_vector_search/_search { "size": 10, "query": { "match_all": {} }, "script_fields": { "my_first_vector_field_score": { "script":{ "lang": "knn", "source": "knn_score", "params": { "field": "my_first_vector_field", "query_value": [1,2,3], "space_type": "l2" } } } } }
When I populate a scripted field, I get this error
{ "error" : { "root_cause" : [ { "type" : "general_script_exception", "reason" : "Failed to compile inline script [knn_score] using lang [knn]" } ], "type" : "search_phase_execution_exception", "reason" : "all shards failed", "phase" : "query", "grouped" : true, "failed_shards" : [ { "shard" : 0, "index" : "test_vector_search", "node" : "R6me5b5HSme_tOfamUqpYA", "reason" : { "type" : "general_script_exception", "reason" : "Failed to compile inline script [knn_score] using lang [knn]", "caused_by" : { "type" : "illegal_argument_exception", "reason" : "knn KNN scoring scripts cannot be used for context [field]" } } } ] }, "status" : 500 }
Does this sound okay? Is there a better way to do it?