Quantum Minds SQL Operators
Introduction
SQL operators in Quantum Minds enable interaction with relational databases through natural language, automated SQL generation, and direct execution. These operators form the foundation for data-driven minds that need to extract, analyze, and process structured data from databases.
Available SQL Operators
Operator | Description | Common Use Cases |
---|---|---|
TextToSQL | Converts natural language to SQL queries | Data exploration, report generation, ad-hoc querying |
SQLExecution | Executes SQL queries against databases | Data retrieval, calculations, data manipulation |
DbChat | Interactive chat interface for SQL databases | Conversational data analysis, guided exploration |
DbChatV2 | Enhanced chat interface with improved context | Complex data analysis, multi-turn queries |
CreateDataset | Creates datasets from dataframes | Data preparation, sharing results, creating persistent data |
SQL.HealthCheck | Analyzes database health | Data quality assessment, schema validation |
SQL.Enhance | Adds context to improve SQL generation | Schema enrichment, query optimization |
TextToSQLV3 | Advanced SQL generation with improved schema understanding | Complex query construction, optimized SQL |
TextToSQLV4 | Latest SQL generation with advanced context handling | Enterprise-grade SQL, complex joins and aggregations |
TextToSQL
The TextToSQL operator converts natural language instructions into SQL queries.
Inputs
Parameter | Type | Required | Description |
---|---|---|---|
prompt | string | Yes | Natural language description of the data you want to query |
dataset | string | Yes | Reference to the dataset to query |
trigger | string | No | Optional control signal to trigger execution |
Outputs
Parameter | Type | Description |
---|---|---|
type | string | Output format (markdown) |
content | string | Generated SQL query |
Example Usage
Prompt: "Show me the top 10 customers by total purchase amount in the last quarter"
Dataset: "sales_database"
Output:
SELECT c.customer_name, SUM(o.total_amount) as total_purchases
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
WHERE o.order_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH)
GROUP BY c.customer_name
ORDER BY total_purchases DESC
LIMIT 10;
Best Practices
- Be specific about exactly what data you need
- Mention key columns, filters, and sorting requirements
- For complex queries, break down into simpler parts
- Reference actual table and column names when possible
SQLExecution
The SQLExecution operator runs SQL queries against connected databases and returns the results.
Inputs
Parameter | Type | Required | Description |
---|---|---|---|
sql | string | Yes | SQL query to execute |
dataset | string | Yes | Dataset to run the query against |
trigger | string | No | Optional control signal to trigger execution |
Outputs
Parameter | Type | Description |
---|---|---|
type | string | Output format (table) |
content | string | Results of the SQL query as tabular data |
Example Usage
Typically connected to a TextToSQL operator to execute the generated SQL, but can also be used with hardcoded queries:
SQL: "SELECT product_name, SUM(quantity) as total_quantity FROM orders GROUP BY product_name ORDER BY total_quantity DESC LIMIT 5"
Dataset: "inventory_db"
Output: [Table containing product names and their total quantities, sorted in descending order]
Best Practices
- Use parameterized queries when possible
- Limit result sets to reasonable sizes
- Consider performance impact for large datasets
- Use appropriate indexes in the underlying database
DbChat
The DbChat operator provides an interactive chat interface for SQL databases, combining SQL generation, execution, and result presentation.
Inputs
Parameter | Type | Required | Description |
---|---|---|---|
prompt | string | Yes | Natural language query or instruction |
dataset | string | Yes | Dataset to query |
trigger | string | No | Optional control signal |
Outputs
Parameter | Type | Description |
---|---|---|
type | string | Output format (markdown) |
content | string | Text response to the query |
sql | markdown | Generated SQL query |
dataframe | markdown | Results as a table |
summary | markdown | Summary of the results |
graph | recharts | Visualization of the results |
Example Usage
Prompt: "What are our sales trends by region over the last year? Show me a chart."
Dataset: "sales_analytics"
Output:
- Text explanation of the sales trends
- SQL query used to extract the data
- Table of results with regional sales by month
- Summary highlighting key insights
- Bar or line chart visualizing the trends
Best Practices
- Start with clear, focused questions
- Follow up with more specific questions to drill down
- Ask for specific visualizations when needed
- Provide context in your questions for better results
DbChatV2
The DbChatV2 operator is an enhanced version of DbChat with improved context retention for multi-turn conversations.
Inputs and Outputs
Similar to DbChat, but with enhanced context handling and more concise outputs.
Example Usage
Initial Prompt: "How many new customers did we acquire last month?"
Follow-up: "Break it down by region"
Follow-up: "Which region showed the most growth compared to the previous month?"
Output: Progressive analysis that maintains context across queries
Key Differences from DbChat
- Better memory of previous questions
- More concise output format
- Improved handling of complex follow-up questions
- Doesn't always generate graphs for every response
CreateDataset
The CreateDataset operator creates persistent datasets from dataframes for reuse in other minds or operators.
Inputs
Parameter | Type | Required | Description |
---|---|---|---|
dataframe | string | Yes | Dataframe to convert to a dataset |
dataset_name | string | Yes | Name for the new dataset |
table_name | string | Yes | Name for the table within the dataset |
remarks | string | Yes | Description of the dataset |
trigger | string | No | Optional control signal |
Outputs
Parameter | Type | Description |
---|---|---|
type | string | Output format (table) |
content | string | Confirmation and metadata |
Example Usage
Dataframe: [Result of previous operator]
Dataset_name: "quarterly_analysis"
Table_name: "regional_performance"
Remarks: "Q2 2023 Regional Sales Performance Analysis"
Output: Confirmation of dataset creation with access information
Best Practices
- Use clear, descriptive names for datasets and tables
- Include comprehensive remarks to help others understand the purpose
- Consider access permissions when creating shared datasets
- Use consistent naming conventions for organizational clarity
SQL.HealthCheck
The SQL.HealthCheck operator analyzes databases for data quality issues, schema consistency, and provides insights.
Inputs
Parameter | Type | Required | Description |
---|---|---|---|
dataset | string | Yes | Dataset to analyze |
trigger | string | No | Optional control signal |
Outputs
Parameter | Type | Description |
---|---|---|
type | string | Output format (table) |
content | string | Overall health assessment |
completeness | markdown | Analysis of missing data |
consistency | markdown | Analysis of data consistency |
validity | markdown | Analysis of data validity |
completeness_prompt | markdown | Suggested prompts to address completeness issues |
consistency_prompt | markdown | Suggested prompts to address consistency issues |
validity_prompt | markdown | Suggested prompts to address validity issues |
Example Usage
Dataset: "customer_relationship_db"
Output:
- Overall health score and summary
- Analysis of null values and incomplete records
- Identification of inconsistent data patterns
- Validation against business rules and data types
- Suggested queries to fix or investigate issues
Best Practices
- Run health checks regularly on critical datasets
- Address high-priority issues identified in the report
- Use the suggested prompts as starting points for remediation
- Schedule automated health checks for ongoing monitoring
SQL.Enhance
The SQL.Enhance operator adds additional context to datasets or knowledge bases to improve query performance.
Inputs
Parameter | Type | Required | Description |
---|---|---|---|
type | string | Yes | Type of enhancement (schema, context, example) |
dataset | string | No | Dataset to enhance (if applicable) |
collection | string | No | Collection to enhance (if applicable) |
context | string | Yes | Enhancement content |
trigger | string | No | Optional control signal |
Outputs
Parameter | Type | Description |
---|---|---|
type | string | Output format (markdown) |
content | string | Confirmation and status |
Example Usage
Type: "schema"
Dataset: "financial_reporting"
Context: "The transactions table contains daily transactions with foreign currency amounts. The exchange_rate field represents the conversion rate to USD at the time of transaction. Historical rates can be found in the forex_rates table indexed by date and currency_code."
Output: Confirmation that schema context has been enhanced
Best Practices
- Add business context to technical schemas
- Include common query patterns and their meanings
- Document relationships between tables clearly
- Update enhancements when schemas or use cases change
TextToSQLV3 and TextToSQLV4
Advanced versions of TextToSQL with improved schema understanding, complex query generation, and optimization capabilities.
Key Differences
Feature | TextToSQL | TextToSQLV3 | TextToSQLV4 |
---|---|---|---|
Schema complexity | Basic | Advanced | Enterprise |
Join handling | Simple joins | Multi-table joins | Complex joins with subqueries |
Aggregation | Basic aggregations | Advanced aggregations | Nested aggregations |
Window functions | Limited | Supported | Comprehensive |
Performance optimization | None | Basic | Advanced |
Context retention | Limited | Improved | Full context awareness |
When to Use TextToSQLV4
- For complex enterprise databases
- When dealing with sophisticated data models
- For queries requiring advanced SQL features
- When performance optimization is critical
Connecting SQL Operators
SQL operators are commonly connected in the following patterns:
Basic Query Pipeline:
TextToSQL → SQLExecution → TableToTextSummaryInteractive Analysis:
DbChat (standalone)Advanced Analysis with Visualization:
TextToSQL → SQLExecution → [TableToGraph, TableToTextSummary]Dataset Creation Pipeline:
TextToSQL → SQLExecution → CreateDatasetHealth Check and Enhancement Loop:
SQL.HealthCheck → TextToSQL → SQLExecution → SQL.Enhance
Best Practices for SQL Operators
Security Considerations
- Always use parameterized queries when possible
- Be aware of SQL injection risks with user inputs
- Apply appropriate access controls to databases
Performance Optimization
- Limit result sets to necessary data
- Use filters early in query chains
- Consider indexing strategies in source databases
- Monitor query execution times
Error Handling
- Handle potential errors in your mind flow
- Provide fallbacks for failed database connections
- Validate inputs before sending to database
Maintenance and Documentation
- Document the purpose of each SQL operator
- Comment complex queries for future reference
- Update schema enhancements when databases change
- Regularly review and optimize database access patterns
Next Steps
Explore how SQL operators can be combined with Table Operators for comprehensive data analysis and visualization.
Overview | Operator Categories | Table Operators | Document Operators