Usage Considerations
Before using the API_Request in-database function, you should:
- Deploy your models on Google Vertex AI;
- Have credentials which has permissions on Vertex AI to use the in-database function.
Usage Example 1: With URL in the ENDPOINT argument
select output as Score from tapidb.API_Request ( on (SELECT Age, Job, Housing, Day1 as "Day", Contact, MaritalStatus, Balance, Campaign,PDays, Default1 as "Default", Education, Loan, Month1 as "Month", Previous, Duration, POutcome from gcp_input) USING AUTHORIZATION('{"Key" : "ya29.<GCP Key generated using 'gcloud auth print-access-token' command>"}') API_TYPE('vertex-ai') ENDPOINT('https://us-central1-aiplatform.googleapis.com/v1/projects/gcp-datascience-languages/locations/us-central1/endpoints/6918043599082881024:predict') CONTENT_TYPE('json-with-keys') CONTENT_FORMAT('{ "instances" : [ "%row" ] }') KEY_START_INDEX('0') ) as "DT" ; *** Query completed. One row found. One column returned. *** Total elapsed time was 3 seconds. Score -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- { "predictions": [ { "scores": [ 0.79788047075271606, 0.20211949944496149 ], "classes": [ "1", "2" ] } ], "deployedModelId": "4671336723257491456", "model": "projects\/313018613455\/locations\/us-central1\/models\/5689174428299034624", "modelDisplayName": "my-automl-model", "modelVersionId": "1" }
Usage Example 2: With endpoint information in AUTHORIZATION and ENDPOINT argument
select output as Score from tapidb.API_Request ( on (SELECT Age, Job, Housing, Day1 as "Day", Contact, MaritalStatus, Balance, Campaign,PDays, Default1 as "Default", Education, Loan, Month1 as "Month", Previous, Duration, POutcome from gcp_input) USING AUTHORIZATION('{ "Project" : "gcp-datascience-languages", "Region" : "us-central1", "Key" : "ya29.<GCP Key generated using 'gcloud auth print-access-token' command>"}') API_TYPE('vertex-ai') ENDPOINT('6918043599082881024') CONTENT_TYPE('json-with-keys') CONTENT_FORMAT('{ "instances" : [ "%row" ] }') KEY_START_INDEX('0') ) as "DT"; *** Query completed. One row found. One column returned. *** Total elapsed time was 3 seconds. Score -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- { "predictions": [ { "scores": [ 0.79788047075271606, 0.20211949944496149 ], "classes": [ "1", "2" ] } ], "deployedModelId": "4671336723257491456", "model": "projects\/313018613455\/locations\/us-central1\/models\/5689174428299034624", "modelDisplayName": "my-automl-model", "modelVersionId": "1" }