milvus-logo
LFAI
< Docs
  • Go

Upsert()

This method updates or inserts data into the specified collection.

func (c *GrpcClient) Upsert(ctx context.Context, collName string, partitionName string, columns ...entity.Column) (entity.Column, error)

Request Parameters

Parameter

Description

Type

ctx

Context for the current call to work.

context.Context

collName

Name of the collection to update or insert data into.

string

partitionName

Name of the partition to update or insert data into.

string

columns

Data to update or insert into the specified collection.

You should include the data for all the fields defined in the collection schema.

...entity.Column

Return

entity.Column

Errors

Any error in the execution of the request. Possible errors are as follows:

  • ErrClientNotReady: The client is not connected to Milvus.

  • ErrCollectionNotExists: The collection with the specified name does not exist.

  • The specified field is invalid.

  • The call to this API fails.

Example

// upsert
pkValues := make([]int64, 0, 100)
varcharValues := make([]string, 0, 100)
vectors:= make([][]float32, 0, 100)
for i := 0; i < 100; i++ {
   pkValues = append(pkValues, int64(i+1))
   varcharValues = append(varcharValues, "bbb")
   v := make([]float32, 0, 768)
   for j := 0; j < 768; j++ {
      v = append(v, rand.Float32())
   }
   vectors = append(vectors, v)
}
resUpsert, errUpsert := mc.Upsert(context.Background(),
   collectionName,
   "",
   entity.NewColumnInt64("id", pkValues),
   entity.NewColumnVarChar("varchar", varcharValues),
   entity.NewColumnFloatVector("vector", 768, vectors),
   )
if errUpsert != nil {
   log.Fatal("failed to upsert data:", errUpsert.Error())
}
log.Println(resUpsert.Name(), resUpsert.Len())

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?