HybridSearch()
This method performs a vector search.
func (c *Client) HybridSearch(ctx context.Context, option HybridSearchOption, callOptions ...grpc.CallOption) ([]ResultSet, error)
Request Parameters
Parameter | Description | Type |
---|---|---|
| Context for the current call to work. |
|
| Optional parameters of the methods. |
|
| Optional parameters for calling the methods. |
|
HybridSearchOption
This is an interface type. The hybridSearchOption
struct types implement this interface type.
You can use the NewHybridSearchOption
function to get the concrete implementation.
NewHybridSearchOption
The signature of this method is as follows:
func NewHybridSearchOption(collectionName string, limit int, annRequests ...*AnnRequest) *hybridSearchOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Number of entities included in the result set. |
|
| One or multiple search requests. |
|
AnnRequest
This is a struct type. The index.CustomAnnParam
struct type implements this interface. You can use the NewAnnRequest
method to create a search request.
NewAnnRequest
This method prepares a search request. The signature is as follows:
func NewAnnRequest(annField string, limit int, vectors ...entity.Vector) *annRequest
Parameter | Description | Type |
---|---|---|
| Name of the target vector field. |
|
| Number of entities to be included in the result set. |
|
| Query vectors |
|
You can chain the following methods to append extra parameter settings to the annRequest
struct.
WithANNSField
This method appends the settings regarding the vector field to use in the current AnnRequest
struct. The signature of the method is as follows:
func (r *AnnRequest) WithANNSField(annsField string) *AnnRequest
Parameter | Description | Type |
---|---|---|
| The name of the vector field to use in the current field. |
|
WithAnnParam
This method appends the settings regarding the search parameters to the current AnnRequest
struct. The signature of this method is as follows:
func (r *AnnRequest) WithAnnParam(ap index.AnnParam) *AnnRequest
Parameter | Description | Type |
---|---|---|
| The index-specific search parameter settings. |
|
WithFilter
This method appends the settings regarding the filter to use in the current AnnRequest
struct. The signature of the method is as follows:
func (r *AnnRequest) WithFilter(expr string) *AnnRequest
Parameter | Description | Type |
---|---|---|
| The metadata-filtering expression. For details, refer to . |
|
WithGroupByField
This method appends the settings regarding the group-by field to use in the current AnnRequest
struct. The signature of the method is as follows:
func (r *AnnRequest) WithGroupByField(groupByField string) *AnnRequest
Parameter | Description | Type |
---|---|---|
| The name of the scalar field that serves as the group-by field. Once set, the search results will be grouped by the specified field. |
|
WithGroupSize
This method appends the settings regarding the group size to use in the current AnnRequest
struct. The signature of the method is as follows:
func (r *AnnRequest) WithGroupSize(groupSize int) *AnnRequest
Parameter | Description | Type |
---|---|---|
| The desired number of entities to return per group. |
|
WithIgnoreGrowing
This method appends the settings regarding whether to ignore growing segments to the current AnnRequest
struct. The signature of the method is as follows:
func (r *AnnRequest) WithIgnoreGrowing(ignoreGrowing bool) *AnnRequest
Parameter | Description | Type |
---|---|---|
| Whether to ignore growing segments from the search results. |
|
WIthOffset
This method appends the settings regarding the offset to the current AnnRequest
struct. The signature of the method is as follows:
func (r *AnnRequest) WithOffset(offset int) *AnnRequest
Parameter | Description | Type |
---|---|---|
| The number of results to skip from the search results. The value of this parameter and that of |
|
WithSearchParam
This method appends the settings regarding the search parameters to the current AnnRequest
struct. The signature of the method is as follows:
func (r *AnnRequest) WithSearchParam(key, value string) *AnnRequest
Parameter | Description | Type |
---|---|---|
| The name of a search parameter. |
|
| The value of the above search parameter. |
|
WithStrictGroupSize
This method appends the settings regarding whether to strictly abide by the specified group size to the current AnnRequest
struct. The signature of the method is as follows:
func (r *AnnRequest) WithStrictGroupSize(strictGroupSize bool) *AnnRequest
Parameter | Description | Type |
---|---|---|
| controls whether the system should strictly enforce the count set by |
|
WithTemplateParam
This method appends the settings regarding the template parameters to the current AnnRequest
struct. The signature of the method is as follows:
func (r *AnnRequest) WithTemplateParam(key string, val any) *AnnRequest
Parameter | Description | Type |
---|---|---|
| The name of a template parameter. |
|
| The value of the above template parameter. |
|
index.AnnParam
This is an interface type. The following struct types implement this interface.
autoAnnParam
This is a struct type that implements the index.AnnParam
interface. You can use NewAutoAnnParam()
to get its concrete implementation.
NewAutoAnnParam
This method prepares the search parameters specific to AUTOINDEX. The signature is as follows:
func NewAutoAnnParam(level int) autoAnnParam
Parameter | Description | Type |
---|---|---|
| An integer that allows users to balance between search recall and performance. For details, refer to Tune Recall Rate. |
|
diskANNParam
This method prepares the search parameters specific to DiskANN. The signature is as follows:
func NewDiskAnnParam(searchList int) diskANNParam
Parameter | Description | Type |
---|---|---|
| Determines the number of candidate neighbors considered for each data point during graph construction. |
|
hsnwAnnParam
This method prepares the search parameters specific to HNSW. The signature is as follows:
func NewHNSWAnnParam(ef int) hsnwAnnParam
Parameter | Description | Type |
---|---|---|
| Controls the breadth of search during nearest neighbor retrieval. It determines how many nodes are visited and evaluated as potential nearest neighbors. This parameter affects only the search process and applies exclusively to the bottom layer of the graph. |
|
ivfAnnParam
This method prepares the search parameters specific to IVF. The signature is as follows:
func NewIvfAnnParam(nprobe int) ivfAnnParam
Parameter | Description | Type |
---|---|---|
| The number of clusters to search for candidates. Higher values allow more clusters to be searched, improving recall by expanding the search scope but at the cost of increased query latency. |
|
scannAnnParam
This method prepares the search parameters specific to SCANN. The signature is as follows:
func NewSCANNAnnParam(nprobe int, reorderK int) scannAnnParam
Parameter | Description | Type |
---|---|---|
| The number of clusters to search for candidates. Higher values allow more clusters to be searched, improving recall by expanding the search scope but at the cost of increased query latency. |
|
sparseAnnParam
This method prepares the search parameters specific to SPARSE_INVERTED. The signature is as follows:
func NewSparseAnnParam() sparseAnnParam
This method has no mandatory parameters.
index.CustomAnnParam
This is a struct type that implements the AnnRequest
interface. You can use NewCustomAnnParam()
to get its concrete implementation.
NewCustomAnnParam
This method prepares the custom ANN search parameters for the hybrid search request. The signature of this method is as follows:
func NewCustomAnnParam() CustomAnnParam
This method has no parameters.
You can chain the following methods to append extra settings to the CustomAnnParam
struct.
WithExtraParam
This method appends extra search parameters to the current AnnRequest
struct. The signature is as follows:
func (b CustomAnnParam) WithExtraParam(key string, value any)
Parameter | Description | Type |
---|---|---|
| The name of an extra search parameter. |
|
| The value of the above extra search parameter. |
|
WithRadius
This method appends the radius parameters to the current AnnRequest
struct. The signature is as follows:
func (b CustomAnnParam) WithRadius(radius float64)
Parameter | Description | Type |
---|---|---|
| The radius for a range search. |
|
WithRangeFilter
This method appends the range filter parameters to the current AnnRequest
struct. The signature is as follows:
func (b CustomAnnParam) WithRangeFilter(rangeFilter float64)
Parameter | Description | Type |
---|---|---|
| The range filter for a range search. |
|
ResultSet
This is a struct type. You can use the GetColumn
method to get the result values in a specific field.
GetColumn
This method returns the query result in a specific column. The signature is as follows:
func (rs *ResultSet) GetColumn(fieldName string) column.Column
Parameter | Description | Type |
---|---|---|
| Name of the target field. |
|
Return
[]ResultSet
Example
queryVector := []float32{0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592}
sparseVector, _ := entity.NewSliceSparseEmbedding([]uint32{1, 21, 100}, []float32{0.1, 0.2, 0.3})
resultSets, err := cli.HybridSearch(ctx, milvusclient.NewHybridSearchOption(
"quick_setup",
3,
milvusclient.NewAnnRequest("dense_vector", 10, entity.FloatVector(queryVector)),
milvusclient.NewAnnRequest("sparse_vector", 10, sparseVector),
).WithReranker(milvusclient.NewRRFReranker()))
if err != nil {
log.Fatal("failed to perform basic ANN search collection: ", err.Error())
}
for _, resultSet := range resultSets {
log.Println("IDs: ", resultSet.IDs)
log.Println("Scores: ", resultSet.Scores)
}