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

Unable to perform knn query [knn] unknown field [k #8124

Closed
alkampfergit opened this issue Apr 15, 2024 · 7 comments · Fixed by #8129
Closed

Unable to perform knn query [knn] unknown field [k #8124

alkampfergit opened this issue Apr 15, 2024 · 7 comments · Fixed by #8129
Labels
8.x Relates to 8.x client version Area: Specification Category: Bug

Comments

@alkampfergit
Copy link

Elastic.Clients.Elasticsearch version:

Elasticsearch version:
8.13.0
.NET runtime version:
.NET 8
Operating system version:
Windows 11
Description of the problem including expected versus actual behavior:
I've created a knn query with the following syntax

        var knnOuterQuery = new QueryDescriptor<object>().Knn(knn => knn
            .Filter(query)
            .Field("vector")
            .NumCandidates(limit * 2)
            .QueryVector(coll));

Then I got an error: ServerError: Type: x_content_parse_exception Reason: "[9:7] [knn] unknown field [k]"

Looking for generated query it contains a k value that it is not supported: this is the request where you can see a k : 0 that is not correct. If I remove that parameter and try to execute the query everything seems to work just fine.

{
  "from": 0,
  "query": {
    "knn": {
      "field": "vector",
      "filter": {
        "match_all": {}
      },
      "k": 0,
      "num_candidates": 10,
      "query_vector": [
        -0.0546875,
        -0.53125,
        0.453125,
        -0.484375
      ]
    }
  },
  "size": 5
}

Indeed the driver has that parameter in the request, but seems not to be understood by the server. I'm constructing the query from a QueryDescriptor() object.

image

Am I doing something wrong or the driver indeed add a wrong "k" argument to the query?

@alkampfergit alkampfergit added 8.x Relates to 8.x client version Category: Bug labels Apr 15, 2024
@pquentin
Copy link
Member

Hello! This is a known issue in the Elasticsearch specification that will be fixed in the next version of the .NET client: elastic/elasticsearch-specification#2490. Sorry about that.

@alkampfergit
Copy link
Author

Is an older version of the driver that works with it? Actually this is pretty a blocking issue in a project of mine because we are planning to use Elastic as vector search.....

@flobernd
Copy link
Member

As @pquentin said, it's already fixed in the specification. The fix will propagate to the .NET client in the next few days. There is no older version of the 8.* client that correctly supports KNN queries. Hope you don't mind waiting a couple of days 🙂 I'll try to do a patch release already today, but can't promise anything.

@alkampfergit
Copy link
Author

Many thanks!!!

@flobernd
Copy link
Member

Fixed in 8.13.6

@alkampfergit
Copy link
Author

Confirmed! All test are green now on my project.

Thanks again!!!

@flobernd
Copy link
Member

@alkampfergit Happy to help you out 🙂 As well thanks to @l-trotta for fixing this issue upstream in the specification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to 8.x client version Area: Specification Category: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants