Generate vector embeddings with model endpoint management

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

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

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:

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 textembedding-gecko@002 model endpoint, run the following statement:

    SELECT
      google_ml.embedding(
        model_id => 'textembedding-gecko@002',
        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:

    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:

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