Search()
This method performs a vector search.
func (c *Client) Search(ctx context.Context, option SearchOption, 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. | 
 | 
SearchOption
This is an interface type. The searchOption struct types implement this interface type.
You can use the NewSearchOption function to get the concrete implementation.
NewSearchOption
The signature of this method is as follows:
func NewSearchOption(collectionName string, limit int, vectors []entity.Vector) *searchOption
| Parameter | Description | Type | 
|---|---|---|
| 
 | Name of the target collection. | 
 | 
| 
 | Number of entities included in the result set. | 
 | 
| 
 | Query vectors | 
 | 
entity.Vector
This is an interface. The following types implement this interface.
entity.FloatVector
This is a list containing numbers of the float32 type. The signature is as follows:
type FloatVector []float32
entity.Float16Vector
This is a list containing numbers of the byte type. The signature is as follows:
type Float16Vector []byte
entity.BFloat16Vector
This is a list containing numbers of the byte type. The signature is as follows:
type BFloat16Vector []byte
entity.BinaryVector
This is a list containing numbers of the byte type. The signature is as follows:
type BinaryVector []byte
entity.Text
This is a string type. The signature is as follows:
type Text string
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}
resultSets, err := cli.Search(ctx, milvusclient.NewSearchOption(
    "quick_setup", // collectionName
    3,             // limit
    []entity.Vector{entity.FloatVector(queryVector)},
))
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)
}