AI Functions
On this page
Install AI Functions
To install AI Functions, navigate to AI > AI & ML Functions, select the deployment on which to install AI Functions.
Once the AI Functions are installed, query them in the SQL Editor or SingleStore notebooks.
|
Category |
Function |
|---|---|
|
Text Processing Functions |
|
| |
| |
| |
| |
| |
|
Embedding Function | |
|
Edit AI Functions
To edit AI Functions, navigate to Settings in the right navigation of the AI Functions tab and select Edit.
|
Workspace Group |
The workspace group in which the AI Function is installed and running. |
|
Models |
Default models used by AI Functions for inference and embedding.
|
|
Settings |
|
|
Cost Estimation |
View the cost estimation of LLM Model, Embedding Model, and Compute. |
|
Region |
View the region of the following:
|
Select Next, review the changes, and select Save to save your settings.
Uninstall AI Functions
To uninstall AI Functions, select the ellipsis (vertical three dots) in the right and then select Uninstall AI Functions.
Text Processing Functions
AI_ COMPLETE
Provides batched LLM powered completion of every input text.
Syntax
AI_COMPLETE(text, model)
Arguments
-
text: A prompt. -
model: An LLM model.
Return Type
string
Usage
|
Basic usage with the default model |
|
|
Basic usage with a specific model |
|
|
Input example on database |
|
AI_ SENTIMENT
Provides sentiment classification and score for all user-defined inputs.
Syntax
AI_SENTIMENT(text, model)
Arguments
-
text: A prompt. -
model: An LLM model.
Return Type
string
Usage
|
Basic usage with default model |
|
|
Basic usage with selected model |
|
|
Input example on database |
|
AI_ TRANSLATE
Provides translation of user-provided documents from source language to target language.
Syntax
AI_TRANSLATE(text, source_languages, target_languages, model)
Arguments
-
text: A prompt. -
source_: The language in which the prompt is written.languages -
target_: The language to which the prompt gets translated.languages -
model: An LLM model.
Return Type
string
Usage
|
Basic usage with default model |
|
|
Basic usage with selected model |
|
|
Input example on database |
|
AI_ SUMMARIZE
Provides summary of user-provided documents within the specified length.
Syntax
AI_SUMMARIZE(text, model, max_lengths)
Arguments
-
text: A prompt. -
model: An LLM model. -
max_: Maximum length of the summary.lengths
Return Type
string
Usage
|
Basic usage with default model and length |
|
|
Basic usage with selected model |
|
|
Input example on database |
|
AI_ CLASSIFY
Provides classification of each input text into one of the given categories or labels.
Syntax
AI_CLASSIFY(text, categories, model)
Arguments
-
text: A prompt. -
categories: Categories for classification. -
model: An LLM model.
Return Type
string
Usage
|
Basic usage with default model |
|
|
Basic usage with selected model |
|
|
Input example on database |
|
AI_ EXTRACT
Extracts information from a block or text based on the specified natural language question.
Syntax
AI_EXTRACT(text, questions, model)
Arguments
-
text: A prompt. -
questions: Input natural language question on which the LLM model extracts information. -
model: An LLM model.
Return Type
string
Usage
|
Basic usage with default model |
|
|
Basic usage with selected model |
|
|
Input example on database |
|
Embedding Function
EMBED_ TEXT
Provides batched embeddings of all input text.
Syntax
EMBED_TEXT(text, model)
Arguments
-
text: A prompt. -
model: An embedding model.
Return Type
bytes
Usage
|
Basic usage with default model |
|
|
Basic usage with selected embedding model |
|
|
Input example on database |
|
Examples
The following examples demonstrate how to use AI functions with the following customer_ table.
CREATE DATABASE reviews;USE reviews;CREATE TABLE customer_reviews (review_id INT PRIMARY KEY,product_id VARCHAR(50),product_name VARCHAR(255),customer_name VARCHAR(100),review_text TEXT,rating INT,review_date DATETIME,language VARCHAR(20) DEFAULT 'English',response_text TEXT,review_embedding BLOB);-- Insert dataINSERT INTO customer_reviews (review_id,product_id,product_name,customer_name,review_text,rating,review_date,language) VALUES(1, 'PROD-101', 'Wireless Headphones', 'John Smith','These headphones are amazing! The sound quality is crystal clear and the battery lasts for days. Highly recommend for anyone looking for quality audio.',5, '2026-05-01', 'English'),(2, 'PROD-101', 'Wireless Headphones', 'Maria Garcia','Disappointed with the build quality. They broke after just two weeks of normal use. Customer service was unhelpful.',1, '2026-05-02', 'English'),(3, 'PROD-102', 'Smart Watch', 'David Lee','Great fitness tracker, but the battery life is shorter than advertised. Overall, good value for the price.',4, '2026-05-03', 'English'),(4, 'PROD-101', 'Wireless Headphones', 'Sophie Martin','Excellente qualité sonore! Je les utilise tous les jours pour le travail et les loisirs.',5, '2026-05-04', 'French'),(5, 'PROD-103', 'Laptop Stand', 'Ahmed Hassan','Perfect ergonomic solution for my home office. Sturdy construction and adjustable height. Worth every penny.',5, '2026-05-05', 'English');
Generate Follow-up Questions for Negative Reviews
The following example uses the AI_ function to generate follow-up questions for negative reviews:
SELECTreview_id,customer_name,product_name,review_text,cluster.AI_COMPLETE(CONCAT('Based on this negative review: "',review_text,'", generate three specific follow-up questions to better understand the issue.')) AS follow_up_questionsFROM customer_reviewsWHERE rating <= 2;
+-----------+----------------+----------------------+--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| review_id | customer_name | product_name | review_text | follow_up_questions |
+-----------+----------------+----------------------+--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 2 | Maria Garcia | Wireless Headphones | Disappointed with the build quality. They broke after just | 1. Can you describe exactly how the product broke and in what specific way? |
| | | | two weeks of normal use. Customer service was unhelpful. | 2. Did you contact customer service through phone, email, or another method, and what precisely did they say that made you feel they were unhelpful? |
| | | | | 3. What type of normal use were you subjecting the product to when it broke? |
+-----------+----------------+----------------------+--------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+Compare Customer Ratings with AI Sentiment
The following example uses the AI_ function to compare customer ratings with AI-generated sentiment analysis:
SELECTreview_id,customer_name,product_name,rating AS star_rating,review_text,cluster.AI_SENTIMENT(review_text) AS ai_sentimentFROM customer_reviewsORDER BY review_date DESC;
+-----------+----------------+----------------------+-------------+---------------------------------------------------------------------------------------------------------------------+----------------------------------------------+
| review_id | customer_name | product_name | star_rating | review_text | ai_sentiment |
+-----------+----------------+----------------------+-------------+---------------------------------------------------------------------------------------------------------------------+----------------------------------------------+
| 3 | David Lee | Smart Watch | 4 | Great fitness tracker, but the battery life is shorter than advertised. Overall, good value for the price. | {'sentiment': 'neutral', 'score': '0.5'} |
| 1 | John Smith | Wireless Headphones | 5 | These headphones are amazing! The sound quality is crystal clear and the battery lasts for days. | {'sentiment': 'positive', 'score': '0.9'} |
| 5 | Ahmed Hassan | Laptop Stand | 5 | Perfect ergonomic solution for my home office. Sturdy construction and adjustable height. Worth every penny. | {'sentiment': 'positive', 'score': '0.95'} |
| 4 | Sophie Martin | Wireless Headphones | 5 | Excellente qualité sonore! Je les utilise tous les jours pour le travail et les loisirs. | {'sentiment': 'positive', 'score': '0.90'} |
| 2 | Maria Garcia | Wireless Headphones | 1 | Disappointed with the build quality. They broke after just two weeks of normal use. Customer service was unhelpful. | {'sentiment': 'negative', 'score': '0.85'} |
+-----------+----------------+----------------------+-------------+---------------------------------------------------------------------------------------------------------------------+----------------------------------------------+Standardize Reviews in English
The following example uses the AI_ function to standardize the reviews in English language:
SELECTreview_id,customer_name,product_name,language AS original_language,review_text AS original_review,CASEWHEN language = 'English' THEN review_textELSE cluster.AI_TRANSLATE(review_text,language,'English')END AS standardized_review_englishFROM customer_reviewsORDER BY review_date DESC;
+-----------+----------------+----------------------+-------------------+---------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------+
| review_id | customer_name | product_name | original_language | original_review | standardized_review_english |
+-----------+----------------+----------------------+-------------------+---------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------+
| 3 | David Lee | Smart Watch | English | Great fitness tracker, but the battery life is shorter than advertised. Overall, good value for the price. | Great fitness tracker, but the battery life is shorter than advertised. Overall, good value for the price. |
| 1 | John Smith | Wireless Headphones | English | These headphones are amazing! The sound quality is crystal clear and the battery lasts for days. | These headphones are amazing! The sound quality is crystal clear and the battery lasts for days. |
| 5 | Ahmed Hassan | Laptop Stand | English | Perfect ergonomic solution for my home office. Sturdy construction and adjustable height. Worth every penny. | Perfect ergonomic solution for my home office. Sturdy construction and adjustable height. Worth every penny. |
| 4 | Sophie Martin | Wireless Headphones | French | Excellente qualité sonore! Je les utilise tous les jours pour le travail et les loisirs. | Excellent sound quality! I use them every day for work and leisure. |
| 2 | Maria Garcia | Wireless Headphones | English | Disappointed with the build quality. They broke after just two weeks of normal use. Customer service was unhelpful. | Disappointed with the build quality. They broke after just two weeks of normal use. Customer service was unhelpful. |
+-----------+----------------+----------------------+-------------------+---------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------+Generate Product-Level Summaries
The following example uses the AI_ function to generate product-level summaries from customer reviews:
SELECTproduct_id,product_name,COUNT(*) AS review_count,AVG(rating) AS avg_rating,cluster.AI_SUMMARIZE(GROUP_CONCAT(review_text SEPARATOR '. ')) AS product_summaryFROM customer_reviewsGROUP BY product_id, product_name;
+------------+----------------------+--------------+------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| product_id | product_name | review_count | avg_rating | product_summary |
+------------+----------------------+--------------+------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PROD-103 | Laptop Stand | 1 | 5.0000 | Excellent ergonomic home office solution with sturdy construction and adjustable height, providing good value. |
| PROD-101 | Wireless Headphones | 3 | 3.6667 | Mixed reviews for headphones: praised for excellent sound quality and long battery life, but criticized for poor durability and potential customer service issues.|
| PROD-102 | Smart Watch | 1 | 4.0000 | Fitness tracker offers good value, though battery life is shorter than expected. |
+------------+----------------------+--------------+------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+Classify Review Intent
The following example uses the AI_ function to classify the review intent:
SELECTreview_id,customer_name,product_name,rating,review_text,cluster.AI_CLASSIFY(review_text,'[praise, complaint, suggestion, question, comparison]') AS review_intentFROM customer_reviewsORDER BY review_date DESC;
+-----------+----------------+----------------------+--------+---------------------------------------------------------------------------------------------------------------------+---------------+
| review_id | customer_name | product_name | rating | review_text | review_intent |
+-----------+----------------+----------------------+--------+---------------------------------------------------------------------------------------------------------------------+---------------+
| 3 | David Lee | Smart Watch | 4 | Great fitness tracker, but the battery life is shorter than advertised. Overall, good value for the price. | complaint |
| 1 | John Smith | Wireless Headphones | 5 | These headphones are amazing! The sound quality is crystal clear and the battery lasts for days. | praise |
| 5 | Ahmed Hassan | Laptop Stand | 5 | Perfect ergonomic solution for my home office. Sturdy construction and adjustable height. Worth every penny. | praise |
| 4 | Sophie Martin | Wireless Headphones | 5 | Excellente qualité sonore! Je les utilise tous les jours pour le travail et les loisirs. | praise |
| 2 | Maria Garcia | Wireless Headphones | 1 | Disappointed with the build quality. They broke after just two weeks of normal use. Customer service was unhelpful. | complaint |
+-----------+----------------+----------------------+--------+---------------------------------------------------------------------------------------------------------------------+---------------+Extract Multiple Insights
The following example uses the AI_ function to extract multiple insights from customer reviews:
SELECTreview_id,product_name,review_text,cluster.AI_EXTRACT(review_text,'What product features are mentioned?') AS features_mentioned,cluster.AI_EXTRACT(review_text,'How long has the customer used this product?') AS usage_durationFROM customer_reviews;
+-----------+----------------------+--------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------+-----------------------------+
| review_id | product_name | review_text | features_mentioned | usage_duration |
+-----------+----------------------+--------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------+-----------------------------+
| 5 | Laptop Stand | Perfect ergonomic solution for my home office. Sturdy construction and adjustable height. Worth every penny. | Sturdy construction, adjustable height | Not specified in the review |
| 2 | Wireless Headphones | Disappointed with the build quality. They broke after just two weeks of normal use. Customer service | Build quality issues, broke after two weeks was unhelpful. | Two weeks |
| 4 | Wireless Headphones | Excellente qualité sonore! Je les utilise tous les jours pour le travail et les loisirs. | Sound quality | Daily (ongoing) |
| 3 | Smart Watch | Great fitness tracker, but the battery life is shorter than advertised. Overall, good value for the price. | Battery life (shorter than advertised), good value for price. | Not specified in the review |
| 1 | Wireless Headphones | These headphones are amazing! The sound quality is crystal clear and the battery lasts for days. | Sound quality (crystal clear), long battery life | Not specified in the review |
+-----------+----------------------+--------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------+-----------------------------+Perform Semantic Search
The following example uses the EMBED_ function to perform semantic search on customer reviews.
SET batch_external_functions = AUTO;SELECTreview_id,product_name,review_text,cluster.EMBED_TEXT(review_text) AS review_embeddingFROM customer_reviews;UPDATE customer_reviewsSET review_embedding = cluster.EMBED_TEXT(review_text)WHERE review_embedding IS NULL;WITH search_query AS (SELECT cluster.EMBED_TEXT('battery problems and short lifespan') AS query_embedding)SELECTcr.review_id,cr.product_name,cr.review_text,cr.rating,DOT_PRODUCT(cr.review_embedding,sq.query_embedding) AS relevance_scoreFROM customer_reviews cr,search_query sqWHERE cr.review_embedding IS NOT NULLORDER BY relevance_score DESC;
+-----------+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+--------+-----------------+
| review_id | product_name | review_text | rating | relevance_score |
+-----------+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+--------+-----------------+
| 3 | Smart Watch | Great fitness tracker, but the battery life is shorter than advertised. Overall, good value for the price. | 4 | NULL |
| 1 | Wireless Headphones | These headphones are amazing! The sound quality is crystal clear and the battery lasts for days. Highly recommend for anyone looking for quality audio.| 5 | NULL |
| 2 | Wireless Headphones | Disappointed with the build quality. They broke after just two weeks of normal use. Customer service was unhelpful. | 1 | NULL |
| 4 | Wireless Headphones | Excellente qualité sonore! Je les utilise tous les jours pour le travail et les loisirs. | 5 | NULL |
| 5 | Laptop Stand | Perfect ergonomic solution for my home office. Sturdy construction and adjustable height. Worth every penny. | 5 | NULL |
+-----------+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+--------+-----------------+Complete Customer Insights
The following example uses the AI_ and AI_ functions to generate complete customer insights for each product:
SELECTproduct_id,product_name,COUNT(*) AS total_reviews,AVG(rating) AS avg_rating,cluster.AI_SUMMARIZE(GROUP_CONCAT(review_text SEPARATOR '. ')) AS overview,cluster.AI_EXTRACT(GROUP_CONCAT(review_text SEPARATOR '. '),'What are the top three issues customers mention?') AS top_issues,cluster.AI_EXTRACT(GROUP_CONCAT(review_text SEPARATOR '. '),'What do customers love most about this product?') AS top_strengthsFROM customer_reviewsGROUP BY product_id, product_name;
+------------+----------------------+---------------+------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------+---------------------------------------------+
| product_id | product_name | total_reviews | avg_rating | overview | top_issues | top_strengths |
+------------+----------------------+---------------+------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------+---------------------------------------------+
| PROD-103 | Laptop Stand | 1 | 5.0000 | Excellent ergonomic home office solution with sturdy construction and adjustable height, providing good value. | 1. Sturdy construction 2. Adjustable height 3. Good value for money | Sturdy construction and adjustable height |
| PROD-101 | Wireless Headphones | 3 | 3.6667 | Mixed reviews for headphones: praised for excellent sound quality and long battery life, but criticized for poor durability and potential customer service issues. | 1. Sound quality 2. Battery life 3. Build quality (durability) | Sound quality and battery life | | |
| PROD-102 | Smart Watch | 1 | 4.0000 | Fitness tracker offers good value, though battery life is shorter than expected. | 1. Battery life 2. Price 3. Functionality | Good value for the price |
+------------+----------------------+---------------+------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------+---------------------------------------------+Example Notebook
The following notebook demonstrates AI Functions:
Demonstrate some common AI function usecases
Note
You can use your existing Standard or Premium workspace with this Notebook.
This feature is currently in Private Preview. Please reach out to support@singlestore.com to confirm if this feature can be enabled in your org.
This Jupyter notebook will help you:
- Load the Amazon Fine Foods Reviews dataset from Kaggle
- Store the data in SingleStore
- Demonstrate powerful AI Functions for text processing and analysis
Prerequisites: Ensure AI Functions are installed on your deployment (AI Services > AI & ML Functions).
Create some simple tables
This setup establishes a basic relational structure to store some reviews for restaurants. Ensure you have selected a database and have CREATE permissions to create/delete tables.
%%sqlCREATE DATABASE IF NOT EXISTS temp;USE temp;
%%sqlDROP TABLE IF EXISTS reviews;CREATE TABLE IF NOT EXISTS reviews (Id INT PRIMARY KEY,ProductId VARCHAR(20),UserId VARCHAR(50),ProfileName VARCHAR(255),HelpfulnessNumerator INT,HelpfulnessDenominator INT,Score INT,Time BIGINT,Summary TEXT,Text TEXT);
Install the required packages
!pip install -q httplib2 kagglehub pandas
Download and Load Dataset
import kagglehubimport pandas as pd# Download the Amazon Fine Foods Reviews dataset from Kaggleprint("Downloading dataset from Kaggle...")path = kagglehub.dataset_download("snap/amazon-fine-food-reviews")print(f"Dataset downloaded to: {path}")# Read the CSV filedf = pd.read_csv(f"{path}/Reviews.csv")# Display dataset infoprint(f"\nDataset shape: {df.shape}")print(f"Columns: {list(df.columns)}")print("\nFirst few rows:")df.head()
Load Data into SingleStore
import singlestoredb as s2# Create SQLAlchemy engine instead of regular connectionengine = s2.create_engine(database='temp')# Take a sample of 10,000 reviews for demo purposessample_df = df.head(10000).copy()print(f"Loading {len(sample_df)} reviews into SingleStore...")# Write dataframe to SingleStore table using SQLAlchemy enginesample_df.to_sql('reviews',con=engine, # Use engine instead of connectionif_exists='append',index=False,chunksize=1000)print("Data loaded successfully!")
Verify Data Load
%%sql-- Check the number of reviews loadedSELECT COUNT(*) as total_reviews FROM reviews;
Sample Data Preview
%%sql-- View sample reviewsSELECT Id, ProductId, Score, Summary, LEFT(Text, 100) as Review_PreviewFROM reviewsLIMIT 10;
AI Functions Demonstrations
Now let's explore the power of SingleStore AI Functions for text analysis and processing. Ensure that AI functions are enabled for the org and you are able to list the available AI functions
%%sqlSHOW functions in cluster;
%%sql-- AI_COMPLETE: Ask general questions and get LLM-powered completionsSELECT cluster.AI_COMPLETE('What is SingleStore?') AS completion;
%%sql-- AI_SENTIMENT: Analyze sentiment of customer reviews for a specific product-- WHERE ProductId = <Your choice>-- Remember to specify the datbase name. In this example 'temp' is the Database nameSELECTId,ProductId,Score,LEFT(Text, 80) as Review_Snippet,cluster.AI_SENTIMENT(Text) AS sentimentFROM temp.reviewsWHERE ProductId = 'B000NY8ODS'LIMIT 10;
%%sql-- Aggregate sentiment analysis across products-- Using CTE to filter and prepare data firstWITH filtered_reviews AS (SELECTProductId,TextFROM temp.reviewsWHERE ProductId IN (SELECT ProductIdFROM temp.reviewsGROUP BY ProductIdHAVING COUNT(*) >= 5)LIMIT 100),grouped_reviews AS (SELECTProductId,COUNT(*) as review_count,GROUP_CONCAT(Text SEPARATOR '. ') as combined_textFROM filtered_reviewsGROUP BY ProductIdLIMIT 5)SELECTProductId,review_count,cluster.AI_SENTIMENT(combined_text) as overall_sentimentFROM grouped_reviews;
%%sql-- AI_SUMMARIZE: Create concise summaries of lengthy reviews-- Filter long reviews first using CTEWITH long_reviews AS (SELECTId,ProductId,Text,LEFT(Text, 150) as Original_ReviewFROM temp.reviewsWHERE LENGTH(Text) > 200LIMIT 5)SELECTId,ProductId,Original_Review,cluster.AI_SUMMARIZE(Text,'aifunctions_chat_default',15) AS summaryFROM long_reviews;
%%sql-- AI_CLASSIFY: Classify customer feedback into categories-- Filter negative reviews first using CTEWITH negative_reviews AS (SELECTId,ProductId,Text,LEFT(Text, 100) as Review_TextFROM temp.reviewsWHERE Score <= 3LIMIT 10)SELECTId,ProductId,Review_Text,cluster.AI_CLASSIFY(Text,'[quality, price, shipping, taste]') AS classificationFROM negative_reviews;
%%sql-- AI_EXTRACT: Extract specific information from reviews-- Filter positive reviews first using CTEWITH positive_reviews AS (SELECTId,ProductId,Text,LEFT(Text, 100) as Review_TextFROM temp.reviewsWHERE Score >= 4LIMIT 10)SELECTId,ProductId,Review_Text,cluster.AI_EXTRACT(Text,'Does this customer indicate they will buy this product again? Answer with yes, no, or unclear only') AS repeat_purchase_intentFROM positive_reviews;
%%sql-- AI_EXTRACT: Identify reviews with high churn risk-- Filter low-rated reviews first using CTEWITH low_rated_reviews AS (SELECTId,ProductId,Score,Text,LEFT(Text, 120) as Review_TextFROM temp.reviewsWHERE Score <= 2LIMIT 10)SELECTId,ProductId,Score,Review_Text,cluster.AI_EXTRACT(Text,'Is this customer at high risk of not purchasing again? Answer with high, medium, or low only') AS churn_riskFROM low_rated_reviews;
%%sql-- AI_TRANSLATE: Translate text between languages-- Filter reviews with substantial summaries first using CTEWITH translatable_reviews AS (SELECTId,Summary as Original_EnglishFROM temp.reviewsWHERE Score = 5AND Summary IS NOT NULLAND LENGTH(Summary) > 20LIMIT 5)SELECTId,Original_English,cluster.AI_TRANSLATE(Original_English,'english','spanish') AS spanish_translationFROM translatable_reviews;
%%sql-- Combined AI Functions: Comprehensive product analysis-- Filter to products with multiple reviews firstWITH popular_products AS (SELECT ProductIdFROM temp.reviewsGROUP BY ProductIdHAVING COUNT(*) >= 10LIMIT 5),product_reviews AS (SELECTr.ProductId,r.Text,r.Score,LEFT(r.Text, 80) as Review_SampleFROM temp.reviews rINNER JOIN popular_products p ON r.ProductId = p.ProductIdLIMIT 10)SELECTProductId,Score,Review_Sample,cluster.AI_SENTIMENT(Text) as sentiment,cluster.AI_CLASSIFY(Text, '[quality, value, taste, packaging]') as category,cluster.AI_SUMMARIZE(Text, 'aifunctions_chat_default', 10) as brief_summaryFROM product_reviews;
Cleanup
%%sqlDROP TABLE IF EXISTS reviews;DROP DATABASE IF EXISTS temp;

Usage Recommendations for AI Functions
To optimize performance and control costs when using AI Functions, SingleStore recommends the following:
-
Use Common Table Expressions (CTEs) to filter rows before making calls to large language models (LLMs).
The query engine currently sends data to the LLM before applying LLM or WHEREfilters. -
LLM calls are expensive.
Begin with a small dataset to evaluate response quality and verify the results meet the requirements before scaling up. -
Enterprise plans support three model providers; Aura, Amazon Bedrock, and Azure AI Services.
Data is processed according to each provider’s policies. If a row violates provider rules, the system fails the batch that includes the row and returns errors for these rows. -
Strict usage quotas apply per model and per organization.
These quotas are not configurable by end users. For higher usage limits, contact SingleStore Support. Self-service quota configuration will be available in the future.
Last modified: