Create a collection (HTTP)
|
For details about additional languages, see: |
Creates a new collection in a database.
|
Ready to write code? See the examples for this method to get started. |
Result
Creates a collection with the specified parameters.
If the command succeeds, the response indicates the success.
Example successful response:
{
"status": {
"ok": 1
}
}
|
You cannot edit a collection’s definition after you create the collection. |
Signature
Use the createCollection command.
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"createCollection": {
"name": "COLLECTION_NAME",
"options": OPTIONS
}
}'
Parameters
| Name | Type | Summary |
|---|---|---|
|
|
The name of the new collection. Collection names must follow these rules:
|
|
|
Optional.
The options for this operation. See Properties of |
| Name | Type | Summary |
|---|---|---|
|
|
Optional.
Specifies the default ID type for documents in the collection.
This is used when you insert a document without an Can be one of:
For examples, see Create a collection and specify the default ID format. For more information, see Document IDs (HTTP). Default: Each autogenerated |
|
|
Optional. The vector configuration for the collection. This includes things like the vector dimension, similarity metric, and source model. Required for vector search. For an example, see Create a collection that can store vector embeddings. The
|
|
|
Optional. Configures selective indexing for data inserted to the collection. The
You must use For examples, see Create a collection and specify which fields to index and Create a collection and specify which fields shouldn’t be indexed. Default: All fields of all documents. |
Examples
The following examples demonstrate how to create a collection.
Create a collection that is not vector-enabled
curl -sS -L -X POST "API_ENDPOINT/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"createCollection": {
"name": "COLLECTION_NAME",
"options": {}
}
}'
Create a collection that can store vector embeddings
Collections that are vector-enabled can store vector embeddings in the reserved $vector field and work with vector search.
For optimal vector search results, you should specify the dimension, metric, and source model of your vector embeddings.
All vector embeddings in a collection should be generated by the same model with the same dimensions.
The source model can be one of: ada002, bert, cohere-v3, gecko, nv-qa-4, openai-v3-large, openai-v3-small, other.
curl -sS -L -X POST "API_ENDPOINT/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"createCollection": {
"name": "COLLECTION_NAME",
"options": {
"vector": {
"dimension": 1024,
"metric": "cosine",
"source_model": "nv-qa-4"
}
}
}
}'
Create a collection and specify the default ID format
For more information about the default ID format, see Document IDs (HTTP). For allowed values, see the Parameters.
curl -sS -L -X POST "API_ENDPOINT/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"createCollection": {
"name": "COLLECTION_NAME",
"options": {
"defaultId": {
"type": "uuidv7"
}
}
}
}'
Create a collection and specify which fields to index
For more information about selective indexing, see Indexes in collections (HTTP).
curl -sS -L -X POST "API_ENDPOINT/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"createCollection": {
"name": "COLLECTION_NAME",
"options": {
"indexing": {
"allow": ["city", "country"]
}
}
}
}'
Create a collection and specify which fields shouldn’t be indexed
For more information about selective indexing, see Indexes in collections (HTTP).
curl -sS -L -X POST "API_ENDPOINT/v1/KEYSPACE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"createCollection": {
"name": "COLLECTION_NAME",
"options": {
"indexing": {
"deny": ["city", "country"]
}
}
}
}'