Skip to main content

AI-powered BigQuery data analysis agent with natural language interface

Project description

๐ŸŒŸ Orion - AI-Powered Data Analysis Agent

PyPI version Python 3.8+ License: MIT LangGraph LangChain Google Cloud Gemini AI Powered by AI

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 Interface

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

  1. Get API Keys (see GETTING_KEYS.md):

    • Google Cloud Project ID
    • Google Cloud service account JSON key
    • Gemini API key from Google AI Studio
  2. Configure .env file:

# 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
  1. 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

High-Level Schema

Detailed Graph Schema

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 Orion
  • save session - Save conversation history
  • load session [path] - Load previous session
  • clear 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:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

๐Ÿ™ Acknowledgments


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

orion_data_analyst-1.1.4.tar.gz (457.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

orion_data_analyst-1.1.4-py3-none-any.whl (53.3 kB view details)

Uploaded Python 3

File details

Details for the file orion_data_analyst-1.1.4.tar.gz.

File metadata

  • Download URL: orion_data_analyst-1.1.4.tar.gz
  • Upload date:
  • Size: 457.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for orion_data_analyst-1.1.4.tar.gz
Algorithm Hash digest
SHA256 3199718438756f942859835c7a66b04897bbe7b8dba9da78a1efd5585b9e95be
MD5 4726c142ccf89e1ae1df3f7965468c43
BLAKE2b-256 8fb10e7d67adf767391d0d5035b7e02191312934c3a73f2890726cf188ed9fe8

See more details on using hashes here.

File details

Details for the file orion_data_analyst-1.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for orion_data_analyst-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4df7ec0d160f626e29397e524210db786347ef9fe97f0f068e020006fc384c72
MD5 7555d378c6cfe3a28963f3f1dc8708d8
BLAKE2b-256 85d52d0f14a29660b4b58bc6688f1089edb9e19a24cbfe5e6ecbcf4dc58f4ee2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page