Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for elastiknn_dense_float_vector in script_score #323

Closed
venkatana-kore opened this issue Nov 12, 2021 · 3 comments
Closed

Support for elastiknn_dense_float_vector in script_score #323

venkatana-kore opened this issue Nov 12, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@venkatana-kore
Copy link

venkatana-kore commented Nov 12, 2021

I'm using elastiknn_dense_float_vector as a vector for a field to achieve ANN search. But I want to use the elastiknn_dense_float_vector in script_score to modify the score which is not working as I'm getting "Fielddata is not supported on field [knn_vectors] of type [elastiknn_dense_float_vector]" as an error.

Any possible way to convert elastiknn_dense_float_vector to dense_vector. If not how can we use elastiknn_dense_float_vector in script_score query.

This is the query I'm using right now and Im using ElaskiKNN 7.9.2 version

{
    "query": {
        "function_score": {
            "query": {
                "bool": {
                    "should": [
                        {
                            "multi_match": {
                                "query": "statement",
                                "fields": [ ]
                            }
                        },
                        {
                            "elastiknn_nearest_neighbors": {
                                "field": "page_title_vectors_knn",
                                "vec": {
                                    "values": []
                                },
                                "model": "lsh",
                                "similarity": "l2",
                                "candidates": 10
                            }
                        }
                    ]
                }
            },
            "functions": [
                {
                    "script_score": {
                        "script": {
                            "source": "double cosVal = Math.acos(cosineSimilarity(params.query_vector, doc["page_title_vectors_knn"])); return 1-(cosVal/3.14);",
                            "params": {
                                "query_vector": []
                            }
                        }
                    }
                }
            ],
            "boost_mode": "multiply",
            "score_mode": "multiply",
            "boost": 1.0
        }
    }
}
@alexklibisz
Copy link
Owner

Hi, thanks for the question. This is currently not supported. I know that it's possible to implement, and I actually did it on a branch at some point in the distant past, but it was never merged. I'm not sure when I'd be able to look into it. If you would be interested in trying it out, I would suggest looking at how the dense_vector type in Elasticsearch is integrated to work with scripts. It would probably work very similarly in Elastiknn.

@venkatana-kore
Copy link
Author

Thanks @alexklibisz for your reply. It would be great if you can give me some inputs in this direction or any resources or pointers on how can I use knn vectors in scripts.

@alexklibisz
Copy link
Owner

They can't be used at all right now. There's no support for it. If you want to try to implement it yourself, see the developer-guide.md and the dense_vector type implementation in Elasticsearch. Otherwise, I'll try to get to it at some point, but can't prioritize it right now.

@alexklibisz alexklibisz added the enhancement New feature or request label Nov 12, 2021
@alexklibisz alexklibisz changed the title How to use type elastiknn_dense_float_vector in script_score Support for elastiknn_dense_float_vector in script_score Nov 12, 2021
@alexklibisz alexklibisz closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants