Skip to main content
Version: V1.2.0

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 must be between 64 and 512 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, Schema = Schema , embedding_function = embedding_function )
ParameterTypeRequiredDescriptionExample value
namestringYesThe name of the collection to be created.my_collection
Schemavector_index | sparse_vector_index | fulltext_indexNoIndex configuration that specifies vector dimensions and distance metrics. If omitted, the default is an HNSW dense index and a full-text index that uses the IK tokenizer.schema = Schema(vector_index=VectorIndexConfig(hnsw=HNSWConfiguration(dimension=384, distance="cosine") ),sparse_vector_index=SparseVectorIndexConfig(embedding_function=BM25EmbeddingFunction(), source_key="#document"), fulltext_index=FulltextIndexConfig(analyzer='ik', properties={'ik_mode':'max_words'}))
embedding_functionEmbeddingFunctionNoFunction used to convert input into vectors. If omitted, DefaultEmbeddingFunction() is used (384 dimensions). If set to None, the collection has no embedding capability. If an embedding function is provided, the dimension is determined automatically according to configuration.dimension.DefaultEmbeddingFunction()

The parameters in Schema are described as follows:

ParameterTypeRequiredDescriptionExample value
vector_indexVectorIndexConfig | HNSWConfiguration | NoneNoDense index configuration. If omitted, an HNSW dense index is used by default. For details, see Dense vector index.vector_index=VectorIndexConfig(hnsw=HNSWConfiguration(dimension=384, distance="cosine") )
sparse_vector_indexSparseVectorIndexConfig | NoneNoSparse index configuration. If omitted, no sparse index is used. For details, see Sparse vector index.sparse_vector_index=SparseVectorIndexConfig(embedding_function=BM25EmbeddingFunction(), source_key="#document")
fulltext_indexFulltextIndexConfig | NoneNoFull-text index configuration. It includes analyzer and properties. If omitted, defaults apply; the default is analyzer='ik'. For details, see Full-text index.FulltextIndexConfig(analyzer='ik', properties={'ik_mode':'max_words'}))
info

When you provide embedding_function, the system automatically calculates the vector dimension by calling the function. If you also specify configuration.dimension, its value must match the dimension of embedding_function. Otherwise, a ValueError is 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
)

config = Configuration(hnsw=HNSWConfiguration(dimension=384), fulltext_config=FulltextIndexConfig(analyzer='ik', properties={'ik_mode':'max_words'}))
collection = client.create_collection(
name="my_collection4",
configuration=config,
embedding_function=None
)

Response parameters​

None