AI data inference solution

Updated at:

Manual deployment

Solution overview

Integrate EventBridge with AI services to run intelligent inference on real-time event bus data, strengthening data processing and unlocking innovative applications.

Using EventBridge as a data hub, you can distribute real-time data streams from various sources to different AI models for inference. EventBridge then routes the inference results to downstream business systems or data stores. Adding AI inference to the ETL Transform step makes data transformation more intelligent, boosts processing efficiency and accuracy, and provides your business with powerful data integration and analysis.

Solution architecture

The following diagram shows the system that this solution deploys on Alibaba Cloud with the default settings. You can adjust some settings during actual deployment, but the overall system remains similar.

image

This tutorial uses sensitive information filtering as an example to demonstrate data cleaning and desensitization for downstream data. AI automatically identifies business-sensitive keywords to safeguard downstream business and data compliance.

The solution works as follows: an input containing sensitive information, such as ["Customer John Doe (+1-555-0100) reported an issue..."], is processed to produce a sanitized output, such as ["Customer *** (+1-***-0100) reported an issue..."]. Because large models can produce non-deterministic results, the output format may vary during testing. In production, you can use prompt engineering to obtain more deterministic outputs.

This solution uses the following cloud services and infrastructure:

Resource

Description

1 event flow

Used to build a data pipeline.

2 Lightweight Message Queue (formerly MNS) queues

Serve as the data source and sink.

Alibaba Cloud Model Studio

Calls a large-model service to process data.

Prerequisites

Before you deploy, follow these instructions to prepare your account.

Prepare your account

  1. If you do not have an Alibaba Cloud account, register on the Alibaba Cloud account registration page. An Alibaba Cloud account is the billing entity for your cloud resources and a prerequisite for this deployment solution.

  2. Top up your Alibaba Cloud account. This deployment solution uses the pay-as-you-go billing method by default. If you deploy any cloud resource using pay-as-you-go, your account balance must be at least 100 CNY.

Enable services

  1. Log on to Model Studio. After you read and agree to the Terms of Service, Model Studio is automatically activated. If the Terms of Service do not appear, this indicates that you have already activated Model Studio.

    • When you activate Model Studio for the first time, the platform automatically grants you a free quota for new users for each model. For more information, see Free quota for new users.

      Note

      Only models in the China (Beijing) region with the service deployment scope set to China (Mainland) are eligible for a free quota. Models in other regions or with different service scopes are not eligible.

    • If you are prompted that identity verification has not been completed when activating the service, first complete Individual identity verification.

  2. If you are using ApsaraMQ for MNS for the first time, activate the service as follows.

    1. Log in to the ApsaraMQ for MNS console.

    2. On the Overview page, click Activate for Free and follow the on-screen instructions.

  3. To activate EventBridge for the first time, follow these steps.

    1. Log on to the EventBridge console.

    2. On the Overview page, in the Activate EventBridge wizard, click Enable For Free and follow the on-screen instructions.

    3. EventBridge requires authorization to receive events. On the Overview page, in the Access Authorization wizard, click Authorize Now.

Get an API key

Get a Model Studio API key

  1. Go to the API Key page of Model Studio.

  2. Click Create API Key. In the dialog box, confirm the Workspace, enter a Description, and select Permissions as needed.

    Note
    1. A RAM user requires authorization from the Alibaba Cloud account before creating an API key.

    2. Do not expose your API key. Unauthorized use can cause security risks and financial losses.

  3. Click OK.

  4. After the API key is created, immediately copy or download the full API key from the result dialog box and store it securely.

    The API key is displayed only once. After you close the dialog box, the list shows only a masked value and you cannot view or copy the full key again. If you did not save the key, reset it or create a new one.

Create the source and sink

Create two queues in Lightweight Message Queue (formerly MNS) to serve as the source and sink for the event flow.

Create MNS queues

  1. Log on to the Lightweight Message Queue (formerly MNS) console.

  2. In the left-side navigation pane, click Queues. From the Region drop-down list, select China (Shenzhen).

  3. Click Create Queue, set Name to eventbridge-dev, and leave the other parameters at their default values.

  4. Click Confirm and wait for the queue to be created.

  5. Repeat the preceding steps to create another queue named eventbridge-online.

Important

If duplicate message consumption occurs, set the Visibility Timeout Period to a value between 60 seconds and 300 seconds.

Build the data processing pipeline

Create and configure an EventBridge event flow to act as the data processing pipeline.

Create event flow and configure source

  1. Log on to the EventBridge console.

  2. In the left-side navigation pane, click Event Streams. From the Region drop-down list, select China (Shenzhen).

  3. Click Create Event Stream.

    1. Enter a custom value for Task Name.

    2. For Metering Method, select Pay-by-event.

  4. On the Task Creation tab, in the Source area, configure the following settings:

    1. For Data Provider, select Lightweight Message Queue (formerly MNS).

    2. For Queue Name, select eventbridge-dev. Leave the other settings as default.

  5. Click Next Step.

Configure filtering

  1. In the Filtering area, configure the following settings:

    1. For Pattern Content, select All Events Match. In real business scenarios, you can also select other filtering rules, or select custom matching to define filtering rules flexibly.

  2. Click Next Step.

Configure transformation

  1. In the Transformation area, configure the following settings:

    1. For Alibaba Cloud Service, select Model/Agent Call (Alibaba Cloud Model Studio). This tutorial uses Model Call as an example.

    2. For Model Name, enter qwen-max.

    3. Configure the Model Context as follows:

      SYSTEM

      Fixed Value

      You are a data compliance officer. You must ensure that all data entering the analysis system complies with GDPR/CCPA regulations and does not contain any personally identifiable information (PII). During the ETL process, your task is to automatically identify and sanitize text containing names, phone numbers, and ID numbers. You must also block sensitive content related to religion, sexuality, and politics.

      USER

      Partial Event

      $.data.messageBody

    4. For Structured Output, select Enable, click Add Field, and then add fields as described in the following table:

      data

      string

      The sanitized data content.

      Required

      cause

      string

      The reason the data was filtered. The value must be in English.

      Optional

    5. For API Key, enter the Model Studio API key that you obtained.

  2. Click Next Step.

Configure sink

  1. In the Sink area, configure the following settings:

    1. For Service Type, select SMQ.

    2. For Queue Name, select the created queue eventbridge-online.

    3. For Message Body, select Partial Event, and enter $.transform0.structuredoutput.

  2. Click Save. Wait for the event flow to be created. The Status changes to Running.

Verify the solution

To verify the model's data sanitization, send a message containing sensitive information from the source queue and then check the processed message in the sink queue.

Send a message

  1. Log on to the Lightweight Message Queue (formerly MNS) console. In the left-side navigation pane, click Queues.

  2. Find the eventbridge-dev queue, and click Send Messages in the Actions column.

  3. In the Send Message area, configure the following settings:

    1. For Message Content, enter Customer John Doe (+1-555-0100) reported an issue.

    2. Set Message Delay Period to 0 seconds.

  4. Click Send Message.

Receive a message

  1. Log on to the Lightweight Message Queue (formerly MNS) console. In the left-side navigation pane, click Queues.

  2. Find the created queue eventbridge-online, and click Send Messages in the Actions column.

  3. In the Receive Message area, click Receive Message.

  4. The received message appears in the list. In the Actions column, click Details and view the Base64-decoded Message. A result similar to the one shown in the following figure indicates that the data has been processed.

Clean up resources

After you finish testing, delete the EventBridge event flow and the two Lightweight Message Queue (formerly MNS) queues to avoid additional charges:

  1. Delete the EventBridge event flow: Log on to the EventBridge console. In the left-side navigation pane, click Event Streams. Find the event flow that you created, click Delete in the Actions column, and then follow the on-screen instructions.

  2. Delete the message queues: Log on to the Lightweight Message Queue (formerly MNS) console. In the left-side navigation pane, click Queues. Find the queues that you created. In the Actions column, click the rightmost icon, click Delete, and then follow the on-screen instructions.

Free trial

Solution overview

Integrate EventBridge with AI services to run intelligent inference on real-time event bus data, strengthening data processing and unlocking innovative applications.

Using EventBridge as a data hub, you can distribute real-time data streams from various sources to different AI models for inference. EventBridge then routes the inference results to downstream business systems or data stores. Adding AI inference to the ETL Transform step makes data transformation more intelligent, boosts processing efficiency and accuracy, and provides your business with powerful data integration and analysis.

Solution architecture

The following diagram shows the system that this solution deploys on Alibaba Cloud with the default settings. You can adjust some settings during actual deployment, but the overall system remains similar.

image

This tutorial uses sensitive information filtering as an example to demonstrate data cleaning and desensitization for downstream data. AI automatically identifies business-sensitive keywords to safeguard downstream business and data compliance.

The solution works as follows: an input containing sensitive information, such as ["Customer John Doe (+1-555-0100) reported an issue..."], is processed to produce a sanitized output, such as ["Customer *** (+1-***-0100) reported an issue..."]. Because large models can produce non-deterministic results, the output format may vary during testing. In production, you can use prompt engineering to obtain more deterministic outputs.

This solution uses the following cloud services and infrastructure:

Resource

Description

1 event flow

Used to build a data pipeline.

2 Lightweight Message Queue (formerly MNS) queues

Serve as the data source and sink.

Alibaba Cloud Model Studio

Calls a large-model service to process data.

One-click deployment

  1. Click the Try Now button on the right side of the page to start creating the resources. Deployment completes in a few minutes.

    Note

    If the page indicates that your account has fewer trial points than the estimated amount required, you must obtain more trial points before you can try this solution. To get more trial points, go to Solution Center Free Trial.

  2. After the deployment is complete, click Next on the RAM User Logon page in the browser pane on the right.

  3. In the left-side pane, under Cloud Resources > Trial Account, copy the Logon Password. Paste it into the Password field in the right-side browser pane, and then click Logon.

  4. After you log on, on the Select MFA Type to Bind page, click Skip Binding in the upper-right corner.

Important
  • After the deployment is complete, you can view information about all created cloud resources by clicking the Cloud Resources menu on the left side of the page.

  • During the trial, if your trial period is about to reach the maximum allowed for this solution, the system prompts you to renew. You can check the Remaining Duration in the upper-right corner of the page. You can also click Renew in the upper-right corner to extend the trial period. When the remaining time reaches zero, all created resources are released automatically.

  • In the following steps, if you need to access a cloud resource, copy the corresponding address from the Cloud Resources pane on the left and paste it into the browser pane on the right.

Enable services

  1. Log on to Model Studio. After you read and agree to the Terms of Service, Model Studio is automatically activated. If the Terms of Service do not appear, this indicates that you have already activated Model Studio.

    • When you activate Model Studio for the first time, the platform automatically grants you a free quota for new users for each model. For more information, see Free quota for new users.

      Note

      Only models in the China (Beijing) region with the service deployment scope set to China (Mainland) are eligible for a free quota. Models in other regions or with different service scopes are not eligible.

    • If you are prompted that identity verification has not been completed when activating the service, first complete Individual identity verification.

  2. If you are using ApsaraMQ for MNS for the first time, activate the service as follows.

    1. Log in to the ApsaraMQ for MNS console.

    2. On the Overview page, click Activate for Free and follow the on-screen instructions.

  3. To activate EventBridge for the first time, follow these steps.

    1. Log on to the EventBridge console.

    2. On the Overview page, in the Activate EventBridge wizard, click Enable For Free and follow the on-screen instructions.

    3. EventBridge requires authorization to receive events. On the Overview page, in the Access Authorization wizard, click Authorize Now.

Get an API key

Get a Model Studio API key

  1. Go to the API Key page of Model Studio.

  2. Click Create API Key. In the dialog box, confirm the Workspace, enter a Description, and select Permissions as needed.

    Note
    1. A RAM user requires authorization from the Alibaba Cloud account before creating an API key.

    2. Do not expose your API key. Unauthorized use can cause security risks and financial losses.

  3. Click OK.

  4. After the API key is created, immediately copy or download the full API key from the result dialog box and store it securely.

    The API key is displayed only once. After you close the dialog box, the list shows only a masked value and you cannot view or copy the full key again. If you did not save the key, reset it or create a new one.

Create the source and sink

Create two queues in Lightweight Message Queue (formerly MNS) to serve as the source and sink for the event flow.

Create MNS queues

  1. Log on to the Lightweight Message Queue (formerly MNS) console.

  2. In the left-side navigation pane, click Queues. From the Region drop-down list, select China (Shenzhen).

  3. Click Create Queue, set Name to eventbridge-dev, and leave the other parameters at their default values.

  4. Click Confirm and wait for the queue to be created.

  5. Repeat the preceding steps to create another queue named eventbridge-online.

Important

If duplicate message consumption occurs, set the Visibility Timeout Period to a value between 60 seconds and 300 seconds.

Build the data processing pipeline

Create and configure an EventBridge event flow to act as the data processing pipeline.

Create event flow and configure source

  1. Log on to the EventBridge console.

  2. In the left-side navigation pane, click Event Streams. From the Region drop-down list, select China (Shenzhen).

  3. Click Create Event Stream.

    1. Enter a custom value for Task Name.

    2. For Metering Method, select Pay-by-event.

  4. On the Task Creation tab, in the Source area, configure the following settings:

    1. For Data Provider, select Lightweight Message Queue (formerly MNS).

    2. For Queue Name, select eventbridge-dev. Leave the other settings as default.

  5. Click Next Step.

Configure filtering

  1. In the Filtering area, configure the following settings:

    1. For Pattern Content, select All Events Match. In real business scenarios, you can also select other filtering rules, or select custom matching to define filtering rules flexibly.

  2. Click Next Step.

Configure transformation

  1. In the Transformation area, configure the following settings:

    1. For Alibaba Cloud Service, select Model/Agent Call (Alibaba Cloud Model Studio). This tutorial uses Model Call as an example.

    2. For Model Name, enter qwen-max.

    3. Configure the Model Context as follows:

      SYSTEM

      Fixed Value

      You are a data compliance officer. You must ensure that all data entering the analysis system complies with GDPR/CCPA regulations and does not contain any personally identifiable information (PII). During the ETL process, your task is to automatically identify and sanitize text containing names, phone numbers, and ID numbers. You must also block sensitive content related to religion, sexuality, and politics.

      USER

      Partial Event

      $.data.messageBody

    4. For Structured Output, select Enable, click Add Field, and then add fields as described in the following table:

      data

      string

      The sanitized data content.

      Required

      cause

      string

      The reason the data was filtered. The value must be in English.

      Optional

    5. For API Key, enter the Model Studio API key that you obtained.

  2. Click Next Step.

Configure sink

  1. In the Sink area, configure the following settings:

    1. For Service Type, select SMQ.

    2. For Queue Name, select the created queue eventbridge-online.

    3. For Message Body, select Partial Event, and enter $.transform0.structuredoutput.

  2. Click Save. Wait for the event flow to be created. The Status changes to Running.

Verify the solution

To verify the model's data sanitization, send a message containing sensitive information from the source queue and then check the processed message in the sink queue.

Send a message

  1. Log on to the Lightweight Message Queue (formerly MNS) console. In the left-side navigation pane, click Queues.

  2. Find the eventbridge-dev queue, and click Send Messages in the Actions column.

  3. In the Send Message area, configure the following settings:

    1. For Message Content, enter Customer John Doe (+1-555-0100) reported an issue.

    2. Set Message Delay Period to 0 seconds.

  4. Click Send Message.

Receive a message

  1. Log on to the Lightweight Message Queue (formerly MNS) console. In the left-side navigation pane, click Queues.

  2. Find the created queue eventbridge-online, and click Send Messages in the Actions column.

  3. In the Receive Message area, click Receive Message.

  4. The received message appears in the list. In the Actions column, click Details and view the Base64-decoded Message. A result similar to the one shown in the following figure indicates that the data has been processed.

Clean up resources

Click imageEnd Trial in the upper-right corner of the solution page, and then click OK in the confirmation dialog box to end the trial and release all resources.

Note

After the solution trial ends, the system deletes the trial account and automatically releases all trial resources.