CQLAI AI Features
CQLAI includes optional AI-powered query generation that converts natural language into CQL queries. This feature is completely optional - CQLAI works as a full-featured CQL shell without any AI configuration.
Overview
Section titled “Overview”Use the .ai command to describe the desired query in plain English:
cqlai> .ai show all active users who registered this month
Generated CQL: SELECT * FROM users WHERE status = 'active' AND created_at >= '2024-01-01' AND created_at < '2024-02-01' ALLOW FILTERING;
Execute? [Y/n]:How It Works
Section titled “How It Works”- Natural Language Input: Type
.aifollowed by the request - Schema Context: CQLAI automatically extracts the current schema
- Query Generation: AI generates a CQL query based on the schema
- Preview & Confirm: Review the generated query before execution
- Execute or Edit: Run the query, modify it, or cancel
Supported AI Providers
Section titled “Supported AI Providers”| Provider | Models | API Key Required | Local Option |
|---|---|---|---|
| OpenAI | GPT-4, GPT-3.5 | Yes | No |
| Anthropic | Claude 3 (Opus, Sonnet, Haiku) | Yes | No |
| Google Gemini | Gemini Pro | Yes | No |
| Ollama | Llama, Mistral, CodeLlama, etc. | No | Yes |
| OpenRouter | Multiple models | Yes | No |
| Synthetic | Open source models | Yes | No |
| Mock | (Testing only) | No | Yes |
Provider Configuration
Section titled “Provider Configuration”OpenAI
Section titled “OpenAI”Best for general-purpose query generation with high accuracy.
Get API Key: platform.openai.com/api-keys
{ "ai": { "provider": "openai", "apiKey": "sk-...", "model": "gpt-4-turbo-preview" }}Recommended Models:
gpt-4-turbo-preview- Best quality (default)gpt-4o- Fast and capablegpt-3.5-turbo- Cost-effective
Environment Variable: OPENAI_API_KEY
Anthropic (Claude)
Section titled “Anthropic (Claude)”Excellent for complex reasoning and context-aware queries.
Get API Key: console.anthropic.com/settings/keys
{ "ai": { "provider": "anthropic", "apiKey": "sk-ant-...", "model": "claude-3-sonnet-20240229" }}Recommended Models:
claude-3-opus-20240229- Most powerfulclaude-3-sonnet-20240229- Balanced (default)claude-3-haiku-20240307- Fastest
Environment Variable: ANTHROPIC_API_KEY
Google Gemini
Section titled “Google Gemini”Fast and capable model from Google.
Get API Key: aistudio.google.com/app/apikey
{ "ai": { "provider": "gemini", "apiKey": "...", "model": "gemini-pro" }}Environment Variable: GEMINI_API_KEY
Ollama (Local)
Section titled “Ollama (Local)”Run AI models locally without sending data externally.
Get Started: ollama.ai
{ "ai": { "provider": "ollama", "model": "llama3.2", "url": "http://localhost:11434/v1" }}Recommended Models:
llama3.2- General purposecodellama- Code-specializedqwen2.5-coder- Code generationmistral- Fast and capable
Setup:
# Install Ollamacurl -fsSL https://ollama.ai/install.sh | sh
# Pull a modelollama pull llama3.2
# Configure CQLAIcqlai # Uses local Ollama automaticallyEnvironment Variables:
OLLAMA_URL- Server URL (default:http://localhost:11434/v1)OLLAMA_MODEL- Model name
OpenRouter
Section titled “OpenRouter”Access multiple AI models through a single API.
Get API Key: openrouter.ai/keys
{ "ai": { "provider": "openrouter", "apiKey": "sk-or-...", "model": "anthropic/claude-3-sonnet", "url": "https://openrouter.ai/api/v1" }}Available Models: See openrouter.ai/models
Synthetic
Section titled “Synthetic”Access various open-source models at affordable prices.
Get Started: synthetic.new
{ "ai": { "provider": "openai", "apiKey": "your-synthetic-api-key", "url": "https://api.synthetic.new/openai/v1", "model": "hf:Qwen/Qwen3-235B-A22B-Instruct-2507" }}Note: Synthetic uses OpenAI-compatible API, so set provider to openai with custom url.
Mock Provider (Testing)
Section titled “Mock Provider (Testing)”For testing without API keys:
{ "ai": { "provider": "mock" }}Usage Examples
Section titled “Usage Examples”Simple Queries
Section titled “Simple Queries”-- List data.ai show all users.ai list the first 10 orders.ai count products by category
-- Filters.ai find users where status is active.ai get orders with total greater than 100.ai show products added in the last 7 daysComplex Queries
Section titled “Complex Queries”-- Aggregations.ai count orders grouped by customer.ai show total revenue per month
-- Joins (via denormalized tables).ai find all orders for customer john@example.com.ai get user details with their recent ordersSchema Operations
Section titled “Schema Operations”-- DDL.ai create a table for storing user sessions with session_id, user_id, created_at, and expires_at.ai add a column 'last_login' to the users table.ai create an index on the email column of users table
-- Discovery.ai what tables exist in this keyspace.ai describe the users table structure.ai show the primary key of orders tableData Modification
Section titled “Data Modification”-- Insert.ai insert a new user with name John Doe and email john@example.com
-- Update.ai update user status to inactive where last_login is older than 90 days.ai set the email to new@example.com for user with id abc123
-- Delete (with warnings).ai delete all expired sessions.ai remove products with stock count of zeroSafety Features
Section titled “Safety Features”Read-Only Preference
Section titled “Read-Only Preference”By default, AI prefers generating SELECT queries unless modifications are explicitly requested:
.ai users -- Generates: SELECT * FROM users.ai delete inactive users -- Generates DELETE with warningsDangerous Operation Warnings
Section titled “Dangerous Operation Warnings”Destructive operations display warnings:
.ai drop the temp_data table
⚠️ WARNING: This is a destructive operation!Generated CQL: DROP TABLE temp_data;
This will permanently delete the table and all its data.Type 'yes' to confirm:Confirmation Required
Section titled “Confirmation Required”All generated queries require confirmation before execution:
.ai show all users
Generated CQL: SELECT * FROM users;
Execute? [Y/n]:Options:
Yor Enter - Execute the queryn- Cancele- Edit the query before executing
Schema Validation
Section titled “Schema Validation”CQLAI validates generated queries against the current schema to catch errors before execution.
Best Practices
Section titled “Best Practices”Be Specific
Section titled “Be Specific”-- Good.ai show users where created_at is after January 1, 2024
-- Too vague.ai show recent usersMention Table Names
Section titled “Mention Table Names”-- Good.ai count rows in the orders table
-- May be ambiguous.ai count all ordersReview Generated Queries
Section titled “Review Generated Queries”Always review the generated CQL before execution, especially for:
- DELETE operations
- UPDATE operations
- DDL commands (CREATE, ALTER, DROP)
Use for Discovery
Section titled “Use for Discovery”AI is useful for exploring the schema:
.ai what tables are in this keyspace.ai show me the schema of the events table.ai how is the users table partitionedTroubleshooting
Section titled “Troubleshooting”AI Not Responding
Section titled “AI Not Responding”- Check API key is configured correctly
- Verify network connectivity to API endpoint
- Check for rate limiting
# Test with curlcurl https://api.openai.com/v1/models \ -H "Authorization: Bearer $OPENAI_API_KEY"Poor Query Generation
Section titled “Poor Query Generation”- Be more specific in the request
- Mention table and column names explicitly
- Try a different model (GPT-4 vs GPT-3.5)
Ollama Connection Issues
Section titled “Ollama Connection Issues”# Check Ollama is runningcurl http://localhost:11434/api/tags
# Check model is pulledollama listPrivacy Considerations
Section titled “Privacy Considerations”When using AI features:
- Schema Information Sent: The schema (table names, columns, types) is sent to the AI provider for context
- Query Intent Sent: The natural language request is sent to the provider
- Data Not Sent: Actual data is never sent to AI providers
For maximum privacy, use Ollama to run models locally.
Next Steps
Section titled “Next Steps”- Commands Reference - All CQLAI commands
- Configuration - Full configuration options
- Troubleshooting - Common issues