Skip to content

Commit d21763f

Browse files
authored
Support offset parameter for hybridSearch interface (#1360)
Signed-off-by: yhmo <yihua.mo@zilliz.com>
1 parent c1060a7 commit d21763f

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,9 @@ public static HybridSearchRequest convertHybridSearchParam(@NonNull HybridSearch
10461046
// set ranker
10471047
BaseRanker ranker = requestParam.getRanker();
10481048
Map<String, String> props = ranker.getProperties();
1049-
props.put("limit", String.format("%d", requestParam.getTopK()));
1050-
props.put("round_decimal", String.format("%d", requestParam.getRoundDecimal()));
1049+
props.put(Constant.LIMIT, String.format("%d", requestParam.getTopK()));
1050+
props.put(Constant.ROUND_DECIMAL, String.format("%d", requestParam.getRoundDecimal()));
1051+
props.put(Constant.OFFSET, String.format("%d", requestParam.getOffset()));
10511052
List<KeyValuePair> propertiesList = ParamUtils.AssembleKvPair(props);
10521053
if (CollectionUtils.isNotEmpty(propertiesList)) {
10531054
propertiesList.forEach(builder::addRankParams);

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class HybridSearchParam {
4444
private final BaseRanker ranker;
4545
private final int topK;
4646
private final List<String> outFields;
47+
private final long offset;
4748
private final int roundDecimal;
4849
private final ConsistencyLevelEnum consistencyLevel;
4950

@@ -59,6 +60,7 @@ private HybridSearchParam(@NonNull Builder builder) {
5960
this.ranker = builder.ranker;
6061
this.topK = builder.topK;
6162
this.outFields = builder.outFields;
63+
this.offset = builder.offset;
6264
this.roundDecimal = builder.roundDecimal;
6365
this.consistencyLevel = builder.consistencyLevel;
6466
this.groupByFieldName = builder.groupByFieldName;
@@ -81,6 +83,7 @@ public static class Builder {
8183
private BaseRanker ranker = null;
8284
private Integer topK;
8385
private final List<String> outFields = Lists.newArrayList();
86+
private Long offset = 0L;
8487
private Integer roundDecimal = -1;
8588
private ConsistencyLevelEnum consistencyLevel = null;
8689
private String groupByFieldName = null;
@@ -204,6 +207,17 @@ public Builder addOutField(@NonNull String fieldName) {
204207
return this;
205208
}
206209

210+
/**
211+
* Specifies the offset place of the returned results.
212+
*
213+
* @param offset the offset position
214+
* @return <code>Builder</code>
215+
*/
216+
public Builder withOffset(@NonNull Long offset) {
217+
this.offset = offset;
218+
return this;
219+
}
220+
207221
/**
208222
* Specifies the decimal place of the returned results.
209223
*
@@ -218,7 +232,7 @@ public Builder withRoundDecimal(@NonNull Integer decimal) {
218232
/**
219233
* Groups the results by a scalar field name.
220234
*
221-
* @param fieldName a scalar field name
235+
* @param groupByFieldName a scalar field name
222236
* @return <code>Builder</code>
223237
*/
224238
public Builder withGroupByFieldName(@NonNull String groupByFieldName) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class HybridSearchReq
3838
private BaseRanker ranker;
3939
private int topK;
4040
private List<String> outFields;
41+
private long offset;
4142
@Builder.Default
4243
private int roundDecimal = -1;
4344
@Builder.Default
@@ -46,4 +47,5 @@ public class HybridSearchReq
4647
private String groupByFieldName;
4748
private Integer groupSize;
4849
private Boolean strictGroupSize;
50+
4951
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,9 @@ public HybridSearchRequest ConvertToGrpcHybridSearchRequest(HybridSearchReq requ
467467
}
468468

469469
Map<String, String> props = ranker.getProperties();
470-
props.put("limit", String.format("%d", request.getTopK()));
471-
props.put("round_decimal", String.format("%d", request.getRoundDecimal()));
470+
props.put(Constant.LIMIT, String.format("%d", request.getTopK()));
471+
props.put(Constant.ROUND_DECIMAL, String.format("%d", request.getRoundDecimal()));
472+
props.put(Constant.OFFSET, String.format("%d", request.getOffset()));
472473
List<KeyValuePair> propertiesList = ParamUtils.AssembleKvPair(props);
473474
if (CollectionUtils.isNotEmpty(propertiesList)) {
474475
propertiesList.forEach(builder::addRankParams);

0 commit comments

Comments
 (0)