Download the PHP package emon/larabot-ai without Composer
On this page you can find all versions of the php package emon/larabot-ai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download emon/larabot-ai
More information about emon/larabot-ai
Files in emon/larabot-ai
Package larabot-ai
Short Description Conversational AI database assistant for Laravel with Schema-RAG and NLโSQL capabilities
License MIT
Informations about the package larabot-ai
LaraBot AI
Conversational AI database assistant for Laravel that combines Schema-RAG and NLโSQL capabilities using Google Gemini AI.
๐ Features
- ๐ค Natural Language to SQL - Ask questions about your database in plain English
- ๐จ HTML Visualizations - AI generates beautiful charts, tables, and cards automatically
- ๐ Documentation RAG - Retrieval Augmented Generation from your project docs
- ๐ Semantic Schema Search - AI embeddings for intelligent table discovery
- ๐ Secure by Design - Read-only DB connection + SQL injection prevention
- โก Auto-Discovery - Automatically learns your database structure
- ๐ Query Logging - Track all queries with performance metrics
- ๐ก๏ธ Rate Limiting - Built-in protection against abuse
- ๐ฏ Column-Aware - Matches queries to specific columns
- ๐ Relationship Discovery - Automatically follows foreign keys
๐ Requirements
- PHP 8.1 or higher
- Laravel 10.x or 11.x
- MySQL 5.7+ / MariaDB 10.3+
- Google Gemini API key (Get free key)
๐ฆ Installation
Step 1: Install via Composer
Step 2: Publish Configuration
Step 3: Publish Migrations
Step 4: Configure Environment
Add to your .env file:
Get your free API key from Google AI Studio.
Step 5: Add Read-Only Database Connection
Add this to config/database.php:
Security Tip: Create a read-only MySQL user:
Then add to .env:
Step 6: Run Migrations
Step 7: Embed Your Database Schema
Interactive Selection: The command will display all available tables and let you select which ones to embed:
- Enter numbers separated by comma:
1,3,5 - Use ranges:
1-5or combine:1,3,5-8 - Type
allto select all tables - Press Enter to cancel
This command will:
- Discover all tables in your database
- Extract column information and relationships
- Generate AI embeddings for semantic search
- Store everything for lightning-fast queries
Time: ~1 second per table (API rate limits: 60 requests/minute)
Example:
Step 8 (Optional): Embed Documentation
If you have markdown documentation in a docs/ directory:
๐ฏ Usage
API Endpoints
The package automatically registers these routes:
Ask Questions
Response:
๐จ HTML Visualizations (New in v1.2.0)
The bot now intelligently generates beautiful HTML/CSS visualizations along with natural language answers!
Key Features:
- โ Natural language answer (always included)
- โ Beautiful HTML visualization (when helpful)
- โ Self-contained (no external dependencies)
- โ Multiple types: stat cards, tables, bar charts, timelines, comparisons, and more
Example:
Visualization Types:
stats_card- Single values (counts, sums)table- Tabular data (5-20 rows)bar_chart- Categories with numberslist- Short lists (2-5 items)comparison- Side-by-side comparisonsmetric_grid- Dashboard-style metricstimeline- Date-ordered eventstext- Plain text (no visualization)
Learn More:
- ๐ HTML Visualization Feature Guide
- ๐ Real Examples
- ๐ What's New in v1.2.0
Example Queries
SQL Queries:
Documentation Queries:
Programmatic Usage
โ๏ธ Configuration
Authentication
By default, bot routes are publicly accessible. To require authentication:
Option 1: Environment Variables (Recommended)
Add to .env:
Option 2: Config File
Edit config/gemini.php:
Option 3: Custom Middleware (Advanced)
Edit config/gemini.php and customize the middleware array:
Testing Authenticated Requests:
Common Auth Guards:
sanctum- Laravel Sanctum (SPA/mobile apps)api- Token-based authenticationweb- Session-based authenticationpassport- Laravel Passport OAuth2
Rate Limiting
Default: 10 requests per minute per user/IP
To customize, modify src/Http/Middleware/BotRateLimitMiddleware.php:
Query Length
Default: 500 characters max
Change in middleware:
Gemini Models
In config/gemini.php:
๐ Security Features
โ
Read-Only Database - Queries execute on separate read-only connection
โ
SQL Injection Prevention - Blocks dangerous SQL patterns
โ
No Mutations - DROP, DELETE, UPDATE, INSERT automatically blocked
โ
Optional Authentication - Support for Sanctum, Passport, and custom guards
โ
Rate Limiting - Prevents API abuse (10 req/min default)
โ
Query Validation - Validates generated SQL before execution
โ
Audit Logging - All queries logged with user ID and timestamps
๐งช How It Works
Architecture
Key Components
- Schema Embeddings - Vector representations of your database tables
- Semantic Search - Finds relevant tables using AI similarity matching
- Relationship Discovery - Automatically includes related tables via foreign keys
- Column-Aware Matching - Matches query terms to specific columns
- SQL Generation - Gemini LLM generates optimized SQL queries
- SQL Validation - Multi-layer security checks before execution
๐ Query Logging
All queries are logged to query_logs table:
Fields: query, intent, generated_sql, retrieved_tables, response_time_ms, success, error_message
๐ง Maintenance
Re-embed Schema After Changes
Run this after migrations or schema changes:
Tip: You can selectively re-embed only the tables that changed by using the interactive selection.
Update Documentation
After updating docs:
๐ Troubleshooting
"403 Forbidden" from Gemini API
Solution: Remove API key restrictions in Google AI Studio.
"429 Too Many Requests"
Solution: Hitting free tier quota limit. Wait or upgrade plan.
"Table X is not in allowed list"
Solution: Schema not embedded. Run php artisan schema:embed and select the tables you need to embed. You can use all to embed all tables or select specific ones.
SQL Validation Errors
Solution: Generated SQL contains dangerous operations or syntax errors. Check query logs.
๐ Documentation
- Installation Guide - Step-by-step setup
- Authentication Guide - Secure your bot routes
- Package Summary - Technical architecture
- HTML Visualizations - Complete guide to visualizations (v1.2.0+)
- Visualization Examples - Real-world examples
- What's New in v1.2.0 - Latest features
๐ค Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Submit a pull request
๐ License
MIT License - see LICENSE file for details.
๐ Credits
Built with:
๐ฌ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
๐ Star History
If this package helped you, please star it on GitHub! โญ
Made with โค๏ธ for the Laravel community
All versions of larabot-ai with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/console Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
guzzlehttp/guzzle Version ^7.5
ramsey/uuid Version ^4.7