createCollection()
A MilvusClient interface. This method creates a collection with simple parameters.
R<RpcStatus> createCollection(CreateSimpleCollectionParam requestParam);
CreateSimpleCollectionParam
Use the CreateSimpleCollectionParam.Builder
to construct a CreateSimpleCollectionParam
object.
import io.milvus.param.highlevel.collection.CreateCollectionParam;
CreateSimpleCollectionParam.Builder builder = CreateSimpleCollectionParam.newBuilder();
Methods of CreateSimpleCollectionParam.Builder
:
Method |
Description |
Parameters |
---|---|---|
withCollectionName(String collectionName) |
Sets the collection name. Collection name cannot be empty or null. |
collectionName: The name of the collection to create. |
withDimension(int dimension) |
Sets the collection vector dimension. Dimension value must be greater than zero and less than 32768. |
dimension: The number of dimensions for the vector field of the collection. |
withMetricType(MetricType metricType) |
Sets the metricType of vectorField. The distance metric used for the collection. |
metricType: The distance metric used for the collection. |
withDescription(String description) |
Sets the collection description. The description can be empty. The default description is "". |
description: The description of the collection to create. |
withPrimaryField(String primaryField) |
Sets the primaryFiled name. The primaryField cannot be empty or null. The default is "id". |
primaryField: The primary field name of the collection. |
withVectorField(String vectorField) |
Sets the vectorField name. The vectorField cannot be empty or null. The default is "vector". |
vectorField: The vector field name of the collection. |
withAutoId(boolean autoId) |
Sets the autoId. The default is Boolean.False. |
autoId: If open autoId towards to this collection. |
withSyncLoad(boolean syncLoad) |
Sets the SyncLoad when loadCollection.The default is Boolean.True. |
syncLoad: If syncLoad when loadCollection. |
withConsistencyLevel(ConsistencyLevelEnum consistencyLevel) |
Sets the consistency level. The default value is ConsistencyLevelEnum.BOUNDED |
consistencyLevel: The consistency level of this collection. |
withPrimaryFieldType(DataType primaryFieldType) |
Sets the primaryFiled type. The primaryField type cannot be empty or null. The default is "DataType.Int64". |
primaryFieldType: The type of the primary field of this collection. |
withMaxLength(Integer maxLength) |
Sets the primaryFiled maxLength. |
maxLength: The max length of the primary field If primaryFiled is specified as varchar. |
build() |
Constructs a CreateSimpleCollectionParam object. |
N/A |
The CreateSimpleCollectionParam.Builder.build()
can throw the following exceptions:
- ParamException: error if the parameter is invalid.
Returns
This method catches all the exceptions and returns an R<RpcStatus>
object.
If the API fails on the server side, it returns the error code and message from the server.
If the API fails by RPC exception, it returns
R.Status.Unknown
and the error message of the exception.If the API succeeds, it returns
R.Status.Success
.
Example
import io.milvus.param.highlevel.collection.*;
CreateSimpleCollectionParam param = CreateSimpleCollectionParam.newBuilder()
.withCollectionName(COLLECTION_NAME)
.withDimension(VECTOR_DIM)
.withPrimaryField(ID_FIELD)
.withVectorField(VECTOR_FIELD)
.withAutoId(true)
.build();
R<RpcStatus> response = client.createCollection(param);
if (response.getStatus() != R.Status.Success.getCode()) {
System.out.println(response.getMessage());
}