chat-bi
chat-bi copied to clipboard
Convert natural language questions into SQL queries and visualize the results.
Chat-BI
โจ Project Overview
Ask questions in plain language, and it automatically retrieves data from your database and creates charts like bar graphs and pie charts for you.
โญ If this project helps you, please give me a Star!
๐๏ธ System Architecture
Frontend (React + TypeScript)
โ
Backend API (FastAPI + Python)
โ
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโ
โ Business DB โ System DB โ
โ (MySQL) โ (MySQL) โ
โโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโ
โ
Vector Database (Milvus)
โ
AI Services (OpenAI)
Workflow
-
Question vectorization: Convert user's natural language questions into vectors to find similar SQL query templates in the database.
-
Generate SQL queries: If no matching template is found, the system generates new SQL queries based on database structure and user questions.
-
Generate natural language answers: After executing SQL queries and retrieving data, the system converts structured data into easy-to-understand natural language responses.
-
Generate descriptions for new templates: The system saves newly generated SQL as templates and creates brief descriptions for future precise matching.
๐ ๏ธ Tech Stack
Backend: Python 3.10+ ยท FastAPI ยท SQLAlchemy ยท PyMilvus ยท OpenAI
Frontend: React 19 ยท TypeScript ยท Tailwind CSS ยท ECharts ยท Vite
Storage: MySQL ยท Milvus
Demo Results
๐ Data Visualization
Homepage

Pie Chart: Monthly customer registration distribution

Line Chart: Sales trend analysis for the last 30 days

๐ฆ Quick Start
๐ณ Docker Deployment (Recommended)
1. Clone Project
git clone https://github.com/sumingcheng/chat-bi.git
cd chat-bi
2. Configure Environment Variables
Copy and edit the environment configuration file:
cp .env-temp .env
Edit the .env file and configure necessary parameters:
# Debug mode
DEBUG=False
DB_HOST=mysql
DB_PORT=3306
DB_USER=root
DB_PASSWORD=admin123456
DB_NAME=chat_bi
DB_SYS_NAME=chat_bi_system
MILVUS_HOST=milvus-standalone
MILVUS_PORT=19530
OPENAI_API_KEY=sk-
EMBEDDING_API_URL=http://172.19.221.125:11434/api/embeddings
EMBEDDING_MODEL=bge-m3
3. Start Services
# Execute in root directory and web directory
make build
# Return to root directory
make up
๐ป Local Development
Backend Development
# Install dependencies
uv sync
# Start backend service
python main.py
# Successful startup display
โก root@DESKTOP-AETE0Q9 ๎ฐ /data/chat-bi ๎ฐ ๎ main ๎ฐ docker logs -f f341b3959a99
INFO: Will watch for changes in these directories: ['/chat-bi']
INFO: Uvicorn running on http://0.0.0.0:13000 (Press CTRL+C to quit)
INFO: Started reloader process [1] using StatReload
INFO: Started server process [8]
INFO: Waiting for application startup.
2025-06-03 04:01:07 [INFO] app:57 - ๐ Application starting...
2025-06-03 04:01:07 [INFO] app:58 - ๐ Checking database table status...
2025-06-03 04:01:07 [INFO] app:39 - โ Business database table 'category' exists
2025-06-03 04:01:07 [INFO] app:39 - โ Business database table 'customer' exists
2025-06-03 04:01:07 [INFO] app:39 - โ Business database table 'product' exists
2025-06-03 04:01:07 [INFO] app:39 - โ Business database table 'sales_order' exists
2025-06-03 04:01:07 [INFO] app:39 - โ Business database table 'order_item' exists
2025-06-03 04:01:07 [INFO] app:39 - โ Business database table 'sales' exists
2025-06-03 04:01:07 [INFO] app:49 - โ System database table 'sql_templates' exists
2025-06-03 04:01:07 [INFO] app:49 - โ System database table 'sql_template_params' exists
2025-06-03 04:01:07 [INFO] app:49 - โ System database table 'query_history' exists
2025-06-03 04:01:07 [INFO] app:63 - ๐ Initializing database tables...
2025-06-03 04:01:07 [INFO] app:68 - Initializing business database tables: ['category', 'customer', 'product', 'sales_order', 'order_item', 'sales']
2025-06-03 04:01:07 [INFO] app:71 - Business database table initialization completed
2025-06-03 04:01:07 [INFO] app:68 - Initializing system database tables: ['sql_templates', 'sql_template_params', 'query_history']
2025-06-03 04:01:07 [INFO] app:71 - System database table initialization completed
2025-06-03 04:01:07 [INFO] app:71 - โ
Database table initialization completed
2025-06-03 04:01:07 [INFO] app:72 - ๐ Chat-BI API started successfully!
INFO: Application startup complete.
Frontend Development
cd web
# Install dependencies
pnpm install
# Start development server
pnpm run dev
๐ Access URLs
After successful startup, you can access:
- Frontend: http://localhost:8888
- Backend API Documentation: http://localhost:13000/docs
- Milvus Management Interface: http://localhost:19000
๐งช Test Data
The project provides test data generation tools:
# Generate test data
python test/generate_test_data.py
# Run test queries
python test/run_test_data.py
๐ค Contributing
We welcome all forms of contributions!
- Author: sumingcheng
- Email: Contact via GitHub Issues
- Project Homepage: https://github.com/sumingcheng/chat-bi