Select a documentation version: <button class="button button-with-icon cloud-select-dropdown__button button-primary" aria-haspopup="true">16.9.0</button>

- [Current (18.4.0)](https://docs.cloud.google.com/alloydb/omni/containers/current/docs/ai/model-endpoint-embeddings.md.txt)
- [18.4.0](https://docs.cloud.google.com/alloydb/omni/containers/18.4.0/docs/ai/model-endpoint-embeddings.md.txt)
- [18.3.0](https://docs.cloud.google.com/alloydb/omni/containers/18.3.0/docs/ai/model-endpoint-embeddings.md.txt)
- [18.1.0](https://docs.cloud.google.com/alloydb/omni/containers/18.1.0/docs/ai/model-endpoint-embeddings.md.txt)
- [17.10.0](https://docs.cloud.google.com/alloydb/omni/containers/17.10.0/docs/ai/model-endpoint-embeddings.md.txt)
- [17.9.0](https://docs.cloud.google.com/alloydb/omni/containers/17.9.0/docs/ai/model-endpoint-embeddings.md.txt)
- [17.7.0](https://docs.cloud.google.com/alloydb/omni/containers/17.7.0/docs/ai/model-endpoint-embeddings.md.txt)
- [17.5.0](https://docs.cloud.google.com/alloydb/omni/containers/17.5.0/docs/ai/model-endpoint-embeddings.md.txt)
- [16.14.0](https://docs.cloud.google.com/alloydb/omni/containers/16.14.0/docs/ai/model-endpoint-embeddings.md.txt)
- [16.13.0](https://docs.cloud.google.com/alloydb/omni/containers/16.13.0/docs/ai/model-endpoint-embeddings.md.txt)
- [16.11.0](https://docs.cloud.google.com/alloydb/omni/containers/16.11.0/docs/ai/model-endpoint-embeddings.md.txt)
- [16.9.0](https://docs.cloud.google.com/alloydb/omni/containers/16.9.0/docs/ai/model-endpoint-embeddings.md.txt)
- [16.8.0](https://docs.cloud.google.com/alloydb/omni/containers/16.8.0/docs/ai/model-endpoint-embeddings.md.txt)
- [16.3.0](https://docs.cloud.google.com/alloydb/omni/containers/16.3.0/docs/ai/model-endpoint-embeddings.md.txt)
- [15.18.0](https://docs.cloud.google.com/alloydb/omni/containers/15.18.0/docs/ai/model-endpoint-embeddings.md.txt)
- [15.17.0](https://docs.cloud.google.com/alloydb/omni/containers/15.17.0/docs/ai/model-endpoint-embeddings.md.txt)
- [15.15.0](https://docs.cloud.google.com/alloydb/omni/containers/15.15.0/docs/ai/model-endpoint-embeddings.md.txt)
- [15.13.0](https://docs.cloud.google.com/alloydb/omni/containers/15.13.0/docs/ai/model-endpoint-embeddings.md.txt)
- [15.12.0](https://docs.cloud.google.com/alloydb/omni/containers/15.12.0/docs/ai/model-endpoint-embeddings.md.txt)
- [15.7.1](https://docs.cloud.google.com/alloydb/omni/containers/15.7.1/docs/ai/model-endpoint-embeddings.md.txt)
- [15.7.0](https://docs.cloud.google.com/alloydb/omni/containers/15.7.0/docs/ai/model-endpoint-embeddings.md.txt)

<br />

This page describes how to generate embeddings using registered model endpoints.

<br />

## Before you begin

Make sure that you have registered your model endpoint with Model endpoint management. For
more information, see [Register a model endpoint with
model endpoint management](https://docs.cloud.google.com/alloydb/docs/ai/register-model-endpoint)

## Generate embeddings

Use the `google_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
  google_ml.embedding(
    model_id => 'MODEL_ID',
    content => '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 endpoint are listed in this section.

#### Text embedding models with built-in support

To generate embeddings for a registered `text-embedding-005` model endpoint, run the following statement:

```sql
    SELECT
      google_ml.embedding(
        model_id => 'text-embedding-005',
        content => 'AlloyDB is a managed, cloud-hosted SQL database service');
```

To generate embeddings for a registered `text-embedding-ada-002` model endpoint by OpenAI, run the following statement:

```sql
    SELECT
      google_ml.embedding(
        model_id => 'text-embedding-ada-002',
        content => 'e-mail spam');
```

To generate embeddings for a registered `text-embedding-3-small` or `text-embedding-3-large` model endpoints by OpenAI, run the following statement:

```sql
  SELECT
    google_ml.embedding(
      model_id => 'text-embedding-3-small',
      content => 'Vector embeddings in AI');
```