Skip to main content

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.

Prerequisites

  • You have installed pyseekdb. For more information about how to install pyseekdb, see Quick Start.

  • You are connected to the database. For more information about how to connect to the database, see Client.

  • 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. 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.

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.

Request parameters

create_collection(name = name,configuration = configuration, embedding_function = embedding_function )
ParameterTypeRequiredDescriptionExample value
namestringYesThe name of the collection to be created.my_collection
configurationHNSWConfigurationNoThe 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_functionEmbeddingFunctionNoThe 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

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