Skip to main content

NewCollection()

This method creates a collection in a Zilliz Cloud cluster.

func (c *GrpcClient) NewCollection(ctx context.Context, collName string, dimension int64, opts ...CreateCollectionOption) error

Request Parameters

Parameter

Description

Type

ctx

Context for the current call to work.

context.Context

collName

Name of the collection to create.

string

dimension

Dimensionality of the vector field.

int64

opts

Extra options for the current request.

This parameter is optional. You can add multiple CreateCollectionOption in the request.

...entity.CreateCollectionOption

entity.CreateCollectionOption

You can add extra collection settings to the NewCollection() request using the following methods.

Method

Description

WithAutoID(autoID bool)

Whether allows Zilliz Cloud to automatically generate IDs upon data insertions.

WithMetricsType(mt entity.MetricType)

Metric type for Zilliz Cloud to measure similarity between vector embeddings.

WithPKFieldName(name string)

Custom name of the primary field.

If not specified, the default value id applies.

WithPKFieldType(tp entity.FieldType)

Data type of the primary field.

If not specified, the default value entity 5 applies, indicating that the values in the primary field are of the int64 type.

WithPKMaxLength(maxLength int64)

Maximum length of the values in the primary field.

This is required only when you set tp in WithPKFieldType() to 21, which indicates that the values in the primary field are of the VarChar type.

WithVectorFieldName(name string)

Custom name of the vector field.

If not specified, the default value vector applies.

Return

Null

Errors

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

  • ErrClientNotReady: The client is not connected to Milvus.

  • A collection with the same name already exists.

  • The call to this API fails.

Example

var collectionName = "test_01"
errNew := mc.NewCollection(context.Background(), collectionName, 768, client.WithConsistencyLevel(entity.ClBounded))
if errNew != nil {
log.Fatal("failed to New collection:", errNew.Error())
}