text2ql: Multi-Target Natural Language Querying via a Language-Agnostic Intermediate Representation
作者: Ritesh Kumar
分类: cs.CL, cs.AI, cs.DB
发布日期: 2026-09-02
💡 一句话要点
提出text2ql以解决自然语言查询数据库的结构性限制
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 自然语言处理 数据库查询 中间表示 可插拔架构 执行准确率 机器学习 智能系统
📋 核心要点
- 现有自然语言查询数据库的方法存在结构性限制,主要依赖于SQL且缺乏语义正确性判断。
- text2ql通过引入语言无关的中间表示和可插拔的渲染器架构,解决了对LLM的依赖和执行准确性问题。
- 实验结果显示,确定性模式在100个测试案例中实现100%执行准确率,LLM模式在精确匹配和执行准确率上也有显著提升。
📝 摘要(中文)
自然语言接口在数据库查询中存在三大结构性限制:仅支持关系型SQL、对大型语言模型(LLM)推理的无条件依赖,以及缺乏运行时信号以判断生成查询的语义正确性。本文提出了text2ql,一个开源的Python框架,通过语言无关的中间表示(QueryIR)和可插拔的渲染器架构,解决了这三大限制。该框架的七阶段检测管道同时支持SQL和GraphQL目标,零LLM确定性模式在中位延迟3.2毫秒下实现100%执行准确率,且每个生成的查询都携带一个在[0.15, 0.97]范围内的运行时置信度分数。通过对Spider和BIRD基准的50个查询随机样本进行评估,LLM支持模式实现62-70%的精确匹配和84-91%的执行准确率,而确定性模式在所有100个测试案例中实现100%执行准确率且无解析错误。
🔬 方法详解
问题定义:本文旨在解决自然语言接口在数据库查询中的结构性限制,现有方法主要依赖SQL,且在查询生成时无法判断语义的正确性。
核心思路:通过引入语言无关的中间表示(QueryIR)和可插拔的渲染器架构,text2ql能够同时支持SQL和GraphQL查询,减少对大型语言模型的依赖。
技术框架:text2ql的整体架构包括一个七阶段的检测管道,能够处理不同类型的查询,并在生成查询时提供运行时置信度分数。
关键创新:最重要的创新在于引入了零LLM确定性模式,该模式在中位延迟3.2毫秒内实现100%执行准确率,且每个查询都附带置信度评分,显著提高了查询的可靠性。
关键设计:在设计中,采用了加法信号模型来计算运行时置信度分数,并通过schema-aware prompting技术提升了精确匹配率,带来了+18.4个百分点的提升。
🖼️ 关键图片
📊 实验亮点
实验结果显示,text2ql的确定性模式在所有100个测试案例中实现了100%的执行准确率,且无解析错误。LLM支持模式在精确匹配率上达到了62-70%,执行准确率为84-91%。此外,schema-aware prompting技术显著提升了精确匹配率,带来了+18.4个百分点的提升。
🎯 应用场景
text2ql的潜在应用场景包括智能数据库查询、自然语言处理系统以及数据分析工具等。其创新的查询生成方式和高准确率的特性使其在实际应用中具有重要价值,能够提升用户与数据库交互的效率和准确性。
📄 摘要(原文)
Natural language interfaces to databases have traditionally suffered from three structural limitations: exclusive targeting of relational SQL, unconditional dependence on large language model (LLM) inference at query time, and absence of any runtime signal when generated queries are semantically incorrect. This paper presents text2ql, an open-source Python framework that addresses all three limitations through a language-agnostic Intermediate Representation (QueryIR) and a pluggable renderer architecture. A single seven-stage detection pipeline serves both SQL and GraphQL targets; a zero-LLM deterministic mode delivers 100% execution accuracy at a median latency of 3.2 ms with no API cost; and every generated query carries a runtime confidence score in [0.15, 0.97] computed from an additive signal model. Evaluated on 50-query random samples from the Spider and BIRD benchmarks (indicative results; full-set evaluation is planned), the LLM-backed mode achieves 62-70% exact match and 84-91% execution accuracy; the deterministic mode achieves 100% execution accuracy with zero parse errors across all 100 test cases. An ablation study isolates schema-aware prompting as the dominant accuracy lever, contributing +18.4 percentage points of exact-match gain over the schema-free baseline on both benchmarks. text2ql is publicly available at https://pypi.org/project/text2ql/ under the Apache 2.0 license.