Skip to main content

Advanced Text-to-SQL library with AI features

Project description

AI Prishtina - Text2SQL-LTM: Professional Text-to-SQL Library

PyPI version Total Downloads Monthly Downloads Weekly Downloads PyPI Downloads Python 3.8+ License: Commercial Tests Coverage

Growing adoption by developers worldwide.

Support This Project

If you find this project helpful, please consider supporting it:

Donate

AI PRISHTINA - Text2SQL-LTM is a comprehensive Text-to-SQL library with AI capabilities. Built with production-ready architecture for natural language to SQL conversion.

Features

RAG-Enhanced Query Generation

  • Vector-based knowledge retrieval with semantic search
  • Schema-aware context augmentation for intelligent SQL generation
  • Query pattern learning from successful executions
  • Adaptive retrieval strategies that improve over time
  • Knowledge fusion across different data sources

SQL Validation & Auto-Correction

  • Intelligent syntax validation with automatic error fixing
  • Security vulnerability detection and prevention
  • Performance optimization suggestions with impact analysis
  • Cross-platform compatibility checking
  • Best practice enforcement with educational feedback

Query Explanation & Teaching System

  • Step-by-step query breakdown with visual execution flow
  • Adaptive explanations based on user expertise level
  • Interactive learning modes with guided practice
  • Personalized learning paths with progress tracking
  • Real-time teaching assistance for SQL education

Automated Schema Discovery & Documentation

  • AI-powered relationship inference between tables
  • Column purpose detection using pattern recognition
  • Data quality assessment with improvement suggestions
  • Auto-generated documentation in multiple formats
  • Business rule extraction from data patterns

Advanced Security Analysis

  • SQL injection detection with real-time prevention
  • Privilege escalation monitoring and alerts
  • Data exposure analysis with compliance checking (GDPR, PCI DSS, SOX)
  • Vulnerability scanning with remediation guidance
  • Security best practice validation

Cross-Platform Query Translation

  • Intelligent dialect conversion between 8+ database platforms
  • Syntax optimization for target platforms
  • Compatibility analysis with migration guidance
  • Performance tuning for specific database engines
  • Feature mapping across different SQL dialects

Automated Test Case Generation

  • Comprehensive test suite creation for SQL queries
  • Edge case detection and test generation
  • Performance test automation with benchmarking
  • Security test scenarios for vulnerability assessment
  • Data validation testing with constraint checking

Quick Start

Installation

pip install ai-prishtina-text2sql-ltm

30-Second Setup

import asyncio
from text2sql_ltm import create_simple_agent, Text2SQLSession

async def main():
    # Just provide your API key - everything else uses smart defaults
    agent = create_simple_agent(api_key="your_openai_key")

    async with Text2SQLSession(agent) as session:
        result = await session.query(
            "Show me the top 10 customers by revenue this year",
            user_id="user123"
        )

        print(f"Generated SQL: {result.sql}")
        print(f"Confidence: {result.confidence}")
        print(f"Explanation: {result.explanation}")

asyncio.run(main())

Feature-Rich Setup

# Enable advanced features with simple flags
agent = create_simple_agent(
    api_key="your_openai_key",
    enable_rag=True,                    # Vector-enhanced generation
    enable_security_analysis=True,      # Security scanning
    enable_explanation=True,            # AI teaching
    enable_test_generation=True         # Automated testing
)

Production Configuration

from text2sql_ltm import create_integrated_agent

# Load from configuration file
agent = create_integrated_agent(config_file="config/production.yaml")

# Or use configuration dictionary
agent = create_integrated_agent(config_dict={
    "memory": {
        "storage_backend": "postgresql",
        "storage_url": "postgresql://user:pass@localhost/db"
    },
    "agent": {
        "llm_provider": "openai",
        "llm_model": "gpt-4",
        "llm_api_key": "your_api_key"
    },
    "ai_features": {
        "enable_rag": True,
        "enable_validation": True,
        "enable_security_analysis": True
    }
})

Advanced Examples

Security Analysis

# Security analysis
security_result = await agent.security_analyzer.analyze_security(
    query="SELECT * FROM users WHERE id = ?",
    user_id="user123",
    context={"user_input": True}
)

print(f"Security Score: {security_result.risk_score}/10")
print(f"Vulnerabilities: {len(security_result.vulnerabilities)}")
print(f"Compliance: {security_result.compliance_status}")

Cross-Platform Translation

# Translate between database dialects
translation_result = await agent.query_translator.translate_query(
    query="SELECT TOP 10 * FROM users",
    source_dialect="sqlserver",
    target_dialect="postgresql",
    optimize_for_target=True
)

print(f"Original: {translation_result.original_query}")
print(f"Translated: {translation_result.translated_query}")
print(f"Compatibility: {translation_result.compatibility}")

Automated Testing

# Generate test suite
test_suite = await agent.test_generator.generate_test_suite(
    query="SELECT name, COUNT(*) FROM users GROUP BY name",
    schema=schema_info,
    test_types=["functional", "edge_case", "performance", "security"]
)

print(f"Generated {len(test_suite.test_cases)} test cases")

Architecture

Text2SQL-LTM features a modular, production-ready architecture:

System Architecture

┌─────────────────────────────────────────────────────────────────────────────────┐
│                           AI-Prishtina-Text2SQL-LTM                             │
│                              Production Architecture                            │
└─────────────────────────────────────────────────────────────────────────────────┘

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   User Input    │    │  Natural Lang   │    │   SQL Output    │
│                 │───▶│   Processing    │───▶│                 │
│ "Show top users"│    │                 │    │ SELECT * FROM.. │
└─────────────────┘    └─────────────────┘    └─────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────────────────────┐
│                            CORE AGENT LAYER                                     │
├─────────────────────────────────────────────────────────────────────────────────┤
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐                  │
│  │ Session Manager │  │ Context Engine  │  │ SQL Generator   │                  │
│  │                 │  │                 │  │                 │                  │
│  │ • User Sessions │  │ • Query Context │  │ • LLM Interface │                  │
│  │ • State Mgmt    │  │ • Schema Context│  │ • SQL Generation│                  │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘                  │
└─────────────────────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────────────────────┐
│                           MEMORY SYSTEM                                        │
├─────────────────────────────────────────────────────────────────────────────────┤
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐                │
│  │ Memory Manager  │  │ Storage Backend │  │ Schema Manager  │                │
│  │                 │  │                 │  │                 │                │
│  │ • Query History │  │ • InMemory      │  │ • Schema Cache  │                │
│  │ • User Context  │  │ • Redis         │  │ • Relationships │                │
│  │ • Learning      │  │ • PostgreSQL    │  │ • Metadata      │                │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘                │
└─────────────────────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────────────────────┐
│                            RAG SYSTEM                                          │
├─────────────────────────────────────────────────────────────────────────────────┤
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐                │
│  │ Vector Store    │  │ Embeddings      │  │ Retrieval       │                │
│  │                 │  │                 │  │                 │                │
│  │ • ChromaDB      │  │ • OpenAI        │  │ • Semantic      │                │
│  │ • Pinecone      │  │ • Sentence-T    │  │ • Similarity    │                │
│  │ • Weaviate      │  │ • Custom        │  │ • Context       │                │
│  │ • 7 Databases   │  │                 │  │                 │                │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘                │
└─────────────────────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────────────────────┐
│                           AI FEATURES                                          │
├─────────────────────────────────────────────────────────────────────────────────┤
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐                │
│  │ SQL Validator   │  │ Security        │  │ Query Explainer │                │
│  │                 │  │ Analyzer        │  │                 │                │
│  │ • Syntax Check  │  │ • Injection Det │  │ • Step-by-step  │                │
│  │ • Performance   │  │ • Risk Analysis │  │ • Educational   │                │
│  │ • Best Practice │  │ • Compliance    │  │ • Adaptive      │                │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘                │
│                                                                                 │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐                │
│  │ Schema          │  │ Query           │  │ Test            │                │
│  │ Discovery       │  │ Translator      │  │ Generator       │                │
│  │                 │  │                 │  │                 │                │
│  │ • Auto Analysis │  │ • Cross-dialect │  │ • Auto Tests    │                │
│  │ • Relationships │  │ • 8+ Databases  │  │ • Edge Cases    │                │
│  │ • Documentation │  │ • Optimization  │  │ • Performance   │                │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘                │
└─────────────────────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────────────────────┐
│                         LLM PROVIDERS                                          │
├─────────────────────────────────────────────────────────────────────────────────┤
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐                │
│  │ OpenAI          │  │ Anthropic       │  │ Google          │                │
│  │ • GPT-4         │  │ • Claude        │  │ • Gemini        │                │
│  │ • GPT-3.5       │  │ • Haiku         │  │ • PaLM          │                │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘                │
│                                                                                 │
│  ┌─────────────────┐  ┌─────────────────┐                                      │
│  │ HuggingFace     │  │ Local Models    │                                      │
│  │ • Transformers  │  │ • Ollama        │                                      │
│  │ • Custom Models │  │ • Custom        │                                      │
│  └─────────────────┘  └─────────────────┘                                      │
└─────────────────────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────────────────────┐
│                        DATABASE TARGETS                                        │
├─────────────────────────────────────────────────────────────────────────────────┤
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐                │
│  │ PostgreSQL      │  │ MySQL           │  │ SQLite          │                │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘                │
│                                                                                 │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐                │
│  │ SQL Server      │  │ Oracle          │  │ MongoDB         │                │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘                │
└─────────────────────────────────────────────────────────────────────────────────┘

Component Directory Structure

text2sql_ltm/
├── __init__.py              # Main library interface
├── agent.py                 # Core agent implementation
├── factory.py               # Agent factory functions
├── types.py                 # Type definitions
├── exceptions.py            # Custom exceptions
├── config/                  # Configuration management
│   ├── __init__.py
│   ├── base.py             # Base configuration
│   ├── memory.py           # Memory configuration
│   ├── agent.py            # Agent configuration
│   └── ai_features.py      # AI features configuration
├── memory/                  # Long-term memory system
│   ├── __init__.py
│   ├── manager.py          # Memory manager
│   ├── simple_manager.py   # Simplified memory manager
│   ├── storage.py          # Storage backends
│   └── types.py            # Memory types
├── rag/                     # RAG implementation
│   ├── __init__.py
│   ├── manager.py          # RAG orchestration
│   ├── vector_store.py     # Vector storage (7 databases)
│   ├── embeddings.py       # Embedding generation
│   └── retrieval.py        # Context retrieval
├── ai_features/             # AI features
│   ├── __init__.py
│   ├── sql_validator.py    # SQL validation
│   ├── explainer.py        # Query explanation
│   ├── schema_discovery.py # Schema analysis
│   ├── query_translator.py # Cross-platform translation
│   ├── security_analyzer.py# Security analysis
│   └── test_generator.py   # Test automation
└── llm/                     # LLM providers
    ├── __init__.py
    ├── base.py             # Base LLM interface
    ├── openai_provider.py  # OpenAI integration
    ├── anthropic_provider.py# Anthropic integration
    ├── google_provider.py  # Google integration
    ├── huggingface_provider.py# HuggingFace integration
    └── local_provider.py   # Local model support

Configuration

YAML Configuration

# config/production.yaml
memory:
  storage_backend: "postgresql"
  storage_url: "${DATABASE_URL}"

agent:
  llm_provider: "openai"
  llm_model: "gpt-4"
  llm_api_key: "${OPENAI_API_KEY}"

ai_features:
  enable_rag: true
  enable_validation: true
  enable_security_analysis: true

  rag:
    vector_store:
      provider: "pinecone"
      api_key: "${PINECONE_API_KEY}"
    embedding:
      provider: "openai"
      api_key: "${OPENAI_API_KEY}"

security:
  require_authentication: true
  rate_limiting_enabled: true

Environment Variables

# Core API Keys
OPENAI_API_KEY=your_openai_key
DATABASE_URL=postgresql://user:pass@localhost/db

# Optional Services
PINECONE_API_KEY=your_pinecone_key
GOOGLE_VISION_API_KEY=your_google_key
REDIS_URL=redis://localhost:6379

Testing

Run the comprehensive test suite:

# Install with test dependencies
pip install text2sql-ltm[test]

# Run all tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=text2sql_ltm --cov-report=html

# Run specific test categories
pytest tests/test_rag_system.py -v
pytest tests/test_security.py -v

Examples

Examples are available in the examples/ directory:

Support & Licensing

Commercial License

Text2SQL-LTM is a commercial product with advanced enterprise features.

For licensing, pricing, and enterprise support, contact:

Alban Maxhuni, PhD Email: info@albanmaxhuni.com Website: albanmaxhuni.com

License Options

  • Individual License: For personal and small team use
  • Enterprise License: For large organizations with advanced features
  • Custom License: Tailored solutions for specific requirements

What's Included

  • Full source code access
  • Priority technical support
  • Regular updates and new features
  • Custom integration assistance
  • Training and consultation
  • SLA guarantees for enterprise

Getting Started

  1. Install: pip install ai-prishtina-text2sql-ltm
  2. Contact: info@albanmaxhuni.com for licensing
  3. Configure: Set up your API keys and configuration
  4. Deploy: Use our production-ready templates
  5. Scale: Leverage enterprise features for your organization

AI-Prishtina-Text2SQL-LTM: Professional database interaction through AI.

© 2025 AI Prishtina, Inc. All rights reserved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

ai_prishtina_text2sql_ltm-1.0.10-py3-none-any.whl (230.3 kB view details)

Uploaded Python 3

File details

Details for the file ai_prishtina_text2sql_ltm-1.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_prishtina_text2sql_ltm-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 d3610e48a0c8acecdcf3b3856432cebdf6fa6ac9a87a84735064b065f9a027bd
MD5 07a99a2edc4cb4111f0af17d03caf305
BLAKE2b-256 42974ade4d64626fbcb0660b87a8e3e813c437c28584b2019a93149514a29645

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