AI Functions Overview
Description
AI functions call external AI models from SQL in VeloDB Cloud. Use an AI resource to configure the provider, endpoint, model, and credentials for text analysis and generation.
The model service must be external to VeloDB Cloud and reachable from the warehouse. Query text is sent to that service, and requests can incur provider charges. Confirm that the provider and model support the selected function.
Configure an AI resource
Before using AI Function, you need to create a Resource of type AI to centrally manage access information for the AI API.
Example: Create an AI resource
CREATE RESOURCE "ai_resource_name"
PROPERTIES (
'type' = 'ai',
'ai.provider_type' = 'openai',
'ai.endpoint' = 'https://<model-service>/<api-path>',
'ai.model_name' = '<model-name>',
'ai.api_key' = '<api-key>',
'ai.temperature' = '0.7',
'ai.max_token' = '1024',
'ai.max_retries' = '3',
'ai.retry_delay_second' = '1',
'ai.dimensions' = '1024'
);
Parameters
Core 26.1.3 requires the general connection properties ai.endpoint, ai.provider_type, and ai.model_name, plus ai.api_key unless the provider is LOCAL. The same resource connection serves text generation and EMBED. Separate embedding connection groups are described below for a future release.
type: Required, must be ai, used as the type identifier for ai.
ai.provider_type: Required for the general model group. Specifies the external AI provider. Supported providers include OpenAI, Anthropic, Gemini, DeepSeek, Local, MoonShot, MiniMax, Zhipu, QWen, Baichuan, VoyageAI, and Jina. If another provider uses an API compatible with OpenAI, Anthropic, or Gemini, specify the corresponding compatible provider type.
A valid provider type does not imply support for every AI function. For example, VoyageAI and Jina support embedding and cannot serve as text generation models.
ai.endpoint: Required for the general model group. Specifies the AI API endpoint.
ai.model_name: Required for the general model group. Specifies the model name.
ai.api_key: API key for the general model group. Required unless ai.provider_type = local.
ai.temperature: Optional. Controls the randomness of generated content. Accepts a float value between 0 and 1.
The default value is -1, which means this parameter is not set.
ai.max_token: Optional. Limits the maximum number of tokens for generated content.
The default value is -1, which means this parameter is not set. The default value for Anthropic is 2048.
ai.max_retries: Optional. The maximum number of retries for a single request. The default value is 3.
ai.retry_delay_second: Optional. The delay time (in seconds) before retrying. The default value is 0.
ai.enable_structured_output (future release, unavailable in Core 26.1.3): Optional Boolean, defaults to true. The query engine batches input rows for scalar AI functions. Enabling this option adds provider-specific format fields to improve response-format reliability. The query engine does not check the configured model's support; LOCAL and MiniMax omit these fields. Set it to false if the model or endpoint rejects them. Batching, system-prompt format instructions, and response validation remain enabled. This property does not apply to AI_AGG or EMBED.
ai.dimensions: Optional, control the vector dimension of EMBED output.
Make sure to confirm that the model filled in ai.model_name supports custom vector dimension before setting,
otherwise it may cause model call failure.
Dedicated embedding model configuration for a future release
In a future release, an AI resource can configure a general model, a text embedding model, and a multimodal embedding model separately. At least one complete group is required. If any connection property or API key is set for a group, that group must include endpoint, provider_type, and model_name, plus api_key for non-LOCAL providers. Missing fields are not inherited from other groups.
| Model group | Connection properties | API key | Usage |
|---|---|---|---|
| General | ai.endpoint, ai.provider_type, ai.model_name | ai.api_key | Text generation and other AI functions; fallback when no dedicated embedding group is configured |
| Text embedding | ai.embed.endpoint, ai.embed.provider_type, ai.embed.model_name | ai.embed.api_key | Text input to EMBED(); fallback for multimodal input |
| Multimodal embedding | ai.embed.mm.endpoint, ai.embed.mm.provider_type, ai.embed.mm.model_name | ai.embed.mm.api_key | JSON multimodal input to EMBED() |
Text EMBED() selects the text embedding group first, then the general group. Multimodal EMBED() selects the multimodal embedding group, then the text embedding group, then the general group. The selected provider and model must support the actual media type. A resource with only embedding groups can serve the corresponding EMBED() calls, but cannot serve text generation functions that require a general model.
The following future-release example configures a resource only for text embedding. It is not valid as a complete resource in Core 26.1.3:
CREATE RESOURCE "text_embed_resource"
PROPERTIES (
"type" = "ai",
"ai.embed.provider_type" = "openai",
"ai.embed.endpoint" = "https://<embedding-service>/v1/embeddings",
"ai.embed.model_name" = "<embedding-model>",
"ai.embed.api_key" = "<api-key>"
);
Replace the connection values with your service configuration. Successful creation returns Query OK. Shared settings such as ai.dimensions and retry parameters still come from the resource configuration.
Reasoning effort for a future release
In a future release, the optional string property ai.effort specifies reasoning effort. By default, it is unset and is not sent to the provider. Use lowercase values, subject to provider validation:
| Provider | Accepted values |
|---|---|
ANTHROPIC | low, medium, high, xhigh, max |
GEMINI | minimal, low, medium, high |
| Property validation for other providers | none, minimal, low, medium, high, xhigh, max |
Passing property validation does not mean every model supports that effort level. Choose a value supported by your service and model. ai.effort does not replace ai.max_token.
An empty string in ALTER RESOURCE removes the ai.effort setting.
Resource permissions
Creating an AI resource requires the warehouse SQL ADMIN privilege. A future release adds the managed setting ai_resource_allowed_user to restrict the creator's identity. This setting is unavailable in Core 26.1.3 and is managed by VeloDB Cloud support.
In that future release, an AI resource newly created by root can only be altered or dropped by root; other accounts are rejected even if they have ADMIN privileges. Resources that existed before the upgrade and lack this marker are not marked retroactively. Other resources retain the existing privilege checks.
Resource selection and session variables
When users call AI-related functions, resources can be specified in the following two ways:
- Explicitly specify the resource: directly pass the resource name when calling the function.
- Implicitly specify the resource: set the Session variable in advance, and the function will automatically use the corresponding resource.
Set Session variable format:
SET default_ai_resource='resource_name';
Function call format:
SELECT AI_FUNCTION([<resource_name>], <args...>);
Resource selection priority
When calling an AI_Function, it determines which resource to use in the following order:
- The resource explicitly specified by the user in the call
- The resource selected by the session variable
default_ai_resource
Example:
SET default_ai_resource='global_default_resource';
SELECT AI_SENTIMENT('this is a test'); -- Uses resource named 'global_default_resource'
SELECT AI_SENTIMENT('invoke_resource', 'this is a test'); --Uses resource named 'invoke_resource'
AI functions
AI functions include:
-
AI_CLASSIFY: Information classification -
AI_EXTRACT: Information extraction -
AI_FILTER:Filter information -
AI_FIXGRAMMAR: Grammar correction -
AI_GENERATE: Text generation -
AI_MASK: Masking sensitive information -
AI_SENTIMENT: Sentiment analysis -
AI_SIMILARITY: Text semantic similarity comparison -
AI_SUMMARIZE: Text summarization -
AI_TRANSLATE: Translation -
AI_AGG: Perform cross-line aggregation analysis on multiple texts
Examples
AI_TRANSLATE
SELECT AI_TRANSLATE('resource_name', 'this is a test', 'Chinese');
-- 这是一个测试
AI_SENTIMENT
SET default_ai_resource = 'resource_name';
SELECT AI_SENTIMENT('Apache Doris is a great DBMS.');
For detailed function and usage, please refer to the documentation of each specific function.