bigfunctions > ask_ai
ask_ai¶
Call or Deploy ask_ai
?
✅ You can call this ask_ai
bigfunction directly from your Google Cloud Project (no install required).
- This
ask_ai
function is deployed inbigfunctions
GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error). - Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework
Public BigFunctions Datasets:
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Description¶
Signature
ask_ai(prompt, model)
Description
Ask Anything!
Google Generative AI model
will get you an answer.
model
must be one of:
gemini-pro
text-bison@001
text-bison@002
text-unicorn@001
code-bison@001
code-bison@002
- ... any future model
null
, thengemini-pro
will be used
Default parameters are used for each model.
Examples¶
1. Clean data
select bigfunctions.eu.ask_ai(
'''
Question: what is the country from the following user input: 'I live in frace' ?
Answer: formatted as alpha three code
'''
, 'gemini-pro')
select bigfunctions.us.ask_ai(
'''
Question: what is the country from the following user input: 'I live in frace' ?
Answer: formatted as alpha three code
'''
, 'gemini-pro')
select bigfunctions.europe_west1.ask_ai(
'''
Question: what is the country from the following user input: 'I live in frace' ?
Answer: formatted as alpha three code
'''
, 'gemini-pro')
+--------+
| answer |
+--------+
| FRA |
+--------+
2. Generate SQL
select bigfunctions.eu.ask_ai(
'''
Question: get the 10 products which generated the most revenue in 2023
Table: sales
Columns: product_id, price, quantity, timestamp
Answer: bigquery sql query
'''
, 'code-bison@002')
select bigfunctions.us.ask_ai(
'''
Question: get the 10 products which generated the most revenue in 2023
Table: sales
Columns: product_id, price, quantity, timestamp
Answer: bigquery sql query
'''
, 'code-bison@002')
select bigfunctions.europe_west1.ask_ai(
'''
Question: get the 10 products which generated the most revenue in 2023
Table: sales
Columns: product_id, price, quantity, timestamp
Answer: bigquery sql query
'''
, 'code-bison@002')
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| answer |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| SELECT product_id, SUM(price * quantity) AS revenue
FROM sales
WHERE timestamp BETWEEN '2023-01-01' AND '2023-12-31'
GROUP BY product_id
ORDER BY revenue DESC
LIMIT 10
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Need help using ask_ai
?
The community can help! Engage the conversation on Slack
For professional suppport, don't hesitate to chat with us.
Found a bug using ask_ai
?
If the function does not work as expected, please
- report a bug so that it can be improved.
- or open the discussion with the community on Slack.
For professional suppport, don't hesitate to chat with us.
Use cases¶
The provided documentation describes a BigQuery function ask_ai
that leverages Google's Generative AI models to answer questions. Here are a few use cases, expanding on the examples provided:
1. Data Cleaning and Transformation:
- Standardizing Country Codes: As shown in the example, you can use
ask_ai
to clean up inconsistent country names entered by users. Imagine a database with a "country" field containing free-text entries like "USA," "United States," "US," "united states of america," etc.ask_ai
can be used to convert these variations into a standardized format, such as the three-letter ISO country code. - Extracting Information from Unstructured Text: Suppose you have a column with customer feedback. You could use
ask_ai
to identify and extract key sentiments (positive, negative, neutral), topics discussed, or specific product mentions. - Data Validation: You could use
ask_ai
to check the validity of data. For example, given a date of birth, you could ask if the person is over 18.
2. Code Generation (SQL and potentially others):
- Generating SQL Queries: This is a powerful use case demonstrated in the documentation. Instead of writing complex SQL queries manually, you can describe what you want to achieve in natural language, and
ask_ai
can generate the corresponding SQL. This is particularly helpful for less experienced SQL users or for quickly prototyping queries. - Generating Other Code: While not explicitly mentioned, the ability to specify different models like
code-bison
suggests the possibility of generating code in other languages. This could be explored for tasks like creating Python scripts for data processing or JavaScript code for web applications, directly within BigQuery.
3. Data Analysis and Insights:
- Summarizing Text: Given a large volume of text data (e.g., customer reviews, news articles),
ask_ai
can provide concise summaries, highlighting key themes and trends. - Answering Business Questions: You could pose questions like "What are the top 3 reasons for customer churn?" or "Which product category has seen the highest growth in the last quarter?" and
ask_ai
could analyze the data and provide answers in natural language. - Generating Reports: By combining the SQL generation capabilities with summarization, you could automate the creation of simple reports based on data in BigQuery.
4. Content Creation and Enhancement:
- Generating Product Descriptions: If you have a database of product features, you could use
ask_ai
to generate compelling product descriptions for marketing materials. - Creating Personalized Content: Based on user data, you could generate personalized recommendations, email messages, or other content.
Limitations:
It's important to be aware that large language models like those used by ask_ai
can sometimes generate incorrect or nonsensical output. It's crucial to validate the results and use the function judiciously, especially in critical applications. Furthermore, cost considerations might be relevant depending on usage volume.
Spread the word¶
BigFunctions is fully open-source. Help make it a success by spreading the word!