Skip to content

Commit

Permalink
enhance:[2.4] return topks when search in restful v2
Browse files Browse the repository at this point in the history
Signed-off-by: lixinguo <[email protected]>
  • Loading branch information
lixinguo committed Feb 13, 2025
1 parent 7a6ccd6 commit daefff0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/distributed/proxy/httpserver/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const (
HTTPReturnRecalls = "recalls"
HTTPReturnLoadState = "loadState"
HTTPReturnLoadProgress = "loadProgress"
HTTPReturnTopks = "topks"

HTTPReturnHas = "has"

Expand Down
6 changes: 3 additions & 3 deletions internal/distributed/proxy/httpserver/handler_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,9 +1011,9 @@ func (h *HandlersV2) search(ctx context.Context, c *gin.Context, anyReq any, dbN
})
} else {
if len(searchResp.Results.Recalls) > 0 {
HTTPReturn(c, http.StatusOK, gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: outputData, HTTPReturnCost: cost, HTTPReturnRecalls: searchResp.Results.Recalls})
HTTPReturn(c, http.StatusOK, gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: outputData, HTTPReturnCost: cost, HTTPReturnRecalls: searchResp.Results.Recalls, HTTPReturnTopks: searchResp.Results.Topks})

Check warning on line 1014 in internal/distributed/proxy/httpserver/handler_v2.go

View check run for this annotation

Codecov / codecov/patch

internal/distributed/proxy/httpserver/handler_v2.go#L1014

Added line #L1014 was not covered by tests
} else {
HTTPReturn(c, http.StatusOK, gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: outputData, HTTPReturnCost: cost})
HTTPReturn(c, http.StatusOK, gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: outputData, HTTPReturnCost: cost, HTTPReturnTopks: searchResp.Results.Topks})
}
}
}
Expand Down Expand Up @@ -1100,7 +1100,7 @@ func (h *HandlersV2) advancedSearch(ctx context.Context, c *gin.Context, anyReq
HTTPReturnMessage: merr.ErrInvalidSearchResult.Error() + ", error: " + err.Error(),
})
} else {
HTTPReturn(c, http.StatusOK, gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: outputData, HTTPReturnCost: cost})
HTTPReturn(c, http.StatusOK, gin.H{HTTPReturnCode: merr.Code(nil), HTTPReturnData: outputData, HTTPReturnCost: cost, HTTPReturnTopks: searchResp.Results.Topks})
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/restful_client_v2/testcases/test_vector_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,9 @@ def test_advanced_search_vector_with_multi_float32_vector_datatype(self, nb, dim
rsp = self.vector_client.vector_advanced_search(payload)
assert rsp['code'] == 0
assert len(rsp['data']) == 10
assert len(rsp['topks']) == 1
assert rsp['topks'][0] == 10




Expand Down

0 comments on commit daefff0

Please sign in to comment.