- Categories:
String & binary functions (AI Functions)
COMPLETE (SNOWFLAKE.CORTEX) (multimodal)¶
Note
AI_COMPLETE is the latest version of this function. Use AI_COMPLETE for the latest functionality. You can continue to use COMPLETE (SNOWFLAKE.CORTEX).
Given an image and a prompt, generates a response (completion) using a language model. This function variant supports image models along with text models, and processes images stored in an internal Snowflake stage or an external stage. COMPLETE can be used to process a single image, multiple images in a batch fashion, applying the same or a different prompt to each image, or multiple images in a single operation (for example, comparison).
Syntax¶
Use one of the following:
Arguments¶
modelA string specifying the model to be used. Specify one of the following models:
claude-3-5-sonnetpixtral-large
Supported models might have different costs and context windows. New models might be added from time to time.
promptA string containing a question about the image and optionally specifying an output format, such as JSON. Either this or the
prompt_objectargument is required.prompt_objectA SQL OBJECT containing a string prompt with numbered placeholders (
{0},{1}, and so on) and one or more text or FILE valuse that are inserted into the prompt. The PROMPT function is a convenient way to create an object with the required layout. Either this argument orpromptis required.file_objectA FILE object that contains an image file to be processed. Use the TO_FILE function to create FILE objects from a stage path. Required when using a string prompt.
FROM tableAn optional table containing image paths and an optional prompt for each image, allowing images to be batch-processed in a single call to COMPLETE.
Returns¶
A string containing the language model’s response.
Usage notes¶
Inputs exceeding the context window limit result in an error. Output which would exceed the context window limit is truncated.
To process multiple images, the prompt must be an object (typically created using the PROMPT function) that specifies a prompt template and the files to be processed.
Only text and images are supported. Video and audio files are not supported.
Images with filename extensions
.jpg,.jpeg,.png,.gif, and.webpare supported.pixtral-largealso supports.bmp.Maximum image size is 10 MB for
pixtral-largeand 3.75 MB forclaude-3-5-sonnet. Additionally,claude-3-5-sonnetdoes not support images with a resolution greater than 8000x8000.The stage containing the images must have server-side encryption enabled. Client-side encrypted stages are not supported.
The function does not support custom network policies.
Stage names are not case-sensitive, but paths are.
Examples¶
The following examples demonstrate the basic capabilities of the COMPLETE function with images.
Visual question answering¶
A chart of inflation rates is used to answer a question about the data.
Comparison between inflation rates in 2023 and in2024 (Statista)¶
Response:
Image classification¶
This example classifies the landmark identified in a single image.
Response:
Entity extraction from an image¶
This example extracts the entities (objects) from an image and returns the results in JSON format.
Response:
Batch processing images from a directory or table¶
For batch processing of multiple images, performing the same operation on each, store the image files in the same stage. Apply the COMPLETE function to each row of the table.
Note
The stage must have a directory table to retrieve the paths to its files.
First, create the table by retrieving the image locations from the directory, convert these to FILE objects, and storing the resulting FILE objects in a column in a table. Use SQL like the following:
Then, apply the COMPLETE function to the column containing the FILE objects. The following example classifies each image in the table:
Response:
If you already have a table with paths to the images, you can use the TO_FILE function to construct the FILE objects within the query:
You can also retrieve the images to be processed directly from a stage’s directory, as shown here:
Providing images and prompts in a table¶
To perform a different operation on each image in a table, provide the images and their corresponding prompts in a
table. In the following example, the table contains the stage path of each image in the img_path column and the
prompt in the prompt column.
Legal notices¶
Refer to Snowflake AI and ML.