In the field of Natural Language Processing (NLP), the Text-to-SQL technology is rapidly evolving. This technology enables ordinary users to query databases using natural language without needing to master SQL, a specialized programming language. However, as database structures become increasingly complex, accurately converting natural language into SQL commands poses a significant challenge.

Recent research teams from South China University of Technology and Tsinghua University have proposed a novel solution — MAG-SQL (Multi-Agent Generation Model), aimed at enhancing the effectiveness of Text-to-SQL. This method leverages multiple intelligent agents working collaboratively to improve the accuracy of SQL generation.

The working principle of MAG-SQL is quite ingenious. Its core components include the "Soft Schema Linker," "Target-Condition Decomposer," "Sub-SQL Generator," and "Sub-SQL Corrector." Initially, the Soft Schema Linker filters out the most relevant database columns for the query, reducing unnecessary information interference and enhancing the accuracy of the generated SQL commands. Subsequently, the Target-Condition Decomposer breaks down complex queries into smaller sub-queries for easier handling.

image.png

Following this, the Sub-SQL Generator creates sub-SQL queries based on previous results, ensuring that SQL commands are refined step-by-step. Finally, the Sub-SQL Corrector is responsible for correcting any errors in the generated SQL, further enhancing overall accuracy. This multi-step processing approach allows MAG-SQL to perform exceptionally well with complex databases.

In recent tests, MAG-SQL has shown impressive results on the BIRD dataset. When using the GPT-4 model, the system achieved an execution accuracy of 61.08%, significantly outperforming the traditional GPT-4's 46.35%. Even with the GPT-3.5 model, MAG-SQL's accuracy reached 57.62%, surpassing the previous MAC-SQL method. Additionally, MAG-SQL performed excellently on another complex dataset, Spider, demonstrating its good versatility.

The introduction of MAG-SQL not only enhances the accuracy of Text-to-SQL but also provides new insights for solving complex queries. This multi-agent framework, through iterative refinement, greatly enhances the capabilities of large language models in practical applications, especially when dealing with complex databases and high-difficulty queries.

Paper link: https://arxiv.org/pdf/2408.07930

Key points:

📊 Accuracy Improvement: MAG-SQL achieved an execution accuracy of 61.08% on the BIRD dataset, far exceeding the traditional GPT-4's 46.35%.

🔍 Multi-Agent Collaboration: This method utilizes multiple agents to work collaboratively, making the SQL generation process more efficient and accurate.

💡 Broad Application Potential: MAG-SQL performed well on other datasets like Spider, indicating its good usability and applicability.