createIndexes

Creates indexes on MongoDB® collections. To create vector indexes, use the kaiIndexOptions parameter. Refer to Vector Indexing for information on vector indexes supported in SingleStore. This command is an extension of the MongoDB® createIndexes command.

Syntax

{
"createIndexes": "<collection_name>",
"indexes": [
{ "name": "<index_name>",
"key": { "<path_to_property>": "vector" },
"kaiIndexOptions": {
"index_type": "string"
"dimensions": <integer_value>,
// other fields relevant to each index type }
} ] }

Arguments

Field

Type

Requirement

Description

createIndexes

String

Required

The collection for which the index is created.

indexes

JSON array

Required

An array that specifies the index to create. Each document in the array specifies a separate index.

name

String

Required

A name for the vector index.

kaiIndexOptions

JSON object

Required

Specifies index options for the vector index.

Remarks

  • The createIndexes command creates an index on the specified field in a collection using a persisted computed column within the same collection.

  • SingleStore recommends creating collections (or tables) before creating a vector index. You must specify the field that holds the vector embeddings while creating the collection. Here's a sample syntax:

    db.createCollection(
    "<collection_name>",
    columns= [{'id': '<vector_field_name>', 'type': "VECTOR(<vector_dimension>, <type>) NOT NULL"}]
    )

    Refer to createCollection for more information.

  • If the specified collection does not exist, it is created along with the required structures. For example:

    db.runCommand({
    createIndexes: "sampleCollection",
    indexes: [
    { key: { "sampleCollection.vectorField": "vector" },
    name: "searchVector_IVF_EUC",
    kaiIndexOptions:
    { "index_type":"IVF_FLAT",
    "nlist":5,
    "nprobe":1,
    "metric_type": "EUCLIDEAN_DISTANCE",
    "dimensions": 2 } }
    ]
    } )
    DESC sampleCollection;
    +-------------------------------+----------------+------+-----+---------+----------+
    | Field                         | Type           | Null | Key | Default | Extra    |
    +-------------------------------+----------------+------+-----+---------+----------+
    | _id                           | bson           | NO   |     | NULL    |          |
    | _more                         | bson           | NO   |     | NULL    |          |
    | $_id                          | longblob       | YES  | UNI | NULL    | computed |
    | $sampleCollection.vectorField | vector(2, F32) | NO   | MUL | NULL    | computed |
    +-------------------------------+----------------+------+-----+---------+----------+
  • Use the index_type and dimensions fields in the kaiIndexOptions parameter to specify the type of vector index and the dimension of the vector, respectively.

  • You can specify supported Index Options in the kaiIndexOptions parameter for each index type. The specified values are set as defaults for the respective index search parameters.

Example

The following example shows how to create a vector index using the createIndexes command.

db.runCommand({
createIndexes: "exampleCollection",
indexes: [
{ key: { "exampleCollection.vectorField": "vector" },
name: "searchVector_IVF_EUC",
kaiIndexOptions:
{ "index_type":"IVF_FLAT",
"nlist":5,
"nprobe":1,
"metric_type": "EUCLIDEAN_DISTANCE",
"dimensions": 2 } }
]
} )

Use the db.<collection_name>.getIndexes() command to view existing indexes on a collection. For example:

db.exampleCollection.getIndexes()
[ { v: 2, key: { _id: 1 }, name: '_id_' },
  { v: 2,
    key: { 'exampleCollection.vectorField': 'vector' },
    name: 'searchVector_IVF_EUC',
    kaiSearchSpec: 
     { nlist: 5,
       nprobe: 1,
       index_type: 'IVF_FLAT',
       metric_type: 'EUCLIDEAN_DISTANCE',
       dimensions: 2 } } ]

References

Last modified: November 4, 2024

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK