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] Add support for knn queries #178

Closed
rharpertm opened this issue Mar 27, 2023 · 2 comments · Fixed by #215
Closed

[FEATURE] Add support for knn queries #178

rharpertm opened this issue Mar 27, 2023 · 2 comments · Fixed by #215
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@rharpertm
Copy link

Is your feature request related to a problem?

Currently, it appears that it's not possible to create an approximate knn query via the library, It'd be great to add support for this query type.

What solution would you like?

It would be nice to have a query structure that fits with the current library conventions. Perhaps something like:

q.knn(knn => knn.Field("search_vector")
                    .Vector(embString)
                    .K(25));

What alternatives have you considered?

For our current use case, we can get around this using a function_score and a Raw query DSL JSON string.

q.FunctionScore(fs =>
                    fs.Functions(f => f.Weight(10))
                        .Query(query =>
                            query.Raw(@"{
	                            ""knn"": {
	                                ""search_vector"": {
	                                    ""vector"": [" + embeddingString + @"],
	                                    ""k"":25
	                                }
	                            }
	                        }")
                        ));

Do you have any additional context?

knn queries have been around since v1.0 of OpenSearch, and itd be awesome to have this query type supported.

@rharpertm rharpertm added enhancement New feature or request untriaged labels Mar 27, 2023
@Xtansia Xtansia added good first issue Good for newcomers and removed untriaged labels Mar 27, 2023
@Xtansia
Copy link
Collaborator

Xtansia commented Mar 27, 2023

@rharpertm Thank you for bringing this to our attention, unfortunately there is a handful of features like this that primarily come from plugins that are not currently implemented in the client. We do have some big overarching actions in progress around code generation to patch these holes (opensearch-project/opensearch-clients#19 & opensearch-project/opensearch-clients#55). In the meantime, however, we would gladly accept a PR to add this specific binding if you or anyone else wished to put one together.

@Xtansia
Copy link
Collaborator

Xtansia commented Jul 5, 2023

Hi @rharpertm,

This support has now been released as part of v1.4.0 of the client.

You can find a brief example of using it here in the integration test: https://github.com/opensearch-project/opensearch-net/blob/v1.4.0/tests/Tests/QueryDsl/Specialized/Knn/KnnQueryUsageTests.cs#L82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants