Create collection
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
dbNamestring- Database name. Operations on collections use default when omitted.
collectionNamestring (required)- Name of the collection.
dimensioninteger- Number of vector components for quick collection setup. Supply this or an explicit schema.
idTypestring- Primary key type for quick setup, such as Int64 or VarChar.
autoIDboolean- Let the server generate primary keys.
metricTypestring- Vector distance metric, such as COSINE, L2, or IP.
vectorFieldTypestring- Vector data type for quick setup. Choose a type compatible with the metric.
consistencyLevelstring- Read consistency level, such as Strong, Session, or Bounded.
primaryFieldNamestring- Primary key field name for quick setup.
vectorFieldNamestring- Vector field name for quick setup.
schemaobject- Explicit collection schema. Put externalSource and externalSpec inside schema for an external collection.
indexParamsarray of object- Index definitions, including the target field, metric and index parameters.
paramsobject- Additional operation parameters.
propertiesobject- Map of property names to their new values.
descriptionstring- Human-readable description.
See HttpClient.createCollection for the Node.js SDK method.