Insert()
This method inserts data into a specific collection.
func (c *Client) Insert(ctx context.Context, option InsertOption, callOptions ...grpc.CallOption) (InsertResult, error)
Request Parameters
Parameter | Description | Type |
---|---|---|
| Context for the current call to work. |
|
| Optional parameters of the methods. |
|
| Optional parameters for calling the methods. |
|
InsertOption
This is an interface type. The columnBasedDataOption
and rowBasedDataOption
struct types implement this interface type.
You can use the NewColumnBasedInsertOption()
or NewRowBasedInsertOption()
function to get the concrete implementation.
NewRowBasedInsertOption
This function requires you to organize your data in rows. The signature of this method is as follows:
func NewRowBasedInsertOption(collName string, rows ...any) *rowBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Data organized in rows. |
|
NewColumnBasedInsertOption
This function requires you to organize your data in columns. The signature of this method is as follows:
func NewColumnBasedInsertOption(collName string, columns ...column.Column) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Data organized in columns. |
|
You can chain the following method to get an implementation of the columnBasedDataOption
struct.
WithColumns
This method appends a generic column to the columnBasedDataOption
struct.
func (opt *columnBasedDataOption) WithColumns(columns ...column.Column) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Data in the column. |
|
WithBoolColumn
This method appends a Boolean column to the columnBasedDataOption
struct.
func (opt *columnBasedDataOption) WithBoolColumn(colName string, data []bool) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Data in the column. |
|
WithInt8Column
This method appends an Int8 column to the columnBasedDataOption
struct.
func (opt *columnBasedDataOption) WithInt8Column(colName string, data []int8) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Data in the column. |
|
WithInt16Column
This method appends an Int16 column to the columnBasedDataOption
struct.
func (opt *columnBasedDataOption) WithInt16Column(colName string, data []int16) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Data in the column. |
|
WithInt32Column
This method appends an Int32 column to the columnBasedDataOption
struct.
func (opt *columnBasedDataOption) WithInt32Column(colName string, data []int32) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Data in the column. |
|
WithInt64Column
This method appends an Int64 column to the columnBasedDataOption
struct.
func (opt *columnBasedDataOption) WithInt64Column(colName string, data []int64) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Data in the column. |
|
WithVarcharColumn
This method appends a VarChar column to the columnBasedDataOption
struct.
func (opt *columnBasedDataOption) WithVarcharColumn(colName string, data []string) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Data in the column. |
|
WithFloatVectorColumn
This method appends a FloatVector column to the columnBasedDataOption
struct.
func (opt *columnBasedDataOption) WithFloatVectorColumn(colName string, dim int, data [][]float32) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Number of dimensions in the column. |
|
| Data in the column. |
|
WithFloat16VectorColumn
This method appends a Float16Vector column to the columnBasedDataOption
struct.
func (opt *columnBasedDataOption) WithFloat16VectorColumn(colName string, dim int, data [][]float32) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Number of dimensions in the column. |
|
| Data in the column. |
|
WithBFloat16VectorColumn
This method appends a BFloat16Vector column to the columnBasedDataOption
struct.
func (opt *columnBasedDataOption) WithBFloat16VectorColumn(colName string, dim int, data [][]float32) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Number of dimensions in the column. |
|
| Data in the column. |
|
WithBinaryVectorColumn
This method appends a BinaryVector column to the columnBasedDataOption
struct.
func (opt *columnBasedDataOption) WithBinaryVectorColumn(colName string, dim int, data [][]byte) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target collection. |
|
| Number of dimensions in the column. |
|
| Data in the column. |
|
WithPartition
This method sets the target partition of this operation.
func (opt *columnBasedDataOption) WithPartition(partitionName string) *columnBasedDataOption
Parameter | Description | Type |
---|---|---|
| Name of the target partition. |
|
column.Column
This is an interface type. The following struct types implement this interface type.
column.ColumnBFloat16Vector
This is a struct type. You can use the NewColumnBFloat16Vector
or NewColumnBFloat16VectorFromFp32Vector
method to implement a BFloat16Vector field.
NewColumnBfloat16Vector
This method creates a BFloat16Vector field with a list of byte sublists as data. The signature of this method is as follows:
func NewColumnBFloat16Vector(fieldName string, dim int, data [][]byte) *ColumnBFloat16Vector
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Number of dimensions in the field. |
|
| Data to be inserted into the field. |
|
NewColumnBFloat16VectorFromFp32Vector
This method creates a BFloat16Vector field with a list of float32 sublists as data. The signature of this method is as follows:
func NewColumnBFloat16VectorFromFp32Vector(fieldName string, dim int, data [][]float32) *ColumnBFloat16Vector
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Number of dimensions in the field. |
|
| Data to be inserted into the field. |
|
column.ColumnBinaryVector
This is a struct type. You can use the NewColumnBinaryVector
method to implement a BinaryVector field.
NewColumnBinaryVector
This method creates a BinaryVector field with a list of byte sublists as data. The signature of this method is as follows:
func NewColumnBinaryVector(fieldName string, dim int, data [][]byte) *ColumnBinaryVector
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Number of dimensions in the field. |
|
| Data to be inserted into the field. |
|
column.ColumnBool
This is a struct type. You can use the NewColumnBool
method to implement a Boolean field.
NewColumnBool
This method creates a Boolean field with a list of Boolean values as data. The signature of this method is as follows:
func NewColumnBool(name string, values []bool) *ColumnBool
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnBoolArray
This is a struct type. You can use the NewColumnBoolArray
method to implement an Array field with elements of the Boolean type.
NewColumnBoolArray
This method creates an Array field with elements of the Boolean type. The signature of this method is as follows:
func NewColumnBoolArray(fieldName string, data [][]bool) *ColumnBoolArray
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnDouble
This is a struct type. You can use the NewColumnDouble
method to implement a Double field.
NewColumnDouble
This method creates a Double field. The signature of this method is as follows:
func NewColumnDouble(name string, values []float64) *ColumnDouble
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnDoubleArray
This is a struct type. You can use the NewColumnDoubleArray
method to implement an Array field with elements of the Double type.
NewColumnDoubleArray
This method creates an Array field with elements of the Double type. The signature of this method is as follows:
func NewColumnDoubleArray(fieldName string, data [][]float64) *ColumnDoubleArray
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnDynamic
This is a struct type. You can use the NewColumnDynamic
method to implement a dynamic field.
NewColumnDynamic
This method creates a dynamic field. The signature of this method is as follows:
func NewColumnDynamic(column *ColumnJSONBytes, outputField string) *ColumnDynamic
Parameter | Description | Type |
---|---|---|
| A column of the JSON type. |
|
| Name of the dynamic field. |
|
column.ColumnFloat
This is a struct type. You can use the NewColumnFloat
method to implement a Float field.
NewColumnFloat
This method creates a Float field. The signature of this method is as follows:
func NewColumnFloat(name string, values []float32) *ColumnFloat
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnFloat16Vector
This is a struct type. You can use the NewColumnFloat16Vector
or NewColumnFloat16VectorFromFp32Vector
method to implement a Float16Vector field.
NewColumnBfloat16Vector
This method creates a Float16Vector field with a list of byte sublists as data. The signature of this method is as follows:
func NewColumnFloat16Vector(fieldName string, dim int, data [][]byte) *ColumnFloat16Vector
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Number of dimensions in the field. |
|
| Data to be inserted into the field. |
|
NewColumnFloat16VectorFromFp32Vector
This method creates a Float16Vector field with a list of float32 sublists as data. The signature of this method is as follows:
func NewColumnFloat16VectorFromFp32Vector(fieldName string, dim int, data [][]float32) *ColumnFloat16Vector
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Number of dimensions in the field. |
|
| Data to be inserted into the field. |
|
column.ColumnFloatArray
This is a struct type. You can use the NewColumnFloatArray
method to implement an Array field with elements of the Float type.
NewColumnFloatArray
This method creates an Array field with elements of the Float type. The signature of this method is as follows:
func NewColumnFloatArray(fieldName string, data [][]float32) *ColumnFloatArray
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnFloatVector
This is a struct type. You can use the NewColumnFloatVector
method to implement a FloatVector field.
NewColumnFloatVector
This method creates a FloatVector field with a list of byte sublists as data. The signature of this method is as follows:
func NewColumnFloatVector(fieldName string, dim int, data [][]float32) *ColumnFloatVector
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Number of dimensions in the field. |
|
| Data to be inserted into the field. |
|
column.ColumnInt16
This is a struct type. You can use the NewColumnInt16
method to implement an Int16 field.
NewColumnInt16
This method creates an Int16 field. The signature of this method is as follows:
func NewColumnInt16(name string, values []int16) *ColumnInt16
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnInt16Array
This is a struct type. You can use the NewColumnInt16Array
method to implement an Array field with elements of the Int16 type.
NewColumnInt16Array
This method creates an Array field with elements of the Int16 type. The signature of this method is as follows:
func NewColumnInt16Array(fieldName string, data [][]int16) *ColumnInt16Array
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnInt32
This is a struct type. You can use the NewColumnInt32
method to implement an Int32 field.
NewColumnInt32
This method creates an Int32 field. The signature of this method is as follows:
func NewColumnInt32(name string, values []int32) *ColumnInt32
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnInt32Array
This is a struct type. You can use the NewColumnInt32Array
method to implement an Array field with elements of the Int32 type.
NewColumnInt32Array
This method creates an Array field with elements of the Int32 type. The signature of this method is as follows:
func NewColumnInt32Array(fieldName string, data [][]int32) *ColumnInt32Array
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnInt64
This is a struct type. You can use the NewColumnInt64
method to implement an Int64 field.
NewColumnInt64
This method creates an Int64 field. The signature of this method is as follows:
func NewColumnInt64(name string, values []int16) *ColumnInt64
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnInt64Array
This is a struct type. You can use the NewColumnInt64Array
method to implement an Array field with elements of the Int64 type.
NewColumnInt64Array
This method creates an Array field with elements of the Int64 type. The signature of this method is as follows:
func NewColumnInt64Array(fieldName string, data [][]int64) *ColumnInt64Array
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnInt8
This is a struct type. You can use the NewColumnInt8
method to implement an Int8 field.
NewColumnInt8
This method creates an Int8 field. The signature of this method is as follows:
func NewColumnInt8(name string, values []int8) *ColumnInt8
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnInt8Array
This is a struct type. You can use the NewColumnInt8Array
method to implement an Array field with elements of the Int8 type.
NewColumnInt8Array
This method creates an Array field with elements of the Int8 type. The signature of this method is as follows:
func NewColumnInt8Array(fieldName string, data [][]int8) *ColumnInt8Array
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnJSONBytes
This is a struct type. You can use the NewColumnJSONBytes
method to implement a JSON field.
NewColumnJSONBytes
This method creates a JSON field. The signature of this method is as follows:
func NewColumnJSONBytes(name string, values [][]byte) *ColumnJSONBytes
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnSparseFloatVector
This is a struct type. You can use the NewColumnSparseVectors
method to implement a SparseFloatVector field.
NewColumnSparseVectors
This method creates a SparseFloatVector field with a list of byte sublists as data. The signature of this method is as follows:
func NewColumnSparseVectors(name string, values []entity.SparseEmbedding) *ColumnSparseFloatVector
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnVarChar
This is a struct type. You can use the NewColumnVarChar
method to implement a VarChar field.
NewColumnVarChar
This method creates a VarChar field. The signature of this method is as follows:
func NewColumnVarChar(name string, values []string) *ColumnVarChar
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.ColumnVarCharArray
This is a struct type. You can use the NewColumnVarCharArray
method to implement an Array field with elements of the VarChar type.
NewColumnVarCharArray
This method creates an Array field with elements of the VarChar type. The signature of this method is as follows:
func NewColumnVarCharArray(fieldName string, data [][]string) *ColumnVarCharArray
Parameter | Description | Type |
---|---|---|
| Name of the field to create. |
|
| Data to be inserted into the field. |
|
column.NullableColumnCreateFunc
This is an interface type. The NullableColumnCreator
struct type implements this interface type. You can use NewNullableColumnCreator()
method to get the concrete implementation.
NewNullableColumnCreator
The signature of this method is as follows:
func NewNullableColumnCreator[col interface {
Column
withValidData([]bool)
}, T any](base func(name string, values []T) col) NullableColumnCreator[col, T]
Parameter | Description | Type |
---|---|---|
| A column interface. |
|
| Data type. |
|
You can chain the following methods to get a nullable column.
New
The signature of this method is as follows:
func (c NullableColumnCreator[col, T]) New(name string, values []T, validData []bool) (col, error)
Parameter | Description | Type |
---|---|---|
| Name of the nullable field. |
|
| Data in this nullable field |
|
| Valid data |
|
entity.SparseEmbedding
This is an interface type. You can use the NewSliceSparseEmbedding
function to get the concrete implementation.
NewSliceSparseEmbedding
The signature is as follows:
func NewSliceSparseEmbedding(positions []uint32, values []float32) (SparseEmbedding, error)
Parameter | Description | Type |
---|---|---|
| Position indexes of the elements in the |
|
| Vector embeddings in a list of float32 numbers. |
|
InsertResult
The InsertResult
struct type is as follows:
type InsertResult struct {
InsertCount int64
IDs column.Column
}
Return
InsertResult
Example
resp, err := cli.Insert(ctx, milvusclient.NewColumnBasedInsertOption("quick_setup").
WithInt64Column("id", []int64{1, 2, 3, 4, 5, 6, 7, 8, 9}).
WithVarcharColumn("color", []string{"pink_8682", "red_7025", "orange_6781", "pink_9298", "red_4794", "yellow_4222", "red_9392", "grey_8510", "white_9381", "purple_4976"}).
WithFloatVectorColumn("vector", 5, [][]float32{
{0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, 0.9029438446296592},
{0.19886812562848388, 0.06023560599112088, 0.6976963061752597, 0.2614474506242501, 0.838729485096104},
{0.43742130801983836, -0.5597502546264526, 0.6457887650909682, 0.7894058910881185, 0.20785793220625592},
{0.3172005263489739, 0.9719044792798428, -0.36981146090600725, -0.4860894583077995, 0.95791889146345},
{0.4452349528804562, -0.8757026943054742, 0.8220779437047674, 0.46406290649483184, 0.30337481143159106},
{0.985825131989184, -0.8144651566660419, 0.6299267002202009, 0.1206906911183383, -0.1446277761879955},
{0.8371977790571115, -0.015764369584852833, -0.31062937026679327, -0.562666951622192, -0.8984947637863987},
{-0.33445148015177995, -0.2567135004164067, 0.8987539745369246, 0.9402995886420709, 0.5378064918413052},
{0.39524717779832685, 0.4000257286739164, -0.5890507376891594, -0.8650502298996872, -0.6140360785406336},
{0.5718280481994695, 0.24070317428066512, -0.3737913482606834, -0.06726932177492717, -0.6980531615588608},
}),
)
if err != nil {
// handle err
}
fmt.Println(resp)