Skip to main content
Version: current [26.x]

Categories: Ai

AI_CLASSIFY

Specialized form of AI_GENERATE for sentiment analysis and document categorization. Classification list provided to LLM as an Array of VARCHAR, INT, FLOAT or BOOLEAN and the return is of the same type.

Syntax

AI_CLASSIFY( [model_name VARCHAR,] prompt VARCHAR | (prompt VARCHAR, file_reference), categories ARRAY<VARCHAR|INT|FLOAT|BOOLEAN> ) → VARCHAR|INT|FLOAT|BOOLEAN

  • model_name (optional): Optional model specification in format 'modelProvider.modelName' (e.g., 'gpt.4o'). modelProvider is the user-defined name for model provider configuration added in the preferences section (see Model Provider Configuration). modelName is one of the models supported and provided by that provider. If not provided, uses the default model for the organization.
  • prompt: Classification instructions for the LLM. Use (prompt, file_reference) to process files from LIST_FILES.
  • categories: Array of possible classifications. The LLM will choose one of these values as the result.

Examples

AI_CLASSIFY example
SELECT 
recipe_name,
AI_CLASSIFY(
'Determine the difficulty level based on these ingredients and steps',
ingredients || ' - Steps: ' || cooking_instructions,
ARRAY['Beginner', 'Easy', 'Intermediate', 'Advanced', 'Expert']
) AS difficulty_level,
prep_time,
number_of_ingredients
FROM recipe_database;

-- Sample output:
-- recipe_name | difficulty_level | prep_time | number_of_ingredients
-- Chocolate Chip Cookies | Easy | 15 | 8
-- Beef Wellington | Expert | 180 | 12
-- Caesar Salad | Beginner | 10 | 6
--
AI_CLASSIFY example
SELECT 
file['path'] as image,
AI_CLASSIFY(
'gpt.4o',
('Determine the type of food in the pictures', file),
ARRAY['Savory', 'Sweet', 'Tart', 'Unknown']
) AS food_type
FROM
TABLE(LIST_FILES('@image_source/path/to/images'));

-- Sample output:
-- image | food_type
-- desserts/chocolate_cake.jpg | Sweet
-- appetizers/bruschetta.jpg | Savory
-- fruits/lemon_tart.jpg | Tart
--
AI_CLASSIFY example
SELECT 
file['path'] as image,
AI_CLASSIFY(
('Determine the type of food in the pictures', file),
ARRAY['Savory', 'Sweet', 'Tart', 'Unknown']
) AS food_type
FROM
TABLE(LIST_FILES('@image_source/path/to/images'));

-- Sample output:
-- image | food_type
-- desserts/chocolate_cake.jpg | Sweet
-- appetizers/bruschetta.jpg | Savory
-- fruits/lemon_tart.jpg | Tart
--

Usage Notes

• Use (prompt VARCHAR, file_reference) to process files from LIST_FILES.

• Optimized for sentiment analysis and document categorization tasks.

• Returns the same data type as the provided categories array (VARCHAR, INT, FLOAT, or BOOLEAN).

• Categories can be of type VARCHAR, INT, FLOAT, or BOOLEAN.

• If no model is specified, uses the default model set for the organization.

• Model specification format: 'modelProvider.modelName' (e.g., 'gpt.4o').