Introduction
While Text-to-SQL (NL2SQL) technologies have advanced significantly, translating natural language into a database query represents only a fraction of the end-to-end data science lifecycle. In industrial settings, users require comprehensive analysis, interactive visualizations, and predictive forecasting rather than simple tabular outputs. Current systems often suffer from fragmentation, high domain adaptation costs, and context window constraints when dealing with massive industrial schemas.
SageCopilot is an industry-grade system designed to bridge these gaps. It automates the entire data science workflow using a dual-phase LLM-agent framework that integrates automated data augmentation, self-reflecting error correction, and a hybrid retrieval strategy.
System Architecture: The Dual-Phase Framework
SageCopilot utilizes a dual-phase architecture to maintain high execution accuracy without the need for expensive domain-specific fine-tuning.
1. Offline Phase: Preparation and Memory Building
Instead of supervised fine-tuning (SFT), which is costly and prone to catastrophic forgetting, SageCopilot builds a "memory" of high-quality examples:
- SQL2NL: To address "cold start" issues, the system uses an LLM to generate natural language questions from existing SQL queries, creating a synthetic training set.
- Data Augmentation: Semantic-preserving techniques generate query variations, ensuring robustness against diverse user phrasing.
- Schema Linking: Relationships between queries and specific database fields are extracted and stored in a vector database for efficient retrieval.
2. Online Phase: Agentic Execution
When a user submits a query, the system follows an agentic workflow:
- Hybrid Recall: Standard vector search often fails on critical domain-specific terms. SageCopilot employs Slot Feature Extraction (SFE) to isolate key terms and find relevant "kernel" examples.
- SQL Reflection: A dedicated module scrutinizes generated SQL for syntax or logic errors, allowing the LLM to self-correct before execution.
- Multi-modal Output: The system generates interactive eCharts visualizations and utilizes the Prophet model for time-series forecasting.
Technical Innovations: Hybrid Recall and Self-Correction
A core challenge identified by the authors is that standard embedding-based retrieval often misses short but vital domain terms, such as "closure rate."
The Slot Feature Extraction (SFE) strategy forces the model to attend to these "slots," significantly improving retrieval accuracy for keyword-dependent queries. Furthermore, the SQL Reflection module demonstrates that LLMs are frequently more effective at correcting their own mistakes when provided with explicit error descriptions than achieving perfect one-shot generation.
Evaluation and Results
The system was evaluated on the DuSQL dataset and a proprietary Real Traffic Dataset from Baidu Inc., which reflects industrial-level complexity.
- Execution Accuracy (EX): SageCopilot achieved 72.6% EX on the Real Traffic Dataset.
- Ablation Studies: The SQL Reflection module provided a 15% accuracy boost, while SFE improved performance by 7% on tricky queries.
- Domain Adaptation: SQL2NL-enhanced examples increased accuracy in specific domains (e.g., supermarket data) from 56.2% to 81.3%.
Conclusion and Future Directions
SageCopilot demonstrates that an agentic, dual-phase approach can effectively automate complex data science tasks in industrial environments. While highly successful in single-query scenarios, challenges remain in multi-round conversation complexity and the refinement of automated chart selection logic. Future work will focus on improving intent understanding for long-running dialogues and enhancing the depth of multi-modal analysis.
Summary updated