让大模型用函数调用查询数据库,统一处理搜索、过滤与聚合。
Querying Databases with Function Calling
- 设计统一接口,支持数据库查询中的搜索、筛选和聚合操作。
- Claude 3.5 Sonnet表现最佳,准确率74.3%,优于GPT-4o等模型。
- 适合需要对接私有数据或实时更新数据的开发者使用。
大型语言模型(LLMs)通过与外部工具集成快速提升能力,其中数据库查询是最有效的应用之一,可访问私有或动态更新的数据。尽管函数调用(Function Calling)是主流工具接口方式,其在数据库查询中的应用仍较薄弱。本文提出一种统一的数据库查询工具定义,涵盖数据获取、搜索查询、过滤条件及聚合、分组操作。为评估效果,我们测试了8个跨5个模型家族的LLM,采用基于Gorilla框架的合成数据库模式与查询生成流水线,以预测查询API与真实答案的精确匹配率(Exact Match)为主要指标。结果显示,Claude 3.5 Sonnet表现最优,精确匹配率达74.3%,次为GPT-4o mini(73.7%)和GPT-4o(71.8%)。分析显示,模型在布尔属性操作上表现良好,但在文本属性过滤上困难;高表现模型如GPT-4o在多数场景稳定,低表现模型则存在显著波动。我们还进行了消融实验,考察并行函数调用、添加推理说明、按集合分离工具、结构化输出的影响。结果表明,函数调用有效赋能大模型数据库查询能力。代码与结果已开源至github.com/weaviate/gorilla。
原文摘要 · Abstract (English)
The capabilities of Large Language Models (LLMs) are rapidly accelerating largely thanks to their integration with external tools. Querying databases is among the most effective of these integrations, enabling LLMs to access private or continually updating data. While Function Calling is the most common method for interfacing external tools to LLMs, its application to database querying as a tool has been underexplored. We propose a tool definition for database querying that unifies accessing data with search queries, filters, or a combination both, as well as transforming results with aggregation and groupby operators. To evaluate its effectiveness, we conduct a study with 8 LLMs spanning 5 model families. We present a novel pipeline adapting the Gorilla LLM framework to create synthetic database schemas and queries. We primarily evaluate the models with the Exact Match of predicted and ground truth query APIs. Among the models tested, Claude 3.5 Sonnet achieves the highest performance with an Exact Match score of 74.3%, followed by GPT-4o mini at 73.7%, and GPT-4o at 71.8%. We further breakdown these results per API component utilized and across synthetic use cases. We find that LLMs are highly effective at utilizing operators on boolean properties, but struggle with text property filters. Across use cases we find robust results with the higher performing models such as GPT-4o, but significant performance variance across use cases from lower performing models. We additionally conduct ablation studies exploring the impact of parallel tool calling, adding a rationale as an argument of the tool call, using a separate tool per database collection, and tool calling with structured outputs. Our findings demonstrate the effectiveness of enabling LLMs to query databases with Function Calling. We have open-sourced our experimental code and results at github.com/weaviate/gorilla.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。