通过查询语义缓存,让自然语言转领域语言更快更准。
RedParrot: Accelerating NL-to-DSL for Business Analytics via Query Semantic Caching

- 用查询骨架缓存替代复杂推理流程,提升响应速度。
- 在六大数据集上平均提速3.6倍,准确率提升8.26%。
- 适合需要低延迟、高精度的电商与广告分析系统。
近期,小红书因电商业务和广告需求激增,亟需高精度、低延迟的实时业务分析能力。传统方案依赖多阶段大模型将自然语言(NL)查询转换为领域特定语言(DSL),但存在延迟高、成本大、错误传播等问题,难以支撑企业级部署。本文提出RedParrot框架,通过语义缓存加速推理。观察到用户查询具有高度重复性和稳定结构模式,RedParrot绕过昂贵的生成流程,将新请求与缓存的“查询骨架”(标准化结构模式)匹配,并复用对应DSL。核心技术包括:(1) 离线构建骨架策略;(2) 基于对比学习训练的实体无关嵌入模型,实现鲁棒匹配;(3) 融合异构知识源的检索增强生成(RAG)方法,应对未见实体。在小红书六个真实企业数据集上,RedParrot实现平均3.6倍加速,准确率提升8.26%。在基于Spider和BIRD改造的新公开基准上,准确率提升34.8%,显著优于标准上下文学习基线。
原文摘要 · Abstract (English)
Recently, at Xiaohongshu, the rapid expansion of e-commerce and advertising demands real-time business analytics with high accuracy and low latency. To meet this demand, systems typically rely on converting natural language (NL) queries into Domain-Specific Languages (DSLs) to ensure semantic consistency, validation, and portability. However, existing multi-stage LLM pipelines for this NL-to-DSL task suffer from prohibitive latency, high cost, and error propagation, rendering them unsuitable for enterprise-scale deployment. In this paper, we propose RedParrot, a novel NL-to-DSL framework that accelerates inference via a semantic cache. Observing the high repetition and stable structural patterns in user queries, RedParrot bypasses the costly pipeline by matching new requests against cached "query skeletons" (normalized structural patterns) and adapting their corresponding DSLs. Our core technical contributions include (1) an offline skeleton construction strategy, (2) an online, entity-agnostic embedding model trained via contrastive learning for robust matching, and (3) a heterogeneous Retrieval-Augmented Generation (RAG) method that integrates diverse knowledge sources to handle unseen entities. Experiments on six real enterprise datasets from Xiaohongshu show RedParrot achieves an average 3.6x speedup and an 8.26% accuracy improvement. Furthermore, on new public benchmarks adapted from Spider and BIRD, it boosts accuracy by 34.8%, substantially outperforming standard in-context learning baselines.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。