API_Request In-database Function Usage | Azure Machine Learning | Vantage - API_Request In-database Function Usage - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

Usage Considerations

Before using the API_Request in-database function, you should:
  • Deploy your models on Azure Machine Learning;
  • Have credentials which has permissions on Azure Machine Learning to use the function.

Usage Example

This example shows the steps to create endpoint on Azure Machine Learning in Azure CLI and use API_Request query to do the scoring from Vantage.
You can download Azure CLI using the link: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli.
  1. Set argument names in Azure CLI.
    export GROUP_NAME=<RG_Name> 
    export LOCATION=<Azure_Region_Name> 
    export WORKSPACE=<WorkSpace_Name> 
    export SUB=<Subscription_id> 
    export ENDPOINT_NAME=sample-endpoint 
    export AZ_ML_EXAMPLE_DIR=<Download azure ml example from https://github.com/Azure/azureml-examples and set it as a root directory> 
    
  2. Set Azure account and Azure Machine Learning workspace in Azure CLI.
    az login 
    az account set --subscription $SUB 
    az group create --name $GROUP_NAME --location $LOCATION 
    az ml workspace create -n $WORKSPACE -g $GROUP_NAME 
    
    cd $AZ_ML_EXAMPLE_DIR/cli/endpoints/online/managed/sample 
    
  3. Create endpoint on Azure Machine Learning in Azure CLI.
    • Create the endpoint.
      az ml online-endpoint create --verbose --name $ENDPOINT_NAME -f endpoint.yml 
    • Create a deployment named 'blue' under the endpoint.
      az ml online-deployment create --verbose --name blue --endpoint $ENDPOINT_NAME -f blue-deployment.yml --all-traffic 
      
    • Get the key used to authenticate the endpoint.
      az ml online-endpoint get-credentials --verbose -n $ENDPOINT_NAME -o tsv --query primaryKey 
      
    • Check the status of the endpoint and the deployment.
      az ml online-endpoint show --verbose -n $ENDPOINT_NAME -o tsv --query scoring_uri
    Once the endpoint is created, you should save the primaryKey and endpoint name.
  4. Use API_Request query from Vantage to score data.
    • ENDPOINT can take a Azure Machine Learning endpoint for scoring.
      SELECT rec_id, output as model_score 
      FROM tapidb.API_Request 
      ( 
        ON (SELECT 751493.0 as "rec_id", 1,2,3,4,5,6,7,8,9,10) 
        USING AUTHORIZATION('{"Key" : "<primaryKey>",
                              "Region" : "<Azure-region-Name>"}')     
        API_TYPE('azure-ml') 
        ENDPOINT('sample-endpoint') 
        CONTENT_TYPE('json') 
        KEY_START_INDEX('1') 
        CONTENT_FORMAT('{"data" : [["%row"]]}') 
      ) as "DT" 
      ORDER BY 1,2
      ; 
      API_Request query result:
      *** Query completed. 
      One row found. 
      2 columns returned. 
      *** Total elapsed time was 3 seconds. 
      rec_id model_score --------- ------------------------------------------------------------
      751493.0 11055.977245525677 +---------+---------+---------+---------+---------+---------+
    • ENDPOINT can also take scoring URL instead of endpoint name.
      select rec_id, output as model_score 
      FROM tapidb.API_Request 
      ( 
        ON (SELECT 751493.0 as "rec_id", 1,2,3,4,5,6,7,8,9,10) 
        USING AUTHORIZATION('{"Key" : "<your_auth_key>", 
                              "Region" : "westus2"}') 
        API_TYPE('azure-ml') 
        ENDPOINT('http://f160edb9-2201-4da6-861c-78de995ab519.westus2.azurecontainer.io/score') 
        CONTENT_TYPE('json') 
        KEY_START_INDEX('1') 
        CONTENT_FORMAT('{"data" : [["%row"]]}') 
      ) as "DT" 
      ORDER BY 1,2
      ; 
      API_Request query result:
      *** Query completed. 
      One row found. 
      2 columns returned. 
      *** Total elapsed time was 3 seconds. 
      rec_id model_score --------- ---------------------------------------------------------------------
      751493.0 6141.267272547496 +---------+---------+---------+---------+---------+---------+---------+