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

Generalize lib interface to return context objects #1925

Merged
merged 2 commits into from
Aug 2, 2024

Conversation

jmazanec15
Copy link
Member

Description

Generalizes the KNNLibrary interface to return an object for both search and indexing so that the plugin can search/index against them. The names of the methods are "getKNNLibraryIndexBuildContext" and "getKNNLibrarySearchContext". In the future, I could see these methods changing into something like getKNNLibraryIndexBuilder and getKNNLibrarySearcher so that the engine actually encapsulates the interactions with the libraries, but that needs some more thought. For now, this change makes it more clear what one of the central roles of the KNNLibrary interface is - telling the plugin how to index/search.

For the quantization framework, making the interface return objects will allow us to properly configure both quantization as well as whatever index we want to use with it. See the following locations for more details where we would do this:

  1. https://github.com/jmazanec15/k-NN-1/blob/method-stage/src/main/java/org/opensearch/knn/index/mapper/MethodFieldMapper.java#L63
  2. https://github.com/jmazanec15/k-NN-1/blob/method-stage/src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java#L376

Again, no functionality change - just more refactoring to better support the quantization framework.

One thing I have realized from these changes is that he KNNMethodContext class needs to be sured-up a bit to be more robust. I will create a separate issue for this.

Check List

  • Commits are signed per the DCO using --signoff.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@jmazanec15 jmazanec15 added Refactoring Improve the design, structure, and implementation while preserving its functionality backport 2.x labels Aug 2, 2024
Generalizes the KNNLibrary to return an object for both search and
indexing so that the plugin can search/index against them. This will
help properly pass information that does not need to be sent to the JNI
for search and index builds.

Signed-off-by: John Mazanec <[email protected]>
naveentatikonda
naveentatikonda previously approved these changes Aug 2, 2024
@heemin32
Copy link
Collaborator

heemin32 commented Aug 2, 2024

How about getKNNLibraryIndexingContext?

heemin32
heemin32 previously approved these changes Aug 2, 2024
@@ -14,7 +14,7 @@
/**
* Default HNSW context for all engines. Have a different implementation if engine context differs.
*/
public final class DefaultHnswContext implements EngineSpecificMethodContext {
public final class DefaultHnswContext implements KNNLibrarySearchContext {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe DefaultHnswSearchContext?

@@ -11,7 +11,7 @@

import java.util.Map;

public final class DefaultIVFContext implements EngineSpecificMethodContext {
public final class DefaultIVFContext implements KNNLibrarySearchContext {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe DefaultIVFSearchContext?

import org.opensearch.knn.index.engine.Parameter;
import org.opensearch.knn.index.engine.model.QueryContext;
import org.opensearch.knn.index.query.request.MethodParameter;

import java.util.Collections;
import java.util.Map;

public class LuceneHNSWContext implements EngineSpecificMethodContext {
public class LuceneHNSWContext implements KNNLibrarySearchContext {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LuceneHNSWSearchContext

@jmazanec15 jmazanec15 dismissed stale reviews from heemin32 and naveentatikonda via 6ce13f2 August 2, 2024 19:08
@jmazanec15 jmazanec15 requested a review from heemin32 August 2, 2024 19:08
@jmazanec15
Copy link
Member Author

Addressed @heemin32 !

* Simple implementation of {@link KNNLibraryIndexBuildContext}
*/
@Builder
public class KNNLibraryIndexBuildContextImpl implements KNNLibraryIndexBuildContext {
Copy link
Collaborator

@heemin32 heemin32 Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class KNNLibraryIndexBuildContextImpl implements KNNLibraryIndexBuildContext {
public class KNNLibraryIndexingContextImpl implements KNNLibraryIndexingContext {

Signed-off-by: John Mazanec <[email protected]>
Copy link
Collaborator

@heemin32 heemin32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jmazanec15 jmazanec15 merged commit a16b8aa into opensearch-project:main Aug 2, 2024
29 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 2, 2024
Generalizes the KNNLibrary to return an object for both search and
indexing so that the plugin can search/index against them. This will
help properly pass information that does not need to be sent to the JNI
for search and index builds.

Signed-off-by: John Mazanec <[email protected]>
(cherry picked from commit a16b8aa)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Refactoring Improve the design, structure, and implementation while preserving its functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants