فهرست منبع

Support offset parameter for hybridSearch interface (#1360)

Signed-off-by: yhmo <yihua.mo@zilliz.com>
groot 1 ماه پیش
والد
کامیت
d21763f102

+ 3 - 2
sdk-core/src/main/java/io/milvus/param/ParamUtils.java

@@ -1046,8 +1046,9 @@ public class ParamUtils {
         // set ranker
         BaseRanker ranker = requestParam.getRanker();
         Map<String, String> props = ranker.getProperties();
-        props.put("limit", String.format("%d", requestParam.getTopK()));
-        props.put("round_decimal", String.format("%d", requestParam.getRoundDecimal()));
+        props.put(Constant.LIMIT, String.format("%d", requestParam.getTopK()));
+        props.put(Constant.ROUND_DECIMAL, String.format("%d", requestParam.getRoundDecimal()));
+        props.put(Constant.OFFSET, String.format("%d", requestParam.getOffset()));
         List<KeyValuePair> propertiesList = ParamUtils.AssembleKvPair(props);
         if (CollectionUtils.isNotEmpty(propertiesList)) {
             propertiesList.forEach(builder::addRankParams);

+ 15 - 1
sdk-core/src/main/java/io/milvus/param/dml/HybridSearchParam.java

@@ -44,6 +44,7 @@ public class HybridSearchParam {
     private final BaseRanker ranker;
     private final int topK;
     private final List<String> outFields;
+    private final long offset;
     private final int roundDecimal;
     private final ConsistencyLevelEnum consistencyLevel;
 
@@ -59,6 +60,7 @@ public class HybridSearchParam {
         this.ranker = builder.ranker;
         this.topK = builder.topK;
         this.outFields = builder.outFields;
+        this.offset = builder.offset;
         this.roundDecimal = builder.roundDecimal;
         this.consistencyLevel = builder.consistencyLevel;
         this.groupByFieldName = builder.groupByFieldName;
@@ -81,6 +83,7 @@ public class HybridSearchParam {
         private BaseRanker ranker = null;
         private Integer topK;
         private final List<String> outFields = Lists.newArrayList();
+        private Long offset = 0L;
         private Integer roundDecimal = -1;
         private ConsistencyLevelEnum consistencyLevel = null;
         private String groupByFieldName = null;
@@ -204,6 +207,17 @@ public class HybridSearchParam {
             return this;
         }
 
+        /**
+         * Specifies the offset place of the returned results.
+         *
+         * @param offset the offset position
+         * @return <code>Builder</code>
+         */
+        public Builder withOffset(@NonNull Long offset) {
+            this.offset = offset;
+            return this;
+        }
+
         /**
          * Specifies the decimal place of the returned results.
          *
@@ -218,7 +232,7 @@ public class HybridSearchParam {
         /**
          * Groups the results by a scalar field name.
          *
-         * @param fieldName a scalar field name
+         * @param groupByFieldName a scalar field name
          * @return <code>Builder</code>
          */
         public Builder withGroupByFieldName(@NonNull String groupByFieldName) {

+ 2 - 0
sdk-core/src/main/java/io/milvus/v2/service/vector/request/HybridSearchReq.java

@@ -38,6 +38,7 @@ public class HybridSearchReq
     private BaseRanker ranker;
     private int topK;
     private List<String> outFields;
+    private long offset;
     @Builder.Default
     private int roundDecimal = -1;
     @Builder.Default
@@ -46,4 +47,5 @@ public class HybridSearchReq
     private String groupByFieldName;
     private Integer groupSize;
     private Boolean strictGroupSize;
+
 }

+ 3 - 2
sdk-core/src/main/java/io/milvus/v2/utils/VectorUtils.java

@@ -467,8 +467,9 @@ public class VectorUtils {
         }
 
         Map<String, String> props = ranker.getProperties();
-        props.put("limit", String.format("%d", request.getTopK()));
-        props.put("round_decimal", String.format("%d", request.getRoundDecimal()));
+        props.put(Constant.LIMIT, String.format("%d", request.getTopK()));
+        props.put(Constant.ROUND_DECIMAL, String.format("%d", request.getRoundDecimal()));
+        props.put(Constant.OFFSET, String.format("%d", request.getOffset()));
         List<KeyValuePair> propertiesList = ParamUtils.AssembleKvPair(props);
         if (CollectionUtils.isNotEmpty(propertiesList)) {
             propertiesList.forEach(builder::addRankParams);