[Paper Review] Querying Large Language Models with SQL
The paper presents Galois, a DB-first prototype that executes SQL queries over data stored in pre-trained LLMs, showing promising results comparable to traditional DBMS for many queries and outlining the main research challenges of hybrid LLM-DB querying.
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.
Motivation & Objective
- Propose a method to query pre-trained LLMs using SQL to access unstructured text-derived knowledge.
- Ground a DB-first architecture where LLMs implement specific physical operators in a traditional query plan.
- Assess feasibility via a prototype (Galois) and preliminary experiments on Spider-based queries.
- Identify key architectural and data-quality challenges in querying LLMs alongside traditional DBMSs.
Proposed method
- Introduce a DB-first architecture (Galois) that decomposes a SQL query into a chain of steps executed by LLMs via specially designed prompts.
- Implement physical operators as text prompts that retrieve key attributes and progressively fill in additional attributes for joins, selections, and projections.
- Convert LLM outputs into structured cells and apply traditional operators (e.g., joins, aggregates) on completed tuples.
- Iterate prompts to gather sufficient tuples while applying normalization and type constraints to mitigate LLM hallucinations.
- Provide a workflow that combines prompt-based retrieval with conventional DB algorithms to process SPJA queries.
Experimental results
Research questions
- RQ1Can SQL queries be effectively executed over data stored in pre-trained LLMs while preserving SQL semantics?
- RQ2What architectural design (DB-first vs LLM-first) is most feasible for hybrid querying of LLMs and traditional DBMSs?
- RQ3What are the main challenges (e.g., schema ambiguity, keys, factuality) in querying LLMs with SQL, and how can they be mitigated?
- RQ4How does Galois perform compared to running the same queries on a traditional DBMS or via NL QA over LLMs?
- RQ5What are the limitations and future directions for integrating LLMs into database-style query processing?
Key findings
- Galois can produce SQL-relational output structures from LLMs for a set of 46 Spider queries and achieve results comparable in schema to ground-truth DB results.
- For GPT-based models, the number of returned tuples is close to ground-truth expectations, whereas smaller models show larger cardinality differences.
- Content accuracy (cell-value level) for Galois on ChatGPT is better on average than NL-question-based QA for the same queries, with selection queries performing best (~80% correct in some subspecies).
- Joins are the most challenging subclass, often failing due to heterogeneous textual formats (e.g., country code variants).
- Well-engineered chain-of-thought prompts did not outperform the automatically generated prompt-based execution in Galois, suggesting prompt automation can be effective.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.