Model endpoint management reference Stay organized with collections Save and categorize content based on your preferences.
Preview This product is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA products are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.
This page lists parameters for different functions provided by thegoogle_ml_integration
extension to register and manage model endpoints. The page also lists the secrets that you can manage by using model endpoint management. To use AI models inproduction environments, seeBuild generative AI applications usingCloud SQL.
google_ml_integration.enable_model_support
database flag toon
. Also, for more information about model endpoint management, seeRegister and call remote AI models in Cloud SQL.Models
Use this reference to understand parameters for functions that let you managemodel endpoints.
google_ml.create_model()
The following shows how to call thegoogle_ml.create_model()
SQL function usedto register model endpoint metadata:
CALLgoogle_ml.create_model(model_id=>'MODEL_ID',model_request_url=>'REQUEST_URL',model_provider=>'PROVIDER_ID',model_type=>'MODEL_TYPE',model_qualified_name=>'MODEL_QUALIFIED_NAME',model_auth_type=>'AUTH_TYPE',model_auth_id=>'AUTH_ID',generate_headers_fn=>'GENERATE_HEADER_FUNCTION',model_in_transform_fn=>'INPUT_TRANSFORM_FUNCTION',model_out_transform_fn=>'OUTPUT_TRANSFORM_FUNCTION');
Parameter | Required | Description |
---|---|---|
MODEL_ID | required for all model endpoints | A unique ID for the model endpoint that you define. |
REQUEST_URL | optional for text embedding model endpoints with built-in support | The model-specific endpoint when adding other text embedding and generic model endpoints. The request URL that the function generates for built-in model endpoints refers to your cluster's project and region or location. If you want to refer to another project, then ensure that you specify the For custom hosted model endpoints, ensure that the model endpoint is accessible through the internet. |
PROVIDER_ID | required for text embedding model endpoints with built-in support | The provider of the model endpoint. The default value iscustom . For Cloud SQL, set the provider togoogle for Vertex AI model endpoints,open_ai for OpenAI model endpoints,anthropic for Anthropic model endpoints,hugging_face for Hugging Face model endpoints, orcustom for custom-hosted model endpoints. |
MODEL_TYPE | optional for generic model endpoints | The model type. You can set this value totext_embedding for text embedding model endpoints orgeneric for all other model endpoints. |
MODEL_QUALIFIED_NAME | required for OpenAI model endpoints; optional for other model endpoints | The fully qualified name in case the model endpoint has multiple versions or if the model endpoint defines it—for example,textembedding-gecko@001 ortextembedding-gecko@002 . Since thetextembedding-gecko@001 model is pre-registered with model endpoint management, you can generate embeddings usingtextembedding-gecko@001 as the model ID. |
AUTH_TYPE | optional unless model endpoint has specific authentication requirement | The authentication type used by the model endpoint. You can set it to eithercloudsql_service_agent_iam for Vertex AI models orsecret_manager for other providers. |
AUTH_ID | don't set for Vertex AI model endpoints; required for all other model endpoints that store secrets in Secret Manager | The secret ID that you set and is subsequently used when registering a model endpoint. |
GENERATE_HEADER_FUNCTION | optional | The function name you set to generate custom headers. The signature of this function depends on thegoogle_ml.predict_row() function. SeeHTTP Header generation function. |
INPUT_TRANSFORM_FUNCTION | optional for text embedding model endpoints with built-in support;don't set for generic model endpoints | The function to transform input of the corresponding prediction function to the model-specific input. SeeTransform functions. |
OUTPUT_TRANSFORM_FUNCTION | optional for text embedding model endpoints with built-in support;don't set for generic model endpoints | The function to transform model specific output to the prediction function output. SeeTransform functions. |
google_ml.alter_model()
The following shows how to call thegoogle_ml.alter_model()
SQL function usedto update model endpoint metadata:
CALLgoogle_ml.alter_model(model_id=>'MODEL_ID',model_request_url=>'REQUEST_URL',model_provider=>'PROVIDER_ID',model_type=>'MODEL_TYPE',model_qualified_name=>'MODEL_QUALIFIED_NAME',model_auth_type=>'AUTH_TYPE',model_auth_id=>'AUTH_ID',generate_headers_fn=>'GENERATE_HEADER_FUNCTION',model_in_transform_fn=>'INPUT_TRANSFORM_FUNCTION',model_out_transform_fn=>'OUTPUT_TRANSFORM_FUNCTION');
google_ml.drop_model()
The following shows how to call thegoogle_ml.drop_model()
SQL function usedto drop a model endpoint:
CALLgoogle_ml.drop_model('MODEL_ID');
Parameter | Description |
---|---|
MODEL_ID | A unique ID for the model endpoint that you define. |
google_ml.list_model()
The following shows how to call thegoogle_ml.list_model()
SQL function usedto list model endpoint information:
SELECTgoogle_ml.list_model('MODEL_ID');
Parameter | Description |
---|---|
MODEL_ID | A unique ID for the model endpoint that you define. |
google_ml.model_info_view
The following shows how to call thegoogle_ml.model_info_view
view that isused to list model endpoint information for all model endpoints:
SELECT*FROMgoogle_ml.model_info_view;
Secrets
Use this reference to understand parameters for functions that let you managesecrets.
google_ml.create_sm_secret()
The following shows how to call thegoogle_ml.create_sm_secret()
SQL functionused to add the secret created in Secret Manager:
CALLgoogle_ml.create_sm_secret(secret_id=>'SECRET_ID',secret_path=>'projects/PROJECT_ID/secrets/SECRET_MANAGER_SECRET_ID/versions/VERSION_NUMBER');
Parameter | Description |
---|---|
SECRET_ID | The secret ID that you set and is subsequently used when registering a model endpoint. |
PROJECT_ID | The ID of your Google Cloud project that contains the secret. This project can be different from the project that contains your Cloud SQL instance. |
SECRET_MANAGER_SECRET_ID | The secret ID set in Secret Manager when you created the secret. |
VERSION_NUMBER | The version number of the secret ID. |
google_ml.alter_sm_secret()
The following shows how to call thegoogle_ml.alter_sm_secret()
SQL functionused to update secret information:
CALLgoogle_ml.alter_sm_secret(secret_id=>'SECRET_ID',secret_path=>'projects/PROJECT_ID/secrets/SECRET_MANAGER_SECRET_ID/versions/VERSION_NUMBER');
Parameter | Description |
---|---|
SECRET_ID | The secret ID that you set and is subsequently used when registering a model endpoint. |
PROJECT_ID | The ID of your Google Cloud project that contains the secret. This project can be different from the project that contains your Cloud SQL instance. |
SECRET_MANAGER_SECRET_ID | The secret ID set in Secret Manager when you created the secret. |
VERSION_NUMBER | The version number of the secret ID. |
google_ml.drop_sm_secret()
The following shows how to call thegoogle_ml.drop_sm_secret()
SQL functionused to drop a secret:
CALLgoogle_ml.drop_sm_secret('SECRET_ID');
Parameter | Description |
---|---|
SECRET_ID | The secret ID that you set and is subsequently used when registering a model endpoint. |
Prediction functions
Use this reference to understand parameters for functions that let you generateembeddings or invoke predictions.
google_ml.embedding()
The following shows how to generate embeddings:
SELECTgoogle_ml.embedding(model_id=>'MODEL_ID',contents=>'CONTENT');
Parameter | Description |
---|---|
MODEL_ID | A unique ID for the model endpoint that you define. |
CONTENT | the text to translate into a vector embedding. |
For examples of SQL queries to generate text embeddings, seeExamples.
google_ml.predict_row()
The following shows how to invoke predictions:
SELECTgoogle_ml.predict_row(model_id=>'MODEL_ID',request_body=>'REQUEST_BODY');
Parameter | Description |
---|---|
MODEL_ID | A unique ID for the model endpoint that you define. |
REQUEST_BODY | the parameters to the prediction function, in JSON format. |
For examples of SQL queries to invoke predictions, seeExamples.
Transform functions
Use this reference to understand parameters for input and output transformfunctions.
Input transform function
The following shows the signature for the prediction function for text embeddingmodel endpoints:
CREATEORREPLACEFUNCTIONINPUT_TRANSFORM_FUNCTION(model_idVARCHAR(100),input_textTEXT)RETURNSJSON;
Parameter | Description |
---|---|
INPUT_TRANSFORM_FUNCTION | The function to transform input of the corresponding prediction function to the model endpoint-specific input. |
Output transform function
The following shows the signature for the prediction function for text embeddingmodel endpoints:
CREATEORREPLACEFUNCTIONOUTPUT_TRANSFORM_FUNCTION(model_idVARCHAR(100),response_jsonJSON)RETURNSreal[];
Parameter | Description |
---|---|
OUTPUT_TRANSFORM_FUNCTION | The function to transform model endpoint-specific output to the prediction function output. |
Transform functions example
To better understand how to create transform functions for your model endpoint,consider a custom-hosted text embedding model endpoint that requires JSON inputand output.
The following example cURL request creates embeddings based on the prompt andthe model endpoint:
curl-m100-XPOSThttps://cymbal.com/models/text/embeddings/v1\-H"Content-Type: application/json"-d'{"prompt": ["Cloud SQL Embeddings"]}'
The following example response is returned:
[[0.3522231-0.359320370.101560560.17734447-0.11606089-0.172660590.025093510.20305622-0.09787305-0.12154685-0.17313677-0.080754670.06821183-0.068965570.1171584-0.009315720.11875633-0.000774820.256049480.05193840.2034983-0.099526640.10347155-0.11935943-0.17872004-0.08706985-0.07056875-0.059293530.4177883-0.143817260.079349260.313682940.125432820.10758053-0.30210832-0.029510150.3908268-0.030910590.05302926-0.00114946-0.162337770.1117468-0.13159040.13947351-0.29569918-0.12330773-0.04354299-0.180689130.144455480.19481727]]
Based on this input and response, you can infer the following:
The model expects JSON input through the
prompt
field. This field accepts anarray of inputs. As thegoogle_ml.embedding()
function is a row levelfunction, it expects one text input at a time. Thus, you need to create aninput transform function that builds an array with a single element.The response from the model is an array of embeddings, one for each promptinput to the model. As the
google_ml.embedding()
function is a row levelfunction, it returns a single input at a time. Thus, you need to create anoutput transform function that can be used to extract the embedding from thearray.
The following example shows the input and output transform functions that isused for this model endpoint when it is registered with model endpoint management:
input transform function
CREATEORREPLACEFUNCTIONcymbal_text_input_transform(model_idVARCHAR(100),input_textTEXT)RETURNSJSONLANGUAGEplpgsqlAS$$DECLAREtransformed_inputJSON;model_qualified_nameTEXT;BEGINSELECTjson_build_object('prompt',json_build_array(input_text))::JSONINTOtransformed_input;RETURNtransformed_input;END;$$;
output transform function
CREATEORREPLACEFUNCTIONcymbal_text_output_transform(model_idVARCHAR(100),response_jsonJSON)RETURNSREAL[]LANGUAGEplpgsqlAS$$DECLAREtransformed_outputREAL[];BEGINSELECTARRAY(SELECTjson_array_elements_text(response_json->0))INTOtransformed_output;RETURNtransformed_output;END;$$;
HTTP header generation function
The following shows signature for the header generation function that can beused with thegoogle_ml.embedding()
prediction function when registering othertext embedding model endpoints.
CREATEORREPLACEFUNCTIONGENERATE_HEADERS(model_idVARCHAR(100),input_textTEXT)RETURNSJSON;
For thegoogle_ml.predict_row()
prediction function, the signature is asfollows:
CREATEORREPLACEFUNCTIONGENERATE_HEADERS(model_idTEXT,inputJSON)RETURNSJSON;
Parameter | Description |
---|---|
GENERATE_HEADERS | The function to generate custom headers. You can also pass the authorization header generated by the header generation function while registering the model endpoint. |
Header generation function example
To better understand how to create a function that generates output in JSON keyvalue pairs that are used as HTTP headers, consider a custom-hosted textembedding model endpoint.
The following example cURL request passes theversion
HTTP header, which isused by the model endpoint:
curl-m100-XPOSThttps://cymbal.com/models/text/embeddings/v1\-H"Content-Type: application/json"\-H"version: 2024-01-01"\-d'{"prompt": ["Cloud SQL Embeddings"]}'
The model expects text input through theversion
field and returns the versionvalue in JSON format. The following example shows the header generation functionthat is used for this text embedding model endpoint when it is registered with modelendpoint management:
CREATEORREPLACEFUNCTIONheader_gen_fn(model_idVARCHAR(100),input_textTEXT)RETURNSJSONLANGUAGEplpgsqlAS$$BEGINRETURNjson_build_object('version','2024-01-01')::JSON;END;$$;
Request URL generation
Use the request URL generation function to infer the request URLs for the modelendpoints with built-in support. The following shows the signature for thisfunction:
CREATEORREPLACEFUNCTIONGENERATE_REQUEST_URL(providergoogle_ml.model_provider,model_typegoogle_ml.MODEL_TYPE,model_qualified_nameVARCHAR(100),model_regionVARCHAR(100)DEFAULTNULL)
Parameter | Description |
---|---|
GENERATE_REQUEST_URL | The function to generate request URL generated by the extension for model endpoints with built-in support. |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-14 UTC.