Package: vanna
GitHubPyPIDocumentationVannaVanna is an MIT-licensed open-source Python RAG (Retrieval-Augmented Generation) framework for SQL generation and related functionality.https://github.com/vanna-ai/vanna/assets/7146154/1901f47a-515d-4982-af50-f12761a3b2ceHow Vanna worksVanna works in two easy steps - train a RAG "model" on your data, and then ask questions which will return SQL queries that can be set up to automatically run on your database.Train a RAG "model" on your data.Ask questions.If you don't know what RAG is, don't worry -- you don't need to know how this works under the hood to use it. You just need to know that you "train" a model, which stores some metadata and then use it to "ask" questions.See thebase classfor more details on how this works under the hood.User InterfacesThese are some of the user interfaces that we've built using Vanna. You can use these as-is or as a starting point for your own custom interface.Jupyter Notebookvanna-ai/vanna-streamlitvanna-ai/vanna-flaskvanna-ai/vanna-slackGetting startedSee thedocumentationfor specifics on your desired database, LLM, etc.If you want to get a feel for how it works after training, you can try thisColab notebook.InstallpipinstallvannaThere are a number of optional packages that can be installed so see thedocumentationfor more details.ImportSee thedocumentationif you're customizing the LLM or vector database.# The import statement will vary depending on your LLM and vector database. This is an example for OpenAI + ChromaDBfromvanna.openai.openai_chatimportOpenAI_Chatfromvanna.chromadb.chromadb_vectorimportChromaDB_VectorStoreclassMyVanna(ChromaDB_VectorStore,OpenAI_Chat):def__init__(self,config=None):ChromaDB_VectorStore.__init__(self,config=config)OpenAI_Chat.__init__(self,config=config)vn=MyVanna(config={'api_key':'sk-...','model':'gpt-4-...'})# See the documentation for other optionsTrainingYou may or may not need to run thesevn.traincommands depending on your use case. See thedocumentationfor more details.These statements are shown to give you a feel for how it works.Train with DDL StatementsDDL statements contain information about the table names, columns, data types, and relationships in your database.vn.train(ddl="""CREATE TABLE IF NOT EXISTS my-table (id INT PRIMARY KEY,name VARCHAR(100),age INT)""")Train with DocumentationSometimes you may want to add documentation about your business terminology or definitions.vn.train(documentation="Our business defines XYZ as ...")Train with SQLYou 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 name, age FROM my-table WHERE name = 'John Doe'")Asking questionsvn.ask("What are the top 10 customers by sales?")You'll get SQLSELECTc.c_nameascustomer_name,sum(l.l_extendedprice*(1-l.l_discount))astotal_salesFROMsnowflake_sample_data.tpch_sf1.lineitemljoinsnowflake_sample_data.tpch_sf1.ordersoONl.l_orderkey=o.o_orderkeyjoinsnowflake_sample_data.tpch_sf1.customercONo.o_custkey=c.c_custkeyGROUPBYcustomer_nameORDERBYtotal_salesdesclimit10;If you've connected to a database, you'll get the table:CUSTOMER_NAMETOTAL_SALES0Customer#0001435006757566.02181Customer#0000952576294115.33402Customer#0000871156184649.51763Customer#0001311136080943.83054Customer#0001343806075141.96355Customer#0001038346059770.32326Customer#0000696826057779.03487Customer#0001020226039653.63358Customer#0000985876027021.58559Customer#0000646605905659.6159You'll also get an automated Plotly chart:RAG vs. Fine-TuningRAGPortable across LLMsEasy to remove training data if any of it becomes obsoleteMuch cheaper to run than fine-tuningMore future-proof -- if a better LLM comes out, you can just swap it outFine-TuningGood if you need to minimize tokens in the promptSlow to get startedExpensive to train and run (generally)Why Vanna?High accuracy on complex datasets.Vanna’s capabilities are tied to the training data you give itMore training data means better accuracy for large and complex datasetsSecure and private.Your database contents are never sent to the LLM or the vector databaseSQL execution happens in your local environmentSelf learning.If using via Jupyter, you can choose to "auto-train" it on the queries that were successfully executedIf using via other interfaces, you can have the interface prompt the user to provide feedback on the resultsCorrect question to SQL pairs are stored for future reference and make the future results more accurateSupports any SQL database.The package allows you to connect to any SQL database that you can otherwise connect to with PythonChoose your front end.Most people start in a Jupyter Notebook.Expose to your end users via Slackbot, web app, Streamlit app, or a custom front end.Extending VannaVanna is designed to connect to any database, LLM, and vector database. There's aVannaBaseabstract base class that defines some basic functionality. The package provides implementations for use with OpenAI and ChromaDB. You can easily extend Vanna to use your own LLM or vector database. See thedocumentationfor more details.Vanna in 100 Secondshttps://github.com/vanna-ai/vanna/assets/7146154/eb90ee1e-aa05-4740-891a-4fc10e611cabMore resourcesFull DocumentationWebsiteDiscord group for support