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

Move query building responsibility to KnnVectorFieldType and engine #2568

Open
jmazanec15 opened this issue Feb 27, 2025 · 0 comments
Open
Labels
Refactoring Improve the design, structure, and implementation while preserving its functionality

Comments

@jmazanec15
Copy link
Member

jmazanec15 commented Feb 27, 2025

Description

Right now, our KNN query building contains a significant number of branches depending on the algo, engine and type (radial vs. knn) and with/without model. Any engine specific feature leads to more branching in the KNNQueryBuilder, KNNQuery or KNNWeight

Ideally, we should provide the parsed context to the engine and it should take care of building the query.

That being said, I have seen a convention in OpenSearch where the MappedFieldType can produce the query: See TextFieldMapper for example.

The KNNQueryBuilder would parse the context and then decide if it is radial or knn and then pass it on to the knnVectorFieldType with new methods:

Query knnQuery(KNNQueryParseContext)

Query radialQuery(RadialQueryParseContext)

From here, the mapped field type could delegate to the engine to validate and create the given query. This would provide for much better encapsulation and less branching.

Related Issues

#1914

@jmazanec15 jmazanec15 added Refactoring Improve the design, structure, and implementation while preserving its functionality and removed untriaged labels Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactoring Improve the design, structure, and implementation while preserving its functionality
Projects
None yet
Development

No branches or pull requests

1 participant