SQLAgent: 作为数据工程师在生成前学习探索
SQLAgent: Learning to Explore Before Generating as a Data Engineer
AI总结:
SQLAgent通过两阶段框架实现数据库探索与查询生成解耦,利用蒙特卡洛树搜索策略构建知识库,并通过双代理系统提升SQL查询准确性。
摘要:
大型语言模型最近在推理和代码生成方面展示了令人印象深刻的 capabilities,使其成为关系数据库自然语言接口的有前景工具。然而,现有方法在复杂的真实世界环境中往往无法泛化,因为SQL推理高度数据库特定,需要深入熟悉独特的模式、模糊的语义和复杂的连接路径。为了解决这一挑战,我们介绍了一种新颖的两阶段基于LLM的框架,将知识获取与查询生成解耦。在探索阶段,系统通过受蒙特卡洛树搜索启发的策略自主构建数据库特定的知识库,生成模式片段、可执行查询和自然语言描述作为使用示例。在部署阶段,双代理系统利用收集的知识作为上下文示例,迭代检索相关信息并生成准确的SQL查询以响应用户问题。这种设计使代理能够主动熟悉未见过的数据库并处理复杂的多步推理。在大规模基准上的大量实验表明,我们的方法在强基线之上显著提高了准确性,突显了其有效性和泛化能力。
英文摘要:
Large Language Models have recently shown impressive capabilities in reasoning and code generation, making them promising tools for natural language interfaces to relational databases. However, existing approaches often fail to generalize in complex, real-world settings due to the highly database-specific nature of SQL reasoning, which requires deep familiarity with unique schemas, ambiguous semantics, and intricate join paths. To address this challenge, we introduce a novel two-stage LLM-based framework that decouples knowledge acquisition from query generation. In the Exploration Stage, the system autonomously constructs a database-specific knowledge base by navigating the schema with a Monte Carlo Tree Search-inspired strategy, generating triplets of schema fragments, executable queries, and natural language descriptions as usage examples. In the Deployment Stage, a dual-agent system leverages the collected knowledge as in-context examples to iteratively retrieve relevant information and generate accurate SQL queries in response to user questions. This design enables the agent to proactively familiarize itself with unseen databases and handle complex, multi-step reasoning. Extensive experiments on large-scale benchmarks demonstrate that our approach significantly improves accuracy over strong baselines, highlighting its effectiveness and generalizability.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。