Skip to main content
Version: V1.1.0

createCollection - Create a collection

The createCollection() method is used to create a new collection, which is equivalent to a table in the database.

info

This API can only be used when connected with SeekdbClient. For more information about SeekdbClient, see SeekdbClient.

Prerequisites

  • You have installed seekdb-js. For more information, see Quick start.

  • You have installed the seekdb server mode. For more information, see Deploy by using yum install.

  • You have connected to the database. For more information, see SeekdbClient.

  • The user to which you are connected has the CREATE permission. For more information about how to view the current user permissions, see View user privileges. If the user does not have this permission, contact the administrator to grant it. For more information about how to directly grant permissions, see Directly grant permissions.

Define a table name

When creating a table, you must first define a table name. The following requirements must be met when defining a table name:

  • In seekdb, the name of each table must be unique within the database.

  • The table name can be between 64 and 512 characters in length.

  • We recommend that you use a meaningful name for the table instead of a generic name such as t1 or table1. For more information about table naming conventions, see Table naming conventions.

Request parameters

createCollection(options: CreateCollectionOptions)
ParameterTypeRequiredDescriptionExample value
namestringYesThe name of the collection to be created.my_collection
configurationConfiguration | HNSWConfigurationNoThe collection configuration, which contains the HNSWConfiguration and FulltextAnalyzerConfig attributes.{hnsw: {dimension: 384, distance: 'cosine'}, fulltextConfig: {analyzer: 'ik', ik_mode: 'smart'}}
embeddingFunctionEmbeddingFunction | nullNoThe embedding function used to convert text to vectors. If you set the parameter to null, the embedding function is not used.DefaultEmbeddingFunction()

The HNSWConfiguration parameter is described as follows:

ParameterTypeRequiredDescriptionExample value
dimensionnumberNoThe vector dimension. If you specify the embeddingFunction parameter, the system automatically infers the value of this parameter from the embeddingFunction.dimension: 384,distance: 'cosine'
distanceDistanceMetricNoThe distance metric. Valid values: 'l2' (Euclidean distance), 'cosine' (cosine similarity), and 'inner_product' (inner product).dimension: 384, distance: 'cosine'
info
  • If you specify the embeddingFunction parameter, the system automatically calculates the vector dimension by calling the function. If you also specify the configuration.dimension parameter, the value of configuration.dimension must match the dimension of the embeddingFunction, otherwise a ValueError will be returned.

  • embeddingFunction (EmbeddingFunction, optional): The function used to convert documents to vectors. If you specify this parameter, the system automatically calculates the dimension and verifies that it matches the value of the configuration.dimension parameter.

Request example

import { SeekdbClient } from "seekdb";

// 1. Connect
const client = new SeekdbClient({
host: "127.0.0.1",
port: 2881,
user: "root",
password: "",
database: "test",
});

// 2. Create collection
const collection = await client.createCollection({ name: "my_collection" });

Response parameters

None