# Vanna — AI SQL Agent That Learns Your Database > Open-source AI SQL agent that trains on your schema and queries. Vanna converts natural language to accurate SQL using RAG over your database documentation and history. ## Install Save as a script file and run: ## Quick Use ```bash pip install vanna ``` ```python 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": "sk-...", "model": "gpt-4o"}) # Train on your schema vn.train(ddl="CREATE TABLE orders (id INT, customer_id INT, total DECIMAL, created_at DATETIME)") # Ask questions in natural language sql = vn.generate_sql("How many orders were placed last month?") print(sql) # SELECT COUNT(*) FROM orders WHERE created_at >= DATE_SUB(NOW(), INTERVAL 1 MONTH) ``` ## What is Vanna? Vanna is an open-source AI SQL agent that learns your specific database. It uses RAG (Retrieval-Augmented Generation) to train on your DDL schemas, documentation, and example queries — then generates accurate SQL from natural language questions. Unlike generic text-to-SQL tools, Vanna improves over time as you add more training data specific to your database. **Answer-Ready**: Vanna is an AI SQL agent using RAG to generate accurate SQL from natural language. Trains on your schema, docs, and query history. Supports PostgreSQL, MySQL, BigQuery, Snowflake, and 15+ databases. Built-in Streamlit UI for non-technical users. 13k+ GitHub stars. **Best for**: Data teams wanting natural language database access. **Works with**: Any SQL database, OpenAI, Anthropic Claude, Ollama. **Setup time**: Under 5 minutes. ## Core Features ### 1. Train on Your Data ```python # Train on DDL vn.train(ddl="CREATE TABLE users (id INT, name VARCHAR, email VARCHAR)") # Train on documentation vn.train(documentation="The users table stores all registered users. The email field is unique.") # Train on example queries vn.train(sql="SELECT name, COUNT(*) as order_count FROM users JOIN orders ON users.id = orders.customer_id GROUP BY name") ``` ### 2. Multi-Database Support | Database | Connector | |----------|-----------| | PostgreSQL | psycopg2 | | MySQL | pymysql | | BigQuery | google-cloud-bigquery | | Snowflake | snowflake-connector | | DuckDB | duckdb | | SQLite | sqlite3 | | Databricks | databricks-sql | ### 3. Built-in UI ```python from vanna.flask import VannaFlaskApp app = VannaFlaskApp(vn) app.run() # Opens web UI at localhost:8084 ``` ### 4. Auto-Visualization ```python # Generate SQL + run it + create chart vn.ask("Show monthly revenue trend as a line chart") # Returns: SQL query, DataFrame result, and Plotly chart ``` ## FAQ **Q: How accurate is it?** A: Accuracy depends on training data quality. With good schema docs and example queries, 85-95% accuracy on typical business questions. **Q: Does it support Claude?** A: Yes, use `vanna.anthropic.Anthropic_Chat` as the LLM backend with any Anthropic model. **Q: Is my data safe?** A: Vanna sends schema metadata and questions to the LLM, not raw data. Use local models via Ollama for full privacy. ## Source & Thanks > Created by [Vanna AI](https://github.com/vanna-ai). Licensed under MIT. > > [vanna-ai/vanna](https://github.com/vanna-ai/vanna) — 13k+ stars ## 快速使用 ```bash pip install vanna ``` 用自然语言查询数据库,AI 自动生成准确 SQL。 ## 什么是 Vanna? Vanna 是开源 AI SQL Agent,通过 RAG 学习你的数据库 schema 和文档,将自然语言转为准确 SQL。越用越准。 **一句话总结**:AI SQL Agent,RAG 学习你的 schema 后自然语言生成 SQL,支持 15+ 数据库,内置 Web UI,13k+ stars。 **适合人群**:需要自然语言查询数据库的数据团队。 ## 核心功能 ### 1. 训练 用 DDL、文档和示例查询训练,越用越准。 ### 2. 多数据库 PostgreSQL、MySQL、BigQuery、Snowflake 等 15+。 ### 3. 内置 UI Flask Web 界面,非技术用户也能用。 ## 常见问题 **Q: 准确率?** A: 训练数据好的情况下 85-95%。 **Q: 数据安全?** A: 只发送 schema 和问题,不发原始数据。可用本地模型。 ## 来源与致谢 > [vanna-ai/vanna](https://github.com/vanna-ai/vanna) — 13k+ stars, MIT --- Source: https://tokrepo.com/en/workflows/0f1fba74-ae4f-4d9c-981c-9661dfbdc88e Author: Script Depot