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

[BUG] Retreive knn_vector value raising an error. What's the alternative? #412

Closed
igaloly opened this issue Jun 1, 2022 · 11 comments
Closed
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@igaloly
Copy link

igaloly commented Jun 1, 2022

What is the bug?
When I try to retrieve a value from a knn_vector, I get this error: knn vector does not support this operation.

I do not want to use _source to get the vector, because it's slow.
What are my options to save vector with the ability to retrieve it values?

Mapping:

{
  "test-1": {
    "mappings": {
      "properties": {
        "vector": {
          "type": "knn_vector",
          "dimension": 768
        }
      }
    }
  }
}

Query:

{
  "size": 0,
  "aggs": {
    "vector_iter": {
      "scripted_metric": {
        ...
        "map_script": "
            for(int i = 0; i < doc['vector'].length; i++) {
                state.sumVector[i] = state.sumVector[i] + doc['vector'][i]; <---- Here's the problem
            }
        ",
        ...
        "params": {
            "vectorLength": 768
        }
      }
    }
  }
}

How can one reproduce the bug?

  1. Create an index
  2. Post some documents with knn_field
  3. Try to reach field value in some index in painless

What is the expected behavior?
To get the value of the specific index

What is your host/environment?

  • Amazon OpenSearch Service
  • OpenSearch v1.2
@igaloly igaloly added bug Something isn't working untriaged labels Jun 1, 2022
@VijayanB VijayanB self-assigned this Jun 2, 2022
@VijayanB
Copy link
Member

VijayanB commented Jun 2, 2022

@igaloly You can use value member to get float [], like below

GET /myindex1/_search?pretty
{
  "size": 3,
  "query": {
    "script_score": {
      "query" : {
        "match_all": {}
       },
      "script": {
        "source" : """
           float sum = 0;
           float []v = doc['vector'].value;
           for (int i=0; i< v.length; i++) { 
             sum += v[i];
           }
           return sum;
        """
      }
    }
  }
}

@igaloly
Copy link
Author

igaloly commented Jun 2, 2022

@VijayanB When performing this query, as you suggested, it raises the error: Illegal list shortcut value [value].

Query:

{
  "size": 0,
  "aggs": {
    "vector_iter": {
      "scripted_metric": {
        ...
        "map_script": "
            float []vector = doc['vector'].value; <---- Here's the problem
            for(int i = 0; i < vector.length; i++) {
                state.sumVector[i] = state.sumVector[i] + vector[i];
            }
        ",
        ...
        "params": {
            "vectorLength": 768
        }
      }
    }
  }
}

Also, Is it slow as params._source['vector']?

@VijayanB
Copy link
Member

VijayanB commented Jun 2, 2022

@igaloly doc values are faster if you are loading few fields from documents instead of whole document. Let me try to reproduce this issue and will get back to you soon.

@VijayanB
Copy link
Member

VijayanB commented Jun 2, 2022

@igaloly I am able to reproduce this issue and figured out that KNNScriptDocValue is only accessible inside script_score context at this moment. We will work on including additional context to make it accessible.

@igaloly
Copy link
Author

igaloly commented Jun 3, 2022

@VijayanB Sounds good.
Do you have any (even rough) time estimate on when it will be available to Managed Opensearch users?

@VijayanB
Copy link
Member

VijayanB commented Jun 10, 2022

@igaloly We are targeting for OpenSearch 2.0.1 ( OpenSource) release. Will confirm in few days on when will this be available for managed OpenSearch users.

@igaloly
Copy link
Author

igaloly commented Jun 26, 2022

Hi @VijayanB
Is there any update?

@VijayanB
Copy link
Member

VijayanB commented Jun 28, 2022

@igaloly Sorry for late response. We released this feature in OpenSearch 2.0.1 ( Open source). Unfortunately, i don't have any information on when will this be available for managed users at this moment.

@vamshin
Copy link
Member

vamshin commented Jun 29, 2022

@igaloly As of today managed service is couple of months behind the OpenSearch version. Stay tuned to managed service release page

@igaloly
Copy link
Author

igaloly commented Jun 29, 2022

@VijayanB @vamshin
Thank you very much!

@vamshin
Copy link
Member

vamshin commented Nov 2, 2022

closing this thread. Feel free to reopen if you see issues.

@vamshin vamshin closed this as completed Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants