arXiv:2607.21756cs.DBcs.LG2026-07

让提示词成为数据库里的可管理数据类型,实现智能优化与执行

Prompt as a Data Type: In-Database LLM Prompt Management and Rewriting

  • 将提示词作为数据库值存储,支持模板、绑定和元信息管理
  • 通过数据库优化器自动重写提示词,提升输出准确率与效率
  • 适合需要动态生成和优化提示的智能数据库应用开发者

大型语言模型(LLMs)在数据库应用中广泛用于分类记录、语义筛选、结构化信息提取和查询结果增强。然而,这些计算所依赖的提示词通常以非结构化形式存储在数据库外部,导致其无法被查询执行、元数据管理与优化机制所感知。本文受石恩布雷克的QUEL数据类型思想及反射编程原则启发,提出PromptDB——一个将提示词视为元组级数据库值的系统。PromptDB引入逻辑上的PROMPT数据类型,其值包含模板、属性绑定、模型元信息与任务元信息。关系表可直接包含PROMPT属性,或通过连接后的视图暴露。用户通过生成的评估视图查询提示值,系统内部则通过EVAL操作符进行提示渲染、重写、优化与执行。使提示词可见,开辟了新的优化空间:借鉴查询优化器思路,利用数据库元数据对提示词进行重写。我们在合成与真实数据工作负载上评估了PromptDB,结果表明,基于数据库引导的提示重写显著提升输出有效性,并在成本-质量权衡上优于静态手动编写提示。

原文摘要 · Abstract (English)

Large Language Models (LLMs) are increasingly used in database-backed applications to classify tuples, filter records using semantic predicates, extract structured attributes, and enrich query results. Yet the prompt that start these computations are typically stored outside the DBMS in unstructured formats, making them invisible to query execution, metadata management, and optimization. Drawing on Stonebraker's QUEL as a Data Type and the principles of reflective programming, this paper introduces PromptDB, a database system that treats prompts as tuple-level database values. PromptDB provides a logical PROMPT datatype whose values store a template, bindings to tuple attributes, model metadata, and task metadata. Relations may contain PROMPT attributes directly in base tables, or expose them through views over joined tuples. Users query prompt-valued attributes through generated evaluation views, while the system internally renders, rewrites, optimizes, and executes prompts through an EVAL operator. Making prompts database-visible creates a new optimization space. The key idea is to bring query-optimizer thinking to prompts: just as query optimizers exploit database metadata to rewrite SQL plans, PromptDB exploits database metadata to rewrite prompts. We evaluate PromptDB on synthetic and real-world data workloads across different tasks. The results show how database-guided rewriting improves output validity and yields favorable cost-quality trade-offs compared with static, manually written prompts.

提示工程数据库LLM优化

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。