journal article·2025-10-16Open access

DKASQL: Dynamic Knowledge Adaptation for Domain-Specific Text-to-SQL

Huaxing Bian, Guanrong Li, Yifan Wang, Qinghan Fu, Jian Shen, Xixian Yao, Zhen Wu

Applied Sciences· Volume 15· Issue 20

Abstract

Text2SQL aims to translate natural language queries into structured query language (SQL). LLM-based Text2SQL methods have gradually become mainstream because of their strong capabilities in language understanding and transformation. However, in real-world scenarios with non-public or limited data resources, these methods still face challenges such as insufficient domain knowledge, SQL generation that violates domain-specific constraints, and even hallucination issues. To address these challenges, this paper proposes DKASQL, a domain-specific Text2SQL method based on dynamic knowledge adaptation. The approach features an extraction module, a generation module, and an LLM-based verification module. Through an iterative “extraction–verification” and “generation–verification” mechanism, it dynamically updates the required knowledge, effectively improving both domain knowledge acquisition and the alignment between generated SQL and domain knowledge. To enhance efficiency, DKASQL also incorporates a memory storage mechanism that automatically retains commonly used domain knowledge to reduce iteration overhead. Experiments on the open-source multi-domain dataset BIRD and the ElecSQL dataset collected from the power-grid supply-chain domain show that DKASQL achieves significant performance improvements. With 7B and 32B base models, DKASQL achieves performance comparable to much larger models such as GPT-4o mini and DeepSeek-V3, with less computational overhead. For instance, on ElecSQL, DKASQL improves the execution success rate (ESR) by up to +26.9% and the result accuracy (RA) by up to +8.8% over GPT-4o mini, highlighting its effectiveness in domain-specific Text2SQL tasks.
Source: crossref · Quality: baseline

Research context

OpenAlex topics: Semantic Web and Ontologies · Advanced Database Systems and Queries · Topic Modeling

SciVX discovery tags are terminology-based. OpenAlex topics are source-provided classifications.

Affiliations

Material Branch, State Grid Jiangsu Electric Power Co., Ltd., Nanjing 211103, China

School of Artificial Intelligence, Nanjing University, Nanjing 210093, China

Funding

Science and Technology Project of State Grid Jiangsu Electric Power Co., Ltd.

References (33)

Show source-provided references
1. Sutskever, I., Vinyals, O., and Le, Q.V. (2014, January 8–13). Sequence to sequence learning with neural networks. Proceedings of the 28th International Conference on Neural Information Processing Systems—Volume 2, Montreal, QC, Canada. NIPS’14.
2. Zhong, V., Xiong, C., and Socher, R. (2017). Seq2sql: Generating structured queries from natural language using reinforcement learning. arXiv.
3. Xu, X., Liu, C., and Song, D. (2017). Sqlnet: Generating structured queries from natural language without reinforcement learning. arXiv.
4. Yu, T., Li, Z., Zhang, Z., Zhang, R., and Radev, D. (2018). TypeSQL: Knowledge-Based Type-Aware Neural Text-to-SQL Generation. Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers), Association for Computational Linguistics.10.18653/v1/N18-2093 ↗
5. Language models are few-shot learners
6. Touvron, H., Lavril, T., Izacard, G., Martinet, X., Lachaux, M.A., Lacroix, T., Rozière, B., Goyal, N., Hambro, E., and Azhar, F. (2023). Llama: Open and efficient foundation language models. arXiv.
7. Du, Z., Qian, Y., Liu, X., Ding, M., Qiu, J., Yang, Z., and Tang, J. (2021). Glm: General language model pretraining with autoregressive blank infilling. arXiv.10.18653/v1/2022.acl-long.26 ↗
8. Zhou, F., Xue, S., Qi, D., Shi, W., Zhao, W., Wei, G., Zhang, H., Jiang, C., Jiang, G., and Chu, Z. (2024). DB-GPT-Hub: Towards Open Benchmarking Text-to-SQL Empowered by Large Language Models. arXiv.
9. Wang, Z., Zhang, R., Nie, Z., and Kim, J. (2024). Tool-assisted agent on sql inspection and refinement in real-world scenarios. arXiv.
10. Can llm already serve as a database interface? a big bench for large-scale database grounded text-to-sqls
11. Iyer, S., Konstas, I., Cheung, A., Krishnamurthy, J., and Zettlemoyer, L. (August, January 30). Learning a Neural Semantic Parser from User Feedback. Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics 2017, Vancouver, BC, Canada.10.18653/v1/P17-1089 ↗
12. Wang, B., Shin, R., Liu, X., Polozov, O., and Richardson, M. (2020, January 5–10). RAT-SQL: Relation-Aware Schema Encoding and Linking for Text-to-SQL Parsers. Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, Online.10.18653/v1/2020.acl-main.677 ↗
13. Hwang, W., Yim, J., Park, S., and Seo, M. (2019). A comprehensive exploration on wikisql with table-aware word contextualization. arXiv.
14. Cao, R., Chen, L., Chen, Z., Zhao, Y., Zhu, S., and Yu, K. LGESQL: Line Graph Enhanced Text-to-SQL Model with Mixed Local and Non-Local Relations. Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers).
15. Zhan, Y., Sun, Y., Weng, H., Cui, L., Wang, G., Xie, J., Tian, Y., Yin, X., Liu, B., and Huang, D. (2024). FuncEvalGMN: Evaluating Functional Correctness of SQL via Graph Matching Network. arXiv.
16. Ryansql: Recursively applying sketch-based slot fillings for complex text-to-sql in cross-domain databases
17. Maamari, K., Abubaker, F., Jaroslawicz, D., and Mhedhbi, A. (2024, January 14). The Death of Schema Linking? Text-to-SQL in the Age of Well-Reasoned Language Models. Proceedings of the NeurIPS 2024 Third Table Representation Learning Workshop, Vancouver, BC, Canada.
18. Achiam, J., Adler, S., Agarwal, S., Ahmad, L., Akkaya, I., Aleman, F.L., Almeida, D., Altenschmidt, J., Altman, S., and Anadkat, S. (2023). Gpt-4 technical report. arXiv.
19. Codes: Towards building open-source language models for text-to-sql
20. Dong, X., Zhang, C., Ge, Y., Mao, Y., Gao, Y., Lin, J., and Lou, D. (2023). C3: Zero-shot text-to-sql with chatgpt. arXiv.
21. Din-sql: Decomposed in-context learning of text-to-sql with self-correction
22. Chen, X., Lin, M., Schaerli, N., and Zhou, D. (2023, January 9–14). Teaching Large Language Models to Self-Debug. Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics, Toronto, ON, Canada.
23. Thorpe, D.G., Duberstein, A.J., and Kinsey, I.A. (2024). Dubo-SQL: Diverse Retrieval-Augmented Generation and Fine Tuning for Text-to-SQL. arXiv.
24. Talaei, S., Pourreza, M., Chang, Y.C., Mirhoseini, A., and Saberi, A. (2024). Chess: Contextual harnessing for efficient sql synthesis. arXiv.
25. Lee, D., Park, C., Kim, J., and Park, H. (2025, January 19–24). MCS-SQL: Leveraging Multiple Prompts and Multiple-Choice Selection For Text-to-SQL Generation. Proceedings of the 31st International Conference on Computational Linguistics, Abu Dhabi, United Arab Emirates.
26. Wang, B., Ren, C., Yang, J., Liang, X., Bai, J., Chai, L., Yan, Z., Zhang, Q.W., Yin, D., and Sun, X. (2025, January 19–24). MAC-SQL: A Multi-Agent Collaborative Framework for Text-to-SQL. Proceedings of the 31st International Conference on Computational Linguistics, Abu Dhabi, United Arab Emirates.
27. Chen, J., Xiao, S., Zhang, P., Luo, K., Lian, D., and Liu, Z. (2024). BGE M3-Embedding: Multi-Lingual, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation. arXiv.10.18653/v1/2024.findings-acl.137 ↗
28. Team, Q. (2024). Qwen2 technical report. arXiv.
29. Guo, D., Yang, D., Zhang, H., Song, J., Zhang, R., Xu, R., Zhu, Q., Ma, S., Wang, P., and Bi, X. (2025). Deepseek-r1: Incentivizing reasoning capability in llms via reinforcement learning. arXiv.
30. Liu, A., Feng, B., Xue, B., Wang, B., Wu, B., Lu, C., Zhao, C., Deng, C., Zhang, C., and Ruan, C. (2024). Deepseek-v3 technical report. arXiv.
31. Hurst, A., Lerer, A., Goucher, A.P., Perelman, A., Ramesh, A., Clark, A., Ostrow, A., Welihinda, A., Hayes, A., and Radford, A. (2024). Gpt-4o system card. arXiv.
32. Large language models are zero-shot reasoners
33. Pourreza, M., Li, H., Sun, R., Chung, Y., Talaei, S., Kakkar, G.T., Gan, Y., Saberi, A., Ozcan, F., and Arik, S.O. (2024). Chase-sql: Multi-path reasoning and preference optimized candidate selection in text-to-sql. arXiv.