milvus-logo
LFAI
< Docs
  • Node

createCollection()

With this method, you can create a new collection with a defined schema based on your specified requirements.

The collection to create must contain a primary key field and a vector field. Int64 or String are supported data type on primary key field.

The collection to create must contain a vector field, which can be DataType.FloatVector or DataType.BinaryVector, and set it's dimensions with the property dim.

Example 1

node sdk v2.2.11+

When the collection is created, the SDK will create and load the collection for you, so you can insert data and search directly.

import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";

new milvusClient(MILUVS_ADDRESS).createCollection({
  collection_name: "my_collection",
  dimension: 128,
});

Parameters

ParametersDescriptionType
collection_namecollection nameString
dimensionvector dimensionnumber
primary_field_name?primary field nameString
id_type?What data type is the id type, default is DataType.Int64,DataType.Int64 or DataType.VarChar
vector_field_name?vector field namestring
metric_type?max length of the varChar fieldstring or MetricType
enableDynamicField?enable dynamic fieldBool
auto_id?enable auto id, default is falesBool
index_params?create index params, same as parameters for method createIndexObject

Example 2

node sdk v2.2.0+

You need to define schema first, then create the collection.

import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";

const schema: Field[] = [
  {
    name: "age",
    description: "id field",
    data_type: DataType.Int64,
    autoID: true,
    is_primary_key: true,
  },
  {
    name: "vector_01",
    description: "vector field",
    data_type: DataType.FloatVector,
    dim: 8,
  },
  {
    name: "name",
    description: "other field",
    data_type: DataType.VarChar,
    max_length: 256,
  },
  {
    name: "meta",
    description: "json field",
    data_type: DataType.JSON,
  },
];

new milvusClient(MILUVS_ADDRESS).createCollection({
  collection_name: "my_collection",
  fields: schema,
  enable_dynamic_field: false,
});

Response

// create collection returns
{ error_code: 'Success', reason: '' }

Parameters

ParametersDescriptionType
collection_nameName of the collection to createString
fieldsfield schema to createField[]
timeout?This parameter is used to specify the length of time, in milliseconds, that the RPC (Remote Procedure Call) is allowed to run. If no value is provided, the default is undefined.Number
consistency_level?Consistency in a distributed database specifically refers to the property that ensures every node or replica has the same view of data when writing or reading data at a given time.String , default: "Bounded"
num_partitions? milvus v2.2.9+ & node sdk v2.2.12+partitions limit, default: 64, max: 4096Field[]
enable_dynamic_field? milvus v2.2.9+ & node sdk v2.2.12+enbale dynamic fieldString

Field

ParametersDescriptionType
nameField nameString
data_typeData type of the field (see the table below)DataType(number) or String
description?Field descriptionString
autoID?Boolean value to indicate whether the IDs are automatically generatedBool
dim?dimension of the vector fieldnumber
max_length?max length of the varChar fieldnumber
is_primary_key?Boolean value to indicate whether this field is used as the primary keyBool
is_partition_key? milvus v2.2.9+ & node sdk v2.2.12+Boolean value to indicate whether this field is used as the partition key enabled field, only support Int64 or VarChar fieldBool

The data_type property

You can either use enum or string, for example: DataType.Int64 or Int64 for the data_type property.

NumberString
1Bool
2Int8
3Int16
4Int32
5Int64
10Float
11Double
21Varchar
23JSON milvus v2.2.9+ & node v2.2.12+
100BinaryVector
101FloatVector

The consistency_level property

The default value is "Bounded", you can set the consistency level as : "Session" or "Bounded" or "Eventually" or "Customized".