q-milvus provides the transparent way to use milvus.
package qmilvus
import (
"context"
"github.com/milvus-io/milvus-sdk-go/v2/entity"
milvus "github.com/yangkequn/q-milvus"
)
type FooEntity struct {
Id int64 `schema:"in,out" primarykey:"true"`
Name string `schema:"in,out" max_length:"2048"`
Vector []float32 `dim:"384" schema:"in" index:"true"`
Score float32 `schema:"out"`
}
//Index: define your index field name and type here. required
func (v FooEntity) Index() (indexFieldName string, index entity.Index) {
index, _ = entity.NewIndexIvfFlat(entity.IP, 256)
return "Vector", index
}
var collection *milvus.Collection = milvus.NewCollection[FooEntity]("milvus.lan:19530", "").Create()
var models []*FooEntity
// insert operation
err:=collection.Insert(models)
// search operation
ids,scores,models,err:=collection.SearchVector(query []float32,10)
// remove operation. type of ids : []int64
err:=collection.RemoveByKey(ids)