Skip to content

Commit

Permalink
Fix test case and merge failure
Browse files Browse the repository at this point in the history
Signed-off-by: John Mazanec <[email protected]>
  • Loading branch information
jmazanec15 committed Oct 5, 2021
1 parent acecd04 commit 9ed7e52
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,6 @@ public KNNVectorFieldMapper build(BuilderContext context) {
// sometimes used to initialize the cluster state/update cluster state, we cannot get the state here
// safely. So, we are unable to validate the model. The model gets validated during ingestion.

if (modelMetadata == null) {
throw new IllegalArgumentException("Model \"" + modelId + "\" does not exist");
}

return new ModelFieldMapper(
name,
new KNNVectorFieldType(buildFullName(context), meta.getValue(), -1, modelIdAsString),
Expand Down Expand Up @@ -319,9 +315,7 @@ public static class KNNVectorFieldType extends MappedFieldType {
String modelId;

public KNNVectorFieldType(String name, Map<String, String> meta, int dimension) {
super(name, false, false, true, TextSearchInfo.NONE, meta);
this.dimension = dimension;
this.modelId = null; // By default, this is null. It will only be set for a mapping with a modelId set.
this(name, meta, dimension, null);
}

public KNNVectorFieldType(String name, Map<String, String> meta, int dimension, String modelId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

import com.google.common.collect.ImmutableMap;
import org.opensearch.action.ActionListener;
import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.opensearch.action.support.master.AcknowledgedResponse;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.opensearch.common.settings.Settings;
import org.opensearch.knn.KNNSingleNodeTestCase;
import org.opensearch.knn.index.util.KNNEngine;
import org.opensearch.knn.indices.Model;
Expand All @@ -24,6 +23,8 @@
import org.opensearch.knn.indices.ModelState;

import java.io.IOException;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand All @@ -50,7 +51,7 @@ public void testCreateIndexFromModel() throws IOException, InterruptedException

// Setup model
ModelMetadata modelMetadata = new ModelMetadata(knnEngine, spaceType, dimension, ModelState.CREATED,
TimeValue.timeValueDays(3), "", "");
ZonedDateTime.now(ZoneOffset.UTC).toString(), "", "");

Model model = new Model(modelMetadata, modelBlob);

Expand All @@ -59,19 +60,36 @@ public void testCreateIndexFromModel() throws IOException, InterruptedException

final CountDownLatch inProgressLatch = new CountDownLatch(1);

ActionListener<AcknowledgedResponse> mappingListener = ActionListener.wrap(response -> {
assertTrue(response.isAcknowledged());
inProgressLatch.countDown();
}, e -> fail("Unable to put mapping: " + e.getMessage()));

String indexName = "test-index";
String fieldName = "test-field";

modelDao.put(modelId, model, ActionListener.wrap(indexResponse -> {
createKNNIndex("test-index");
PutMappingRequest request = new PutMappingRequest(indexName).type("_doc");
request.source(fieldName, "type=knn_vector,model_id=" + modelId);
client().admin().indices().putMapping(request, mappingListener);
CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(indexName)
.setSettings(Settings.builder()
.put("number_of_shards", 1)
.put("number_of_replicas", 0)
.put("index.knn", true)
.build()
).addMapping(
"_doc", ImmutableMap.of(
"properties", ImmutableMap.of(
fieldName, ImmutableMap.of(
"type", "knn_vector",
"model_id", modelId
)
)
)
);

client().admin().indices().create(createIndexRequestBuilder.request(),
ActionListener.wrap(
createIndexResponse -> {
assertTrue(createIndexResponse.isAcknowledged());
inProgressLatch.countDown();
}, e -> fail("Unable to create index: " + e.getMessage())
)
);

}, e ->fail("Unable to put model: " + e.getMessage())));

assertTrue(inProgressLatch.await(20, TimeUnit.SECONDS));
Expand Down

0 comments on commit 9ed7e52

Please sign in to comment.