Skip to main content
ChartDB’s AI features enable intelligent DDL script generation for easy database migrations. You can use OpenAI’s GPT models or self-hosted LLM inference servers.

What AI Features Do

ChartDB’s AI capabilities include:

DDL Export

Generate DDL scripts in any database dialect for migrations

Smart Conversion

Convert schemas between MySQL, PostgreSQL, SQLite, SQL Server, etc.

Dialect Translation

Translate database-specific syntax to your target platform

Schema Optimization

Get suggestions for schema improvements and best practices
AI features are completely optional. ChartDB works perfectly without AI for schema visualization and manual editing.

Option 1: OpenAI API

The simplest way to enable AI features is using OpenAI’s API.

Get an API Key

1

Create OpenAI Account

2

Add Payment Method

Navigate to BillingPayment methods and add a payment method
3

Generate API Key

Go to API KeysCreate new secret key
Copy the key immediately - you won’t be able to see it again!
4

Set Usage Limits

Under BillingUsage limits, set a monthly budget to prevent unexpected charges

Configure ChartDB

Pass the API key when running the container:
docker run \
  -e OPENAI_API_KEY=sk-proj-your-key-here \
  -p 8080:80 \
  ghcr.io/chartdb/chartdb:latest
Recommended: Runtime configuration keeps secrets out of images

Test the Configuration

1

Open ChartDB

Navigate to http://localhost:8080 (or your configured port)
2

Create or Import Schema

Create a new diagram or import an existing database schema
3

Export with AI

Click ExportAI-Powered Export and select a target database
4

Verify Output

You should see a DDL script generated for your target database dialect
If AI features aren’t working, check the browser console (F12) for error messages about the API key.

Option 2: Self-Hosted LLM

For complete data privacy or to avoid API costs, use a self-hosted LLM inference server.

Supported Inference Servers

Any server compatible with OpenAI’s API format will work:
High-performance inference server optimized for throughput.Installation:
pip install vllm
Run Server:
python -m vllm.entrypoints.openai.api_server \
  --model Qwen/Qwen2.5-32B-Instruct-AWQ \
  --port 8000
Configure ChartDB:
docker run \
  -e OPENAI_API_ENDPOINT=http://host.docker.internal:8000/v1 \
  -e LLM_MODEL_NAME=Qwen/Qwen2.5-32B-Instruct-AWQ \
  -p 8080:80 \
  ghcr.io/chartdb/chartdb:latest
vLLM is excellent for high-throughput scenarios and supports many quantization formats (AWQ, GPTQ, etc.)
For DDL generation and schema conversion, these models work well:
ModelSizeQualitySpeedMemory
Qwen 2.5 32B32BExcellentMedium20GB+
Qwen 2.5 14B14BVery GoodFast10GB+
Qwen 2.5 7B7BGoodVery Fast6GB+
Llama 3.1 70B70BExcellentSlow40GB+
Llama 3.1 8B8BGoodVery Fast6GB+
Mistral 7B7BGoodVery Fast6GB+
Use quantized models (AWQ, GPTQ, or GGUF) to reduce memory requirements. A 32B AWQ model can run in ~20GB RAM instead of 64GB.

Configuration Examples

Complete vLLM Setup

# 1. Start vLLM server
docker run --gpus all -p 8000:8000 \
  vllm/vllm-openai:latest \
  --model Qwen/Qwen2.5-32B-Instruct-AWQ \
  --quantization awq

# 2. Build ChartDB with vLLM config
docker build \
  --build-arg VITE_OPENAI_API_ENDPOINT=http://localhost:8000/v1 \
  --build-arg VITE_LLM_MODEL_NAME=Qwen/Qwen2.5-32B-Instruct-AWQ \
  --build-arg VITE_DISABLE_ANALYTICS=true \
  -t chartdb-vllm .

# 3. Run ChartDB (use host network on Linux)
docker run --network host chartdb-vllm

# Or on Mac/Windows:
docker run \
  -e OPENAI_API_ENDPOINT=http://host.docker.internal:8000/v1 \
  -e LLM_MODEL_NAME=Qwen/Qwen2.5-32B-Instruct-AWQ \
  -p 8080:80 \
  chartdb-vllm

Ollama with Docker Compose

docker-compose.yml
version: '3.8'

services:
  ollama:
    image: ollama/ollama:latest
    ports:
      - "11434:11434"
    volumes:
      - ollama_data:/root/.ollama
    restart: unless-stopped

  chartdb:
    image: ghcr.io/chartdb/chartdb:latest
    ports:
      - "8080:80"
    environment:
      - OPENAI_API_ENDPOINT=http://ollama:11434/v1
      - LLM_MODEL_NAME=llama3.1
      - HIDE_CHARTDB_CLOUD=true
      - DISABLE_ANALYTICS=true
    depends_on:
      - ollama
    restart: unless-stopped

volumes:
  ollama_data:
# Start services
docker-compose up -d

# Pull model into Ollama
docker-compose exec ollama ollama pull llama3.1

# Access ChartDB
open http://localhost:8080

Network Configuration

When running both the LLM server and ChartDB in Docker:
Use --network host for simplest setup:
# LLM server
docker run --network host vllm/vllm-openai:latest --model ...

# ChartDB
docker run --network host \
  -e OPENAI_API_ENDPOINT=http://localhost:8000/v1 \
  -e LLM_MODEL_NAME=your-model \
  chartdb

Hybrid Setup

You can switch between OpenAI and self-hosted LLMs by changing environment variables:
# Use OpenAI during development
docker run -e OPENAI_API_KEY=sk-... -p 8080:80 chartdb

# Switch to self-hosted for production
docker run \
  -e OPENAI_API_ENDPOINT=http://vllm:8000/v1 \
  -e LLM_MODEL_NAME=Qwen/Qwen2.5-32B-Instruct-AWQ \
  -p 8080:80 chartdb
Never configure both options simultaneouslyUse either:
  • OPENAI_API_KEY (for OpenAI)
OR:
  • OPENAI_API_ENDPOINT + LLM_MODEL_NAME (for self-hosted)
Configuring both will cause conflicts.

AI Feature Usage

Once configured, use AI features in ChartDB:
1

Create/Import Schema

Create a new diagram or import your database schema using the Smart Query
2

Open Export

Click the Export button in the top toolbar
3

Select AI Export

Choose AI-Powered Export from the export options
4

Choose Target Database

Select your target database dialect:
  • PostgreSQL
  • MySQL
  • SQL Server
  • MariaDB
  • SQLite
  • CockroachDB
  • ClickHouse
5

Generate DDL

The AI will generate optimized DDL scripts for your target database
6

Review & Copy

Review the generated script and copy it for use in your migration

Troubleshooting

Cause: Environment variables not set correctlySolution:
# Check container environment
docker exec <container-id> env | grep -E 'OPENAI|LLM'

# Verify config.js endpoint
curl http://localhost:8080/config.js

# Check browser console (F12) for errors
Ensure you’re using the correct variable names (no VITE_ prefix for runtime).
Cause: Network configuration or incorrect endpointSolution:
# Test from ChartDB container
docker exec <container-id> wget -O- http://your-endpoint/v1/models

# For localhost servers, use correct hostname:
# - Linux: http://localhost:8000/v1
# - Mac/Windows: http://host.docker.internal:8000/v1
# - Docker Compose: http://service-name:8000/v1
Verify the endpoint is accessible from the ChartDB container.
Cause: Model name doesn’t match what’s loaded in the serverSolution:
# Check available models
curl http://localhost:8000/v1/models

# Ensure LLM_MODEL_NAME matches exactly
# For vLLM, use the full model path:
-e LLM_MODEL_NAME=Qwen/Qwen2.5-32B-Instruct-AWQ

# For Ollama, use the model name:
-e LLM_MODEL_NAME=llama3.1
Cause: Model is too large or not enough resourcesSolution:
  • Use a smaller/quantized model (7B instead of 32B)
  • Increase memory allocation for Docker
  • Use GPU acceleration if available
  • Increase timeout in your inference server
# vLLM with GPU
docker run --gpus all vllm/vllm-openai:latest --model ...

# Increase Docker memory (Docker Desktop)
# Settings → Resources → Memory → 16GB+
Cause: Model too small or not suited for code generationSolution:
  • Use larger models (14B+ recommended)
  • Try Qwen 2.5 series (optimized for code)
  • Ensure model supports instruction following
  • Check if quantization is too aggressive (Q4 vs Q8)
Recommended models for best results:
  • Qwen 2.5 32B Instruct (AWQ)
  • Qwen 2.5 14B Instruct
  • Llama 3.1 70B Instruct
Cause: Both OpenAI and custom endpoint configuredSolution:
# Remove one configuration set

# Option 1: OpenAI only
docker run -e OPENAI_API_KEY=sk-... chartdb

# Option 2: Custom endpoint only
docker run \
  -e OPENAI_API_ENDPOINT=http://... \
  -e LLM_MODEL_NAME=... \
  chartdb

# NOT: Both together

Performance Optimization

Hardware Requirements

For self-hosted LLMs:
Model SizeRAM RequiredGPU MemorySpeed
7B (Q4)6 GB4 GBFast
7B (Q8)8 GB6 GBFast
14B (AWQ)10 GB8 GBMedium
32B (AWQ)20 GB16 GBMedium
70B (AWQ)40 GB32 GBSlow
AWQ and GPTQ quantization provide the best quality-to-size ratio. Q4 is fast but lower quality.

Optimization Tips

Use Quantization

AWQ or GPTQ models offer 2-3x memory reduction with minimal quality loss

GPU Acceleration

Use --gpus all with vLLM or enable GPU in LM Studio for 10-50x speedup

Batch Inference

vLLM automatically batches requests for better throughput

Model Caching

Keep models loaded in memory to avoid reload overhead

Security & Privacy

Self-hosted LLMs provide complete data privacy:
Benefits of Self-Hosting:
  • Schema data never leaves your network
  • No external API calls
  • Full audit trail
  • No usage limits or costs
  • Compliance with data regulations (GDPR, HIPAA, etc.)
Best Practices:
1

Network Isolation

Run LLM servers on isolated networks with no internet access
2

Access Control

Use authentication for inference server APIs in production
3

Monitoring

Log all AI requests for audit purposes
4

Model Validation

Verify model sources and checksums before deployment

Cost Comparison

OptionSetup CostRunning CostPrivacyPerformance
OpenAI APIFree~$0.01-0.10 per request⚠️ Data sent to OpenAIFast (API latency)
Self-hosted (CPU)Free~$0.50/hr server cost✅ Complete privacySlow (CPU inference)
Self-hosted (GPU)$500-5000 hardware~$0.10-1.00/hr electricity✅ Complete privacyFast (GPU inference)
Cloud GPU (AWS/GCP)Free~$1-5/hr instance cost⚠️ Data in cloudFast (GPU inference)
For occasional use, OpenAI API is most cost-effective. For frequent use or privacy requirements, self-hosted is better.

Next Steps

Docker Deployment

Learn how to deploy ChartDB with Docker

Configuration

Explore all configuration options