The complexity of SQL and the spatial semantics of PostGIS create barriers for non-experts working with spatial data. Although large language models can translate natural language into SQL, spatial Text-to-SQL is more error-prone than general Text-to-SQL because it must resolve geographic intent, schema ambiguity, geometry-bearing tables and columns, spatial function choice, and coordinate reference system and measurement assumptions. We introduce a multi-agent framework that addresses these coupled challenges through staged interpretation, schema grounding, logical planning, SQL generation, and execution-based review. The framework is supported by a knowledge base with programmatic schema profiling, semantic enrichment, and embedding-based retrieval. We evaluated the framework on the non-spatial KaggleDBQA benchmark and on SpatialQueryQA, a new multi-level and coverage-oriented benchmark with diverse geometry types, workload categories, and spatial operations. On KaggleDBQA, the system reached 81.2% accuracy, 221 of 272 questions, after reviewer corrections. On SpatialQueryQA, the system achieved 87.7% accuracy, 79 of 90, compared with 76.7% without the review stage. These results show that decomposing the task into specialized but tightly coupled agents improves robustness, especially for spatially sensitive queries. The study improves access to spatial analysis and provides a practical step toward more reliable spatial Text-to-SQL systems and autonomous GIS.
翻译:SQL的复杂性和PostGIS的空间语义为非专业用户处理空间数据设置了障碍。尽管大语言模型能将自然语言翻译为SQL,但空间文本转SQL比通用文本转SQL更易出错,因为需要解析地理意图、模式歧义、包含几何数据的表和列、空间函数选择,以及坐标参考系和测量假设。我们提出了一种多智能体框架,通过分阶段解释、模式锚定、逻辑规划、SQL生成和执行反馈来解决这些耦合挑战。该框架由包含程序化模式分析、语义增强和基于嵌入检索的知识库支撑。我们在非空间KaggleDBQA基准测试和新构建的多层级、全覆盖基准测试SpatialQueryQA(涵盖多样几何类型、工作负载类别和空间操作)上评估了该框架。在KaggleDBQA上,经反馈修正后系统准确率达81.2%(272题中答对221题)。在SpatialQueryQA上,系统准确率达87.7%(90题中答对79题),而未使用反馈阶段时准确率为76.7%。结果表明,将任务分解为专业化但紧密耦合的智能体可提升鲁棒性,尤其适用于敏感的空间查询。本研究提升了空间分析的可及性,并为构建更可靠的空间文本转SQL系统和自主GIS迈出了实践性一步。