Manually Training Vanna¶
This notebook shows how to manually train Vanna. If you prefer to automatically train Vanna, see here
Install Vanna¶
First we install Vanna from PyPI and import it. Here, we'll also install the Snowflake connector. If you're using a different database, you'll need to install the appropriate connector.
%pip install vanna
import vanna as vn
Login¶
Creating a login and getting an API key is as easy as entering your email (after you run this cell) and entering the code we send to you. Check your Spam folder if you don't see the code.
api_key = vn.get_api_key('my-email@example.com')
vn.set_api_key(api_key)
Set your Model¶
You need to choose a globally unique model name. Try using your company name or another unique string. All data from models are isolated - there's no leakage.
vn.set_model('my-model') # Enter your model name here. This is a globally unique identifier for your model.
Train with DDL Statements¶
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
)
""")
Train with Documentation¶
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")
Train with SQL¶
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'")
View Training Data¶
At any time you can see what training data is in your model
vn.get_training_data()
id | training_data_type | question | content | |
---|---|---|---|---|
0 | 15-doc | documentation | None | This is a table in the PARTSUPP table.\n\nThe ... |
1 | 11-doc | documentation | None | This is a table in the CUSTOMER table.\n\nThe ... |
2 | 14-doc | documentation | None | This is a table in the ORDERS table.\n\nThe fo... |
3 | 1244-sql | sql | What are the names of the top 10 customers? | SELECT c.c_name as customer_name\nFROM snowf... |
4 | 1242-sql | sql | What are the top 5 customers in terms of total... | SELECT c.c_name AS customer_name, SUM(l.l_quan... |
5 | 17-doc | documentation | None | This is a table in the REGION table.\n\nThe fo... |
6 | 16-doc | documentation | None | This is a table in the PART table.\n\nThe foll... |
7 | 1243-sql | sql | What are the top 10 customers with the highest... | SELECT c.c_name as customer_name,\n sum(... |
8 | 1239-sql | sql | What are the top 100 customers based on their ... | SELECT c.c_name as customer_name,\n sum(... |
9 | 13-doc | documentation | None | This is a table in the SUPPLIER table.\n\nThe ... |
10 | 1241-sql | sql | What are the top 10 customers in terms of tota... | SELECT c.c_name as customer_name,\n sum(... |
11 | 12-doc | documentation | None | This is a table in the LINEITEM table.\n\nThe ... |
12 | 18-doc | documentation | None | This is a table in the NATION table.\n\nThe fo... |
13 | 1248-sql | sql | How many customers are in each country? | SELECT n.n_name as country,\n count(*) a... |
14 | 1240-sql | sql | What is the number of orders placed each week? | SELECT date_trunc('week', o_orderdate) as week... |
Removing Training Data¶
If you added some training data by mistake, you can remove it. Model performance is directly linked to the quality of the training data.
vn.remove_training_data(id='my-training-data-id')
Asking Questions¶
vn.ask()