All Products
Search
Document Center

DashVector:Create a collection

Last Updated:Mar 18, 2025

This topic describes how to create a collection by using the HTTP API.

Prerequisites

Method and URL

POST https://{Endpoint}/v1/collections

Example

Note

You need to replace YOUR_API_KEY with your API key and YOUR_CLUSTER_ENDPOINT with the endpoint of your cluster in the sample code for the code to run properly.

# Create a collection and set its name to quickstart, the number of vector dimensions to 4, 
# vector data type to the default value of FLOAT, 
# and distance metric to dotproduct.
# Predefine the name, weight, and age fields, and set their data types to STRING, FLOAT, and INT, respectively.

curl -XPOST \
  -H 'dashvector-auth-token: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "quickstart", 
    "dimension": 4, 
    "metric": "dotproduct", 
    "fields_schema": {
      "name": "STRING",
      "age": "INT",
      "weight": "FLOAT",
      "id": 1234567890
    }
  }' https://YOUR_CLUSTER_ENDPOINT/v1/collections

# example output:
# {"request_id":"19215409-ea66-4db9-8764-26ce2eb5bb99","code":0,"message":""}

Request parameters

Parameter

Location

Type

Required

Description

{Endpoint}

path

str

Yes

The endpoint of the cluster. You can view the endpoint on the cluster details page in the console.

dashvector-auth-token

header

str

Yes

The API key.

name

body

str

Yes

The name of the collection to be created.

dimension

body

int

Yes

The number of vector dimensions. Valid values: (1, 20000].

dtype

body

str

No

The vector data type. Valid values: FLOAT (default) and INT.

fields_schema

body

object

No

The predefined fields.

metric

body

str

No

The distance metric. Valid values: euclidean, dotproduct, and cosine (default).

If the value is cosine, dtype must be set to FLOAT.

Note

For more information about the advantages of predefining fields during collection creation, see Schema-free.

Response parameters

Parameter

Type

Description

Example

code

int

The returned status code. For more information, see Status codes.

0

message

str

The returned message.

success

request_id

str

The unique ID of the request.

19215409-ea66-4db9-8764-26ce2eb5bb99