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.
Figures & tables
Fig. 1 : The NL-to-DSL translation process in business analytics context.
Fig. 2 : (Top) The typical agentic workflow is a long-chain solution requiring multiple LLM calls, the cost of which is analyzed in Section II-C . (Bottom) In contrast, our proposed RedParrot leverages historical skeleton caching to create an accelerating shortcut, significantly simplifying the workflow.
Component
Definition
Measure
A quantitative value dynamically computed via aggregation (e.g., ‘SUM‘, ‘COUNT‘) or arithmetic operations on one or more fields.
Dimension
A categorical field or perspective used to group, segment, or disaggregate a measure.
Filter
A condition that constrains data by filtering rows, either before aggregation (like a ‘WHERE‘ clause) or after aggregation (like a ‘HAVING‘ clause).
TABLE I : Definitions of the general DSL components.
Steps
P90 (s)
#(Token)
Accuracy
Problem Analysis
6.00
8,821
94.07
Data Retrieval
5.05
4,043
66.95
Dimension Generation
4.60
3,901
56.67
Measure Generation
7.20
3,741
60.00
Filter Generation
7.40
5,765
36.67
Total
30.25
26,271
35.00
TABLE II : Cost statistics of the long-chain pipeline
Fig. 3 : (a) Visualization of query skeleton clusters and (b) corresponding examples of user queries and their DSLs. Skeletons within the same cluster share similar structural patterns in their DSL representations.
Fig. 4 : An overview of the construction process for the skeleton cache (top right) and the triplet dataset (bottom right). Both processes share a common preprocessing pipeline: (1) query skeletons are first grouped into coarse clusters. (2) Then, within each cluster, skeletons are further partitioned into fine-grained groups by identifying the connected components in a similarity graph, which is constructed by thresholding the pairwise adjacency matrices.
Fig. 5 : An example of a DSL rewriting prompt.
Dataset
-095
-0916
# Test
# Train
# Test
# Train
RED-commerce
445
4494
373
4310
RED-community
66
61
RED-trading
31
24
TABLE III : Dataset statistics
Methods
RED-Commerce-095
RED-Commerce-0916
TB
DM
MS
FT
ACC
P90
TB
DM
MS
FT
ACC
P90
LongChain-DS
69.66
82.7
53.93
97.53
45.62
22.00
70.25
80.97
51.48
95.98
45.84
25.00
LongChain-Qwen
15.05
66.42
47.19
92.81
9.66
21.00
18.5
64.76
47.19
90.62
11.53
22.00
RedParrot-RAW
77.93
72.52
66.89
83.56
44.37
7.16
87.67
78.02
65.95
86.06
47.45
6.63
RedParrot-MAN
86.94
79.28
70.27
96.85
51.13
10.43
91.15
84.99
72.39
93.57
58.45
10.45
RedParrot
85.36
76.13
69.37
91.22
48.65
7.16
90.62
81.5
70.24
91.42
57.64
7.15
TABLE IV : Main results.
Method
Spider-DSL Acc(%)
Simple
Moderate
Challenging
Overall
ICL
53.9
42.2
47.4
47.9
RedParrot
87.3
73.9
71.3
77.8
Δ
+33.4
+31.7
+23.9
+29.9
TABLE V : Performance comparison of RedParrot and ICL on Spider-DSL and BIRD-DSL .
Methods
RED-Commerce-0916
TB
DM
MS
FT
ACC (%)
P90 (s)
RedParrot
90.62
81.50
70.24
90.62
57.64
7.15
-encoder
88.47
79.09
67.56
92.22
51.74 ( ↓ 5.90 )
/
-knowledge
91.26
90.98
82.51
65.30
53.36 ( ↓ 4.28 )
/
-cache
70.25
80.97
51.48
95.98
45.84 ( ↓ 11.80 )
25.00 ( × 3.50 )
TABLE VI : Ablation results of RedParrot .
Fig. 6 : Embedding Space Comparison via PCA.
Dataset
Embedding Model
HR@5
FHR@5
Commerce
Qwen3-embedding-0.6B
85.79
56.84
Entity-agnostic model
93.57
75.34
Δ
7.78
19.4
Community
Qwen3-embedding-0.6B
95.08
81.97
Entity-agnostic model
100
100
Δ
4.92
18.03
TABLE VII : Hit rate performance comparison.
Fig. 7 : Sensitivity Analysis of Similarity Threshold and Component Number Threshold.
Dataset
Strategy
ACC (%)
Cov. (%)
Overhead (s)
Commerce
N/A
46.55
22.13
50.11
Full Rebuild
41.34
22.13
48.7
Incremental
51.72
22.13
9.48 ( ×5.13 )
Community
N/A
64.28
12.17
15.66
Full Rebuild
58.26
14.71
16.61
Incremental
60.0
13.04
4.93 ( ×3.36 )
TABLE VIII : Comparison among cache updating strategies.
Fig. 8 : Distribution of execution error categories in NL-to-DSL generation.
DAQUV Corp. Seoul, Republic of Korea · Dept. of Management Information Systems Chungbuk National University BigDataLabs, Co., Ltd. Cheongju, Republic of Korea