The proliferation of Large Language Models (LLMs) has transformed natural language interaction with databases, enabling the conversion of complex questions into structured queries. However, most existing Text-to-SQL models are optimized for a single dialect, such as MySQL. In modern cloud environments, services often require support for a diverse array of database languages, ranging from relational standards like PostgreSQL to graph-based languages like Cypher and nGQL. Training a single dense model on multiple dialects frequently leads to performance degradation due to syntactic interference and data imbalance.
To address these challenges, the MoMQ framework introduces a Mixture-of-Experts (MoE) approach specifically designed for multi-dialect query generation across both relational and non-relational databases.
The Challenge: Dialect Interference and Data Imbalance
Developing a "polyglot" model for database queries faces two primary obstacles:
- Dialect Interference: Different database management systems (DBMS) often use conflicting syntaxes for identical logical operations. For instance, while MySQL uses
SELECT, graph databases like Cypher useMATCH. Standard fine-tuning on mixed datasets can cause "syntactic confusion," where the model generates invalid hybrid queries. - Data Imbalance: High-resource dialects like MySQL benefit from vast datasets, whereas niche languages like NebulaGraph's nGQL suffer from a lack of training data. This imbalance often leads models to overfit on popular dialects while failing to generalize to low-resource ones.
The MoMQ Framework
MoMQ leverages a Mixture-of-Experts architecture implemented via Low-Rank Adaptation (LoRA) modules. This "MoE-peft" strategy is computationally efficient, allowing a base LLM to be specialized for multiple tasks without the overhead of training a massive MoE model from scratch.
Architectural Innovation
The core of MoMQ lies in its hierarchical expert organization and routing mechanism:
- Dialect Expert Groups: Dedicated groups of experts are assigned to each dialect (MySQL, PostgreSQL, Cypher, nGQL). This isolation allows the model to capture dialect-specific syntax without interference from other languages.
- Shared Expert Group: A set of experts accessible to all dialects captures "common knowledge," such as natural language understanding and general schema mapping logic. This facilitates knowledge transfer from high-resource to low-resource dialects.
- Multi-Level Routing: A Dialect Router first directs tokens to the appropriate dialect group using a "dialect smoothing" technique, which allows common tokens (e.g.,
LIMIT,ORDER BY) to be processed by multiple groups. Within each group, an Expert Router selects the top-k experts for the specific input.
Experimental Evaluation
The authors evaluated MoMQ using a newly constructed multi-dialect benchmark covering four distinct languages: MySQL, PostgreSQL (PG), Cypher, and nGQL. The dataset includes 3,000 training samples per dialect, converted from established benchmarks like Spider and BIRD.
MoMQ was tested against standard full fine-tuning and vanilla LoRA across three model backbones: Qwen2-1.5B, Qwen2-7B, and Qwen1.5-14B.
Results and Discussion
The experimental results demonstrate that MoMQ consistently outperforms baseline methods across all tested dialects and model sizes.
Key findings include:
- Performance Gains: MoMQ improved execution accuracy (EX) by an average of 3-5% compared to full fine-tuning and LoRA baselines.
- Robustness to Imbalance: In scenarios with imbalanced data, MoMQ showed a significant advantage, improving accuracy for low-resource dialects by up to 6%.
- Knowledge Transfer: Analysis of expert activation patterns confirms that the model successfully performs token-level knowledge transfer, utilizing shared experts to bridge the gap between different database paradigms.
Conclusion
MoMQ represents a significant step forward in multi-dialect query generation. By isolating dialect-specific syntax while sharing core logical knowledge through a Mixture-of-Experts framework, it effectively mitigates interference and leverages cross-dialect commonalities. While challenges remain in bridging the structural gap between relational and graph logic, MoMQ provides a scalable and efficient solution for building versatile, multi-lingual database interfaces.
Summary updated