Skip to content
MilvusNode SDK
Sections

Create collection

Markdown

Copy for agent

Connection and CORS help

Use HTTPS for remote clusters or HTTP on loopback. Requests go directly from your browser to the endpoint. When copying an authenticated cURL command, set MILVUS_TOKEN in your shell.

For cross-origin requests, configure the endpoint to answer OPTIONS and allow the docs origin, POST, Content-Type, and Authorization if you use a token. Try the copied cURL command to troubleshoot outside the browser.

POST/v2/vectordb/collections/create

{
  "dbName": "default",
  "collectionName": "books_demo",
  "dimension": 4,
  "metricType": "COSINE",
  "primaryFieldName": "id",
  "vectorFieldName": "vector"
}

Example response

{
  "code": 0,
  "data": {}
}
cURL command
curl --request POST --url 'https://your-cluster.example.com/v2/vectordb/collections/create' \
  --header 'Content-Type: application/json' \
  --header "Authorization: Bearer ${MILVUS_TOKEN}" \
  --data-raw '{
  "dbName": "default",
  "collectionName": "books_demo",
  "dimension": 4,
  "metricType": "COSINE",
  "primaryFieldName": "id",
  "vectorFieldName": "vector"
}'

Create a collection using a vector dimension for quick setup or an explicit schema for custom fields and functions.

Request fields

dbName string
Database name. Operations on collections use default when omitted.
collectionName string (required)
Name of the collection.
dimension integer
Number of vector components for quick collection setup. Supply this or an explicit schema.
idType string
Primary key type for quick setup, such as Int64 or VarChar.
autoID boolean
Let the server generate primary keys.
metricType string
Vector distance metric, such as COSINE, L2, or IP.
vectorFieldType string
Vector data type for quick setup. Choose a type compatible with the metric.
consistencyLevel string
Read consistency level, such as Strong, Session, or Bounded.
primaryFieldName string
Primary key field name for quick setup.
vectorFieldName string
Vector field name for quick setup.
schema object
Explicit collection schema. Put externalSource and externalSpec inside schema for an external collection.
indexParams array of object
Index definitions, including the target field, metric and index parameters.
params object
Additional operation parameters.
properties object
Map of property names to their new values.
description string
Human-readable description.

See HttpClient.createCollection for the Node.js SDK method.