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 @@ -266,11 +266,12 @@ public SearchResp search(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStu
SearchResults response = blockingStub.search(searchRequest);
rpcUtils.handleResponse(title, response.getStatus());

return SearchResp.builder()
SearchResp.SearchRespBuilder respBuilder = SearchResp.builder()
.searchResults(convertUtils.getEntities(response))
.sessionTs(response.getSessionTs())
.recalls(response.getResults().getRecallsList())
.build();
.recalls(response.getResults().getRecallsList());
fillSearchRespFromExtraInfo(respBuilder, response.getStatus().getExtraInfoMap());
return respBuilder.build();
}

public SearchResp hybridSearch(MilvusServiceGrpc.MilvusServiceBlockingStub blockingStub, HybridSearchReq request) {
Expand All @@ -287,10 +288,27 @@ public SearchResp hybridSearch(MilvusServiceGrpc.MilvusServiceBlockingStub block
SearchResults response = blockingStub.hybridSearch(searchRequest);
rpcUtils.handleResponse(title, response.getStatus());

return SearchResp.builder()
SearchResp.SearchRespBuilder respBuilder = SearchResp.builder()
.searchResults(convertUtils.getEntities(response))
.recalls(response.getResults().getRecallsList())
.build();
.sessionTs(response.getSessionTs())
.recalls(response.getResults().getRecallsList());
fillSearchRespFromExtraInfo(respBuilder, response.getStatus().getExtraInfoMap());
return respBuilder.build();
}

private void fillSearchRespFromExtraInfo(SearchResp.SearchRespBuilder respBuilder, java.util.Map<String, String> extraInfo) {
if (extraInfo.containsKey("report_value")) {
respBuilder.cost(Long.parseLong(extraInfo.get("report_value")));
}
if (extraInfo.containsKey("scanned_remote_bytes")) {
respBuilder.scannedRemoteBytes(Long.parseLong(extraInfo.get("scanned_remote_bytes")));
}
if (extraInfo.containsKey("scanned_total_bytes")) {
respBuilder.scannedTotalBytes(Long.parseLong(extraInfo.get("scanned_total_bytes")));
}
if (extraInfo.containsKey("cache_hit_ratio")) {
respBuilder.cacheHitRatio(Float.parseFloat(extraInfo.get("cache_hit_ratio")));
}
}

public QueryIterator queryIterator(RpcStubWrapper blockingStub,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ public class SearchResp {
private List<List<SearchResult>> searchResults;
private long sessionTs; // default eventually ts
private List<Float> recalls;
private Long cost;
private Long scannedRemoteBytes;
private Long scannedTotalBytes;
private Float cacheHitRatio;

private SearchResp(SearchRespBuilder builder) {
this.searchResults = builder.searchResults;
this.sessionTs = builder.sessionTs;
this.recalls = builder.recalls;
this.cost = builder.cost;
this.scannedRemoteBytes = builder.scannedRemoteBytes;
this.scannedTotalBytes = builder.scannedTotalBytes;
this.cacheHitRatio = builder.cacheHitRatio;
}

public static SearchRespBuilder builder() {
Expand Down Expand Up @@ -63,19 +71,59 @@ public void setRecalls(List<Float> recalls) {
this.recalls = recalls;
}

public Long getCost() {
return cost;
}

public void setCost(Long cost) {
this.cost = cost;
}

public Long getScannedRemoteBytes() {
return scannedRemoteBytes;
}

public void setScannedRemoteBytes(Long scannedRemoteBytes) {
this.scannedRemoteBytes = scannedRemoteBytes;
}

public Long getScannedTotalBytes() {
return scannedTotalBytes;
}

public void setScannedTotalBytes(Long scannedTotalBytes) {
this.scannedTotalBytes = scannedTotalBytes;
}

public Float getCacheHitRatio() {
return cacheHitRatio;
}

public void setCacheHitRatio(Float cacheHitRatio) {
this.cacheHitRatio = cacheHitRatio;
}

@Override
public String toString() {
return "SearchResp{" +
"searchResults=" + searchResults +
", sessionTs=" + sessionTs +
", recalls=" + recalls +
", cost=" + cost +
", scannedRemoteBytes=" + scannedRemoteBytes +
", scannedTotalBytes=" + scannedTotalBytes +
", cacheHitRatio=" + cacheHitRatio +
'}';
}

public static class SearchRespBuilder {
private List<List<SearchResult>> searchResults = new ArrayList<>();
private long sessionTs = 1L; // default eventually ts
private List<Float> recalls = new ArrayList<>();
private Long cost;
private Long scannedRemoteBytes;
private Long scannedTotalBytes;
private Float cacheHitRatio;

public SearchRespBuilder searchResults(List<List<SearchResult>> searchResults) {
this.searchResults = searchResults;
Expand All @@ -92,6 +140,26 @@ public SearchRespBuilder recalls(List<Float> recalls) {
return this;
}

public SearchRespBuilder cost(Long cost) {
this.cost = cost;
return this;
}

public SearchRespBuilder scannedRemoteBytes(Long scannedRemoteBytes) {
this.scannedRemoteBytes = scannedRemoteBytes;
return this;
}

public SearchRespBuilder scannedTotalBytes(Long scannedTotalBytes) {
this.scannedTotalBytes = scannedTotalBytes;
return this;
}

public SearchRespBuilder cacheHitRatio(Float cacheHitRatio) {
this.cacheHitRatio = cacheHitRatio;
return this;
}

public SearchResp build() {
return new SearchResp(this);
}
Expand Down
6 changes: 6 additions & 0 deletions sdk-core/src/test/java/io/milvus/v2/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ public void setUp() {
when(blockingStub.query(any())).thenReturn(QueryResults.newBuilder().build());
when(blockingStub.delete(any())).thenReturn(MutationResult.newBuilder().setDeleteCnt(2L).build());
SearchResults searchResults = SearchResults.newBuilder()
.setStatus(Status.newBuilder().setCode(0)
.putExtraInfo("report_value", "123")
.putExtraInfo("scanned_remote_bytes", "456")
.putExtraInfo("scanned_total_bytes", "789")
.putExtraInfo("cache_hit_ratio", "0.5")
.build())
.setResults(SearchResultData.newBuilder().addScores(1L).addTopks(0L).build())
.build();
when(blockingStub.search(any())).thenReturn(searchResults);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,9 @@ void testV2BuilderClasses() {
VerifyClass(QueryResp.class.getName(), config);
VerifyClass(QueryResp.QueryResult.class.getName(), config);
VerifyClass(RunAnalyzerResp.class.getName(), config);
config.setIgnoredMethods(Arrays.asList("getSearchResults", "setSearchResults", "getRecalls", "setRecalls"));
VerifyClass(SearchResp.class.getName(), config);
config.clearIgnoredMethods();
VerifyClass(SearchResp.SearchResult.class.getName(), config);
VerifyClass(UpsertResp.class.getName(), config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ void testSearch() {
.build();
SearchResp statusR = client_v2.search(request);
logger.info(statusR.toString());
Assertions.assertEquals(123L, statusR.getCost());
Assertions.assertEquals(456L, statusR.getScannedRemoteBytes());
Assertions.assertEquals(789L, statusR.getScannedTotalBytes());
Assertions.assertEquals(0.5f, statusR.getCacheHitRatio());
}

@Test
Expand Down
Loading