opendistro-for-elasticsearch / k-NN

🆕 A machine learning plugin which supports an approximate k-NN search algorithm for Open Distro.
https://opendistro.github.io/
Apache License 2.0
277 stars 55 forks source link

Casting knn_vector to dense_vector or Painless ArrayList for custom operations #229

Closed elb3k closed 3 years ago

elb3k commented 4 years ago

I am using knn_vector type with l2 distance. Finding k candidates works great and fast. But I need to get accuracy field as well. Accuracy is defined as 1 - l1norm( normalize(vector), normalize(input) ) / 2

To calculate accuracy as script_field, I need to cast knn_vector to dense_vector or ArrayList (in Painless scripting language).

Is there any formal way of converting knn_vector to dense_vector? P.S I am calculating accuracy after knn query (with k=5), so semi-efficent or not efficent methods are fine.

vamshin commented 4 years ago

Hi @Elbek-Khoshimjonov,

Looks like casting knn_vector in painless scripting seems to be a saolution(Does not look easy though). Share us the sample queries on how you do this for community members ending up on this thread for similar operations.