Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
Signed-off-by: John Mazanec <[email protected]>
  • Loading branch information
jmazanec15 committed Aug 2, 2024
1 parent 00002b3 commit 2149099
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public KNNLibrarySearchContext getKNNLibrarySearchContext(String methodName) {
}

@Override
public KNNLibraryIndexBuildContext getKNNLibraryIndexBuildContext(KNNMethodContext knnMethodContext) {
public KNNLibraryIndexingContext getKNNLibraryIndexingContext(KNNMethodContext knnMethodContext) {
String method = knnMethodContext.getMethodComponentContext().getName();
validateMethodExists(method);
KNNMethod knnMethod = methods.get(method);
return knnMethod.getKNNLibraryIndexBuildContext(knnMethodContext);
return knnMethod.getKNNLibraryIndexingContext(knnMethodContext);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ public int estimateOverheadInKB(KNNMethodContext knnMethodContext, int dimension
}

@Override
public KNNLibraryIndexBuildContext getKNNLibraryIndexBuildContext(KNNMethodContext knnMethodContext) {
public KNNLibraryIndexingContext getKNNLibraryIndexingContext(KNNMethodContext knnMethodContext) {
Map<String, Object> parameterMap = new HashMap<>(methodComponent.getAsMap(knnMethodContext.getMethodComponentContext()));
parameterMap.put(KNNConstants.SPACE_TYPE, knnMethodContext.getSpaceType().getValue());
return KNNLibraryIndexBuildContextImpl.builder().parameters(parameterMap).build();
return KNNLibraryIndexingContextImpl.builder().parameters(parameterMap).build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* Default HNSW context for all engines. Have a different implementation if engine context differs.
*/
public final class DefaultHnswContext implements KNNLibrarySearchContext {
public final class DefaultHnswSearchContext implements KNNLibrarySearchContext {

private final Map<String, Parameter<?>> supportedMethodParameters = ImmutableMap.<String, Parameter<?>>builder()
.put(MethodParameter.EF_SEARCH.getName(), new Parameter.IntegerParameter(MethodParameter.EF_SEARCH.getName(), null, value -> true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import java.util.Map;

public final class DefaultIVFContext implements KNNLibrarySearchContext {
public final class DefaultIVFSearchContext implements KNNLibrarySearchContext {

private final Map<String, Parameter<?>> supportedMethodParameters = ImmutableMap.<String, Parameter<?>>builder()
.put(MethodParameter.NPROBE.getName(), new Parameter.IntegerParameter(MethodParameter.NPROBE.getName(), null, value -> true))
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/opensearch/knn/index/engine/KNNEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ public boolean isTrainingRequired(KNNMethodContext knnMethodContext) {
}

@Override
public KNNLibraryIndexBuildContext getKNNLibraryIndexBuildContext(KNNMethodContext knnMethodContext) {
return knnLibrary.getKNNLibraryIndexBuildContext(knnMethodContext);
public KNNLibraryIndexingContext getKNNLibraryIndexingContext(KNNMethodContext knnMethodContext) {
return knnLibrary.getKNNLibraryIndexingContext(knnMethodContext);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public interface KNNLibrary {
* @param knnMethodContext to get build context for
* @return parameter map
*/
KNNLibraryIndexBuildContext getKNNLibraryIndexBuildContext(KNNMethodContext knnMethodContext);
KNNLibraryIndexingContext getKNNLibraryIndexingContext(KNNMethodContext knnMethodContext);

/**
* Gets metadata related to methods supported by the library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
/**
* Context a library gives to build one of its indices
*/
public interface KNNLibraryIndexBuildContext {
public interface KNNLibraryIndexingContext {
/**
* Get map of parameters that get passed to the library to build the index
*
* @return Map of parameters
*/
Map<String, Object> getLibraryParameters();

KNNLibraryIndexBuildContext EMPTY = Collections::emptyMap;
KNNLibraryIndexingContext EMPTY = Collections::emptyMap;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import java.util.Map;

/**
* Simple implementation of {@link KNNLibraryIndexBuildContext}
* Simple implementation of {@link KNNLibraryIndexingContext}
*/
@Builder
public class KNNLibraryIndexBuildContextImpl implements KNNLibraryIndexBuildContext {
public class KNNLibraryIndexingContextImpl implements KNNLibraryIndexingContext {

private Map<String, Object> parameters;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/opensearch/knn/index/engine/KNNMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public interface KNNMethod {
* Parse knnMethodContext into context that the library can use to build the index
*
* @param knnMethodContext to generate the context for
* @return KNNLibraryIndexBuildContext
* @return KNNLibraryIndexingContext
*/
KNNLibraryIndexBuildContext getKNNLibraryIndexBuildContext(KNNMethodContext knnMethodContext);
KNNLibraryIndexingContext getKNNLibraryIndexingContext(KNNMethodContext knnMethodContext);

/**
* Get the search context for a particular method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.opensearch.knn.index.KNNSettings;
import org.opensearch.knn.index.SpaceType;
import org.opensearch.knn.index.engine.AbstractKNNMethod;
import org.opensearch.knn.index.engine.DefaultHnswContext;
import org.opensearch.knn.index.engine.DefaultHnswSearchContext;
import org.opensearch.knn.index.engine.Encoder;
import org.opensearch.knn.index.engine.MethodComponent;
import org.opensearch.knn.index.engine.MethodComponentContext;
Expand Down Expand Up @@ -51,7 +51,7 @@ public class FaissHNSWMethod extends AbstractKNNMethod {
* @see AbstractKNNMethod
*/
public FaissHNSWMethod() {
super(initMethodComponent(), Set.copyOf(SUPPORTED_SPACES), new DefaultHnswContext());
super(initMethodComponent(), Set.copyOf(SUPPORTED_SPACES), new DefaultHnswSearchContext());
}

private static MethodComponent initMethodComponent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.opensearch.knn.common.KNNConstants;
import org.opensearch.knn.index.SpaceType;
import org.opensearch.knn.index.engine.AbstractKNNMethod;
import org.opensearch.knn.index.engine.DefaultIVFContext;
import org.opensearch.knn.index.engine.DefaultIVFSearchContext;
import org.opensearch.knn.index.engine.Encoder;
import org.opensearch.knn.index.engine.MethodComponent;
import org.opensearch.knn.index.engine.MethodComponentContext;
Expand Down Expand Up @@ -55,7 +55,7 @@ public class FaissIVFMethod extends AbstractKNNMethod {
* @see AbstractKNNMethod
*/
public FaissIVFMethod() {
super(initMethodComponent(), Set.copyOf(SUPPORTED_SPACES), new DefaultIVFContext());
super(initMethodComponent(), Set.copyOf(SUPPORTED_SPACES), new DefaultIVFSearchContext());
}

private static MethodComponent initMethodComponent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class LuceneHNSWMethod extends AbstractKNNMethod {
* @see AbstractKNNMethod
*/
public LuceneHNSWMethod() {
super(initMethodComponent(), Set.copyOf(SUPPORTED_SPACES), new LuceneHNSWContext());
super(initMethodComponent(), Set.copyOf(SUPPORTED_SPACES), new LuceneHNSWSearchContext());
}

private static MethodComponent initMethodComponent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.Collections;
import java.util.Map;

public class LuceneHNSWContext implements KNNLibrarySearchContext {
public class LuceneHNSWSearchContext implements KNNLibrarySearchContext {

private final Map<String, Parameter<?>> supportedMethodParameters = ImmutableMap.<String, Parameter<?>>builder()
.put(MethodParameter.EF_SEARCH.getName(), new Parameter.IntegerParameter(MethodParameter.EF_SEARCH.getName(), null, value -> true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.opensearch.knn.index.KNNSettings;
import org.opensearch.knn.index.SpaceType;
import org.opensearch.knn.index.engine.AbstractKNNMethod;
import org.opensearch.knn.index.engine.DefaultHnswContext;
import org.opensearch.knn.index.engine.DefaultHnswSearchContext;
import org.opensearch.knn.index.engine.MethodComponent;
import org.opensearch.knn.index.engine.Parameter;

Expand Down Expand Up @@ -39,7 +39,7 @@ public class NmslibHNSWMethod extends AbstractKNNMethod {
* @see AbstractKNNMethod
*/
public NmslibHNSWMethod() {
super(initMethodComponent(), Set.copyOf(SUPPORTED_SPACES), new DefaultHnswContext());
super(initMethodComponent(), Set.copyOf(SUPPORTED_SPACES), new DefaultHnswSearchContext());
}

private static MethodComponent initMethodComponent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class MethodFieldMapper extends KNNVectorFieldMapper {
this.fieldType.putAttribute(KNN_ENGINE, knnEngine.getName());

try {
Map<String, Object> libParams = knnEngine.getKNNLibraryIndexBuildContext(knnMethodContext).getLibraryParameters();
Map<String, Object> libParams = knnEngine.getKNNLibraryIndexingContext(knnMethodContext).getLibraryParameters();
this.fieldType.putAttribute(PARAMETERS, XContentFactory.jsonBuilder().map(libParams).toString());
} catch (IOException ioe) {
throw new RuntimeException(String.format("Unable to create KNNVectorFieldMapper: %s", ioe));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/opensearch/knn/training/TrainingJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void run() {
setVersionInKnnMethodContext();
Map<String, Object> trainParameters = model.getModelMetadata()
.getKnnEngine()
.getKNNLibraryIndexBuildContext(knnMethodContext)
.getKNNLibraryIndexingContext(knnMethodContext)
.getLibraryParameters();
trainParameters.put(
KNNConstants.INDEX_THREAD_QTY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void testAddKNNBinaryField_fromScratch_nmslibCurrent() throws IOException
);

String parameterString = XContentFactory.jsonBuilder()
.map(knnEngine.getKNNLibraryIndexBuildContext(knnMethodContext).getLibraryParameters())
.map(knnEngine.getKNNLibraryIndexingContext(knnMethodContext).getLibraryParameters())
.toString();

FieldInfo[] fieldInfoArray = new FieldInfo[] {
Expand Down Expand Up @@ -331,7 +331,7 @@ public void testAddKNNBinaryField_fromScratch_faissCurrent() throws IOException
knnMethodContext.getMethodComponentContext().setIndexVersion(Version.CURRENT);

String parameterString = XContentFactory.jsonBuilder()
.map(knnEngine.getKNNLibraryIndexBuildContext(knnMethodContext).getLibraryParameters())
.map(knnEngine.getKNNLibraryIndexingContext(knnMethodContext).getLibraryParameters())
.toString();

FieldInfo[] fieldInfoArray = new FieldInfo[] {
Expand Down Expand Up @@ -398,7 +398,7 @@ public void testAddKNNBinaryField_whenFaissBinary_thenAdded() throws IOException
knnMethodContext.getMethodComponentContext().setIndexVersion(Version.CURRENT);

String parameterString = XContentFactory.jsonBuilder()
.map(knnEngine.getKNNLibraryIndexBuildContext(knnMethodContext).getLibraryParameters())
.map(knnEngine.getKNNLibraryIndexingContext(knnMethodContext).getLibraryParameters())
.toString();

FieldInfo[] fieldInfoArray = new FieldInfo[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AbstractKNNLibraryTests extends KNNTestCase {
private final static KNNMethod INVALID_METHOD_THROWS_VALIDATION = new AbstractKNNMethod(
MethodComponent.Builder.builder(INVALID_METHOD_THROWS_VALIDATION_NAME).build(),
Set.of(SpaceType.DEFAULT),
new DefaultHnswContext()
new DefaultHnswSearchContext()
) {
@Override
public ValidationException validate(KNNMethodContext knnMethodContext) {
Expand Down Expand Up @@ -83,7 +83,7 @@ public void testEngineSpecificMethods() {
);
}

public void testGetKNNLibraryIndexBuildContext() {
public void testGetKNNLibraryIndexingContext() {
// Check that map is expected
Map<String, Object> expectedMap = new HashMap<>(VALID_EXPECTED_MAP);
expectedMap.put(KNNConstants.SPACE_TYPE, SpaceType.DEFAULT.getValue());
Expand All @@ -92,15 +92,15 @@ public void testGetKNNLibraryIndexBuildContext() {
SpaceType.DEFAULT,
new MethodComponentContext(VALID_METHOD_NAME, Collections.emptyMap())
);
assertEquals(expectedMap, TEST_LIBRARY.getKNNLibraryIndexBuildContext(knnMethodContext).getLibraryParameters());
assertEquals(expectedMap, TEST_LIBRARY.getKNNLibraryIndexingContext(knnMethodContext).getLibraryParameters());

// Check when invalid method is passed in
KNNMethodContext invalidKnnMethodContext = new KNNMethodContext(
KNNEngine.DEFAULT,
SpaceType.DEFAULT,
new MethodComponentContext("invalid", Collections.emptyMap())
);
expectThrows(IllegalArgumentException.class, () -> TEST_LIBRARY.getKNNLibraryIndexBuildContext(invalidKnnMethodContext));
expectThrows(IllegalArgumentException.class, () -> TEST_LIBRARY.getKNNLibraryIndexingContext(invalidKnnMethodContext));
}

private static class TestAbstractKNNLibrary extends AbstractKNNLibrary {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void testValidateWithData() throws IOException {
assertNull(knnMethod.validateWithData(knnMethodContext3, testVectorSpaceInfo));
}

public void testGetKNNLibraryIndexBuildContext() {
public void testGetKNNLibraryIndexingContext() {
SpaceType spaceType = SpaceType.DEFAULT;
String methodName = "test-method";
Map<String, Object> generatedMap = ImmutableMap.of("test-key", "test-value");
Expand All @@ -154,15 +154,15 @@ public void testGetKNNLibraryIndexBuildContext() {

assertEquals(
expectedMap,
knnMethod.getKNNLibraryIndexBuildContext(
knnMethod.getKNNLibraryIndexingContext(
new KNNMethodContext(KNNEngine.DEFAULT, spaceType, new MethodComponentContext(methodName, generatedMap))
).getLibraryParameters()
);
}

public void testGetKNNLibrarySearchContext() {
String methodName = "test-method";
KNNLibrarySearchContext knnLibrarySearchContext = new DefaultHnswContext();
KNNLibrarySearchContext knnLibrarySearchContext = new DefaultHnswSearchContext();
KNNMethod knnMethod = new TestKNNMethod(
MethodComponent.Builder.builder(methodName).build(),
Set.of(SpaceType.L2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testGetMethodAsMap_whenMethodIsHNSWFlat_thenCreateCorrectIndexDescri
KNNMethodContext knnMethodContext = KNNMethodContext.parse(in);
knnMethodContext.getMethodComponentContext().setIndexVersion(Version.CURRENT);

Map<String, Object> map = Faiss.INSTANCE.getKNNLibraryIndexBuildContext(knnMethodContext).getLibraryParameters();
Map<String, Object> map = Faiss.INSTANCE.getKNNLibraryIndexingContext(knnMethodContext).getLibraryParameters();

assertTrue(map.containsKey(INDEX_DESCRIPTION_PARAMETER));
assertEquals(expectedIndexDescription, map.get(INDEX_DESCRIPTION_PARAMETER));
Expand Down Expand Up @@ -84,7 +84,7 @@ public void testGetMethodAsMap_whenMethodIsHNSWPQ_thenCreateCorrectIndexDescript
KNNMethodContext knnMethodContext = KNNMethodContext.parse(in);
knnMethodContext.getMethodComponentContext().setIndexVersion(Version.CURRENT);

Map<String, Object> map = Faiss.INSTANCE.getKNNLibraryIndexBuildContext(knnMethodContext).getLibraryParameters();
Map<String, Object> map = Faiss.INSTANCE.getKNNLibraryIndexingContext(knnMethodContext).getLibraryParameters();

assertTrue(map.containsKey(INDEX_DESCRIPTION_PARAMETER));
assertEquals(expectedIndexDescription, map.get(INDEX_DESCRIPTION_PARAMETER));
Expand Down Expand Up @@ -113,7 +113,7 @@ public void testGetMethodAsMap_whenMethodIsHNSWSQFP16_thenCreateCorrectIndexDesc
KNNMethodContext knnMethodContext = KNNMethodContext.parse(in);
knnMethodContext.getMethodComponentContext().setIndexVersion(Version.CURRENT);

Map<String, Object> map = Faiss.INSTANCE.getKNNLibraryIndexBuildContext(knnMethodContext).getLibraryParameters();
Map<String, Object> map = Faiss.INSTANCE.getKNNLibraryIndexingContext(knnMethodContext).getLibraryParameters();

assertTrue(map.containsKey(INDEX_DESCRIPTION_PARAMETER));
assertEquals(expectedIndexDescription, map.get(INDEX_DESCRIPTION_PARAMETER));
Expand All @@ -134,7 +134,7 @@ public void testGetMethodAsMap_whenMethodIsIVFFlat_thenCreateCorrectIndexDescrip
Map<String, Object> in = xContentBuilderToMap(xContentBuilder);
KNNMethodContext knnMethodContext = KNNMethodContext.parse(in);

Map<String, Object> map = Faiss.INSTANCE.getKNNLibraryIndexBuildContext(knnMethodContext).getLibraryParameters();
Map<String, Object> map = Faiss.INSTANCE.getKNNLibraryIndexingContext(knnMethodContext).getLibraryParameters();

assertTrue(map.containsKey(INDEX_DESCRIPTION_PARAMETER));
assertEquals(expectedIndexDescription, map.get(INDEX_DESCRIPTION_PARAMETER));
Expand Down Expand Up @@ -164,7 +164,7 @@ public void testGetMethodAsMap_whenMethodIsIVFPQ_thenCreateCorrectIndexDescripti
Map<String, Object> in = xContentBuilderToMap(xContentBuilder);
KNNMethodContext knnMethodContext = KNNMethodContext.parse(in);

Map<String, Object> map = Faiss.INSTANCE.getKNNLibraryIndexBuildContext(knnMethodContext).getLibraryParameters();
Map<String, Object> map = Faiss.INSTANCE.getKNNLibraryIndexingContext(knnMethodContext).getLibraryParameters();

assertTrue(map.containsKey(INDEX_DESCRIPTION_PARAMETER));
assertEquals(expectedIndexDescription, map.get(INDEX_DESCRIPTION_PARAMETER));
Expand Down Expand Up @@ -192,7 +192,7 @@ public void testGetMethodAsMap_whenMethodIsIVFSQFP16_thenCreateCorrectIndexDescr
Map<String, Object> in = xContentBuilderToMap(xContentBuilder);
KNNMethodContext knnMethodContext = KNNMethodContext.parse(in);

Map<String, Object> map = Faiss.INSTANCE.getKNNLibraryIndexBuildContext(knnMethodContext).getLibraryParameters();
Map<String, Object> map = Faiss.INSTANCE.getKNNLibraryIndexingContext(knnMethodContext).getLibraryParameters();

assertTrue(map.containsKey(INDEX_DESCRIPTION_PARAMETER));
assertEquals(expectedIndexDescription, map.get(INDEX_DESCRIPTION_PARAMETER));
Expand Down
Loading

0 comments on commit 2149099

Please sign in to comment.