Guides

How to Query Your Database with Vanna AI

Arkzero ResearchApr 23, 20267 min read

Last updated Apr 23, 2026

Vanna AI is an open-source text-to-SQL framework that translates plain-English questions into SQL queries against your database. After connecting to PostgreSQL, SQLite, Snowflake, or another supported database and training Vanna on your schema with example question-to-SQL pairs, anyone on your team can get answers without writing SQL. Vanna 2.0, released in early 2026, adds a built-in web interface suited for team deployment and streaming responses.
Vanna AI logo on a clean background representing text-to-SQL technology

What Vanna AI Does

If your team relies on a developer or analyst to run database queries every time someone needs an answer, Vanna AI removes that bottleneck. It sits between your database and your users, takes a question in plain English, generates the corresponding SQL, executes it, and returns the result as a data table or chart.

The mechanism behind this is retrieval-augmented generation. When you set up Vanna, you give it your database's table definitions and a set of example question-SQL pairs. Vanna stores these in a local vector database. When someone asks a question, Vanna finds the most relevant examples and schema fragments, assembles them into context for the language model, and uses that context to generate a query that fits your actual data structure rather than guessing column names.

Vanna 2.0, released in early 2026, added production-ready features including streaming responses, a built-in web interface, and user-awareness that makes it practical to deploy for a whole team, not just run locally by one analyst.

Step 1: Install Vanna

You need Python 3.9 or later. Open a terminal and run:

pip install vanna

To add OpenAI integration and the built-in Flask web interface:

pip install "vanna[openai]" flask

If you prefer a fully local setup where no data leaves your machine, install Ollama and pull a model before running Vanna:

brew install ollama
ollama pull llama3.2
pip install "vanna[ollama]"

The local Ollama setup is slower and slightly less accurate on complex queries, but it keeps all data on your own hardware, which matters for sensitive business data.

Step 2: Connect to Your Database

Vanna works with PostgreSQL, SQLite, Snowflake, BigQuery, MySQL, DuckDB, and most other major databases. The connection setup differs slightly per database, but the pattern is the same.

For PostgreSQL with OpenAI as the LLM:

from vanna.openai import OpenAI_Chat
from vanna.chromadb import ChromaDB_VectorStore

class MyVanna(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': 'your_openai_key',
    'model': 'gpt-4o'
})

vn.connect_to_postgres(
    host='localhost',
    dbname='your_database',
    user='your_user',
    password='your_password',
    port=5432
)

For a local SQLite file, replace the connection call with:

vn.connect_to_sqlite('path/to/database.db')

ChromaDB is the default vector store for training data and runs locally without any additional setup. For team deployments where multiple people share the same training data, Vanna supports hosted vector stores including Pinecone.

Step 3: Train Vanna on Your Schema

This is the step that determines whether Vanna produces useful output or unreliable guesses. Without training, a language model has no knowledge of your column names, table relationships, or the logic behind your business data. With training, it does.

Start by feeding Vanna your DDL, which is the table and column definitions from your database. For SQLite:

df_ddl = vn.run_sql("SELECT sql FROM sqlite_master WHERE type='table' AND sql IS NOT NULL")
for ddl in df_ddl['sql'].to_list():
    vn.train(ddl=ddl)

For PostgreSQL:

schema = vn.run_sql("""
    SELECT table_name, column_name, data_type
    FROM information_schema.columns
    WHERE table_schema = 'public'
    ORDER BY table_name, ordinal_position
""")
vn.train(documentation=schema.to_markdown())

Then add example question-to-SQL pairs. These do more for accuracy than anything else in the training process. Aim for ten to fifteen examples that cover the questions your team asks most often:

vn.train(
    question="What were total sales by product category last month?",
    sql="""SELECT c.name, SUM(o.amount) as total
           FROM orders o JOIN categories c ON o.category_id = c.id
           WHERE o.created_at >= date_trunc('month', current_date - interval '1 month')
           GROUP BY c.name ORDER BY total DESC"""
)

vn.train(
    question="Which customers have not placed an order in 90 days?",
    sql="""SELECT customer_id, email, MAX(created_at) as last_order
           FROM orders GROUP BY customer_id, email
           HAVING MAX(created_at) < current_date - 90"""
)

A consistent finding across teams that have deployed Vanna in production: questions involving date arithmetic and multi-table joins benefit most from explicit training examples. Generic LLM knowledge handles single-table aggregations reasonably well, but date filters and join paths across related tables require domain-specific examples to get right.

Step 4: Ask Questions and Browse Results

Once trained, you have two ways to interact with Vanna. The first is directly in Python:

sql = vn.generate_sql("What were last month's top ten customers by revenue?")
print(sql)  # inspect the generated SQL first
df = vn.run_sql(sql)
print(df)

Printing the generated SQL before running it is good practice, especially early on. You can see exactly what Vanna generated and verify the logic before acting on the results.

The second option is Vanna's built-in web interface:

from vanna.flask import VannaFlaskApp
app = VannaFlaskApp(vn)
app.run()

This starts a local server at http://localhost:8084 with a chat interface. Users type a question, see the SQL Vanna generated, and browse results in an interactive table. Responses stream in real-time, and Vanna can also render simple charts. Vanna 2.0 ships with a <vanna-chat> web component you can embed directly into an internal tool or dashboard page.

Where Vanna Works Well and Where It Struggles

In independent benchmarks on real enterprise schemas, Vanna with full schema training achieves roughly 75 to 80 percent accuracy on novel questions. Without training, a generic LLM on the same questions scores below 50 percent. The difference is entirely explained by the context provided during the training phase.

Vanna handles straightforward aggregations, group-bys, date ranges, and joins between tables it has been trained on with high reliability. It struggles with deeply nested subqueries, questions that require business logic not encoded in the schema (for example, "show me at-risk accounts" where at-risk is a concept not reflected in any column), and tables it has never seen during training.

When Vanna produces a wrong answer, it typically produces syntactically valid SQL that returns incorrect data rather than an outright error. This is the practical risk to manage. For analysis that informs decisions, sanity-check results against known totals before acting on them. Building a few validation queries into your routine is the fastest way to catch errors early.

Adding more training examples is the reliable fix for persistent errors. If a category of question keeps failing, add two or three more examples covering that pattern and accuracy improves measurably.

Deploying Vanna for a Team

If you want more than one person using Vanna, the Flask app needs to run on a server your team can access. Any standard deployment that hosts a Python Flask app works: a cloud VM, a Docker container, or a managed platform like Railway or Render.

Training data lives in a ChromaDB directory on disk by default. For team deployments, either point all instances at a shared network volume or migrate to a hosted vector store so that training updates made by one person are immediately visible to everyone else.

If your data lives in flat files rather than a database, setting up a schema, training Vanna, and maintaining a server is significant overhead. VSLZ handles plain-English data analysis from a direct file upload with no schema training or infrastructure required.

Practical Summary

Vanna's setup reduces to four steps: install the package, connect to your database, train it on your schema and a set of example queries, then ask questions through Python or the web app. The training step is what makes Vanna accurate. Teams that skip it get below-50-percent accuracy on novel questions; teams that complete it with fifteen or more domain-specific examples typically land above 75 percent. For any team with data locked in a database that wants to give non-technical colleagues a query interface without building a full BI stack, Vanna 2.0 is a practical starting point.

FAQ

Does Vanna AI work with any database?

Vanna supports PostgreSQL, MySQL, SQLite, Snowflake, BigQuery, DuckDB, Oracle, and ClickHouse. The connection is configured with a single line of Python for each database type. Most major databases used by businesses have a supported Vanna adapter.

How accurate is Vanna AI at generating SQL?

With full schema training and fifteen or more example question-SQL pairs, Vanna achieves roughly 75 to 80 percent accuracy on novel questions. Without training, accuracy on domain-specific queries falls below 50 percent. Accuracy improves as you add more training examples that cover your specific use cases.

Can I run Vanna AI without sending data to OpenAI?

Yes. Vanna supports local LLMs via Ollama, which means all inference happens on your own machine with no data sent externally. Install Ollama, pull a model like llama3.2, and configure Vanna to use it instead of OpenAI. Performance is slower and accuracy is slightly lower than GPT-4o, but the data never leaves your infrastructure.

How do I share Vanna AI with my team?

Vanna 2.0 includes a Flask web application that you can deploy on any server your team can access. It provides a chat interface where users type questions and get results in an interactive table. Vanna also ships a <vanna-chat> web component you can embed into an existing internal dashboard or intranet page.

What is the difference between Vanna AI and a BI tool like Tableau or Looker?

Vanna AI generates SQL from plain-English questions against any database you connect it to, without requiring you to build a semantic layer or maintain a dashboard. BI tools like Tableau and Looker require upfront data modeling and produce fixed dashboards. Vanna is better for flexible conversational queries; BI tools are better for standardized reporting that multiple stakeholders view regularly.

Related

OpenMetadata data catalog interface showing database schema discovery
Guides

How to Set Up OpenMetadata for Data Discovery

OpenMetadata is an open-source data catalog that gives teams a single place to discover, document, and govern their data assets. Setting it up takes under 30 minutes using Docker: spin up the containers, log into the UI at localhost:8585, then connect your first data source using one of 90+ pre-built connectors. Once ingestion runs, every table, column, and owner is searchable and lineage-linked across your entire stack.

Arkzero Research · Apr 29, 2026
Streamlit logo on a clean white background
Guides

How to Build a Data Dashboard with Streamlit

Streamlit is an open-source Python library that turns a script into a shareable web dashboard without any front-end code. Install it with pip, write a Python file that loads your CSV with pandas, add sidebar widgets for filtering, and render interactive charts with Plotly. Push the file to GitHub, connect it to Streamlit Community Cloud, and anyone with the URL can view live results. No server configuration required.

Arkzero Research · Apr 29, 2026
Airbyte Cloud data integration platform
Guides

How to Set Up Airbyte Cloud for Data Syncing

Airbyte Cloud is a managed data integration platform that syncs data from SaaS tools, databases, and APIs into a central warehouse without requiring Docker, infrastructure, or engineering resources. A free 30-day trial lets you connect sources like Salesforce, HubSpot, Stripe, or Google Sheets to destinations like BigQuery, Snowflake, or Postgres in minutes. This guide walks through the full setup from account creation to your first automated sync.

Arkzero Research · Apr 29, 2026