Perform AI Queries
This feature is 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.
Introduction
If your data warehouse includes SQL functions for generative AI models, you can call those AI functions directly in Holistics.
When you perform an AI query, you call an AI model from your cloud data warehouse and run it on your database's columns, returning the output to Holistics. The AI processing happens entirely within your secure data warehouse environment, ensuring data privacy and compliance.
Prerequisites
To use AI functions in Holistics, you'll need a connection to a supported data warehouse with AI capabilities enabled. Currently, this feature works with Databricks (using their AI Functions) and Snowflake (using Cortex functions).
Your database user will need the appropriate permissions to execute AI functions in your warehouse. This typically means having access to run the AI-specific SQL functions like ai_complete()
in Snowflake or ai_query()
in Databricks. If you're unsure about your permissions, try running a simple AI query directly in your warehouse first.
Available AI functions
These are the AI functions available in Holistics's AQL. Behind the scene, Holistics translate these into relevant SQL functions provided by the data warehouses.
Function | Description | Example Usage | Return Type |
---|---|---|---|
ai_query() | Query an AI model with custom prompts | ai_query('gpt-4', concat('Summarize this review: ', comment)) | Text |
ai_classify() | Classify text into predefined categories | ai_classify(ticket_text, 'bug', 'feature', 'question') | Text (category) |
ai_similarity() | Calculate semantic similarity between texts | ai_similarity(product_desc1, product_desc2) | Number (0-1) |
ai_summarize() | Generate concise summaries of long text | ai_summarize(article_content) | Text |
For detailed syntax and more examples, see the AI Functions Reference.
How it works & examples
AI functions excel at three main tasks:
- Text Analysis: Classify sentiment, extract themes, summarize content
- Data Enrichment: Auto-categorize items, generate descriptions, extract attributes
- Similarity Matching: Find duplicates, build recommendations, detect patterns
Your first AI query
Let's start with a simple sentiment analysis on customer reviews:
// Analyze sentiment of customer feedback
dimension feedback_sentiment {
model: reviews
type: "text"
definition: @aql
ai_classify(reviews.comment, 'positive', 'negative', 'neutral')
;;
}
This will classify each review as positive, negative, or neutral using AI.
Customer Feedback Analysis
Let's look at an example that analyzes customer reviews to understand sentiment.
// 1. Define the review model with AI enhancements
Model enhanced_reviews {
type: 'table'
table_name: 'customer_reviews'
dimension review_text {
type: 'text'
definition: 'review_text'
}
dimension sentiment {
type: 'text'
definition: @aql
ai_classify(review_text, 'positive', 'negative', 'neutral')
;;
}
dimension sentiment_score {
type: 'number'
definition: @aql
case(
when: sentiment == 'positive', then: 1,
when: sentiment == 'neutral', then: 0,
when: sentiment == 'negative', then: -1
)
;;
}
dimension review_summary {
type: 'text'
definition: @aql
ai_summarize(review_text)
;;
}
dimension mentioned_features {
type: 'text'
definition: @aql
ai_query(
'gpt-4',
concat('List product features mentioned in this review (comma-separated): ', review_text)
)
;;
}
metric avg_sentiment_score {
type: 'average'
definition: @aql avg(sentiment_score) ;;
}
metric review_count {
type: 'count'
definition: @aql count(review_id) ;;
}
}
Product Categorization & Enrichment
Auto-categorize products and enhance descriptions with AI.
Model smart_products {
type: 'table'
table_name: 'products'
dimension name {
type: 'text'
definition: 'product_name'
}
dimension description {
type: 'text'
definition: 'product_description'
}
// Auto-categorize products
dimension ai_category {
type: 'text'
definition: @aql
ai_classify(
description,
'Electronics & Tech',
'Fashion & Apparel',
'Home & Living',
'Sports & Outdoors',
'Beauty & Health',
'Books & Media',
'Toys & Games',
'Food & Beverages'
)
;;
}
// Generate SEO description
dimension seo_description {
type: 'text'
definition: @aql
ai_query(
'gpt-4',
concat('Write a 50-word SEO-optimized description for: ', name, '. ', description)
)
;;
}
// Extract key attributes
dimension product_attributes {
type: 'text'
definition: @aql
ai_query(
'gpt-4',
concat('Extract key attributes (size, color, material, etc.) as JSON from: ', description)
)
;;
}
// Find similar products
dimension similarity_to_featured {
type: 'number'
definition: @aql
ai_similarity(description, 'some featured product description')
;;
}
}
Support Ticket Intelligence
Automatically classify, prioritize, and summarize support tickets.
Model intelligent_tickets {
type: 'table'
table_name: 'support_tickets'
dimension ticket_content {
type: 'text'
definition: 'ticket_description'
}
// Classify ticket type
dimension ticket_type {
type: 'text'
definition: @aql
ai_classify(
ticket_content,
'bug',
'feature_request',
'how_to_question',
'account_issue',
'performance_problem'
)
;;
}
// Determine urgency
dimension urgency_level {
type: 'text'
definition: @aql
ai_classify(
ticket_content,
'critical - system down',
'high - major issue',
'medium - workflow blocked',
'low - minor inconvenience'
)
;;
}
// Generate summary for agents
dimension ticket_summary {
type: 'text'
definition: @aql
ai_summarize(ticket_content)
;;
}
// Extract affected features
dimension affected_features {
type: 'text'
definition: @aql
ai_query(
'gpt-4',
concat('List the product features or components mentioned in this ticket: ', ticket_content)
)
;;
}
// Suggest resolution
dimension suggested_resolution {
type: 'text'
definition: @aql
ai_query(
'gpt-4',
concat('Based on this issue, suggest a brief resolution approach: ', ticket_summary)
)
;;
}
}
Next steps
- Explore the AI Functions Reference for detailed syntax
- Join the Holistics Community to share use cases
- Contact support for help with specific implementations