ask_my_data¶
ask_my_data(question, fully_qualified_table)
Description¶
Ask your data any question
in natural language.
This function calls
generate_sql
to convert thequestion
into a SQL query adapted to your data and execute it.
(If the execution fails, the temporary tablebigfunction_result
gives details).
Param | Description |
---|---|
question |
A question to ask over your data. It may start with a verb |
fully_qualified_table |
A table whose schema will be given to the generative AI model for context. - fully_qualified_table format must be like PROJECT.DATASET.TABLE .- fully_qualified_table must exist.- You must have read permission on the table schema |
Usage¶
Call or Deploy ask_my_data
?
Call ask_my_data
directly
The easiest way to use bigfunctions
ask_my_data
function is deployed in 39 public datasets for all of the 39 BigQuery regions.- It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)
Public BigFunctions Datasets
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Deploy ask_my_data
in your project
Why deploy?
- You may prefer to deploy
ask_my_data
in your own project 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).
- Get started by reading the framework page
Deployment
ask_my_data
function can be deployed with:
pip install bigfunctions
bigfun get ask_my_data
bigfun deploy ask_my_data
Examples¶
call bigfunctions.eu.ask_my_data("get the 3 products which generated the most revenue in 2023", "bigfunctions.eu.sales");
select * from bigfunction_result;
call bigfunctions.us.ask_my_data("get the 3 products which generated the most revenue in 2023", "bigfunctions.us.sales");
select * from bigfunction_result;
call bigfunctions.europe_west1.ask_my_data("get the 3 products which generated the most revenue in 2023", "bigfunctions.europe_west1.sales");
select * from bigfunction_result;
+------------+---------+
| product_id | revenue |
+------------+---------+
+ 8 + 50286 |
+ 6 + 46172 |
+ 10 + 27972 |
+------------+---------+
Use cases¶
A business analyst wants to understand sales data for 2023, specifically which products generated the most revenue. They have a BigQuery table named sales
in their project (e.g., my-project.sales_data.sales
) containing product IDs, revenue figures, and other sales-related information.
Instead of writing a complex SQL query, the analyst uses the ask_my_data
function like so:
CALL bigfunctions.us.ask_my_data(
'Get the 3 products which generated the most revenue in 2023',
'my-project.sales_data.sales'
);
SELECT * FROM bigfunction_result;
This function call takes two arguments:
'Get the 3 products which generated the most revenue in 2023'
: The natural language question the analyst wants to ask the data.'my-project.sales_data.sales'
: The fully qualified name of the table the question pertains to. This allows the function to understand the structure of the data and generate the appropriate SQL query.
The ask_my_data
function then internally translates the natural language question into a SQL query (likely involving aggregation, filtering, and ordering), executes it against the specified table, and stores the results in a temporary table named bigfunction_result
. The analyst can then retrieve the results by querying bigfunction_result
.
This simplified approach allows users without extensive SQL knowledge to extract insights from their data using natural language, making data analysis more accessible and efficient.
Need help or Found a bug?
Get help using ask_my_data
The community can help! Engage the conversation on Slack
We also provide professional suppport.
Report a bug about ask_my_data
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.
We also provide professional suppport.