Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.common.collect.Lists;
import com.google.common.util.concurrent.*;
import com.google.gson.reflect.TypeToken;
import io.grpc.StatusRuntimeException;
import io.milvus.common.utils.GTsDict;
import io.milvus.common.utils.JsonUtils;
Expand Down Expand Up @@ -1331,9 +1332,22 @@ public R<RpcStatus> createIndex(@NonNull CreateIndexParam requestParam) {
try {
// prepare index parameters
CreateIndexRequest.Builder createIndexRequestBuilder = CreateIndexRequest.newBuilder();
List<KeyValuePair> extraParamList = ParamUtils.AssembleKvPair(requestParam.getExtraParam());
if (CollectionUtils.isNotEmpty(extraParamList)) {
extraParamList.forEach(createIndexRequestBuilder::addExtraParams);
Map<String, String> extraParams = requestParam.getExtraParam();
for (Map.Entry<String, String> entry : extraParams.entrySet()) {
if (entry.getKey().equals(Constant.PARAMS)) {
Map<String, String> tempParams = JsonUtils.fromJson(entry.getValue(), new TypeToken<Map<String, String>>() {}.getType());
for (String key : tempParams.keySet()) {
createIndexRequestBuilder.addExtraParams(KeyValuePair.newBuilder()
.setKey(key)
.setValue(tempParams.get(key))
.build());
}
} else {
createIndexRequestBuilder.addExtraParams(KeyValuePair.newBuilder()
.setKey(entry.getKey())
.setValue(entry.getValue())
.build());
}
}

CreateIndexRequest.Builder builder = createIndexRequestBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package io.milvus.response;

import com.google.gson.reflect.TypeToken;
import io.milvus.common.utils.JsonUtils;
import io.milvus.grpc.IndexDescription;
import io.milvus.grpc.DescribeIndexResponse;

Expand Down Expand Up @@ -149,12 +151,18 @@ public MetricType getMetricType() {
}

public String getExtraParam() {
if (this.params.containsKey(Constant.PARAMS)) {
// may throw IllegalArgumentException
return params.get(Constant.PARAMS);
Map<String, String> extraParams = new HashMap<>();
for (Map.Entry<String, String> entry : this.params.entrySet()) {
if (entry.getKey().equals(Constant.INDEX_TYPE) || entry.getKey().equals(Constant.METRIC_TYPE)) {
} else if (entry.getKey().equals(Constant.PARAMS)) {
Map<String, String> tempParams = JsonUtils.fromJson(entry.getValue(), new TypeToken<Map<String, String>>() {}.getType());
extraParams.putAll(tempParams);
} else {
extraParams.put(entry.getKey(), entry.getValue());
}
}

return "";
return JsonUtils.toJson(extraParams);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,12 @@ public Void createIndex(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub
}
Map<String, Object> extraParams = indexParam.getExtraParams();
if (extraParams != null && !extraParams.isEmpty()) {
JsonObject params = new JsonObject();
for (String key : extraParams.keySet()) {
params.addProperty(key, extraParams.get(key).toString());
builder.addExtraParams(KeyValuePair.newBuilder()
.setKey(key)
.setValue(extraParams.get(key).toString())
.build());
}
// the extra params is a JSON format string like "{\"M\": 8, \"efConstruction\": 64}"
builder.addExtraParams(KeyValuePair.newBuilder()
.setKey(Constant.PARAMS)
.setValue(params.toString())
.build());
}

Status status = blockingStub.createIndex(builder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,17 @@ public static final class IndexDesc {
private IndexBuildState indexState = IndexBuildState.IndexStateNone;
@Builder.Default
String indexFailedReason = "";

// In 2.4/2.5, properties only contains one item "mmap.enabled".
// To keep consistence with other SDKs, we intend to remove this member from IndexDesc,
// and put "mmap.enabled" into the "extraParams", the reasons:
// (1) when createIndex() is call, "mmap.enabled" is passed by the IndexParam.extraParams
// (2) other SDKs don't have a "properties" member for describeIndex()
// (3) now the "mmap.enabled" is dispatched to "properties" by ConvertUtils.convertToDescribeIndexResp(),
// once there are new property available, the new property will be dispatched to "extraParams",
// the "properties" member is not maintainable.
@Builder.Default
@Deprecated
private Map<String, String> properties = new HashMap<>();
}
}
9 changes: 7 additions & 2 deletions sdk-core/src/main/java/io/milvus/v2/utils/ConvertUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ public DescribeIndexResp convertToDescribeIndexResp(List<IndexDescription> respo
// may throw IllegalArgumentException
metricType = IndexParam.MetricType.valueOf(param.getValue());
} else if (param.getKey().equals(Constant.MMAP_ENABLED)) {
properties.put(param.getKey(), param.getValue());
properties.put(param.getKey(), param.getValue()); // just for compatible with old versions
extraParams.put(param.getKey(), param.getValue());
} else if (param.getKey().equals(Constant.PARAMS)) {
extraParams = JsonUtils.fromJson(param.getValue(), new TypeToken<Map<String, String>>() {}.getType());
Map<String, String> tempParams = JsonUtils.fromJson(param.getValue(), new TypeToken<Map<String, String>>() {}.getType());
tempParams.remove(Constant.MMAP_ENABLED); // "mmap.enabled" in "params" is not processed by server
extraParams.putAll(tempParams);
} else {
extraParams.put(param.getKey(), param.getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@
import io.milvus.param.highlevel.dml.GetIdsParam;
import io.milvus.param.highlevel.dml.response.DeleteResponse;
import io.milvus.param.highlevel.dml.response.GetResponse;
import io.milvus.param.index.CreateIndexParam;
import io.milvus.param.index.DescribeIndexParam;
import io.milvus.param.index.DropIndexParam;
import io.milvus.param.index.GetIndexStateParam;
import io.milvus.param.index.*;
import io.milvus.param.partition.GetPartitionStatisticsParam;
import io.milvus.param.partition.ShowPartitionsParam;
import io.milvus.pool.MilvusClientV1Pool;
Expand Down Expand Up @@ -457,13 +454,14 @@ void testFloatVectors() {
Assertions.assertEquals(R.Status.Success.getCode(), createIndexR.getStatus().intValue());

// create index on vector field
String params = "{\"efConstruction\":64,\"M\":16,\"mmap.enabled\":true}";
indexParam = CreateIndexParam.newBuilder()
.withCollectionName(randomCollectionName)
.withFieldName(DataType.FloatVector.name())
.withIndexName("abv")
.withIndexType(IndexType.HNSW)
.withMetricType(MetricType.L2)
.withExtraParam("{\"M\":16,\"efConstruction\":64}")
.withExtraParam(params)
.withSyncMode(Boolean.TRUE)
.withSyncWaitingInterval(500L)
.withSyncWaitingTimeout(30L)
Expand Down Expand Up @@ -491,8 +489,24 @@ void testFloatVectors() {
Assertions.assertEquals(rowCount, indexDesc.getIndexedRows());
Assertions.assertEquals(0L, indexDesc.getPendingIndexRows());
Assertions.assertTrue(indexDesc.getIndexFailedReason().isEmpty());
String extraParams = indexDesc.getExtraParam();
Assertions.assertEquals(params.replace("\"", ""), extraParams.replace("\"", ""));
System.out.println("Index description: " + indexDesc.toString());

R<RpcStatus> alterR = client.alterIndex(AlterIndexParam.newBuilder()
.withCollectionName(randomCollectionName)
.withIndexName("abv")
.withMMapEnabled(false)
.build());
Assertions.assertEquals(R.Status.Success.getCode(), alterR.getStatus().intValue());

descIndexR = client.describeIndex(descIndexParam);
Assertions.assertEquals(R.Status.Success.getCode(), descIndexR.getStatus().intValue());
indexDescWrapper = new DescIndexResponseWrapper(descIndexR.getData());
indexDesc = indexDescWrapper.getIndexDescByFieldName(DataType.FloatVector.name());
extraParams = indexDesc.getExtraParam();
Assertions.assertEquals("{efConstruction:64,M:16,mmap.enabled:false}", extraParams.replace("\"", ""));

// load collection
R<RpcStatus> loadR = client.loadCollection(LoadCollectionParam.newBuilder()
.withCollectionName(randomCollectionName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ void createIndex() {
.withFieldName("aaa")
.withIndexType(IndexType.IVF_FLAT)
.withMetricType(MetricType.L2)
.withExtraParam("dummy")
.withExtraParam("{\"dummy\": 0}")
.withSyncMode(Boolean.TRUE)
.withSyncWaitingInterval(500L)
.withSyncWaitingTimeout(2L)
Expand All @@ -1445,7 +1445,7 @@ void createIndex() {
.withFieldName("field1")
.withIndexType(IndexType.BIN_IVF_FLAT)
.withMetricType(MetricType.L2)
.withExtraParam("dummy")
.withExtraParam("{\"dummy\": 1}")
.withSyncMode(Boolean.TRUE)
.withSyncWaitingInterval(500L)
.withSyncWaitingTimeout(2L)
Expand All @@ -1472,7 +1472,7 @@ void createIndex() {
.withFieldName("field1")
.withIndexType(IndexType.IVF_FLAT)
.withMetricType(MetricType.L2)
.withExtraParam("dummy")
.withExtraParam("{\"dummy\": 2}")
.withSyncMode(Boolean.TRUE)
.withSyncWaitingInterval(500L)
.withSyncWaitingTimeout(2L)
Expand Down Expand Up @@ -2737,7 +2737,8 @@ void testDescIndexResponseWrapper() {
assertEquals(fieldName, indexDesc.getFieldName());
assertEquals(indexType, indexDesc.getIndexType());
assertEquals(metricType, indexDesc.getMetricType());
assertEquals(0, extraParam.compareTo(indexDesc.getExtraParam()));
String params = indexDesc.getExtraParam();
assertEquals(0, extraParam.compareTo(params.replace("\"", "")));

assertFalse(wrapper.toString().isEmpty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,9 @@ void testIndex() {
Map<String, String> indexProps = desc.getProperties();
Assertions.assertTrue(indexProps.containsKey(Constant.MMAP_ENABLED));
Assertions.assertEquals("false", indexProps.get(Constant.MMAP_ENABLED));
extraParams = desc.getExtraParams();
Assertions.assertTrue(extraParams.containsKey(Constant.MMAP_ENABLED));
Assertions.assertEquals("false", extraParams.get(Constant.MMAP_ENABLED));

client.dropIndexProperties(DropIndexPropertiesReq.builder()
.collectionName(randomCollectionName)
Expand All @@ -1261,6 +1264,8 @@ void testIndex() {
desc = descResp.getIndexDescByFieldName("vector");
indexProps = desc.getProperties();
Assertions.assertFalse(indexProps.containsKey(Constant.MMAP_ENABLED));
extraParams = desc.getExtraParams();
Assertions.assertFalse(extraParams.containsKey(Constant.MMAP_ENABLED));

// drop index
client.dropIndex(DropIndexReq.builder()
Expand Down
Loading