Modifies the configuration of a registered AI model in the polar_ai schema.
Syntax
boolean AI_AlterModel(text model_id, text model_url, text model_provider, text model_type, text model_name, text model_config, regprocedure model_headers_fn, regprocedure model_in_transform_fn, regprocedure model_out_transform_fn);Parameters
| Parameter | Description |
|---|---|
model_id | The unique identifier of the AI model to update. Required. The value must differ from model_name and cannot start with an underscore (_). Built-in models created by the Polar_AI extension use the underscore prefix. To list all registered models, run SELECT * FROM polar_ai._ai_models;. |
model_url | The endpoint URL of the AI model. Supported protocols: HTTP, HTTPS, and FILE. Cannot be NULL if specified. For example, use the endpoint from the call information of a model deployed on Platform for AI (PAI). |
model_provider | The provider of the AI model. Examples: AWS, Alibaba, Baidu, Tencent. Accepts NULL. |
model_type | The type of the AI model. Examples: LSTM, GRU. Accepts NULL. |
model_name | The name of the AI model. Example: text-embedding-v2. Cannot be NULL if specified. |
model_config | The model authentication configuration in JSON format. Cannot be NULL if specified. Format: { "author_type": "token", "token": "<YOUR_API_KEY>" }. Both author_type and token fields are required. Only token-based authentication is supported. API keys are encrypted at rest. For example, use the token from the call information of a model deployed on PAI. |
model_headers_fn | The function that constructs custom request headers. Returns JSONB. Default: NULL. Omit this parameter if the model has no special header requirements. |
model_in_transform_fn | The function that converts input data to the format expected by the AI model. Cannot be NULL if specified. |
model_out_transform_fn | The function that parses the raw output returned by the AI model. Cannot be NULL if specified. |
Return values
| Value | Description |
|---|---|
t | The update succeeded. |
f | The update failed. |
Usage notes
Only
model_idis required. All other parameters are optional. Parameters set to NULL are ignored — the corresponding fields in the model configuration remain unchanged.If you specify
model_urlandmodel_config, the values must be accurate and not NULL. Passing NULL for either parameter prevents the model from being called.
Examples
Update the model URL:
SELECT polar_ai.AI_AlterModel('my_text_embedding_model', model_url=>'http://....');Update the model provider:
SELECT polar_ai.AI_AlterModel('my_text_embedding_model', model_provider=>'Alibaba');Update the model type:
SELECT polar_ai.AI_AlterModel('my_text_embedding_model', model_type=>'GRU');Update the model name:
SELECT polar_ai.AI_AlterModel('my_text_embedding_model', model_name=>'text-embedding-v3');Update the API key:
SELECT polar_ai.AI_AlterModel('my_text_embedding_model', model_config=>'{"token": "your-new-api-key", "author_type": "token"}');The following example returns f because the model_config parameter is set to NULL, which causes the model to fail to be called:
SELECT polar_ai.AI_AlterModel('my_text_embedding_model', model_config=>NULL);
---
f