Runs machine learning and natural language processing (NLP) tasks against a registered model, including 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 the model to call. |
content | The input data for the model. Supported data types include text, images, complex data structures, and records. The type must match the content parameter defined in the function. Cast explicitly when needed — for example, 'your text'::text. |
Return value
Returns a JSON binary (JSONB) object. Parse the object to extract custom results such as text and image vectors.
Usage notes
Before calling
AI_CallModel, create a model withAI_CreateModel.Always specify the
contentparameter with an explicit cast to match the expected input type.
Examples
The following example calls a text embedding model and converts a text string into a vector. All calls use the polar_ai schema.
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]