This is a simple Text-to-SQL demo application for interacting with a complex database inspired by the Northwind database, designed for use with the Multinear platform.
This project demonstrates how to build a proof-of-concept Text-to-SQL engine that translates natural language business questions into SQL queries, executes them against a complex database, and returns the results.
The real challenge is to ensure that the Text-to-SQL engine is reliable - generates accurate and efficient queries, handles complex database schemas, and provides meaningful insights without errors. GenAI is a powerful technology, but it's also unpredictable by design, and the only way to make it reliable is to build comprehensive test coverage and guardrails.
That's exactly what the Multinear platform is for. Multinear allows developers to define evaluations in a simple yet powerful way and iteratively develop their GenAI applications, ensuring reliability and security.
-
Clone the Repository
git clone https://github.com/multinear-demo/demo-windforest-vanilla-py cd demo-windforest-vanilla-py -
Configure Environment Variables
Create a
.envfile in the root directory and add your OpenAI API key:echo "OPENAI_API_KEY=your-api-key-here" > .env
uv is the fastest way to run the application with minimal setup.
# Setup Environment
uv sync
# Start the Application
uv run main.pypyenv allows you to manage multiple Python versions and virtual environments.
# Setup Environment
pyenv install 3.9
pyenv virtualenv 3.9 text-to-sql
pyenv local text-to-sql
pip install -r requirements.txt
# Start the Application
python main.py# Setup Environment
python3 -m venv .venv
source .venv/bin/activate
# On Windows:
# .\.venv\Scripts\activate
pip install -r requirements.txt
# Start the Application
python3 main.pyOpen http://127.0.0.1:8080 to see the application.
Try asking different business questions to interact with the database:
- What are the top 5 customers by sales?
- Show all orders shipped to Europe in the last quarter
- List employees with a KPI score above 4.5
- Inventory levels for bestselling books
Enable LLM tracing with Arize Phoenix in the .env file (see .env.example and tracing.py).
# Using uv
uv run --with jupyter jupyter lab notebook.ipynb
# Using pyenv / virtualenv
pip install jupyter
jupyter lab notebook.ipynbThe data generation script creates a realistic and complex dataset inspired by the Northwind database.
python3 generate.pyMore documentation available at GENERATE.md.
Key system components:
- Text-to-SQL Engine that converts natural language questions into SQL queries using OpenAI's GPT-4, executes them against the SQLite database, and returns the results.
- API Server with
FastAPIendpoints for handling user queries. - HTML & React JS frontend.
- Data Generator that creates realistic and complex data inspired by the Northwind database, including customers, orders, employees, products, and more.
- Experiment Runner entry point for
Multinearplatform. - Configuration for evaluation tasks.
The platform is designed to facilitate the development and evaluation of GenAI applications through systematic experimentation.
-
Define Tasks
Configure your evaluation tasks in
.multinear/config.yaml. Each task represents a specific input scenario for the Text-to-SQL engine and defines how to evaluate the output. -
Execute Experiments
Run
Multinearplatform.# Using uv uv run multinear web_dev # Using pyenv / virtualenv multinear web_dev
Open http://127.0.0.1:8000 and start experimenting.
This project is licensed under the MIT License.
Built by Multinear.
