All Products
Search
Document Center

PolarDB:AI_CallModel

Last Updated:Mar 28, 2026

Invokes a registered model to run 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

ParameterTypeDescription
model_idtextThe unique name of the model to invoke.
contentanyelementThe input data for the model. Supported data types include text, images, complex data structures, and records. Must match the data type specified in the model_in_transform_fn function used when creating the model.

Return value

Returns a JSONB (JSON binary) object. Parse the JSONB object to extract results such as text or image embedding vectors.

Usage notes

  • Before calling AI_CallModel, create a model using AI_CreateModel.

  • The content parameter type must match the type defined in the function of the target model. For text input, cast the value explicitly: content::text.

Example

Convert text into embedding vectors using a registered model:

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

Sample output:

[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]