Integrate Mistral AI as an embedding provider

Integrate Mistral AI as an external embedding provider for Astra DB vectorize to leverage Mistral AI’s embeddings API within Astra DB Serverless.

Prerequisites

To configure the Mistral AI embedding provider integration, you need the following:

Create the Mistral AI API key

Sign in to your Mistral AI account and create a new API key with unrestricted access to the API. Make sure to copy the API key to a secure location.

Don’t modify or delete the API key in your Mistral AI account after you’ve added it to Astra DB. This breaks the integration. For more information, see Embedding provider authentication.

Add the Mistral AI integration to your organization

Use the Astra Portal to add the Mistral AI embedding provider integration to your Astra DB organization:

  1. In the Astra Portal navigation menu, click Integrations.

  2. In the All Integrations section, select Mistral AI Embedding provider.

  3. Click Add integration.

  4. In the Add Integration dialog, do the following:

    1. Enter a unique API key name.

      You can’t change API key names. Make sure the name is meaningful and that it helps you identify your Mistral AI API key in Astra DB.

      API key names must start and end with a letter or number, and they can’t exceed 50 characters. Valid characters include letters, numbers, underscores (_), and hyphens (-).

    2. Enter your Mistral AI API key.

    3. In the Add databases to scope section, select a Serverless (Vector) database that you want to use the Mistral AI API key.

      When you create a collection in a scoped database, you can choose any of the API keys that are available to the database. Astra DB uses the API key to request embeddings from your embedding provider when you load data into the collection.

      You can add up to 10 databases at once, and you can add more databases later.

      For greater access control, you can add multiple API keys, and each API key can have different scoped databases. Additionally, you can add the same database to multiple API key scopes.

      For example, you can have a few broadly-scoped API keys or many narrowly-scoped API keys.

  5. Click Add Integration.

    The Mistral AI integration switches to Active, and your API key and its scoped databases appear in the API keys section. If you want to add more API keys for this integration, click Add API key.

When you create collections in the scoped databases, you can select the Mistral AI integration, and then use it to generate embeddings.

Add the Mistral AI integration to a new collection

Before you can use the Mistral AI integration to generate embeddings, you must add the integration to a new collection.

You can’t change a collection’s embedding provider or embedding generation method after you create it. To use a different embedding provider, you must create a new collection with a different embedding provider integration.

  • Astra Portal

  • Python

  • TypeScript

  • Java

  • curl

  1. In the Astra Portal, go to Databases, and then select your Serverless (Vector) database.

  2. Click Data Explorer.

  3. In the Keyspace field, select the keyspace where you want to create the collection or use default_keyspace.

  4. Click Create Collection.

  5. In the Create collection dialog, enter a name for the collection. Collection names can contain no more than 50 characters, including letters, numbers, and underscores.

  6. Turn on Vector-enabled collection.

  7. Under Embedding generation method, select the Mistral AI embedding provider integration.

    If the integration isn’t listed, follow the steps in Add the Mistral AI integration to your organization and Manage scoped databases to make sure the integration is active and that your database is scoped to at least one API key.

  8. Complete the following fields:

    • API key: The API key that you want the collection to use to access your embedding provider and generate embeddings. This field is only active if the database is scoped to multiple Mistral AI API keys.

    • Embedding model: The model that you want to use to generate embeddings. The available models are: mistral-embed.

    • Dimensions: The number of dimensions that you want the generated vectors to have. Most models automatically populate the Dimensions. You can edit this field if the model supports a range of dimensions or the embedding provider integration uses an endpoint-defined model. Your chosen embedding model must support the specified number of dimensions.

    • Similarity metric: The method you want to use to calculate vector similarity scores. The available metrics are Cosine, Dot Product, and Euclidean.

  9. Click Create collection.

Use the Python client to create a collection that uses the Mistral AI integration.

Initialize the client

If you haven’t done so already, initialize the client before creating a collection:

import os
from astrapy import DataAPIClient
from astrapy.constants import VectorMetric
from astrapy.info import CollectionVectorServiceOptions

# Initialize the client and get a "Database" object
client = DataAPIClient(os.environ["ASTRA_DB_APPLICATION_TOKEN"])
database = client.get_database(os.environ["ASTRA_DB_API_ENDPOINT"])
print(f"* Database: {database.info().name}\n")

Create a collection integrated with Mistral AI:

collection = database.create_collection(
    "COLLECTION_NAME",
    metric=VectorMetric.SIMILARITY_METRIC,
    dimension=MODEL_DIMENSIONS, # optional
    service=CollectionVectorServiceOptions(
        provider="mistral",
        model_name="MODEL_NAME",
        authentication={
            "providerKey": "API_KEY_NAME",
        },
    ),
)
print(f"* Collection: {collection.full_name}\n")

Replace the following:

  • COLLECTION_NAME: The name for your collection.

  • SIMILARITY_METRIC: The method you want to use to calculate vector similarity scores. The available metrics are COSINE (default), DOT_PRODUCT, and EUCLIDIAN.

  • API_KEY_NAME: The name of the Mistral AI API key that you want to use for your collection. Must be the name of an existing Mistral AI API key in the Astra Portal.

  • MODEL_NAME: The desired model to use to generate embeddings. For Mistral AI, the supported 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 dimension, Astra DB can use a default dimension value. 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.

Use the TypeScript client to create a collection that uses the Mistral AI integration.

Initialize the client

If you haven’t done so already, initialize the client before creating a collection:

import { DataAPIClient, VectorDoc, UUID } from '@datastax/astra-db-ts';

const { ASTRA_DB_APPLICATION_TOKEN, ASTRA_DB_API_ENDPOINT } = process.env;

// Initialize the client and get a 'Db' object
const client = new DataAPIClient(ASTRA_DB_APPLICATION_TOKEN);
const db = client.db(ASTRA_DB_API_ENDPOINT);

console.log(`* Connected to DB ${db.id}`);

Create a collection integrated with Mistral AI:

(async function () {
  const collection = await db.createCollection('COLLECTION_NAME', {
    vector: {
      dimension: MODEL_DIMENSIONS, // optional
      metric: 'SIMILARITY_METRIC', // optional
      service: {
        provider: 'mistral',
        modelName: 'MODEL_NAME',
        authentication: {
          providerKey: 'API_KEY_NAME',
        },
      },
    },
  });
  console.log(`* Created collection ${collection.keyspace}.${collection.collectionName}`);

Replace the following:

  • COLLECTION_NAME: The name for your collection.

  • SIMILARITY_METRIC: The method you want to use to calculate vector similarity scores. The available metrics are COSINE (default), DOT_PRODUCT, and EUCLIDIAN.

  • API_KEY_NAME: The name of the Mistral AI API key that you want to use for your collection. Must be the name of an existing Mistral AI API key in the Astra Portal.

  • MODEL_NAME: The desired model to use to generate embeddings. For Mistral AI, the supported 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 dimension, Astra DB can use a default dimension value. 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.

Use the Java client to create a collection that uses the Mistral AI integration.

Initialize the client

If you haven’t done so already, initialize the client before creating a collection:

import com.datastax.astra.client.Collection;
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.Database;
import com.datastax.astra.client.model.CollectionOptions;
import com.datastax.astra.client.model.Document;
import com.datastax.astra.client.model.FindIterable;
import com.datastax.astra.client.model.FindOptions;
import com.datastax.astra.client.model.SimilarityMetric;

// Replace SIMILARITY_METRIC with your desired similarity metric:
// COSINE, DOT_PRODUCT, EUCLIDIAN
import static com.datastax.astra.client.model.SimilarityMetric.SIMILARITY_METRIC;

public class Quickstart {

  public static void main(String[] args) {
    // Loading Arguments
    String astraToken = System.getenv("ASTRA_DB_APPLICATION_TOKEN");
    String astraApiEndpoint = System.getenv("ASTRA_DB_API_ENDPOINT");

    // Initialize the client
    DataAPIClient client = new DataAPIClient(astraToken);
    System.out.println("Connected to AstraDB");

    Database db = client.getDatabase(astraApiEndpoint);
    System.out.println("Connected to Database.");

Create a collection integrated with Mistral AI:

    Collection<Document> collection = db.createCollection("COLLECTION_NAME",
            CollectionOptions.builder()
                    .vectorSimilarity(SimilarityMetric.SIMILARITY_METRIC)
                    .vectorDimension(MODEL_DIMENSIONS) // optional
                    .vectorize("mistral", "MODEL_NAME", "API_KEY_NAME")
                    .build());
    System.out.println("Created a collection");

Replace the following:

  • COLLECTION_NAME: The name for your collection.

  • SIMILARITY_METRIC: The method you want to use to calculate vector similarity scores. The available metrics are COSINE (default), DOT_PRODUCT, and EUCLIDIAN.

  • API_KEY_NAME: The name of the Mistral AI API key that you want to use for your collection. Must be the name of an existing Mistral AI API key in the Astra Portal.

  • MODEL_NAME: The desired model to use to generate embeddings. For Mistral AI, the supported 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 dimension, Astra DB can use a default dimension value. 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.

Use the Data API to create a collection that uses the Mistral AI integration:

curl -sS -L -X POST "$ASTRA_DB_API_ENDPOINT/api/json/v1/default_keyspace" \
--header "Token: $ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "createCollection": {
    "name": "COLLECTION_NAME",
    "options": {
      "vector": {
        "dimension": MODEL_DIMENSIONS, # optional
        "metric": "SIMILARITY_METRIC", # optional
        "service": {
          "provider": "mistral",
          "modelName": "MODEL_NAME",
          "authentication": {
            "providerKey": "API_KEY_NAME"
          }
        }
      }
    }
  }
}' | jq

Replace the following:

  • COLLECTION_NAME: The name for your collection.

  • SIMILARITY_METRIC: The method you want to use to calculate vector similarity scores. The available metrics are COSINE (default), DOT_PRODUCT, and EUCLIDIAN.

  • API_KEY_NAME: The name of the Mistral AI API key that you want to use for your collection. Must be the name of an existing Mistral AI API key in the Astra Portal.

  • MODEL_NAME: The desired model to use to generate embeddings. For Mistral AI, the supported 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 dimension, Astra DB can use a default dimension value. 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.

If you get a Collection Limit Reached or TOO_MANY_INDEXES message, you must delete a collection before you can create a new one.

Serverless (Vector) databases created after June 24, 2024 can have approximately 10 collections. Databases created before this date can have approximately 5 collections. The collection limit is based on the number of indexes.

After you create a collection, load data into the collection.

Load and search data with vectorize

  1. Load vector data into your vectorize-integrated collection.

    When you load structured JSON or CSV data, the Vector Field specifies field to use to generate embeddings with $vectorize.

    The Load Data dialog with Vector Field dropdown expanded.
  2. After loading data, you can perform a similarity search using text, rather than a vector.

Manage scoped databases

For each API key, you select the databases that can use that API key. These are referred to as scoped databases.

To change the scoped databases for an existing Mistral AI API key, do the following:

  1. In the Astra Portal navigation menu, click Integrations, and then select Mistral AI.

  2. In the API keys section, expand each API key to show the list of scoped databases.

  3. Add or remove databases from each API key’s scope, as needed:

    • To remove a database from the API key’s scope, click Delete, enter the Database name, and then click Remove scope.

    • To add a database to the API key’s scope, click More, select Add database, select the Serverless (Vector) database that you want to add to the scope, and then click Add database.

Remove Mistral AI API keys

Removing API keys immediately disables $vectorize embedding generation for any collections that used the removed API keys. Make sure the API key is not used by any active collections before you remove it.

Removing API keys from Astra DB Serverless does not delete them from your Mistral AI account.

To remove API keys, do the following:

  1. In the Astra Portal navigation menu, click Integrations, and then select Mistral AI Embedding provider.

  2. In the API keys section, locate the API key that you want to remove, click More, and then select Remove API key.

  3. In the confirmation dialog, enter the API key name, and then click Remove key.

  4. In your Mistral AI account, delete the API key if you don’t plan to reuse it.

  5. If you no longer want to use this embedding provider or you are not rotating the API key, then you must recreate any collections that used the removed API key to generate embeddings. For more information, see Change providers or credentials.

Rotate Mistral AI API keys

To rotate API keys, you must remove the API key, and then recreate it with the same name and scoped databases.

Removing the API key immediately disables $vectorize embedding generation for any collections that used that API key. Vectorize remains unavailable until you add the new API key to the Mistral AI integration.

For more information, see Change providers or credentials.

To rotate API keys, do the following:

  1. In your Mistral AI, create a new API key.

  2. Remove the API key that you want to rotate. Make a note of the API key’s name and scoped databases. When you recreate the API key, it must have the exact same name and scope.

  3. In the Astra Portal navigation menu, click Integrations, and then select Mistral AI Embedding provider.

  4. In the API keys section, add a new API key with the same name as the removed API key.

    If the name doesn’t match, any collections that used the removed API key can’t detect the replacement API key.

  5. Add all relevant databases to the new API key’s scoped databases.

    At minimum, you must add all databases that used the removed API key so that the collections in those databases can detect the replacement API key. To ensure that you don’t miss any databases, DataStax recommends adding all of the databases that were in the removed API key’s scope.

Remove the Mistral AI integration from your organization

To remove the Mistral AI embedding provider integration from your Astra DB organization remove all existing Mistral AI API keys, and then recreate any collections that used the integration to generate embeddings.

Troubleshoot vectorize

When working with vectorize, including the $vectorize reserved field in the Data API, errors can occur from two sources:

Astra DB

There is an issue within Astra DB, including the Astra DB platform, the Data API server, Data API clients, or something else.

Some of the most common Astra DB vectorize errors are related to scoped databases. In your vectorize integration settings, make sure your database is in the scope of the credential that you want to use. Scoped database errors don’t apply to the NVIDIA Astra-hosted embedding provider integration.

When using the Data API with collections, make sure you don’t use $vector and $vectorize in the same query. For more information, see the Data API collections references, such as Vector and vectorize, Insert many documents, and Sort clauses for documents.

When using the Data API with tables, you can only run a vector search on one vector column at a time. To generate an embedding from a string, the target vector column must have a defined embedding provider integration. For more information, see the Data API tables references, such as Vector type and Sort clauses for rows.

The embedding provider

The embedding provider encountered an issue while processing the embedding generation request. Astra DB passes these errors to you through the Astra Portal or Data API with a qualifying statement such as The embedding provider returned a HTTP client error.

Possible embedding provider errors include rate limiting, billing or account funding issues, chunk or token size limits, and so on. For more information about these errors, see the embedding provider’s documentation, including the documentation for your chosen model.

Carefully read all error messages to determine the source and possible cause for the issue.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

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