This page describes how to register an AI model endpoint
and generate vector embeddings with model endpoint management.

To use AI models in
production environments, see
[Generate and manage vector embeddings](https://docs.cloud.google.com/sql/docs/mysql/generate-manage-vector-embeddings.md.txt).


After the model endpoints are added and registered in model endpoint management, you can
reference them using the model ID to generate embeddings.

## Before you begin

Make sure that you complete the following actions:

- Register your model endpoint with model endpoint management. For more information, see [Register and call remote AI models using model endpoint management](https://docs.cloud.google.com/sql/docs/mysql/model-endpoint-register-model.md.txt).
- Create or update your Cloud SQL instance so that the instance can integrate with Vertex AI. For more information, see [Enable database integration with Vertex AI](https://docs.cloud.google.com/sql/docs/mysql/integrate-cloud-sql-with-vertex-ai.md.txt#enable-database-integration-with-vertex-ai).

## Generate embeddings

Use the `mysql.ml_embedding()` SQL function to call the registered model endpoint with
the text embedding model type to generate embeddings.

To call the model and generate embeddings, use the following SQL query:

```sql
SELECT
  mysql.ml_embedding(
    'MODEL_ID',
    'CONTENT');
```

Replace the following:

- `MODEL_ID`: the model ID you defined when registering the model endpoint
- `CONTENT`: the text to translate into a vector embedding

## Examples

Some examples for generating embeddings using registered model endpoints are listed in this section.

### Text embedding models with built-in support

Vertex AI embedding models are supported by default. You don't need to
register them. To generate embeddings for a registered `gemini-embedding-001`
model endpoint, run the following statement:

```sql
    SELECT
      mysql.ml_embedding(
        'gemini-embedding-001',
        'Cloud SQL is a managed, cloud-hosted SQL database service');
```