๐ฏ 86% execution accuracy on Spider benchmark with zero API costs and 100% data privacy
๐ Bilingual support - Works perfectly with English and Chinese queries
English | ไธญๆๆๆกฃ
- ๐ธ Ongoing Costs: Continuous API fees that scale with usage
- ๐ Privacy Risk: Your sensitive data leaves your infrastructure
- ๐ Network Dependency: Requires internet, adds latency
- ๐ซ Compliance Issues: Many industries can't send data to cloud
- โ Zero Cost: No API fees, ever
- ๐ 100% Private: Data never leaves your machine
- โก Fast: 5-6 seconds average response time
- ๐ Proven: 86% execution accuracy on Spider benchmark
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ Your Local Environment โ
โ โ
โ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ User โโโโโโถโ LocalSQLAgent โโโโโโถโ Ollama + LLM โ โ
โ โ Query โ โ (Intelligent โ โ qwen2.5-coder:7bโ โ
โ โโโโโโโโโโโโโโ โ Agent) โ โโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโฌโโโโโโโโโโ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Your Databases โ โ
โ โ PostgreSQLโMySQLโMongoDBโ... โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ ๐ฐ $0 Cost ๐ 100% Private โก 5.4s Avg ๐ 86% EA โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# macOS/Linux
curl -fsSL https://ollama.com/install.sh | sh
# Pull the recommended model (4.7GB)
ollama pull qwen2.5-coder:7bgit clone https://github.com/tokligence/LocalSQLAgent.git
cd LocalSQLAgent
pip install -e .from localsql import IntelligentSQLAgent
# Connect to your database
agent = IntelligentSQLAgent("postgresql://localhost/mydb")
# Ask questions in natural language
result = agent.query("Show me top 10 customers by revenue last month")
print(result)โ qwen2.5-coder:7b - Best balance of accuracy, speed, and resource usage
- 86% execution accuracy on Spider benchmark*
- 5.4s average response time
- 4.7GB disk space
- ~6GB RAM required
*Tested on MacBook Pro (M-series, 48GB RAM) with Spider dev dataset (50 samples)
| Model | EA (%) | Speed | Verdict |
|---|---|---|---|
| qwen2.5-coder:7b | 86% | 5.4s | โ Best Choice |
| deepseek-coder-v2:16b | 68% | 4.0s | โ Good alternative |
| codestral:22b | 82% | 30.6s | |
| qwen2.5:14b | 82% | 10.0s | โ General model, not optimized |
Key Finding: Smaller domain-specific models outperform larger general models for SQL tasks
View detailed model analysis โ
- Automatically learns from SQL execution errors
- Self-corrects common mistakes (ambiguous columns, missing GROUP BY, etc.)
- Improves accuracy from 82% to 86% through error recovery
# English
result = agent.query("Show me sales trends")
# ไธญๆๅๆ ทๅฎ็พๆฏๆ
result = agent.query("ๆพ็คบไธไธชๆ้ๅฎๅ10็ไบงๅ")- PostgreSQL, MySQL, SQLite
- MongoDB (via SQL interface)
- ClickHouse, DuckDB
- Any SQL-compatible database
- REST API with FastAPI
- Docker support
- Concurrent request handling (10+ QPS)
- Comprehensive test suite
- Execution Accuracy (EA): 86%
- Average Latency: 5.41s
- Average Attempts: 2.5
- Success Rate: 100% (with retries)
| Attempts | EA (%) | Latency | Finding |
|---|---|---|---|
| 1 | 84% | 2.4s | Fast but may fail |
| 5 | 85% | 4.0s | +1% EA improvement |
| 7 | 85% | 4.8s | No further gain |
Recommendation: Use 1-3 attempts for best speed/accuracy balance
# Start the API server
python api_server.py
# Query via HTTP
curl -X POST http://localhost:8000/query \
-H "Content-Type: application/json" \
-d '{"query": "Show me all users who joined this month"}'docker build -t localsqlagent .
docker run -p 8000:8000 localsqlagentagent = IntelligentSQLAgent(
db_url="postgresql://localhost/mydb",
model_name="deepseek-coder-v2:16b", # Use alternative model
max_attempts=3,
temperature=0.1
)| Solution | Cost Model | Data Privacy | Setup Time |
|---|---|---|---|
| LocalSQLAgent | Free Forever | โ 100% Local | 5 minutes |
| Cloud APIs | Usage-based billing | 30 minutes | |
| Self-hosted GPU | Infrastructure costs | โ Local | Days-Weeks |
We welcome contributions! See CONTRIBUTING.md for guidelines.
Apache 2.0 - Free for commercial use
- Powered by Ollama
- Spider dataset from Yale University
- Built with love by Tokligence
Ready to eliminate API costs? Star โญ this repo and get started in 5 minutes!