AI-powered BigQuery data analysis agent with natural language interface
Project description
๐ Orion - AI-Powered Data Analysis Agent
An intelligent data analysis agent that transforms natural language questions into SQL queries, executes them on BigQuery, performs statistical analysis, and generates actionable business insights.
๐ GitHub: https://github.com/gavrielhan/orion-data-analyst
๐ฆ PyPI: https://pypi.org/project/orion-data-analyst/
โจ What is Orion?
Orion is your AI business analyst that:
- Understands natural language - Ask questions in plain English
- Generates smart SQL - Powered by Google Gemini AI
- Analyzes data automatically - Statistical analysis, trends, segmentation
- Provides insights - Actionable recommendations with business context
- Creates visualizations - Charts saved automatically
- Self-heals errors - Automatically fixes and retries failed queries
- Remembers conversations - Handles follow-up questions with context
Built with LangGraph for modular AI reasoning and Google BigQuery for data warehousing.
๐ Quick Start
Installation
Option 1: Install from PyPI (Recommended)
pip install orion-data-analyst
Option 2: Install from Source
git clone https://github.com/gavrielhan/orion-data-analyst.git
cd orion-data-analyst
pip install -e .
Setup
-
Get API Keys (see GETTING_KEYS.md):
- Google Cloud Project ID
- Google Cloud service account JSON key
- Gemini API key from Google AI Studio
-
Configure
.envfile:
# Copy example
cp .env.example .env
# Edit with your credentials
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
GEMINI_API_KEY=your-gemini-api-key
- Run Orion:
orion
๐ก Usage Examples
Basic Queries
You: show me top 10 products by revenue
Orion: [Generates SQL, executes, analyzes, and displays ranked results]
You: what are the sales trends for the last 6 months?
Orion: [Creates time-series analysis with month-over-month growth]
You: segment customers by purchase behavior
Orion: [Performs customer segmentation and analysis]
Follow-up Questions
You: show top customers
Orion: [Displays ranked customer list]
You: show the same for the last quarter
Orion: [Uses conversation context to apply date filter]
You: break that down by region
Orion: [Further segments the previous results]
Visualizations & Exports
You: create a bar chart of sales by category
Orion: [Generates chart and saves to ~/orion_results/]
You: save this as csv
Orion: [Exports results to ~/orion_results/results_TIMESTAMP.csv]
Meta-Questions (Instant Responses)
You: what can you do?
Orion: [Explains capabilities without querying database]
You: which datasets can you query?
Orion: [Lists available tables and schemas]
๐๏ธ Architecture
Orion uses a modular node-based architecture powered by LangGraph:
High-Level Architecture
Detailed Graph Schema
See ARCHITECTURE.md for detailed component descriptions.
๐ฏ Key Features
๐ค Intelligent SQL Generation
- Natural language to SQL using Google Gemini
- Automatic schema context injection
- Self-healing with error feedback loops (max 3 retries)
- Handles complex JOINs across multiple tables
๐ก๏ธ Safety & Validation
- Blocks malicious queries (DROP, DELETE, etc.)
- BigQuery cost estimation before execution
- Query syntax validation with dry-run
- Row limits to prevent runaway queries
- Human-in-the-loop approval for expensive operations
๐ Advanced Analytics
- Ranking: Top N analysis with contribution %
- Trends: Time-series with growth rates
- Segmentation: Group-by analysis
- RFM Analysis: Customer segmentation (Recency, Frequency, Monetary)
- Anomaly Detection: Outlier identification
- Comparative Analysis: Period-over-period comparison
๐ฌ Conversation Memory
- Remembers last 5 interactions
- Context-aware follow-up questions
- Session save/load for long conversations
- Automatic context pruning for token efficiency
๐ Visualizations
- Chart Types: Bar, Line, Pie, Scatter, Box, Candle
- Auto-saved to
~/orion_results/(configurable) - Smart chart type selection based on data
- CSV export for further analysis
โก Performance Optimizations
- Query Caching: Instant responses for repeated queries (1-hour TTL)
- Schema Caching: Reduces API calls to BigQuery metadata
- Rate Limiting: Token bucket algorithm for Gemini API
- Streaming: Large result handling
๐จ Polished UX
- Colored terminal output with formatted text
- Progress indicators at each step
- Helpful error messages with action links
- Startup validation with setup guidance
๐๏ธ Project Structure
orion-data-analyst/
โโโ assets/ # Images and diagrams
โ โโโ orion_face.png # Main interface screenshot
โ โโโ high_level_schema.png # High-level architecture diagram
โ โโโ graph_schema.png # Detailed graph flow diagram
โโโ src/
โ โโโ __init__.py
โ โโโ cli.py # CLI interface with session management
โ โโโ config.py # Configuration loader (.env)
โ โโโ agent/
โ โ โโโ __init__.py
โ โ โโโ graph.py # LangGraph workflow orchestration
โ โ โโโ nodes.py # All 10 agent nodes
โ โ โโโ state.py # Centralized AgentState (TypedDict)
โ โโโ utils/
โ โโโ __init__.py
โ โโโ cache.py # Query result caching
โ โโโ formatter.py # ANSI terminal formatting
โ โโโ rate_limiter.py # API rate limiting
โ โโโ schema_fetcher.py # BigQuery schema utilities
โ โโโ visualizer.py # Chart generation (matplotlib/seaborn)
โโโ tests/ # Test suite
โ โโโ __init__.py
โ โโโ test_nodes.py # Node unit tests
โ โโโ test_graph.py # Graph integration tests
โโโ .env.example # Configuration template
โโโ requirements.txt # Dependencies
โโโ setup.py # PyPI packaging
โโโ pyproject.toml # Modern Python packaging
โโโ install.sh # One-line installer
โโโ ARCHITECTURE.md # Detailed architecture docs
โโโ GETTING_KEYS.md # API key setup guide
โโโ README.md # This file
โ๏ธ Configuration
All configuration via .env file:
# REQUIRED
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
GEMINI_API_KEY=your-gemini-api-key
# OPTIONAL
GEMINI_MODEL=gemini-2.0-flash-exp # Choose Gemini model
ORION_OUTPUT_DIR=~/orion_results # Results directory
BIGQUERY_DATASET=bigquery-public-data.thelook_ecommerce
MAX_QUERY_ROWS=10000 # Row limit
QUERY_TIMEOUT=300 # Timeout (seconds)
๐ Dataset
Uses Google BigQuery's public e-commerce dataset:
- Dataset:
bigquery-public-data.thelook_ecommerce - Tables:
orders,order_items,products,users - Schema: Automatically loaded with column descriptions
๐ง Development
Run from Source
git clone https://github.com/gavrielhan/orion-data-analyst.git
cd orion-data-analyst
pip install -e .
orion
๐ Commands
In the Orion CLI:
exit/quit/q- Exit Orionsave session- Save conversation historyload session [path]- Load previous sessionclear cache- Clear query cache
๐ ๏ธ Technology Stack
| Component | Technology |
|---|---|
| AI Orchestration | LangGraph |
| LLM Integration | LangChain |
| AI Model | Google Gemini 2.0 Flash |
| Data Warehouse | Google BigQuery |
| Data Processing | pandas |
| Visualization | matplotlib, seaborn |
| State Management | TypedDict (Python) |
| Configuration | python-dotenv |
| Packaging | setuptools, PyPI |
๐ License
MIT License - see LICENSE file for details.
๐ค Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
๐ Acknowledgments
- Built with LangGraph by LangChain
- Powered by Google Gemini
- Data from BigQuery Public Datasets
Made with โค๏ธ by Gavriel Hannuna
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file orion_data_analyst-1.1.3.tar.gz.
File metadata
- Download URL: orion_data_analyst-1.1.3.tar.gz
- Upload date:
- Size: 453.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cece600b3d27e924e76c8add329db399ed9cfce602c2b0b1948f595cafe401e
|
|
| MD5 |
30b9f62a64c435ef976dc8bd63f418a7
|
|
| BLAKE2b-256 |
917669b78b2feaa0835be6657556d387a567011f9cefdaa1e347079a9a12151f
|
File details
Details for the file orion_data_analyst-1.1.3-py3-none-any.whl.
File metadata
- Download URL: orion_data_analyst-1.1.3-py3-none-any.whl
- Upload date:
- Size: 49.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3264130c66df39f2c715e6e71d11fed3cb4717ccc605c48b25b752b92967fe3d
|
|
| MD5 |
ff340c940fed67123278eee0ebc4fda8
|
|
| BLAKE2b-256 |
dd37ce11bfdcc7d9bb3a3a548341b946028be89823d0426054b866791b856723
|