All Products
Search
Document Center

PolarDB:AI_CallModel

Last Updated:Mar 19, 2025

Calls a model to perform machine learning and natural language processing (NLP) tasks, such as sentiment analysis, question answering, translation, summarization, and text generation.

Syntax

jsonb AI_CallModel(text model_id, anyelement content);

Parameters

Parameter

Description

model_id

The unique name of an existing model that you want to call.

content

The input data for the model. Various data types are supported, including texts, images, complex data structures, and records. For more information, see the "Description" section of this topic.

Return values

Returns a JSON binary (JSONB) object. The JSONB object can be parsed to generate custom results, such as text and image vectors.

Description

  • Before you call the function, create a model by using the AI_CreateModel function.

  • The content parameter supports various data types and matches the content parameter specified in the model_in_transform_fn function. You must specify the content parameter when you call the function. For example, if you want to input text into the model, specify the parameter as content::text.

Examples

Call an existing model to convert text into vectors.

SELECT polar_ai.AI_CallModel('my_text_embedding_model', '风急天高猿啸哀'::text);

Sample result:

---
 [1.4284451007843018, -2.7454426288604736, 1.5957790613174438, -2.182790756225586, 3.9757323265075684, -3.0645480155944824, 3.613696336746216, -3.484774351119995, -2.174361228942871, 1.0907986164093018, 1.4526909589767456, 1.3686197996139526, 1.4130642414093018, -1.694422721862793, 2.053454637527466, 4.982985973358154, 1.7921278476715088, 2.6027371883392334, 0.1595267355442047, 1.7544844150543213, 2.0501770973205566]