Create a vector index (Python)

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 (Python) 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
create_vector_index(
  name: str,
  column: str,
  *,
  definition: TableVectorIndexDefinition | dict[str, Any],
  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 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

str

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

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

definition

TableVectorIndexDefinition | dict

Optional. Specifies the indexed column and index options. If you use this parameter, the column and options parameters are not accepted.

options

TableVectorIndexOptions | dict

Optional. Specifies the index options:

  • metric: The similarity metric to use for vector search.

    Can be one of the values in astrapy.constants.VectorMetric: COSINE, DOT_PRODUCT, EUCLIDEAN.

    Default: COSINE

  • source_model: 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.

    Default: other

if_not_exists

bool

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

table_admin_timeout_ms

int

Optional. 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.

from astrapy import DataAPIClient

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

# Index a vector column
table.create_vector_index(
    "INDEX_NAME", column="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.

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

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

# Index a vector column
table.create_vector_index(
    "INDEX_NAME",
    column="VECTOR_COLUMN_NAME",
    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.

from astrapy import DataAPIClient

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

# Index a vector column
table.create_vector_index(
    "INDEX_NAME",
    column="VECTOR_COLUMN_NAME",
    if_not_exists=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