github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/docs/create_collection.md (about)

     1  # Create Collection
     2  
     3  API to create a collection according to the specified schema.
     4  
     5  ## Parameters
     6  
     7  | Parameter    | Description                                                  | Type                     |
     8  | ------------ | ------------------------------------------------------------ | ------------------------ |
     9  | `ctx`        | Context to control API invocation process                    | context.Context          |
    10  | `collSchema` | Collection schema definition                                 | Pointer of entity.Schema |
    11  | `shardNum`   | Shard number of the collection to create. If the `shardNum` is set to 0, default shard number will be used. | INT32   |
    12  
    13  
    14  ## Schema
    15  
    16  A schema specifies the features of the collection to create and the fields within the collection.
    17  
    18  ### Collection schema
    19  
    20  A collection schema is the logical definition of a collection.
    21  
    22  | Parameter |   Description |  Type |
    23  | --------- | ------ | ---------- |
    24  | `Collection Name` | Name of the collection to create. | String |
    25  | `Description` | Description of the collection to create. | String |
    26  | `AutoID` | Automatically assigns IDs to entities in the collection if it is set to `true`. | Boolean |
    27  | `Fields` | Defines the fields in the collection.  | See [Field Schema of Milvus](https://github.com/milvus-io/milvus-sdk-go/blob/7410632233597d4af58df727682ffb29f1d1d51d/entity/schema.go#L54-L63) for more information. |
    28  
    29  ### Field schema
    30  
    31  A field schema is the logical definition of a field.
    32  
    33  | Parameter  |   Description                                  |  Type        |
    34  | ---------- | ---------------------------------------------- | ------------ |
    35  |  `ID`      | Field ID generated when collection is created. | int64        |
    36  | `Name`     | Name of the field.                             | int64        |
    37  | `PrimaryKey` | Switch value of primary key enablement.      | Boolean      |
    38  | `AutoID`   | Switch value of auto-generated ID enablement.  | Boolean |
    39  | `Description` | Description of the field.                   | String       |
    40  | `DataType` | Data type of the field. | See [FieldType](https://github.com/milvus-io/milvus-sdk-go/blob/9a7ab65299b4281cc24ad9da7834f6e25866f435/entity/schema.go#L116) for more information. |
    41  | `TypeParams` | Type parameters for the field.               | Map of key string value string |
    42  | `IndexParams` | Index parameters for the field.             | Map of key string value string |
    43  
    44  
    45  ## Response
    46  
    47  `err`: error in the creation process (if any). Possible errors are listed below:
    48  
    49    - `ErrClientNotReady`: error that the client is not connected.
    50  
    51    - error that collection with same name already exists.
    52      
    53    - error that API invocation failed.
    54  
    55  ## Example
    56  
    57  ```go
    58  ctx := context.Background()
    59  schema := &entity.Schema{
    60  // omit for simpliciy
    61  } 
    62  
    63  // cli is a valid Client instance
    64  err := cli.CreateCollection(ctx, schema, 1)
    65  // handles the error not nil
    66  ```