Create a vector index

Tables with the Data API are currently in public preview. Development is ongoing, and the features and functionality are subject to change. Astra DB Serverless, and the use of such, is subject to the DataStax Preview Terms.

Creates a new index for a vector column in a table in a Serverless (Vector) 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 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.

Does not return anything.

Parameters

Use the create_vector_index method, which belongs to the astrapy.table.Table class.

Method signature
python
create_vector_index(
  name: str,
  *,
  column: str,
  options: TableVectorIndexOptions | dict[str, Any],
  if_not_exists: bool,
  table_admin_timeout_ms: int,
  request_timeout_ms: int,
  timeout_ms: int,
) -> None
Name Type Summary

name

str

The name of the index.

Index names must be unique within a keyspace.

column

str

The name of the table column on which to create the index. The column must be of type vector.

The column name must use snake case, not camel case.

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

options

TableVectorIndexOptions | dict | None

Specifies index options:

  • metric: One of the values in astrapy.constants.VectorMetric selects a similarity metric, such as COSINE (default), DOT_PRODUCT, or EUCLIDEAN.

  • source_model: Enable certain vector optimizations on the index by specifying the source model for your vectors, such as 'openai_v3_large', 'openai_v3_small', 'ada002', 'gecko', 'bert', or 'other' (default). If a model is specified, the index automatically uses the parameters best suited to that embedding model.

If passed, it must be an instance of TableVectorIndexOptions or an equivalent dictionary.

if_not_exists

bool | None

If True, and an index with the given name already exists in the keyspace, then the command succeeds and silently does nothing. In this case, no actual index creation takes place on the database.

If False (default), an error occurs if an index with the specified name already exists.

ifNotExists: True, does not check the type or content of any existing indexes. This parameter checks index names only.

This means that the command succeeds if the given index name is already in use, even if the type or indexed column is different.

table_admin_timeout_ms

int | None

A timeout, in milliseconds, to impose on the underlying API request. If not provided, the Table defaults apply. This parameter is aliased as request_timeout_ms and timeout_ms for convenience.

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.

python
from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Index a vector column
table.create_vector_index("example_index_name", column="example_vector_column")

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

You can specify the embedding source model and the similarity metric when you create a vector index.

python
from astrapy import DataAPIClient
from astrapy.constants import VectorMetric
from astrapy.info import TableVectorIndexOptions

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Index a vector column
table.create_vector_index(
    "example_index_name",
    column="example_vector_column",
    options=TableVectorIndexOptions(
        metric=VectorMetric.DOT_PRODUCT,
        source_model="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.

python
from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Index a vector column
table.create_vector_index(
    "example_index_name",
    column="example_vector_column",
    if_not_exists=True,
)

Client reference

For more information, see the client reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2025 DataStax | 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: +1 (650) 389-6000, info@datastax.com