hybridSearchAsync()
Runs a multi-vector similarity search with a ranker asynchronously and returns a future.
public CompletableFuture<SearchResp> hybridSearchAsync(HybridSearchReq request)
This method uses the same request parameters as hybridSearch() but returns a CompletableFuture<SearchResp> immediately. Use the returned future to consume the result or handle the exceptional completion when the operation fails.
Request Syntax
CompletableFuture<SearchResp> future = client.hybridSearchAsync(HybridSearchReq.builder()
.collectionName(String collectionName)
.searchRequests(List<AnnSearchReq> searchRequests)
.functionScore(FunctionScore functionScore)
.limit(long limit)
.build());
For the full list of HybridSearchReq builder methods, refer to hybridSearch().
RETURN TYPE:
CompletableFuture<SearchResp>
RETURNS:
A future completed with a SearchResp object that contains search results, recalls, cost, scanned byte counts, and cache hit ratio, or completed exceptionally when the operation fails. The SearchResp object exposes the following getters:
-
getSearchResults()(List<List<SearchResult>>) -The search results, one list per query vector. Each SearchResult has the following getters:
-
getEntity()(Map<String, Object>) -The retrieved entity data.
-
getScore()(Float) -The similarity score of the result.
-
getId()(Object) -The primary key value of the result.
-
getPrimaryKey()(String) -The primary key value rendered as a string.
-
-
getSessionTs()(long) -The session timestamp used for the search.
-
getRecalls()(List<Float>) -The recall values of the search, one per query vector.
-
getCost()(Long) -The time cost of the search operation, in milliseconds.
-
getScannedRemoteBytes()(Long) -The number of bytes scanned from remote storage.
-
getScannedTotalBytes()(Long) -The total number of bytes scanned during the search.
-
getCacheHitRatio()(Float) -The cache hit ratio of the search.
EXCEPTIONS:
-
MilvusClientException
This exception will be raised when request validation, transport, or server execution fails.
Example
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.service.vector.request.HybridSearchReq;
import io.milvus.v2.service.vector.request.AnnSearchReq;
import io.milvus.v2.service.vector.response.SearchResp;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
ConnectConfig connectConfig = ConnectConfig.builder()
.uri("http://localhost:19530")
.token("root:Milvus")
.build();
MilvusClientV2 client = new MilvusClientV2(connectConfig);
CompletableFuture<SearchResp> future = client.hybridSearchAsync(HybridSearchReq.builder()
.collectionName("my_collection")
.searchRequests(Arrays.asList(
AnnSearchReq.builder()
.vectorFieldName("dense_vector")
.vectors(Collections.singletonList(queryVector))
.build(),
AnnSearchReq.builder()
.vectorFieldName("sparse_vector")
.vectors(Collections.singletonList(sparseVector))
.build()))
.build());
SearchResp response = future.get();