Skip to main content

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

ctx

Context for the current call to work.

context.Context

option

Optional parameters of the methods.

HybridSearchOption

callOptions

Optional parameters for calling the methods.

grpc.CallOption

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

collectionName

Name of the target collection.

string

limit

Number of entities included in the result set.

int

annRequests

One or multiple search requests.

...*annRequest

annRequest

This is a struct type. You can use the NewAnnRequest method to create a search request.

NewAnnRequest

The signature is as follows:

func NewAnnRequest(annField string, limit int, vectors ...entity.Vector) *annRequest

Parameter

Description

Type

annField

Name of the target vector field.

string

limit

Number of entities to be included in the result set.

int

vectors

Query vectors

[]entity.Vector

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

fieldName

Name of the target field.

string

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)
}