milvus
This commit is contained in:
38
bin/main.go
38
bin/main.go
@@ -193,27 +193,57 @@ func main() {
|
||||
}
|
||||
|
||||
// 用向量查询相似图片
|
||||
sp, _ := entity.NewIndexFlatSearchParam()
|
||||
sp, _ := entity.NewIndexIvfFlatSearchParam(64)
|
||||
vectors := []entity.Vector{
|
||||
entity.FloatVector(similar.Embedding),
|
||||
}
|
||||
resultx, err := milvusConnection.Client.Search(
|
||||
context.Background(), // ctx
|
||||
collection_name, // CollectionName
|
||||
[]string{}, // PartitionNames
|
||||
nil, // PartitionNames
|
||||
"", // expr
|
||||
[]string{"id", "article_id"}, // OutputFields
|
||||
vectors, // vectors
|
||||
"embedding", // vectorField
|
||||
entity.L2, // entity.MetricType
|
||||
10, // topK
|
||||
sp,
|
||||
sp, // searchParam
|
||||
)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
println(resultx)
|
||||
// 输出结果
|
||||
for _, item := range resultx {
|
||||
fmt.Println(item.Scores)
|
||||
fmt.Println(item.IDs)
|
||||
fmt.Println(item.ResultCount)
|
||||
fmt.Println(item.Fields)
|
||||
}
|
||||
|
||||
//func printResult(sRet *client.SearchResult) {
|
||||
// randoms := make([]float64, 0, sRet.ResultCount)
|
||||
// scores := make([]float32, 0, sRet.ResultCount)
|
||||
//
|
||||
// var randCol *entity.ColumnDouble
|
||||
// for _, field := range sRet.Fields {
|
||||
// if field.Name() == randomCol {
|
||||
// c, ok := field.(*entity.ColumnDouble)
|
||||
// if ok {
|
||||
// randCol = c
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// for i := 0; i < sRet.ResultCount; i++ {
|
||||
// val, err := randCol.ValueByIdx(i)
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// randoms = append(randoms, val)
|
||||
// scores = append(scores, sRet.Scores[i])
|
||||
// }
|
||||
// fmt.Printf("\trandoms: %v, scores: %v\n", randoms, scores)
|
||||
//}
|
||||
})
|
||||
|
||||
// 获取图片信息列表(分页)
|
||||
|
Reference in New Issue
Block a user