Skip to content

Commit

Permalink
Move engine and lib components into separate files (#445)
Browse files Browse the repository at this point in the history
Refactors library and engine structure to be less coupled. Pulls classes
and interfaces out into individual files. Cleans up implementation.

Co-authored-by: John Mazanec <jmazane@amazon.com>
  • Loading branch information
opensearch-trigger-bot[bot] and jmazanec15 authored Jul 13, 2022
1 parent 9930909 commit 32395a3
Show file tree
Hide file tree
Showing 11 changed files with 642 additions and 756 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,7 @@ public void addKNNBinaryField(FieldInfo field, DocValuesProducer valuesProducer)

KNNEngine knnEngine = model.getModelMetadata().getKnnEngine();

engineFileName = buildEngineFileName(
state.segmentInfo.name,
knnEngine.getLatestBuildVersion(),
field.name,
knnEngine.getExtension()
);
engineFileName = buildEngineFileName(state.segmentInfo.name, knnEngine.getVersion(), field.name, knnEngine.getExtension());
indexPath = Paths.get(((FSDirectory) (FilterDirectory.unwrap(state.directory))).getDirectory().toString(), engineFileName)
.toString();

Expand All @@ -119,12 +114,7 @@ public void addKNNBinaryField(FieldInfo field, DocValuesProducer valuesProducer)
String engineName = field.attributes().getOrDefault(KNNConstants.KNN_ENGINE, KNNEngine.DEFAULT.getName());
KNNEngine knnEngine = KNNEngine.getEngine(engineName);

engineFileName = buildEngineFileName(
state.segmentInfo.name,
knnEngine.getLatestBuildVersion(),
field.name,
knnEngine.getExtension()
);
engineFileName = buildEngineFileName(state.segmentInfo.name, knnEngine.getVersion(), field.name, knnEngine.getExtension());
indexPath = Paths.get(((FSDirectory) (FilterDirectory.unwrap(state.directory))).getDirectory().toString(), engineFileName)
.toString();

Expand Down
327 changes: 327 additions & 0 deletions src/main/java/org/opensearch/knn/index/util/Faiss.java

Large diffs are not rendered by default.

23 changes: 6 additions & 17 deletions src/main/java/org/opensearch/knn/index/util/KNNEngine.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.knn.index.util;
Expand Down Expand Up @@ -42,8 +36,8 @@ public enum KNNEngine implements KNNLibrary {
this.knnLibrary = knnLibrary;
}

private String name;
private KNNLibrary knnLibrary;
private final String name;
private final KNNLibrary knnLibrary;

/**
* Get the engine
Expand All @@ -60,7 +54,7 @@ public static KNNEngine getEngine(String name) {
return FAISS;
}

throw new IllegalArgumentException("Invalid engine type: " + name);
throw new IllegalArgumentException(String.format("Invalid engine type: %s", name));
}

/**
Expand Down Expand Up @@ -91,13 +85,8 @@ public String getName() {
}

@Override
public String getLatestBuildVersion() {
return knnLibrary.getLatestBuildVersion();
}

@Override
public String getLatestLibVersion() {
return knnLibrary.getLatestLibVersion();
public String getVersion() {
return knnLibrary.getVersion();
}

@Override
Expand Down
Loading

0 comments on commit 32395a3

Please sign in to comment.