vanna.base.base

class VannaBase(abc.ABC):

Helper class that provides a standard way to create an ABC using inheritance.

config
run_sql_is_set
def generate_sql(self, question: str, **kwargs) -> str:
def generate_followup_questions(self, question: str, **kwargs) -> str:
def generate_questions(self, **kwargs) -> list[str]:

Example:

vn.generate_questions()

Generate a list of questions that you can ask Vanna.AI.

@abstractmethod
def generate_embedding(self, data: str, **kwargs) -> list[float]:
@abstractmethod
def get_similar_question_sql(self, question: str, **kwargs) -> list:
@abstractmethod
def add_question_sql(self, question: str, sql: str, **kwargs) -> str:
@abstractmethod
def add_ddl(self, ddl: str, **kwargs) -> str:
@abstractmethod
def add_documentation(self, doc: str, **kwargs) -> str:
@abstractmethod
def get_training_data(self, **kwargs) -> pandas.core.frame.DataFrame:
@abstractmethod
def remove_training_data(id: str, **kwargs) -> bool:
@abstractmethod
def get_sql_prompt( self, question: str, question_sql_list: list, ddl_list: list, doc_list: list, **kwargs):
@abstractmethod
def get_followup_questions_prompt( self, question: str, question_sql_list: list, ddl_list: list, doc_list: list, **kwargs):
@abstractmethod
def submit_prompt(self, prompt, **kwargs) -> str:
@abstractmethod
def generate_question(self, sql: str, **kwargs) -> str:
@abstractmethod
def generate_plotly_code( self, question: str = None, sql: str = None, df_metadata: str = None, **kwargs) -> str:
def connect_to_snowflake( self, account: str, username: str, password: str, database: str, role: Optional[str] = None, warehouse: Optional[str] = None):
def connect_to_sqlite(self, url: str):

Connect to a SQLite database. This is just a helper function to set [vn.run_sql][vanna.run_sql]

Arguments:
  • url (str): The URL of the database to connect to.
Returns:

None

def connect_to_postgres( self, host: str = None, dbname: str = None, user: str = None, password: str = None, port: int = None):

Connect to postgres using the psycopg2 connector. This is just a helper function to set [vn.run_sql][vanna.run_sql] Example:

vn.connect_to_postgres(
    host="myhost",
    dbname="mydatabase",
    user="myuser",
    password="mypassword",
    port=5432
)
Arguments:
  • host (str): The postgres host.
  • dbname (str): The postgres database name.
  • user (str): The postgres user.
  • password (str): The postgres password.
  • port (int): The postgres Port.
def connect_to_bigquery(self, cred_file_path: str = None, project_id: str = None):

Connect to gcs using the bigquery connector. This is just a helper function to set [vn.run_sql][vanna.run_sql] Example:

vn.connect_to_bigquery(
    project_id="myprojectid",
    cred_file_path="path/to/credentials.json",
)
Arguments:
  • project_id (str): The gcs project id.
  • cred_file_path (str): The gcs credential file path
def run_sql(sql: str, **kwargs) -> pandas.core.frame.DataFrame:
def ask( self, question: Optional[str] = None, print_results: bool = True, auto_train: bool = True) -> Optional[Tuple[Optional[str], Optional[pandas.core.frame.DataFrame], Optional[plotly.graph_objs._figure.Figure]]]:
def train( self, question: str = None, sql: str = None, ddl: str = None, documentation: str = None, plan: vanna.types.TrainingPlan = None) -> str:

Example:

vn.train()

Train Vanna.AI on a question and its corresponding SQL query. If you call it with no arguments, it will check if you connected to a database and it will attempt to train on the metadata of that database. If you call it with the sql argument, it's equivalent to [add_sql()][vanna.add_sql]. If you call it with the ddl argument, it's equivalent to [add_ddl()][vanna.add_ddl]. If you call it with the documentation argument, it's equivalent to [add_documentation()][vanna.add_documentation]. Additionally, you can pass a [TrainingPlan][vanna.TrainingPlan] object. Get a training plan with [vn.get_training_plan_experimental()][vanna.get_training_plan_experimental].

Arguments:
  • question (str): The question to train on.
  • sql (str): The SQL query to train on.
  • ddl (str): The DDL statement.
  • documentation (str): The documentation to train on.
  • plan (TrainingPlan): The training plan to train on.
def get_training_plan_generic(self, df) -> vanna.types.TrainingPlan:
def get_training_plan_snowflake( self, filter_databases: Optional[List[str]] = None, filter_schemas: Optional[List[str]] = None, include_information_schema: bool = False, use_historical_queries: bool = True) -> vanna.types.TrainingPlan:
def get_plotly_figure( self, plotly_code: str, df: pandas.core.frame.DataFrame, dark_mode: bool = True) -> plotly.graph_objs._figure.Figure:

Example:

fig = vn.get_plotly_figure(
    plotly_code="fig = px.bar(df, x='name', y='salary')",
    df=df
)
fig.show()

Get a Plotly figure from a dataframe and Plotly code.

Arguments:
  • df (pd.DataFrame): The dataframe to use.
  • plotly_code (str): The Plotly code to use.
Returns:

plotly.graph_objs.Figure: The Plotly figure.

class SplitStorage(VannaBase):

Helper class that provides a standard way to create an ABC using inheritance.

def get_similar_question_sql(self, embedding: str, **kwargs) -> list:
@abstractmethod
def store_question_sql_embedding(self, embedding: str, **kwargs) -> str:
@abstractmethod
def store_ddl_embedding(self, embedding: str, **kwargs) -> str:
@abstractmethod
def store_documentation_embedding(self, embedding: str, **kwargs) -> str:
@abstractmethod
def get_similar_question_sql_ids(self, embedding: str, **kwargs) -> list:
@abstractmethod
def get_question_sql(self, question_sql_ids: list, **kwargs) -> list:
@abstractmethod
def get_documentation(self, doc_ids: list, **kwargs) -> list:
@abstractmethod
def get_ddl(self, ddl_ids: list, **kwargs) -> list: