Browse Source

query/search/get/createColl highLevel interface add params consistencyLevel (#545)

xushuang.hu 2 years ago
parent
commit
cb0134f6eb

+ 3 - 0
examples/main/java/io/milvus/HighLevelExample.java

@@ -22,6 +22,7 @@ package io.milvus;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import io.milvus.client.MilvusServiceClient;
+import io.milvus.common.clientenum.ConsistencyLevelEnum;
 import io.milvus.common.utils.JacksonUtils;
 import io.milvus.common.utils.VectorUtils;
 import io.milvus.grpc.*;
@@ -208,6 +209,7 @@ public class HighLevelExample {
                 .withLimit(100L)
                 .withOffset(0L)
                 .withOutputFields(Lists.newArrayList("int32", "int64"))
+                .withConsistencyLevel(ConsistencyLevelEnum.STRONG)
                 .build();
 
         R<SearchResponse> response = milvusClient.search(searchSimpleParam);
@@ -228,6 +230,7 @@ public class HighLevelExample {
                 .withOutputFields(Lists.newArrayList("int32", "int64"))
                 .withLimit(100L)
                 .withOffset(0L)
+                .withConsistencyLevel(ConsistencyLevelEnum.STRONG)
                 .build();
 
         R<QueryResponse> response = milvusClient.query(querySimpleParam);

+ 3 - 3
src/main/java/io/milvus/client/AbstractMilvusGrpcClient.java

@@ -2918,7 +2918,7 @@ public abstract class AbstractMilvusGrpcClient implements MilvusClient {
                     .withCollectionName(requestParam.getCollectionName())
                     .withExpr(expr)
                     .withOutFields(requestParam.getOutputFields())
-                    .withConsistencyLevel(ConsistencyLevelEnum.BOUNDED)
+                    .withConsistencyLevel(requestParam.getConsistencyLevel())
                     .build();
             R<QueryResults> queryResp = query(queryParam);
             QueryResultsWrapper queryResultsWrapper = new QueryResultsWrapper(queryResp.getData());
@@ -2962,7 +2962,7 @@ public abstract class AbstractMilvusGrpcClient implements MilvusClient {
                     .withOutFields(requestParam.getOutputFields())
                     .withOffset(requestParam.getOffset())
                     .withLimit(requestParam.getLimit())
-                    .withConsistencyLevel(ConsistencyLevelEnum.BOUNDED)
+                    .withConsistencyLevel(requestParam.getConsistencyLevel())
                     .build();
             R<QueryResults> response = query(queryParam);
             if(!Objects.equals(response.getStatus(), R.success().getStatus())){
@@ -3017,7 +3017,7 @@ public abstract class AbstractMilvusGrpcClient implements MilvusClient {
                     .withExpr(requestParam.getFilter())
                     .withTopK(requestParam.getLimit())
                     .withParams(JacksonUtils.toJsonString(requestParam.getParams()))
-                    .withConsistencyLevel(ConsistencyLevelEnum.BOUNDED)
+                    .withConsistencyLevel(requestParam.getConsistencyLevel())
                     .build();
 
             // search

+ 15 - 1
src/main/java/io/milvus/param/highlevel/collection/CreateSimpleCollectionParam.java

@@ -74,6 +74,8 @@ public class CreateSimpleCollectionParam {
         private boolean autoId = Boolean.FALSE;
         private boolean syncLoad = Boolean.TRUE;
 
+        private ConsistencyLevelEnum consistencyLevel = ConsistencyLevelEnum.BOUNDED;
+
         private Builder() {
         }
 
@@ -163,6 +165,18 @@ public class CreateSimpleCollectionParam {
             return this;
         }
 
+        /**
+         * Sets the consistency level. The default value is {@link ConsistencyLevelEnum#BOUNDED}.
+         * @see ConsistencyLevelEnum
+         *
+         * @param consistencyLevel consistency level
+         * @return <code>Builder</code>
+         */
+        public Builder withConsistencyLevel(@NonNull ConsistencyLevelEnum consistencyLevel) {
+            this.consistencyLevel = consistencyLevel;
+            return this;
+        }
+
         /**
          * Verifies parameters and creates a new {@link CreateSimpleCollectionParam} instance.
          *
@@ -189,7 +203,7 @@ public class CreateSimpleCollectionParam {
                     .withShardsNum(Constant.SHARD_NUMBER_DEFAULT)
                     .withDescription(description)
                     .withFieldTypes(fieldTypes)
-                    .withConsistencyLevel(ConsistencyLevelEnum.BOUNDED)
+                    .withConsistencyLevel(consistencyLevel)
                     .withEnableDynamicField(Boolean.TRUE)
                     .build();
 

+ 18 - 3
src/main/java/io/milvus/param/highlevel/dml/GetIdsParam.java

@@ -19,7 +19,7 @@
 
 package io.milvus.param.highlevel.dml;
 
-import com.google.common.collect.Lists;
+import io.milvus.common.clientenum.ConsistencyLevelEnum;
 import io.milvus.exception.ParamException;
 import io.milvus.param.ParamUtils;
 import lombok.Getter;
@@ -39,11 +39,13 @@ public class GetIdsParam {
     private final String collectionName;
     private final List<?> primaryIds;
     private final List<String> outputFields;
+    private final ConsistencyLevelEnum consistencyLevel;
 
     private GetIdsParam(@NonNull Builder builder) {
         this.collectionName = builder.collectionName;
         this.primaryIds = builder.primaryIds;
         this.outputFields = builder.outputFields;
+        this.consistencyLevel = builder.consistencyLevel;
     }
 
     public static Builder newBuilder() {
@@ -55,8 +57,10 @@ public class GetIdsParam {
      */
     public static class Builder<T> {
         private String collectionName;
-        private List<T> primaryIds = new ArrayList<>();
-        private final List<String> outputFields = Lists.newArrayList();
+        private final List<T> primaryIds = new ArrayList<>();
+        private final List<String> outputFields = new ArrayList<>();
+
+        private ConsistencyLevelEnum consistencyLevel = null;
 
         private Builder() {
         }
@@ -105,6 +109,17 @@ public class GetIdsParam {
             return this;
         }
 
+        /**
+         * ConsistencyLevel of consistency level.
+         *
+         * @param consistencyLevel consistency level
+         * @return <code>Builder</code>
+         */
+        public Builder withConsistencyLevel(ConsistencyLevelEnum consistencyLevel) {
+            this.consistencyLevel = consistencyLevel;
+            return this;
+        }
+
         /**
          * Verifies parameters and creates a new {@link GetIdsParam} instance.
          *

+ 15 - 0
src/main/java/io/milvus/param/highlevel/dml/QuerySimpleParam.java

@@ -19,6 +19,7 @@
 
 package io.milvus.param.highlevel.dml;
 
+import io.milvus.common.clientenum.ConsistencyLevelEnum;
 import io.milvus.exception.ParamException;
 import io.milvus.param.ParamUtils;
 import io.milvus.param.dml.QueryParam;
@@ -41,6 +42,7 @@ public class QuerySimpleParam {
     private final String filter;
     private final Long offset;
     private final Long limit;
+    private final ConsistencyLevelEnum consistencyLevel;
 
     private QuerySimpleParam(@NotNull Builder builder) {
         this.collectionName = builder.collectionName;
@@ -48,6 +50,7 @@ public class QuerySimpleParam {
         this.filter = builder.filter;
         this.offset = builder.offset;
         this.limit = builder.limit;
+        this.consistencyLevel = builder.consistencyLevel;
     }
 
     public static Builder newBuilder() {
@@ -63,6 +66,7 @@ public class QuerySimpleParam {
         private String filter = "";
         private Long offset = 0L;
         private Long limit = 0L;
+        private ConsistencyLevelEnum consistencyLevel = null;
 
         private Builder() {
         }
@@ -137,6 +141,17 @@ public class QuerySimpleParam {
             return this;
         }
 
+        /**
+         * ConsistencyLevel of consistency level.
+         *
+         * @param consistencyLevel consistency level
+         * @return <code>Builder</code>
+         */
+        public Builder withConsistencyLevel(ConsistencyLevelEnum consistencyLevel) {
+            this.consistencyLevel = consistencyLevel;
+            return this;
+        }
+
         /**
          * Verifies parameters and creates a new {@link QuerySimpleParam} instance.
          *

+ 16 - 0
src/main/java/io/milvus/param/highlevel/dml/SearchSimpleParam.java

@@ -20,9 +20,11 @@
 package io.milvus.param.highlevel.dml;
 
 import com.google.common.collect.Lists;
+import io.milvus.common.clientenum.ConsistencyLevelEnum;
 import io.milvus.exception.ParamException;
 import io.milvus.param.Constant;
 import io.milvus.param.ParamUtils;
+import io.milvus.param.dml.SearchParam;
 import lombok.Getter;
 import lombok.NonNull;
 import lombok.ToString;
@@ -47,6 +49,7 @@ public class SearchSimpleParam {
     private final int limit;
 
     private final Map<String, Object> params;
+    private final ConsistencyLevelEnum consistencyLevel;
 
     private SearchSimpleParam(@NotNull Builder builder) {
         this.collectionName = builder.collectionName;
@@ -56,6 +59,7 @@ public class SearchSimpleParam {
         this.offset = builder.offset;
         this.limit = builder.limit;
         this.params = builder.params;
+        this.consistencyLevel = builder.consistencyLevel;
     }
 
     public static Builder newBuilder() {
@@ -72,6 +76,7 @@ public class SearchSimpleParam {
         private String filter = "";
         private Long offset = 0L;
         private int limit = 10;
+        private ConsistencyLevelEnum consistencyLevel = null;
 
         private final Map<String, Object> params = new HashMap<>();
 
@@ -163,6 +168,17 @@ public class SearchSimpleParam {
             return this;
         }
 
+        /**
+         * ConsistencyLevel of consistency level.
+         *
+         * @param consistencyLevel consistency level
+         * @return <code>Builder</code>
+         */
+        public Builder withConsistencyLevel(ConsistencyLevelEnum consistencyLevel) {
+            this.consistencyLevel = consistencyLevel;
+            return this;
+        }
+
         /**
          * Verifies parameters and creates a new {@link SearchSimpleParam} instance.
          *