Skip to content

Commit

Permalink
Merge pull request #275 from gen-mind/patch/milvus-connect
Browse files Browse the repository at this point in the history
patch milvus connection
  • Loading branch information
apaladiychuk authored Jun 25, 2024
2 parents e7f14d9 + 65c5f32 commit cca1b77
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/backend/core/storage/milvus.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type (
)

func (c *milvusClient) Delete(ctx context.Context, collection string, documentIDs ...int64) error {
if c.client == nil {
return fmt.Errorf("milvus is not initialized")
}
var docsID []string
for _, id := range documentIDs {
docsID = append(docsID, strconv.FormatInt(id, 10))
Expand Down Expand Up @@ -92,6 +95,9 @@ func (v MilvusConfig) Validate() error {
}

func (c *milvusClient) Load(ctx context.Context, collection string, vector []float32) ([]*MilvusPayload, error) {
if c.client == nil {
return nil, fmt.Errorf("milvus is not initialized")
}
vs := []entity.Vector{entity.FloatVector(vector)}
sp, _ := entity.NewIndexFlatSearchParam()
result, err := c.client.Search(ctx, collection, []string{}, "", responseColumns, vs, ColumnNameVector, c.MetricType, 10, sp)
Expand Down Expand Up @@ -147,6 +153,7 @@ func NewMilvusClient(cfg *MilvusConfig) (MilvusClient, error) {
zap.S().Debugf("________________________milvus client created")
if err != nil {
zap.S().Errorf("connect to milvus error", zap.Error(err))

}
return &milvusClient{
client: client,
Expand All @@ -159,7 +166,9 @@ func (c *milvusClient) Save(ctx context.Context, collection string, payloads ...
var ids, documentIDs, chunks []int64
var contents [][]byte
var vectors [][]float32

if c.client == nil {
return fmt.Errorf("milvus is not initialized")
}
for _, payload := range payloads {
ids = append(ids, payload.ID)
documentIDs = append(documentIDs, payload.DocumentID)
Expand Down

0 comments on commit cca1b77

Please sign in to comment.