计算机科学 ›› 2026, Vol. 53 ›› Issue (6A): 250900107-7.doi: 10.11896/jsjkx.250900107

• 人工智能 • 上一篇    下一篇

思维链与检索增强结合的Text-to-SQL方法研究

胥亚飞1, 刘传有2, 刘少华1   

  1. 1 海军工程大学 武汉 430000
    2 广州资金集中收付管理中心 广州 510000
  • 出版日期:2026-06-16 发布日期:2026-06-12
  • 通讯作者: 胥亚飞(564639715@qq.com)

Study on Text-to-SQL Approach Integrating Chain-of-Thought Reasoning with Retrieval Augmentation

XU Yafei1, LIU Chuanyou2, LIU Shaohua1   

  1. 1 Naval University of Engineering,Wuhan 430000,China
    2 Guangzhou Cash Concentration and Payment Management Center,Guangzhou 510000,China
  • Published:2026-06-16 Online:2026-06-12
  • About author:XU Yafei,born in 1990,postgraduate.His main research interests include financial informatization and artificial intelligence.

摘要: Text-to-SQL技术可将自然语言自动转换为SQL,大幅降低非专业人员使用数据库的门槛,但在财务等垂直领域仍面临查询意图复杂、表述模糊两大难题。为此,提出“思维链+检索增强”协同框架。首先设计迭代蒸馏算法,利用3B小模型在Spider,BIRD,BookSQL上自动生成并验证2万余条含详细推理步骤的高质量思维链种子数据,显著弥补小模型复杂推理短板;其次,创新提出“问题骨架+SQL骨架”双向量检索机制,剔除表名列名干扰,将历史相似查询及隐含语义作为示例动态拼入提示,实现领域模糊表述精准对齐。实验表明,仅3B参数的Qwen2.5-Coder在Spider-dev达86.5%执行准确率,达到GPT-4等强模型的效果;在更复杂的BIRD-dev达59.6%,超越众多大模型;在自建Financial财务数据集达81.2%,领先现有方法超1个百分点。该方法以低成本、小参数实现了复杂且模糊自然语言查询的高精度SQL生成。

关键词: 财务信息化系统, 人工智能, 自然语言处理, Text-to-SQL, 大语言模型

Abstract: Text-to-SQL technology enables the automatic conversion of natural language into SQL,significantly lowering the barrier for non-experts to interact with databases.However,in vertical domains such as finance,it still faces two major challenges:complex query intents and ambiguous expressions.To address these,this paper proposes a collaborative framework that integrates Chain-of-Thought reasoning with retrieval augmentation.Firstly,it designs an iterative distillation algorithm that leverages a compact 3-billion-parameter model to automatically generate and verify over 20 000 high-quality Chain-of-Thought seed examples with detailed reasoning steps on the Spider,BIRD,and BookSQL datasets,effectively compensating for the limitations of small models in complex reasoning tasks.Secondly,it introduces an innovative dual-vector retrieval mechanism based on “question ske-letons” and “SQL skeletons” to eliminate interference from table and column names,dynamically incorporating historically similar queries and implicit semantics as examples within prompts,thereby achieving precise alignment of ambiguous domain-specific expressions.Experimental results demonstrate that Qwen2.5-Coder,with only 3 billion parameters,attains 86.5% execution accuracy on Spider-dev—comparable to powerful models such as GPT-4,achieves 59.6% on the more challenging BIRD-dev,outperforming many larger models,and reaches 81.2% on a proprietary financial dataset,exceeding existing methods by over 1 percentage point.This approach delivers high-precision SQL generation for complex and ambiguous natural language queries at low cost and with a relatively small model size.

Key words: Financial information systems, Artificial intelligence, Natural language processing, Text-to-SQL, Large-scale language models

中图分类号: 

  • TP391
[1] LIU X Y,SHEN S Y,LI B Y,et al.A Survey of NL2SQL with Large Language Models:Where are we,and where are we going?[J].arXiv:2408.05109,2024.
[2] GEORGE K,GEORGIA K.A survey on deep learning approaches for text-to-SQL[J].The VLDB Journal,2023,32(4):905-936.
[3] JOSH A,ADLER S,AGARWAL S,et al.Gpt-4 technical report [J].arXiv:2303.08774,2023.
[4] HUGO T,LAVRIL T,LZACARD G,et al.Llama:Open and efficient foundation language models [J].arXiv:2302.13971,2023.
[5] GAN,Y J,CHEN X Y,XIE J X,et al.Natural SQL:Making SQL easier to infer from natural language specifications [C]//Findings of the Association for Computational Linguistics.2021:2030-2042.
[6] TORSTEN S,NATHAN S,DZMITRY B.PICARD:Parsing incrementally for constrained auto-regressive decoding from language models [C]//Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing.2021:0895-9901.
[7] ILYA S,ORIOL V,QUOC V L.Sequence to sequence learning with neural networks [C]//Advances in Neural Information Processing.2014:1-9.
[8] DONG Q X,LI L,DAI D M,et al.A survey on in-context lear-ning[C]//Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing.2024:1107-1128.
[9] WANG B,REN C Y,YANG J,et al.Mac-sql:A multi-agent collaborative framework for text-to-sql [C]//Proceedings of the 31st International Conference on Computational Linguistics.2025:540-557.
[10] POURREZA M,DAVOOD R.Din-sql:Decomposed in-contextlearning of text-to-sql with self-correction [C]//Advances in Neural Information Processing Systems.2023:36339-36348.
[11] JACOB D,CHANG M W,LEE K,et al.Bert:Pre-training of deep bidirectional transformers for language understanding [C]//Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics:Human Language Technologies.2019:4171-4186.
[12] TAO Y,ZHANG R,YANG K,et al.Spider:A large-scale human-labeled dataset for complex and cross-domain semantic parsing and text-to-sql task [C]//2018 Conference on Empirical Methods in Natural Language Processing.EMNLP,2018:3911-3921.
[13] WANG B,SHIN R,LIU X D,et al.Rat-sql:Relation-awareschema encoding and linking for text-to-sql parsers [C]//Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics.2020:7567-7578.
[14] FRANCO S,GORI M,TSOI A C,et al.The graph neural network model [J].IEEE Transactions on Neural Networks,2008,20(1):61-80.
[15] LI H Y,ZHANG J,LIU H B,et al.Codes:Towards buildingopen-source language models for text-to-sql [C]//Proceedings of the ACM on Management of Data.2024:1-28.
[16] LI R,LOUBNA B A,ZI Y T,et al.Starcoder:may the source be with you![J].arXiv:2305.06161,2023.
[17] GAO D W,WANG H B,LI Y L,et al.Text-to-sql empowered by large language models:A benchmark evaluation [C]//Proceedings of the VLDB Endowment.2024:1132-1145.
[18] DONG X M,ZHANG C,GE Y H,et al.C3:Zero-shot text-to-sql with chatgpt[J].arXiv:2307.07306,2023.
[19] CUI Y M,CHE W X,LIU T,et al.Pre-training with wholeword masking for chinesebert[J].IEEE/ACM Transactions on Audio,Speech,and Language Processing,2021(29):3504-3514.
[20] GAN Y J,CHEN X Y,HUANG Q P,et al.Towards robustness of text-to-SQL models against synonym substitution[J].arXiv:2106.01065,2021.
[21] DENG X,AHMED H A,CHRISTOPHER M,et al,Structure-grounded pretraining for text-to-sql[J].arXiv:2010.12773,2020.
[22] GAO D W,WANG H B,LI Y L,et al.Text-to-sql empowered by large language models:A benchmark evaluation[J].arXiv:2308.15363,2023.
[23] WEI J,WANG X Z,DALE S,et al.Chain-of-thought prompting elicits reasoning in large language models[C]//Advances in Neural Information Processing Systems.2022:24824-24837.
[24] KUMAR R,AMAR R D,SHRUTENDRA H,et al.Booksql:A large scale text-to-sql dataset for accounting domain[J].arXiv:2406.07860,2024.
[25] LI H Y,WU S,ZHANG X K,et al.Omnisql:Synthesizing high-quality text-to-sql data at scale[J].arXiv:2503.02240,2025.
[26] POURREZA M,DAVOOD R.Dts-sql:Decomposed text-to-sql with small large language models[J].arXiv:2402.01117,2024.
[27] YANG J X,HUI B Y,YANG M,et al.Synthesizing text-to-SQL data from weak and strong LLMs[C]//Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics.2024:7864-7875.
Viewed
Full text


Abstract

Cited

  Shared   
  Discussed   
No Suggested Reading articles found!