AI Functions
AI functions are only available on Databricks and Snowflake data platforms. These functions leverage the native AI capabilities provided by these platforms and are not supported on other database systems.
ai_query
ai_query(model, prompt)
ai_query('databricks-meta-llama-3-3-70b-instruct', 'What is Apache Spark?') // => "Apache Spark is an open-source unified analytics engine..."
ai_query('gpt-4', 'Explain data warehousing concepts') // => "Data warehousing is the process of collecting and managing data..."
Description
Queries an AI model with a text prompt and returns the generated response. This function enables natural language interactions with large language models directly within your queries.
The exact models available and their pricing depend on your database platform:
- Databricks: Supports models like Meta Llama, DBRX, and others. See Databricks AI Functions pricing.
- Snowflake: Supports various models including Claude, Llama, Mistral, and GPT models through Cortex. See Snowflake Cortex LLM Functions for available models and consult your Snowflake account for pricing details.
Check your platform's documentation for the most up-to-date model list and pricing information.
Return type
Text
ai_similarity
ai_similarity(text1, text2)
ai_similarity('Apache Spark', 'Apache Spark') // => 1.0
ai_similarity('cat', 'dog') // => 0.8
ai_similarity('database', 'spreadsheet') // => 0.6
ai_similarity('apple', 'quantum physics') // => 0.1
Description
Calculates the semantic similarity between two text strings using embedding-based comparison. Returns a value between 0 and 1, where 1 indicates identical meaning and 0 indicates no semantic similarity.
Return type
Number
ai_classify
ai_classify(text, ...categories)
ai_classify('My password is leaked.', 'urgent', 'not urgent') // => 'urgent'
ai_classify('Thank you for your purchase', 'complaint', 'feedback', 'inquiry') // => 'feedback'
ai_classify('When will my order arrive?', 'technical', 'billing', 'shipping', 'general') // => 'shipping'
Description
Classifies the input text into one of the provided categories using AI. The function analyzes the semantic content of the text and returns the most appropriate category from the list provided.
Return type
Text
ai_summarize
ai_summarize(content)
ai_summarize('Long article about climate change impacts on coastal regions...') // => "This article discusses the significant effects of climate change on coastal areas, including rising sea levels, increased storm intensity, and ecosystem disruption."
ai_summarize(product_reviews.review_text) // => "Customers praise the product's durability and ease of use but note concerns about the price point."
Description
Generates a concise summary of the provided text content using AI. This function is useful for creating executive summaries, condensing long-form content, or providing quick insights from verbose text data.
Return type
Text