- Uses Agentic RAG to search for table metadata, sample queries and rules for writing better SQL queries.
- Uses dynamic few-shot examples and rules to improve query construction.
- Provides an interactive Streamlit UI for users to query the database.
Key capabilities
- Natural language to SQL conversion
- Retrieve table metadata, sample queries and rules using Agentic RAG
- Better query construction with the help of dynamic few-shot examples and rules
- Interactive Streamlit UI
Simple queries to try
- “Who are the top 5 drivers with the most race wins?”
- “Compare Mercedes vs Ferrari performance in constructors championships”
- “Show me the progression of fastest lap times at Monza”
- “Which drivers have won championships with multiple teams?”
- “What tracks have hosted the most races?”
- “Show me Lewis Hamilton’s win percentage by season”
Advanced queries with table joins
- “How many races did the championship winners win each year?”
- “Compare the number of race wins vs championship positions for constructors in 2019”
- “Show me Lewis Hamilton’s race wins and championship positions by year”
- “Which drivers have both won races and set fastest laps at Monaco?”
- “Show me Ferrari’s race wins and constructor championship positions from 2015-2020”
Code
The complete code is available in the Agno repository.Usage
Run PgVector
Load knowledge base
The knowledge base contains table metadata, rules and sample queries that help the Agent generate better responses.Pro tips for enhancing the knowledge base:
- Add
table_rulesandcolumn_rulesto guide the Agent on query formats - Add sample queries to
cookbook/examples/apps/sql_agent/knowledge_base/sample_queries.sql
Launch the app