--- slug: /create-collection-of-api --- # create_collection - Create a collection `create_collection()` is used to create a new collection, which is a table in the database. :::info This API is only available when you are connected to the database using a client. For more information about the client, see [Client](../50.client.md). ::: ## Prerequisites * You have installed pyseekdb. For more information about how to install pyseekdb, see [Quick Start](../../10.pyseekdb-sdk/10.pyseekdb-sdk-get-started.md). * You are connected to the database. For more information about how to connect to the database, see [Client](../50.client.md). * If you are using seekdb in server mode or OceanBase Database, make sure that the user has the `CREATE` privilege. For more information about how to view the privileges of the current user, see [View user privileges](https://en.oceanbase.com/docs/common-oceanbase-database-10000000001971368). If the user does not have the privilege, contact the administrator to grant it. For more information about how to directly grant privileges, see [Directly grant privileges](https://en.oceanbase.com/docs/common-oceanbase-database-10000000001974754). ## Define the table name When creating a table, you must first define its name. The following requirements apply when defining the table name: * In seekdb, each table name must be unique within the database. * The table name cannot exceed 64 characters. * We recommend that you give the table a meaningful name instead of using generic names such as t1 or table1. For more information about table naming conventions, see [Table naming conventions](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000003977289). ## Request parameters ```python create_collection(name = name,configuration = configuration, embedding_function = embedding_function ) ``` |Parameter|Type|Required|Description|Example value| |---|---|---|---|---| |`name`|string|Yes|The name of the collection to be created. |my_collection| |`configuration`|HNSWConfiguration|No|The index configuration, which specifies the dimension and distance metric. If not provided, the default values `dimension=384` and `distance='cosine'` are used. If set to `None`, the dimension is calculated from the `embedding_function` value. |HNSWConfiguration(dimension=384, distance='cosine')| |`embedding_function`|EmbeddingFunction|No|The function to convert data into vectors. If not provided, `DefaultEmbeddingFunction()(384 dimensions)` is used. If set to `None`, the collection will not include embedding functionality, and if provided, it will be calculated based on `configuration.dimension`.|DefaultEmbeddingFunction()| :::info When you provide `embedding_function`, the system will automatically calculate the vector dimension by calling this function. If you also provide `configuration.dimension`, it must match the dimension of `embedding_function`. Otherwise, a ValueError will be raised. ::: ## Request example ```python import pyseekdb from pyseekdb import DefaultEmbeddingFunction, HNSWConfiguration # Create a client client = pyseekdb.Client() # Create a collection with default embedding function (auto-calculates dimension) collection = client.create_collection( name="my_collection" ) # Create a collection with custom embedding function ef = UserDefinedEmbeddingFunction() // define your own Embedding function, See section.6 config = HNSWConfiguration(dimension=384, distance='cosine') # Must match EF dimension collection = client.create_collection( name="my_collection2", configuration=config, embedding_function=ef ) # Create a collection without embedding function (vectors must be provided manually) collection = client.create_collection( name="my_collection3", configuration=HNSWConfiguration(dimension=384, distance='cosine'), embedding_function=None # Explicitly disable embedding function ) ``` ## Response parameters None ## References * [Query a collection](200.get-collection-of-api.md) * [Create or query a collection](250.get-or-create-collection-of-api.md) * [Get a collection list](300.list-collection-of-api.md) * [Count the number of collections](350.count-collection-of-api.md) * [Delete a collection](400.delete-collection-of-api.md)