让AI在未知数据库下也能准确写SQL,靠的是边查边学的强化学习方法。
TRUST-SQL: Tool-Integrated Multi-Turn Reinforcement Learning for Text-to-SQL over Unknown Schemas
- 用四阶段协议逐步验证数据库元信息,避免盲目推理。
- 相比标准方法,40亿和80亿参数模型分别提升30.6%和16.6%准确率。
- 无需预先加载表结构,适合真实企业复杂数据库场景。
文本转SQL在完整模式假设下已取得显著进展,但在真实企业环境中,数据库包含数百张表且元数据混乱,该假设不成立。本文研究未知模式场景,提出TRUST-SQL(基于工具的多轮强化学习框架)。将任务建模为部分可观测马尔可夫决策过程,智能体采用结构化四阶段协议,基于已验证元信息进行推理。关键创新是双轨GRPO策略,通过词级别掩码优势分离探索奖励与执行结果,解决信用分配问题,相较标准GRPO提升9.9%相对性能。在五个基准测试上,4B与8B模型平均绝对提升分别为30.6%和16.6%。尽管不依赖预加载元数据,其性能仍持续匹配或超越依赖模式填充的强基线。
原文摘要 · Abstract (English)
Text-to-SQL parsing has achieved remarkable progress under the Full Schema Assumption. However, this premise fails in real-world enterprise environments where databases contain hundreds of tables with massive noisy metadata. Rather than injecting the full schema upfront, an agent must actively identify and verify only the relevant subset, giving rise to the Unknown Schema scenario we study in this work. To address this, we propose TRUST-SQL (Truthful Reasoning with Unknown Schema via Tools). We formulate the task as a Partially Observable Markov Decision Process where our autonomous agent employs a structured four-phase protocol to ground reasoning in verified metadata. Crucially, this protocol provides a structural boundary for our novel Dual-Track GRPO strategy. By applying token-level masked advantages, this strategy isolates exploration rewards from execution outcomes to resolve credit assignment, yielding a 9.9% relative improvement over standard GRPO. Extensive experiments across five benchmarks demonstrate that TRUST-SQL achieves an average absolute improvement of 30.6% and 16.6% for the 4B and 8B variants respectively over their base models. Remarkably, despite operating entirely without pre-loaded metadata, our framework consistently matches or surpasses strong baselines that rely on schema prefilling.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。