Alter a table (Go)
Alters a table by doing one of the following:
-
Adding one or more columns to a table
-
Dropping one or more columns from a table
-
Adding automatic embedding generation for one or more vector columns
-
Removing automatic embedding generation for one or more vector columns
You cannot change a column’s type. Instead, you must drop the column and add a new column.
After you add a column, you should index the column if you want to filter or sort on the column. For more information, see Create an index (Go) and Create a vector index (Go).
|
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
Adds or drops columns, or adds or removes a vectorize integration for vector columns. Removing a vectorize integration for a column does not remove the vector embeddings stored in the column.
Returns a Table object that represents the table after the modification.
Parameters
Use the Alter method, which belongs to the Table type.
Method signature
func (t *Table) Alter(
ctx context.Context,
op table.AlterOperation,
opts ...options.AlterTableOption
) error
| Name | Type | Summary |
|---|---|---|
|
|
The context for the operation. |
|
|
The alter operation to perform. Can be one of the following:
|
|
Optional.
A builder to generate options for this operation.
See Methods of the |
| Method | Summary |
|---|---|
|
Optional. General API options for this operation, including the timeout. |
Examples
The following examples demonstrate how to alter a table.
Add columns to a table
When you add columns, the columns are defined in the same way as they are when you create a table.
After you add a column, you should index the column if you want to filter or sort on the column. For more information, see Create an index (Go) and Create a vector index (Go).
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddColumns{
Columns: table.Columns{
{Name: "is_summer_reading", Column: table.Boolean()},
{Name: "library_branch", Column: table.Text()},
},
})
if err != nil {
log.Fatal(err)
}
}
Add vector columns to a table
After you add a vector column, you should index the column if you want run vector searches on the column. For more information, Create a vector index (Go).
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddColumns{
Columns: table.Columns{
{Name: "example_vector", Column: table.Vector(1024)},
},
})
if err != nil {
log.Fatal(err)
}
}
Add a vector column and configure an embedding provider integration
When you add a vector column to a table, you can configure an embedding provider integration for the column. The integration will automatically generate vector embeddings for any data inserted into the column.
The configuration depends on the embedding provider.
The original data isn’t stored automatically. If you want to store the original data in addition to the vector embeddings that were generated from the data, then you need to create a separate column and manually store the original data in that column.
After you add a vector column, you should index the column if you want run vector searches on the column. For more information, Create a vector index (Go).
Configure Azure OpenAI as the embedding provider
For more detailed instructions, see Integrate Azure OpenAI as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddColumns{
Columns: table.Columns{
// This column will store vector embeddings.
// The configured vector service
// will automatically generate vector embeddings
// for any text inserted to this column.
{
Name: "VECTOR_COLUMN_NAME",
Column: table.VectorWithService(MODEL_DIMENSIONS, &table.VectorService{
Provider: "azureOpenAI",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
Parameters: map[string]string{
"resourceName": "RESOURCE_NAME",
"deploymentId": "DEPLOYMENT_ID",
},
}),
},
// If you want to store the original text
// in addition to the generated embeddings
// you must create a separate column.
{Name: "TEXT_COLUMN_NAME", Column: table.Text()},
},
})
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
TEXT_COLUMN_NAME: The name for the text column that will store the original text. Omit this column if you won’t store the original text in addition to the generated embeddings. -
API_KEY_NAME: The name of the Azure OpenAI API key that you want to use. Must be the name of an existing Azure OpenAI API key in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:text-embedding-3-small,text-embedding-3-large,text-embedding-ada-002.For Azure OpenAI, you must select the model that matches the one deployed to your
DEPLOYMENT_IDin Azure. -
MODEL_DIMENSIONS: The number of dimensions that you want the generated vectors to have. Your chosen embedding model must support the specified number of dimensions.If you omit the dimension, Astra DB can use a default dimension value. However, some models don’t have default dimensions. You can use the Data API to find supported embedding providers and their configuration parameters, including dimensions ranges and default dimensions.
-
RESOURCE_NAME: The name of your Azure OpenAI Service resource, as defined in the resource’s Instance details. For more information, see the Azure OpenAI documentation. -
DEPLOYMENT_ID: Your Azure OpenAI resource’s Deployment name. For more information, see the Azure OpenAI documentation.
Configure Hugging Face (Dedicated) as the embedding provider
For more detailed instructions, see Integrate Hugging Face Dedicated as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddColumns{
Columns: table.Columns{
// This column will store vector embeddings.
// The configured vector service
// will automatically generate vector embeddings
// for any text inserted to this column.
{
Name: "VECTOR_COLUMN_NAME",
Column: table.VectorWithService(MODEL_DIMENSIONS, &table.VectorService{
Provider: "huggingfaceDedicated",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
Parameters: map[string]string{
"endpointName": "ENDPOINT_NAME",
"regionName": "REGION",
"cloudName": "CLOUD_PROVIDER",
},
}),
},
// If you want to store the original text
// in addition to the generated embeddings
// you must create a separate column.
{Name: "TEXT_COLUMN_NAME", Column: table.Text()},
},
})
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
TEXT_COLUMN_NAME: The name for the text column that will store the original text. Omit this column if you won’t store the original text in addition to the generated embeddings. -
API_KEY_NAME: The name of the Hugging Face Dedicated user access token that you want to use. Must be the name of an existing Hugging Face Dedicated user access token in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:endpoint-defined-model.For Hugging Face Dedicated, you must deploy the model as a text embeddings inference (TEI) container.
You must set
MODEL_NAMEtoendpoint-defined-modelbecause this integration uses the model specified in your dedicated endpoint configuration. -
MODEL_DIMENSIONS: The number of dimensions that you want the generated vectors to have. Your chosen embedding model must support the specified number of dimensions.If you omit the dimension, Astra DB can use a default dimension value. However, some models don’t have default dimensions. You can use the Data API to find supported embedding providers and their configuration parameters, including dimensions ranges and default dimensions.
-
ENDPOINT_NAME: The programmatically-generated name of your Hugging Face Dedicated endpoint. This is the first part of the endpoint URL. For example, if your endpoint URL ishttps://mtp1x7muf6qyn3yh.us-east-2.aws.endpoints.huggingface.cloud, the endpoint name ismtp1x7muf6qyn3yh. -
REGION: The cloud provider region your Hugging Face Dedicated endpoint is deployed to. For example,us-east-2. -
CLOUD_PROVIDER: The cloud provider your Hugging Face Dedicated endpoint is deployed to. For example,aws.
Configure Hugging Face (Serverless) as the embedding provider
For more detailed instructions, see Integrate Hugging Face Serverless as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddColumns{
Columns: table.Columns{
// This column will store vector embeddings.
// The configured vector service
// will automatically generate vector embeddings
// for any text inserted to this column.
{
Name: "VECTOR_COLUMN_NAME",
Column: table.VectorWithService(MODEL_DIMENSIONS, &table.VectorService{
Provider: "huggingface",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
}),
},
// If you want to store the original text
// in addition to the generated embeddings
// you must create a separate column.
{Name: "TEXT_COLUMN_NAME", Column: table.Text()},
},
})
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
TEXT_COLUMN_NAME: The name for the text column that will store the original text. Omit this column if you won’t store the original text in addition to the generated embeddings. -
API_KEY_NAME: The name of the Hugging Face Serverless user access token that you want to use. Must be the name of an existing Hugging Face Serverless user access token in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:sentence-transformers/all-MiniLM-L6-v2,intfloat/multilingual-e5-large,intfloat/multilingual-e5-large-instruct,BAAI/bge-small-en-v1.5,BAAI/bge-base-en-v1.5,BAAI/bge-large-en-v1.5. -
MODEL_DIMENSIONS: The number of dimensions that you want the generated vectors to have. Your chosen embedding model must support the specified number of dimensions.If you omit the dimension, Astra DB can use a default dimension value. However, some models don’t have default dimensions. You can use the Data API to find supported embedding providers and their configuration parameters, including dimensions ranges and default dimensions.
Configure Jina AI as the embedding provider
For more detailed instructions, see Integrate Jina AI as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddColumns{
Columns: table.Columns{
// This column will store vector embeddings.
// The configured vector service
// will automatically generate vector embeddings
// for any text inserted to this column.
{
Name: "VECTOR_COLUMN_NAME",
Column: table.VectorWithService(MODEL_DIMENSIONS, &table.VectorService{
Provider: "jinaAI",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
}),
},
// If you want to store the original text
// in addition to the generated embeddings
// you must create a separate column.
{Name: "TEXT_COLUMN_NAME", Column: table.Text()},
},
})
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
TEXT_COLUMN_NAME: The name for the text column that will store the original text. Omit this column if you won’t store the original text in addition to the generated embeddings. -
API_KEY_NAME: The name of the Jina AI API key that you want to use. Must be the name of an existing Jina AI API key in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:jina-embeddings-v2-base-en,jina-embeddings-v2-base-de,jina-embeddings-v2-base-es,jina-embeddings-v2-base-code,jina-embeddings-v2-base-zh. -
MODEL_DIMENSIONS: The number of dimensions that you want the generated vectors to have. Your chosen embedding model must support the specified number of dimensions.If you omit the dimension, Astra DB can use a default dimension value. However, some models don’t have default dimensions. You can use the Data API to find supported embedding providers and their configuration parameters, including dimensions ranges and default dimensions.
Configure Mistral AI as the embedding provider
For more detailed instructions, see Integrate Mistral AI as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddColumns{
Columns: table.Columns{
// This column will store vector embeddings.
// The configured vector service
// will automatically generate vector embeddings
// for any text inserted to this column.
{
Name: "VECTOR_COLUMN_NAME",
Column: table.VectorWithService(MODEL_DIMENSIONS, &table.VectorService{
Provider: "mistral",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
}),
},
// If you want to store the original text
// in addition to the generated embeddings
// you must create a separate column.
{Name: "TEXT_COLUMN_NAME", Column: table.Text()},
},
})
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
TEXT_COLUMN_NAME: The name for the text column that will store the original text. Omit this column if you won’t store the original text in addition to the generated embeddings. -
API_KEY_NAME: The name of the Mistral AI API key that you want to use. Must be the name of an existing Mistral AI API key in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:mistral-embed. -
MODEL_DIMENSIONS: The number of dimensions that you want the generated vectors to have. Your chosen embedding model must support the specified number of dimensions.If you omit the dimension, Astra DB can use a default dimension value. However, some models don’t have default dimensions. You can use the Data API to find supported embedding providers and their configuration parameters, including dimensions ranges and default dimensions.
Configure NVIDIA as the embedding provider
For more detailed instructions, see Integrate NVIDIA as an embedding provider. Your database must be in a supported region.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddColumns{
Columns: table.Columns{
// This column will store vector embeddings.
// The configured vector service
// will automatically generate vector embeddings
// for any text inserted to this column.
{
Name: "VECTOR_COLUMN_NAME",
Column: table.VectorWithService(1024, &table.VectorService{
Provider: "nvidia",
ModelName: "nvidia/nv-embedqa-e5-v5",
}),
},
// If you want to store the original text
// in addition to the generated embeddings
// you must create a separate column.
{Name: "TEXT_COLUMN_NAME", Column: table.Text()},
},
})
if err != nil {
log.Fatal(err)
}
}
Configure OpenAI as the embedding provider
For more detailed instructions, see Integrate OpenAI as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddColumns{
Columns: table.Columns{
// This column will store vector embeddings.
// The configured vector service
// will automatically generate vector embeddings
// for any text inserted to this column.
{
Name: "VECTOR_COLUMN_NAME",
Column: table.VectorWithService(MODEL_DIMENSIONS, &table.VectorService{
Provider: "openai",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
Parameters: map[string]string{
"organizationId": "ORGANIZATION_ID",
"projectId": "PROJECT_ID",
},
}),
},
// If you want to store the original text
// in addition to the generated embeddings
// you must create a separate column.
{Name: "TEXT_COLUMN_NAME", Column: table.Text()},
},
})
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
TEXT_COLUMN_NAME: The name for the text column that will store the original text. Omit this column if you won’t store the original text in addition to the generated embeddings. -
API_KEY_NAME: The name of the OpenAI API key that you want to use. Must be the name of an existing OpenAI API key in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:text-embedding-3-small,text-embedding-3-large,text-embedding-ada-002. -
MODEL_DIMENSIONS: The number of dimensions that you want the generated vectors to have. Your chosen embedding model must support the specified number of dimensions.If you omit the dimension, Astra DB can use a default dimension value. However, some models don’t have default dimensions. You can use the Data API to find supported embedding providers and their configuration parameters, including dimensions ranges and default dimensions.
-
ORGANIZATION_ID: Optional. The ID of the OpenAI organization that owns the API key. Only required if your OpenAI account belongs to multiple organizations or if you are using a legacy user API key to access projects. For more information about organization IDs, see the OpenAI API reference. -
PROJECT_ID: Optional. The ID of the OpenAI project that owns the API key. This cannot use the default project. Only required if your OpenAI account belongs to multiple organizations or if you are using a legacy user API key to access projects. For more information about project IDs, see the OpenAI API reference.
Configure Upstage as the embedding provider
For more detailed instructions, see Integrate Upstage as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddColumns{
Columns: table.Columns{
// This column will store vector embeddings.
// The configured vector service
// will automatically generate vector embeddings
// for any text inserted to this column.
{
Name: "VECTOR_COLUMN_NAME",
Column: table.VectorWithService(MODEL_DIMENSIONS, &table.VectorService{
Provider: "upstageAI",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
}),
},
// If you want to store the original text
// in addition to the generated embeddings
// you must create a separate column.
{Name: "TEXT_COLUMN_NAME", Column: table.Text()},
},
})
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
TEXT_COLUMN_NAME: The name for the text column that will store the original text. Omit this column if you won’t store the original text in addition to the generated embeddings. -
API_KEY_NAME: The name of the Upstage API key that you want to use. Must be the name of an existing Upstage API key in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:solar-embedding-1-large. -
MODEL_DIMENSIONS: The number of dimensions that you want the generated vectors to have. Your chosen embedding model must support the specified number of dimensions.If you omit the dimension, Astra DB can use a default dimension value. However, some models don’t have default dimensions. You can use the Data API to find supported embedding providers and their configuration parameters, including dimensions ranges and default dimensions.
Configure Voyage AI as the embedding provider
For more detailed instructions, see Integrate Voyage AI as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddColumns{
Columns: table.Columns{
// This column will store vector embeddings.
// The configured vector service
// will automatically generate vector embeddings
// for any text inserted to this column.
{
Name: "VECTOR_COLUMN_NAME",
Column: table.VectorWithService(MODEL_DIMENSIONS, &table.VectorService{
Provider: "voyageAI",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
}),
},
// If you want to store the original text
// in addition to the generated embeddings
// you must create a separate column.
{Name: "TEXT_COLUMN_NAME", Column: table.Text()},
},
})
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
TEXT_COLUMN_NAME: The name for the text column that will store the original text. Omit this column if you won’t store the original text in addition to the generated embeddings. -
API_KEY_NAME: The name of the Voyage AI API key that you want to use. Must be the name of an existing Voyage AI API key in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:voyage-2,voyage-code-2,voyage-finance-2,voyage-large-2,voyage-large-2-instruct,voyage-law-2,voyage-multilingual-2. -
MODEL_DIMENSIONS: The number of dimensions that you want the generated vectors to have. Your chosen embedding model must support the specified number of dimensions.If you omit the dimension, Astra DB can use a default dimension value. However, some models don’t have default dimensions. You can use the Data API to find supported embedding providers and their configuration parameters, including dimensions ranges and default dimensions.
Drop columns from a table
Dropping columns produces tombstones. Excessive tombstones can impact query performance.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.DropColumns{
Columns: []string{"is_summer_reading", "library_branch"},
})
if err != nil {
log.Fatal(err)
}
}
Add automatic embedding generation to existing vector columns
You can configure an embedding provider integration for an existing vector column. The integration will automatically generate vector embeddings for any data inserted into the column.
The configuration depends on the embedding provider.
If your vector column already includes vector data, make sure the service options are compatible with the existing embeddings. This ensures accurate vector search results.
Configure Azure OpenAI as the embedding provider
For more detailed instructions, see Integrate Azure OpenAI as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddVectorize{
Columns: map[string]table.VectorService{
"VECTOR_COLUMN_NAME": {
Provider: "azureOpenAI",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
Parameters: map[string]string{
"resourceName": "RESOURCE_NAME",
"deploymentId": "DEPLOYMENT_ID",
},
},
},
},
)
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
API_KEY_NAME: The name of the Azure OpenAI API key that you want to use. Must be the name of an existing Azure OpenAI API key in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:text-embedding-3-small,text-embedding-3-large,text-embedding-ada-002.For Azure OpenAI, you must select the model that matches the one deployed to your
DEPLOYMENT_IDin Azure. -
RESOURCE_NAME: The name of your Azure OpenAI Service resource, as defined in the resource’s Instance details. For more information, see the Azure OpenAI documentation. -
DEPLOYMENT_ID: Your Azure OpenAI resource’s Deployment name. For more information, see the Azure OpenAI documentation.
Configure Hugging Face (Dedicated) as the embedding provider
For more detailed instructions, see Integrate Hugging Face Dedicated as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddVectorize{
Columns: map[string]table.VectorService{
"VECTOR_COLUMN_NAME": {
Provider: "huggingfaceDedicated",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
Parameters: map[string]string{
"endpointName": "ENDPOINT_NAME",
"regionName": "REGION",
"cloudName": "CLOUD_PROVIDER",
},
},
},
},
)
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
API_KEY_NAME: The name of the Hugging Face Dedicated user access token that you want to use. Must be the name of an existing Hugging Face Dedicated user access token in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:endpoint-defined-model.For Hugging Face Dedicated, you must deploy the model as a text embeddings inference (TEI) container.
You must set
MODEL_NAMEtoendpoint-defined-modelbecause this integration uses the model specified in your dedicated endpoint configuration. -
ENDPOINT_NAME: The programmatically-generated name of your Hugging Face Dedicated endpoint. This is the first part of the endpoint URL. For example, if your endpoint URL ishttps://mtp1x7muf6qyn3yh.us-east-2.aws.endpoints.huggingface.cloud, the endpoint name ismtp1x7muf6qyn3yh. -
REGION: The cloud provider region your Hugging Face Dedicated endpoint is deployed to. For example,us-east-2. -
CLOUD_PROVIDER: The cloud provider your Hugging Face Dedicated endpoint is deployed to. For example,aws.
Configure Hugging Face (Serverless) as the embedding provider
For more detailed instructions, see Integrate Hugging Face Serverless as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddVectorize{
Columns: map[string]table.VectorService{
"VECTOR_COLUMN_NAME": {
Provider: "huggingface",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
},
},
},
)
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
API_KEY_NAME: The name of the Hugging Face Serverless user access token that you want to use. Must be the name of an existing Hugging Face Serverless user access token in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:sentence-transformers/all-MiniLM-L6-v2,intfloat/multilingual-e5-large,intfloat/multilingual-e5-large-instruct,BAAI/bge-small-en-v1.5,BAAI/bge-base-en-v1.5,BAAI/bge-large-en-v1.5.
Configure Jina AI as the embedding provider
For more detailed instructions, see Integrate Jina AI as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddVectorize{
Columns: map[string]table.VectorService{
"VECTOR_COLUMN_NAME": {
Provider: "jinaAI",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
},
},
},
)
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
API_KEY_NAME: The name of the Jina AI API key that you want to use. Must be the name of an existing Jina AI API key in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:jina-embeddings-v2-base-en,jina-embeddings-v2-base-de,jina-embeddings-v2-base-es,jina-embeddings-v2-base-code,jina-embeddings-v2-base-zh.
Configure Mistral AI as the embedding provider
For more detailed instructions, see Integrate Mistral AI as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddVectorize{
Columns: map[string]table.VectorService{
"VECTOR_COLUMN_NAME": {
Provider: "mistral",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
},
},
},
)
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
API_KEY_NAME: The name of the Mistral AI API key that you want to use. Must be the name of an existing Mistral AI API key in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:mistral-embed.
Configure NVIDIA as the embedding provider
For more detailed instructions, see Integrate NVIDIA as an embedding provider. Your database must be in a supported region.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddVectorize{
Columns: map[string]table.VectorService{
"VECTOR_COLUMN_NAME": {
Provider: "nvidia",
ModelName: "nvidia/nv-embedqa-e5-v5",
},
},
},
)
if err != nil {
log.Fatal(err)
}
}
Configure OpenAI as the embedding provider
For more detailed instructions, see Integrate OpenAI as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddVectorize{
Columns: map[string]table.VectorService{
"VECTOR_COLUMN_NAME": {
Provider: "openai",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
Parameters: map[string]string{
"organizationId": "ORGANIZATION_ID",
"projectId": "PROJECT_ID",
},
},
},
},
)
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
API_KEY_NAME: The name of the OpenAI API key that you want to use. Must be the name of an existing OpenAI API key in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:text-embedding-3-small,text-embedding-3-large,text-embedding-ada-002. -
ORGANIZATION_ID: Optional. The ID of the OpenAI organization that owns the API key. Only required if your OpenAI account belongs to multiple organizations or if you are using a legacy user API key to access projects. For more information about organization IDs, see the OpenAI API reference. -
PROJECT_ID: Optional. The ID of the OpenAI project that owns the API key. This cannot use the default project. Only required if your OpenAI account belongs to multiple organizations or if you are using a legacy user API key to access projects. For more information about project IDs, see the OpenAI API reference.
Configure Upstage as the embedding provider
For more detailed instructions, see Integrate Upstage as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddVectorize{
Columns: map[string]table.VectorService{
"VECTOR_COLUMN_NAME": {
Provider: "upstageAI",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
},
},
},
)
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
API_KEY_NAME: The name of the Upstage API key that you want to use. Must be the name of an existing Upstage API key in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:solar-embedding-1-large.
Configure Voyage AI as the embedding provider
For more detailed instructions, see Integrate Voyage AI as an embedding provider.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.AddVectorize{
Columns: map[string]table.VectorService{
"VECTOR_COLUMN_NAME": {
Provider: "voyageAI",
ModelName: "MODEL_NAME",
Authentication: map[string]string{
"providerKey": "API_KEY_NAME",
},
},
},
},
)
if err != nil {
log.Fatal(err)
}
}
Replace the following:
-
TABLE_NAME: The name for your table. -
VECTOR_COLUMN_NAME: The name for your vector column. -
API_KEY_NAME: The name of the Voyage AI API key that you want to use. Must be the name of an existing Voyage AI API key in the Astra Portal. For more information, see Embedding provider authentication.Alternatively, you can omit this parameter and instead provide the authentication key in the
SetEmbeddingAPIKeymethod of the options builder when you instantiate aTableobject with the commands to create a table or get a table. The client will send thex-embedding-api-keyheader with the specified key to any underlying HTTP request that requires vectorize authentication. Header authentication overrides theAPI_KEY_NAMEparameter if you set both. If you use the header instead of specifying theAPI_KEY_NAMEparameter, you must include the header in every command that uses vectorize, including writes and vector search. You can use this authentication method only if all affected columns use the same embedding provider. -
MODEL_NAME: The model that you want to use to generate embeddings. The available models are:voyage-2,voyage-code-2,voyage-finance-2,voyage-large-2,voyage-large-2-instruct,voyage-law-2,voyage-multilingual-2.
Remove automatic embedding generation from vector columns
You can remove automatic embedding generation for one or more vector columns. Removing a vectorize integration from a column does not remove the vector embeddings stored in the column.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/table"
)
func main() {
ctx := context.Background()
// Get an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
tbl := database.Table("TABLE_NAME")
// Add columns
err := tbl.Alter(ctx, table.DropVectorize{
Columns: []string{"plot_synopsis"},
})
if err != nil {
log.Fatal(err)
}
}
Client reference
For more information, see the client reference.