Create a vector index (TypeScript)

Creates a new index for a vector column in a table in a database. You must create a vector index if you want to perform a vector search on vector embeddings stored in a column.

To create an index on a non-vector column, see Create an index (TypeScript) instead.

To manage indexes, your application token must have the same level of permissions that you need to manage tables.

Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart.

Result

Creates an index for the specified vector column.

Returns a promise that resolves once the operation completes.

Parameters

Use the createVectorIndex method, which belongs to the Table class.

Method signature
async createVectorIndex(
  name: string,
  column: keyof Schema | Partial<Record<keyof Schema, string>>,
  options?: {
    ifNotExists?: boolean,
    options?: {
      metric?: string,
      sourceModel?: string,
      timeout?: number | TimeoutDescriptor,
    },
  }
): void
Name Type Summary

name

string

The name of the index.

Index names for tables must follow these rules:

  • Must be unique within the keyspace

  • Can contain letters, numbers, and underscores

  • Must have a length of 1 to 100 characters

column

string

The name of the vector column on which to create the index.

To create indexes on non-vector columns, see Create an index (TypeScript).

options

TableCreateVectorIndexOptions

Optional. The options for this operation. See Properties of options for more details.

Properties of options
Name Type Summary

metric

string

Optional. The similarity metric to use for vector search.

Can be one of: cosine, dot_product, euclidean.

For an example, see Create a vector index and specify the source model and similarity metric.

Default: cosine

sourceModel

string

Optional. The model used to generate the embeddings that the indexed column stores. This enables certain vector optimizations on the index.

Can be one of: ada002, bert, cohere-v3, gecko, nv-qa-4, openai-v3-large, openai-v3-small, other.

For an example, see Create a vector index and specify the source model and similarity metric.

Default: other

ifNotExists

boolean

Optional. Whether the command should silently succeed even if an index with the given name already exists in the keyspace and no new index was created.

This option only checks index names. It does not check index definitions.

Default: false

timeout

number | TimeoutDescriptor

A timeout, in milliseconds, to impose on the underlying API request.

Examples

The following examples demonstrate how to create a vector index.

Create a vector index with the default source model and similarity metric

If you do not specify the source model and similarity metric, the default values are used. For more information, see Parameters.

import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient();
const database = client.db("API_ENDPOINT", {
  token: "APPLICATION_TOKEN",
});
const table = database.table("TABLE_NAME");

// Index a vector column
(async function () {
  await table.createVectorIndex("INDEX_NAME", "VECTOR_COLUMN_NAME");
})();

Create a vector index and specify the source model and similarity metric

When you create a vector index, you can specify the embedding source model, the similarity metric, or both.

import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient();
const database = client.db("API_ENDPOINT", {
  token: "APPLICATION_TOKEN",
});
const table = database.table("TABLE_NAME");

// Index a vector column
(async function () {
  await table.createVectorIndex("INDEX_NAME", "VECTOR_COLUMN_NAME", {
    options: {
      metric: "dot_product",
      sourceModel: "nv-qa-4",
    },
  });
})();

Create an index only if the index does not exist

Use this option to silently do nothing if an index with the specified name already exists.

This option only checks index names. It doesn’t check the type or content of any existing indexes.

import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient();
const database = client.db("API_ENDPOINT", {
  token: "APPLICATION_TOKEN",
});
const table = database.table("TABLE_NAME");

// Index a vector column
(async function () {
  await table.createVectorIndex("INDEX_NAME", "VECTOR_COLUMN_NAME", {
    ifNotExists: true,
  });
})();

Client reference

For more information, see the client reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM