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

[FEATURE]: knn based queries are getting rejected by SearchSourceBuilder.parseXContent #1035

Closed
vineethk1984 opened this issue Aug 10, 2023 · 2 comments

Comments

@vineethk1984
Copy link

vineethk1984 commented Aug 10, 2023

Is your feature request related to a problem?

We use SearchSourceBuilder.parseXContent to validate the incoming queries and have put guardrails preventing
customers from running expensive queries.
Running below query throws ParsingException[unknown query [knn] error from SearchSourceBuilder.fromXContent

{
  "size": 2,
  "query": {
    "knn": {
      "my_vector1": {
        "vector": [0.1, 0.2, 0.3],
        "k": 2
      }
    }
  }
}

Dependency: opensearch-2.6.0
Pom:

<dependency>
    <groupId>org.opensearch</groupId>
    <artifactId>opensearch</artifactId>
    <version>2.6.0</version>
</dependency>

Error stack trace

ParsingException[unknown query [knn]
]; nested: NamedObjectNotFoundException[[4:5] unknown field [knn]];
	at __randomizedtesting.SeedInfo.seed([56E084C5B196F75:A6CF98EA22D26BD0]:0)
	at org.opensearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder(AbstractQueryBuilder.java:341)
	at org.opensearch.search.builder.SearchSourceBuilder.parseXContent(SearchSourceBuilder.java:1183)
	at org.opensearch.search.builder.SearchSourceBuilder.fromXContent(SearchSourceBuilder.java:140)
	at org.opensearch.search.builder.SearchSourceBuilder.fromXContent(SearchSourceBuilder.java:135)
	at org.opensearch.search.builder.SearchSourceBuilderTests.testKnnParsing(SearchSourceBuilderTests.java:359)

What solution would you like?

This is happening because OpenSearch project doesn't have a KnnQueryBuilder class.
Once created, has to get referenced in SearchModule.registerQueryParsers method as
registerQuery(new QuerySpec<>(KnnQueryBuilder.NAME, KnnQueryBuilder::new, KnnQueryBuilder::fromXContent));

What alternatives have you considered?

We rely heavily on these validations and changing the implemention would require our team go through the entire suite of performance and fmea tests.

Do you have any additional context?

I have the code ready and open to contribute as soon as this request is approved.

Screenshot 2023-08-10 at 12 48 16 PM

@peternied peternied transferred this issue from opensearch-project/.github Aug 10, 2023
@navneet1v
Copy link
Collaborator

@vineethk1984

This is happening because OpenSearch project doesn't have a KnnQueryBuilder class.

So the KNN query is part of K-NN plugin. This is the reason why it is not part of OpenSearch core repo. You need to install the k-NN plugin so that query type is registered.

I am not able to understand what is required here. Can you please add more details what are the expectations here? because as per my understanding Plugins need to register SearchPlugin interfaces to register the query types they are providing.

@vamshin
Copy link
Member

vamshin commented Aug 16, 2023

Hi @vineethk1984,

This issue seem to be fixed in 2.6 version of client opensearch-project/opensearch-java#539. Can you double check if its 2.6.0 java client?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants