AI_COMPLETE
AI_COMPLETE is the core scalar function for generative AI tasks on the Singdata Lakehouse platform. It allows you to invoke large language models (LLMs) directly within the SQL environment, generating responses based on text prompts or multimodal inputs, enabling tasks such as text completion, translation, sentiment analysis, code generation, and complex reasoning.
Singdata pushes AI computation down to the storage layer and execution engine, so data can be intelligently processed within the platform without being transferred to external environments — safeguarding data security while significantly reducing task latency.
Syntax
AI_COMPLETE supports two calling forms:
Text mode
Image mode
Parameter Description
model (required)
Specifies the language model to invoke. Two sources are supported:
Source 1: API Gateway Endpoint (recommended)
The platform administrator pre-configures model services in the API Gateway (including provider, version, and authentication credentials). Regular users reference them using the endpoint: prefix without needing to know the underlying connection details.
Source 2: API Connection object
Users create connection objects themselves via CREATE API CONNECTION, suitable for scenarios requiring custom service addresses, authentication keys, or connections to privately deployed models.
CREATE API CONNECTION field descriptions:
| Field | Description |
|---|---|
TYPE | Fixed as ai_function |
PROVIDER | Model provider identifier, e.g. 'bailian', 'openai', 'anthropic' |
BASE_URL | API base address of the model service |
API_KEY | Authentication key required to call the service |
prompt (required)
The input content to send to the model, of type STRING.
Text mode: pass a string directly:
Dynamic content can be concatenated using CONCAT or ||:
Image mode: use named tuple syntax to pass both a text prompt and an image URL:
options (optional)
Passed using the json '{}' literal syntax to control execution behavior and model parameters:
| Parameter key | Type | Description |
|---|---|---|
model.params.temperature | FLOAT | Output randomness, range [0, 2]; lower values produce more deterministic output |
model.params.max_tokens | INT | Maximum number of output tokens |
model.params.top_p | FLOAT | Nucleus sampling probability, range (0, 1] |
model.params.enable_thinking | BOOL | Whether to enable thinking mode; recommended to set to false for batch processing |
response.timeout | STRING | Timeout per request in seconds, e.g. "60" |
task.concurrency | STRING | Concurrency level for batch processing, e.g. "5" |
Return Value
Returns a STRING — the response text generated by the model.
- When prompt is
NULLor an empty string, returnsNULL - When the endpoint does not exist, throws
CZLH-67000: No available endpoints found - When the model format is invalid (missing
endpoint:orconnection:prefix), throwsCZLH-65000: Invalid model coordinates
Usage Examples
Basic Text Completion
Batch Processing Table Data
Dynamic Prompt with CONCAT
Image Description
Image with a Specific Question
Batch Image Processing
Combining with Other AI Functions
Notes
- Model selection: Image mode requires a model that supports multimodal input (e.g.
doubao-seed-2-0-pro-260215). Text-only models such asqwen3-max-previewdo not support image input — passing an image does not cause an error, but the image content is ignored and the response is generated from the text prompt only. - Thinking mode: The qwen3 model series enables thinking mode by default, which increases latency and token consumption. For batch processing scenarios, it is recommended to disable it via options:
json '{"model.params":{"enable_thinking":false}}'. - Image field cannot be NULL: Passing NULL for the
imagefield in image mode throwsinvalid type of image field: void. EnsureGET_PRESIGNED_URL()returns a valid URL. - NULL and empty strings: When prompt is
NULLor an empty string, the function returnsNULLwithout error. - Error codes: A missing endpoint throws
CZLH-67000; an invalid model format (missingendpoint:prefix) throwsCZLH-65000. - Token limits: Different models have different context window limits. Inputs exceeding the limit will be truncated or cause an error. Pay attention to input length when processing long text.
