Skip to main content
QUICK REVIEW

[论文解读] Querying Large Language Models with SQL

Mohammed Saeed, Nicola De Cao|arXiv (Cornell University)|Apr 2, 2023
Natural Language Processing Techniques被引用 9
一句话总结

本文提出了 Galois,一个以数据库为先的原型,在数据存储于预训练 LLM 的情形下执行 SQL 查询,在许多查询上与传统 DBMS 的结果相当,并概述了混合 LLM-数据库查询的主要研究挑战。

ABSTRACT

In many use-cases, information is stored in text but not available in structured data. However, extracting data from natural language text to precisely fit a schema, and thus enable querying, is a challenging task. With the rise of pre-trained Large Language Models (LLMs), there is now an effective solution to store and use information extracted from massive corpora of text documents. Thus, we envision the use of SQL queries to cover a broad range of data that is not captured by traditional databases by tapping the information in LLMs. To ground this vision, we present Galois, a prototype based on a traditional database architecture, but with new physical operators for querying the underlying LLM. The main idea is to execute some operators of the the query plan with prompts that retrieve data from the LLM. For a large class of SQL queries, querying LLMs returns well structured relations, with encouraging qualitative results. Preliminary experimental results make pre-trained LLMs a promising addition to the field of database systems, introducing a new direction for hybrid query processing. However, we pinpoint several research challenges that must be addressed to build a DBMS that exploits LLMs. While some of these challenges necessitate integrating concepts from the NLP literature, others offer novel research avenues for the DB community.

研究动机与目标

  • 提出一种使用 SQL 查询预训练 LLM 以访问非结构化文本派生知识的方法。
  • 确立一个以数据库为先的架构,在其中 LLM 实现传统查询计划中的特定物理算子。
  • 通过原型(Galois)及基于 Spider 的初步实验来评估可行性。
  • 在与传统 DBMS 联合查询 LLM 时,识别关键的架构和数据质量挑战。

提出的方法

  • 引入一个以数据库为先的架构(Galois),将 SQL 查询分解为一系列通过专门设计的提示由 LLM 执行的步骤。
  • 将物理算子实现为文本提示,以检索关键属性并逐步为连接、选择和投影填充附加属性。
  • 将 LLM 的输出转化为结构化单元格,并在完成的元组上应用传统算子(如连接、聚合)。
  • 迭代提示以获取足够的元组,同时应用归一化与类型约束以缓解 LLM 的幻觉。
  • 提供一个工作流,将基于提示的检索与传统数据库算法相结合来处理 SPJA 查询。

实验结果

研究问题

  • RQ1SQL 查询在存储于预训练 LLM 的数据上能否有效执行并保留 SQL 语义?
  • RQ2在 LLM 与传统 DBMS 的混合查询中,哪种架构设计(数据库为先 vs LLM 为先)最可行?
  • RQ3在用 SQL 查询 LLM 时,主要挑战(如模式不确定、键、事实性)有哪些,如何缓解?
  • RQ4Galois 与在传统 DBMS 上执行相同查询或通过对 LLM 的 NL 问答相比,性能如何?
  • RQ5将 LLMs 集成到数据库风格查询处理中的局限性与未来方向是什么?

主要发现

  • Galois 能为 46 个 Spider 查询从 LLMs 生成 SQL-关系结构,并在架构上达到与 ground-truth 数据库结果相当的结果。
  • 对于基于 GPT 的模型,返回的元组数量接近 ground-truth 期望,而较小的模型则表现出更大的基数差异。
  • 在同一查询上,Galois 在 ChatGPT 上的内容准确性(单元格值层面)总体优于同一查询的基于 NL 问答的方法,选择查询在某些子类别中表现最佳(约 80% 的正确率)。
  • 连接是最具挑战性的子类,由于文本格式异质性(如国家代码变体)常常失败。
  • 设计良好的连锁式推理提示未能超过 Galois 中自动生成提示执行的效果,提示自动化可以是有效的。

更好的研究,从现在开始

从论文设计到论文写作,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。