Build an intent recognition application flow

更新时间:
复制 MD 格式

Learn how to build an intent recognition customer service application flow in LangStudio. This flow integrates intent recognition and Retrieval-Augmented Generation (RAG) to classify user needs and retrieve relevant answers from a knowledge base. You can customize this template for your scenarios.

Background

The intent recognition customer service application flow combines NLP and deep learning to deliver smarter customer support. It identifies user intents, retrieves answers from a knowledge base via RAG, and returns relevant solutions. Developers can use Python to adjust response strategies and customize the template for domains such as e-commerce, banking, and telecommunications.

Prerequisites

  • LangStudio supports Faiss and Milvus as vector databases. If you plan to use Milvus, you must create a Milvus instance. Create a Milvus Instance and Instance Management.

    Note

    Faiss works for testing without a separate database. For production, use Milvus to handle larger-scale data.

  • The RAG knowledge base corpus has been uploaded to OSS.

1. (Optional) Deploy LLM and embedding models

Deploy model services from Model Gallery. If you already have a model service that supports the OpenAI API, skip this step.

Go to Quick Start > Model Gallery and deploy models for the following two scenarios. Model Deployment and Training.

  • For Scenario, select Large Language Models. For this example, deploy DeepSeek-R1. One-click Deployment of DeepSeek-V4 and DeepSeek-R1 Models.

    Note

    In this example, the Intent Recognition, Question Rewrite, and Answer User Question nodes share the same model connection, so you only deploy DeepSeek-R1 once. In production, deploy separate models per node for better accuracy.

  • For Scenario, select Embedding. For this example, deploy the bge-m3 general-purpose vector model.

2. Create connections

2.1 Create an LLM service connection

This LLM service connection uses a model service (EAS service) deployed from QuickStart > Model Gallery. Other connection types are described in Connection Configuration.

In LangStudio, select a workspace. Under Configure Service Connection, go to the Model Service tab and click New Connection to create a generic LLM service connection.

Key parameters:

Parameter

Description

Model name

The model name is on the model's details page in Model Gallery. Create a Connection - Model Service.

Service provider

  • PAI-EAS Model Service: Used in this example. For EAS Service, select the LLM service deployed in Section 1. The base_url and api_key auto-populate with the VPC access address and token of the deployed LLM.

  • Third-party Model Service: Use a third-party model service. For example, if using the official DeepSeek service, the base_url is https://api.deepseek.com, and the api_key can be obtained from the DeepSeek official website.

2.2 Create an embedding model service connection

Similar to Section 2.1, create a generic embedding model service connection.

Set the Service Provider to PAI-EAS Model Service, and configure the EAS Service, Model Name, base_url, and api_key fields.

3. Create a knowledge base index

Creating a knowledge base index involves parsing, chunking, and vectorizing the corpus, then storing the results in a vector database. Key parameters are described below. Knowledge Base Management.

Parameter

Description

Basic configuration

Data source OSS path

Specify the OSS path to the RAG knowledge base corpus prepared in the Prerequisites section.

Output OSS path

Path for intermediate results and index data generated during parsing.

Important

With Faiss, index files are saved to OSS. If you use the default PAI role (the Instance RAM Role set when starting the runtime for application flow development), the flow can access your workspace's default storage bucket. Set this parameter to a directory within the OSS bucket that contains your workspace's default storage path. If you use a custom role, grant it OSS access (the AliyunOSSFullAccess policy is recommended). Manage RAM Role Permissions.

Embedding model and database

Embedding type

Select General Embedding Model.

Embedding connection

Select the embedding model service connection created in Section 2.2.

Vector database type

Select Faiss. This document uses a Faiss vector database as an example.

4. Create and run the application flow

  1. Go to LangStudio, select a workspace, go to the Applications tab, and click Create Application to create an Intent Recognition Customer Service application flow.

    On the New Application Flow page, select the Create from Template tab, enter a Name (for example, intent-002), and select a runtime.

  2. Start the runtime: Click Create Runtime in the upper-right corner and configure it. Note: The runtime must be running before you can parse Python nodes or view more tools.

    Configure parameters including Runtime name, Resource specification, Security group, vSwitch, Mount configuration, and Maximum duration per run. Select a VPC from the VPC configuration dropdown.

    VPC configuration: If you chose Milvus as the vector database type in Step 3, select the same VPC as the Milvus instance or ensure VPC interconnection. Faiss does not require VPC configuration. This example uses Faiss.

  3. Develop the application flow.

    image

    Keep defaults for other settings, or adjust as needed. Key node configurations:

    • Intent Recognition: Uses an LLM to analyze user input and route to the corresponding branch.

      • Multi-intent configuration: Define intents with clear, non-overlapping descriptions. This example uses the default intent "Questions about Alibaba Cloud PAI products".

      • Model Settings: Select the connection created in Section 2.1.

      • Chat History: Toggle to use conversation history as an input variable.

    • Question Rewrite: Uses an LLM to rewrite the matched intent information.

      • Model Settings: Select the connection created in Section 2.1.

      • Chat History: Use the same configuration as the Intent Recognition node.

    • Knowledge Base Retrieval: Retrieves relevant text from the knowledge base. Knowledge Base Management.

      • Knowledge base index name: Select the knowledge base index created in Step 3.

      • Top K: Number of top matching entries to return.

    • Answer User Question: Uses an LLM to answer the user's question.

      • Model Settings: Select the connection created in Section 2.1.

      • Chat History: Use the same configuration as the Intent Recognition node.

    • Other Intent: Runs custom Python code for complex data processing.

    • Variable Aggregation: Merges outputs from different intent branches into a unified variable.

    Pre-built Component Reference.

  4. Debug/Run: Click Run in the upper-right corner to run the application flow. For common runtime issues, see FAQ.

    A chat test panel appears on the right. Enter test questions to verify behavior. For example, entering "hello" returns "Sorry, I can only answer questions about Alibaba Cloud PAI." Entering "What are the features of Alibaba Cloud PAI products?" returns a feature list including AI computing resource management, AI workspace, and AI asset management (dataset management, model management, task management), confirming the flow works correctly.

  5. View Trace: Click View Traces below the generated answer to see the trace details or topology view.

    The Trace details page shows a waterfall chart of span durations — for example, intent-002 (CHAIN/17.41s), intent_recognition (TASK/717.25ms), ChatCompletion (LLM/707.14ms), rewrite (TASK/369.96ms), and index_lookup (TASK/429.68ms). Click a span to view its details, including application name, API name, spanId, status code, and input/output data. The top of the page shows the TraceID, start time, total duration, and total tokens.

5. Deploy the application flow

On the application flow development page, click Deploy in the upper-right corner to deploy the flow as an EAS service. Key parameters:

  • Resource deployment > Number of instances: Set to 1 for testing. In production, configure multiple instances to reduce single-point-of-failure risk.

  • VPC > VPC: If you chose Milvus in Step 3, configure the same VPC as the Milvus instance or ensure VPC interconnection. Faiss does not require VPC configuration. This example uses Faiss.

Deploy an Application Flow.

6. Call the service

After deployment, you are redirected to the PAI-EAS page. On the Debug tab, send a request. The request body key must match the "Dialogue Input" parameter in the flow's "Start" node. This example uses the default field, question.

For example, enter {"question":"hello"} in the request body and click Send Request. A 200 status code and the response {"output":"Sorry, I can only answer questions about Alibaba Cloud PAI."} confirm successful debugging.

In raw mode, enter a JSON object such as {"question":"What are the functions of Alibaba Cloud PAI DSW"}. A Status Code: 200 and JSON response with the answer indicate a successful service call.

Other calling methods, such as API calls, are described in Deploy an Application Flow - Call the Service.

Related documents