PolarDB for AI integrates the Qwen large language model (LLM) of Alibaba Cloud into PolarDB. You can use the Qwen LLM as a built-in model of PolarDB to perform data inference and interaction.
Scenarios
Sentiment analysis model: evaluates the emotional tone or attitude expressed in a sentence.
Output: Negative | Chat model: generates responses based on input text.
Output: I am a large language model of Alibaba Cloud. You can call me Qwen. |
Summarization model: generates a concise summary of a longer text.
Output: In recent years, the Chinese film market has favored realistic themes. In 2018, Dying to Survive won the box office with 3.1 billion yuan. Films including The White Storm 2: Drug Lords, Raging Fire, and Chinese Doctors also succeeded. This summer... | Translation model: translates Chinese text into English.
Output: This product appears good but has poor performance. I do not recommend that you buy it. |
Positive comment model: generates positive comments based on the input content.
Output: Since its launch, the Huawei Mate 60 Pro has quickly won the favor of consumers with its exceptional performance and innovative technology. The sales have been exceptionally strong, even leading to shortages. Renowned... | Negative comment model: generates negative comments based on the input content.
Output: Although the sales of the Huawei Mate 60 Pro appear to be strong, this short-term market reaction may not be sufficient to prove the long-term competitiveness of the product. In the current complex global technology landscape,... |
Limits
Online inference can process only a single data entry at a time. Offline inference can handle multiple data entries in batches.
The maximum input length of the Qwen LLM is 8,000 tokens. However, due to the limits of the model on computing resources, if the model cannot generate an output within 10 seconds, no final result is generated. In this case, you can add AI nodes to improve performance.
Examples
Prepare the environment
Add AI nodes and configure the database account for the AI nodes. For more information, see Enable the PolarDB for AI feature.
If you add AI nodes when you purchase the cluster, you can directly configure an account for the AI nodes to connect to the database.
Connect to the PolarDB cluster by using a cluster endpoint. For more information, see Connect to a cluster by using the cluster endpoint to use the PolarDB for AI feature
Prepare data
Create a table named
textinfo
.CREATE TABLE IF NOT EXISTS textinfo ( id INT NOT NULL, content TEXT NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Add the following data to the
textinfo
table.INSERT INTO textinfo (id,content) VALUES (1, "This product appears good but has poor performance. I do not recommend that you buy it."); INSERT INTO textinfo (id,content) VALUES (2. "The Mate 60 Pro, the latest mobile phone developed by Huawei, has been highly popular and in strong demand since its launch and is now out of stock. Guo Mingji, a well-known analyst, posted on Monday that he has significantly raised the shipment expectations for the Mate 60 Pro. He emphasized that the influence of Huawei on the technology industry and stock market is undeniable and the company is making a strong comeback.") INSERT INTO textinfo (id,content) VALUES (3,"In recent years, the Chinese film market has increasingly favored realistic themes. In 2018, Dying to Survive became the summer box office champion with 3.1 billion yuan in sales. Films including The White Storm 2: Drug Lords, Raging Fire, and Chinese Doctors also achieved significant success. This summer, realistic-themed movies such as Lost in the Stars, Never Say Never, and No More Bets gained immense popularity, which reflects the interest of the audience in close-to-life content. INSERT INTO textinfo (id,content) VALUES (4,"Who are you?"); INSERT INTO textinfo (id,content) VALUES (5,"This item only looks decent; the actual experience is very poor. I do not recommend purchasing it.");
Call the Qwen LLM
Sentiment analysis model
Evaluates the emotional tone or attitude expressed in a sentence. This type of model is widely used in various fields, such as e-commerce review analysis, news reporting bias or tendency analysis, and public opinion monitoring.
/*polar4ai*/SELECT * FROM PREDICT (MODEL _polar4ai_tongyi_sa, SELECT content FROM textinfo WHERE id = 1) WITH ();
Sample output:
Negative
Positive/negative comment model
Generates positive or negative comments based on a given content.
Generate positive comments:
/*polar4ai*/SELECT * FROM PREDICT (MODEL _polar4ai_tongyi_p_comment, SELECT content FROM textinfo WHERE id = 2) WITH ();
Sample output:
The Huawei Mate 60 Pro has been selling extremely well since its launch, which demonstrates strong consumer recognition and support for the Huawei brand. As a well-known technology company in China, Huawei has always attracted significant attention in the smartphone market. The post of Guo Mingjī further confirms the influence of Huawei in the technology industry and stock market, which indicates that Huawei is gradually regaining its prominent position in these areas. The influence of Huawei extends beyond product sales. Huawei also plays a key role in driving advancements in the broader technology sector and influencing the stock market. We must encourage and support excellent enterprises like Huawei to promote the sustained development of the science and technology industry in China.
Generate negative comments:
/*polar4ai*/SELECT * FROM PREDICT (MODEL _polar4ai_tongyi_n_comment, SELECT content FROM textinfo WHERE id = 2) WITH ();
Sample output:
The strong sales performance of the Huawei Mate 60 Pro has come as a surprise, but it also reflects that consumer recognition and support for the Huawei brand remain high. However, this success may also be related to the current instability in the global technology market. As a Chinese company, Huawei has faced significant political and economic pressures in international markets, which may potentially impact its sales performance in the long term. In addition, the comments of Guo Mingjī, a well-known analyst, may be overly optimistic and ignore the challenges and difficulties that Huawei faces. In conclusion, although the influence of Huawei is returning, the future market performance of the brand requires a more thorough analysis.
Summarization model
Generates a concise summary for a longer text.
/*polar4ai*/SELECT * FROM PREDICT (MODEL _polar4ai_tongyi_summarize, SELECT content FROM textinfo WHERE id = 3) WITH ();
Sample output:
In recent years, the Chinese film market has increasingly favored realistic themes. In 2018, Dying to Survive became the summer box office champion with 3.1 billion yuan in sales. Films including The White Storm 2: Drug Lords, Raging Fire, and Chinese Doctors also succeeded. This summer, realistic-themed movies such as Lost in the Stars, Never Say Never, and No More Bets gained immense popularity, which reflects the interest of the audience in content close to life.
Translation model
Translates Chinese text into English.
/*polar4ai*/SELECT * FROM PREDICT (MODEL _polar4ai_tongyi_tran_2_en, SELECT content FROM textinfo WHERE id = 1) WITH ();
Sample output:
This product appears good but has poor performance. I do not recommend that you buy it.
Translate text from a specific language such as English into Chinese.
/*polar4ai*/SELECT * FROM PREDICT (MODEL _polar4ai_tongyi_tran_2_zh, SELECT content FROM textinfo WHERE id = 5) WITH ();
Sample output:
这件商品看起来还不错,实际体验却很差。 我不推荐购买。
Chat model
Generates responses based on input text. The input content may contain explicit prompts based on which answers are generated.
/*polar4ai*/SELECT * FROM PREDICT (MODEL _polar4ai_tongyi, SELECT content FROM textinfo WHERE id = 4) WITH ();
Sample output:
I am a large language model of Alibaba Cloud. You can call me Qwen.
You can directly input plain text
to obtain the answer.
/*polar4ai*/SELECT * FROM PREDICT (MODEL _polar4ai_tongyi, SELECT 'Who are you?') WITH ();
Sample output:
I am a large language model of Alibaba Cloud. You can call me Qwen.