Vanna works in two easy steps - train a model on your data, and then ask questions.
When you ask a question, we utilize a custom model for your dataset to generate SQL, as seen below. Your model performance and accuracy depends on the quality and quantity of training data you use to train your model.
You can start by automatically training Vanna (currently works for Snowflake) or add manual training data.
pip install vanna
Depending on the database you're using, you can also install the associated database drivers
pip install 'vanna[snowflake]'
import vanna as vn
If you prefer to manually train, you do not need to connect to a database. You can use the train function with other parmaeters like ddl
vn.train(ddl="""
CREATE TABLE IF NOT EXISTS my-table (
id INT PRIMARY KEY,
name VARCHAR(100),
age INT
)
""")
Sometimes you may want to add documentation about your business terminology or definitions.
vn.train(documentation="Our business defines OTIF score as the percentage of orders that are delivered on time and in full")
You can also add SQL queries to your training data. This is useful if you have some queries already laying around. You can just copy and paste those from your editor to begin generating new SQL.
vn.train(sql="SELECT * FROM my-table WHERE name = 'John Doe'")
vn.ask("What are the top 10 customers by sales?")
SELECT c.c_name as customer_name,
sum(l.l_extendedprice * (1 - l.l_discount)) as total_sales
FROM snowflake_sample_data.tpch_sf1.lineitem l join snowflake_sample_data.tpch_sf1.orders o
ON l.l_orderkey = o.o_orderkey join snowflake_sample_data.tpch_sf1.customer c
ON o.o_custkey = c.c_custkey
GROUP BY customer_name
ORDER BY total_sales desc limit 10;
CUSTOMER_NAME | TOTAL_SALES | |
---|---|---|
0 | Customer#000143500 | 6757566.0218 |
1 | Customer#000095257 | 6294115.3340 |
2 | Customer#000087115 | 6184649.5176 |
3 | Customer#000131113 | 6080943.8305 |
4 | Customer#000134380 | 6075141.9635 |
5 | Customer#000103834 | 6059770.3232 |
6 | Customer#000069682 | 6057779.0348 |
7 | Customer#000102022 | 6039653.6335 |
8 | Customer#000098587 | 6027021.5855 |
9 | Customer#000064660 | 5905659.6159 |
Author: Vanna-ai
Source Code: https://github.com/vanna-ai/vanna
License: MIT license