Paper deep dive
Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases
Zhao Tan, Yiji Zhao, Shiyu Wang, Chang Xu, Yuxuan Liang, Xiping Liu, Shirui Pan, Ming Jin
Intelligence
Status: succeeded | Model: Gemma-4-26B-A4B | Prompt: intel-v1 | Confidence: 93%
Last extracted: 7/21/2026, 12:44:11 AM
Summary
The paper introduces Sonar-TS, a neuro-symbolic framework for Natural Language Querying for Time Series Databases (NLQ4TSDB). It addresses the limitations of Text-to-SQL (lack of morphological expressivity) and Time Series Models (scalability issues) via a 'Search-Then-Verify' pipeline. Sonar-TS uses SQL to search a multi-scale feature index for candidate windows and Python to verify them against raw signals. The authors also introduce NLQTSBench, a large-scale benchmark for evaluating NLQ over TSDB-scale histories, featuring a four-level taxonomy of complexity.
Entities (8)
Relation Signals (6)
Sonar-TS â creates â NLQTSBench
confidence 95% ¡ we introduce NLQTSBench, the first large-scale benchmark designed for NLQ over TSDB-scale histories
Sonar-TS â solves â NLQ4TSDB
confidence 95% ¡ we propose Sonar-TS, a neuro-symbolic framework that tackles NLQ4TSDB
Sonar-TS â uses â Search-Then-Verify
confidence 95% ¡ Sonar-TS... tackles NLQ4TSDB via a âSearch-Then-Verifyâ pipeline
Text-to-SQL â failstohandle â morphological intents
confidence 90% ¡ existing Text-to-SQL methods are not designed for continuous morphological intents such as shapes or anomalies
Time Series Question Answering â struggleswith â ultra-long histories
confidence 90% ¡ time series models struggle to handle ultra-long histories
NLQTSBench â contains â NLQTSBench-Lite
confidence 85% ¡ we release NLQTSBench-Lite, a compatibility set... NLQTSBench is designed for long-horizon querying
Cypher Suggestions (0)
No Cypher suggestions yet.
Abstract
Abstract:Natural Language Querying for Time Series Databases (NLQ4TSDB) aims to assist non-expert users retrieve meaningful events, intervals, and summaries from massive temporal records. However, existing Text-to-SQL methods are not designed for continuous morphological intents such as shapes or anomalies, while time series models struggle to handle ultra-long histories. To address these challenges, we propose Sonar-TS, a neuro-symbolic framework that tackles NLQ4TSDB via a Search-Then-Verify pipeline. Analogous to active sonar, it utilizes a feature index to ping candidate windows via SQL, followed by generated Python programs to lock on and verify candidates against raw signals. To enable effective evaluation, we introduce NLQTSBench, the first large-scale benchmark designed for NLQ over TSDB-scale histories. Our experiments highlight the unique challenges within this domain and demonstrate that Sonar-TS effectively navigates complex temporal queries where traditional methods fail. This work presents the first systematic study of NLQ4TSDB, offering a general framework and evaluation standard to facilitate future research.
Tags
Links
- Source: https://arxiv.org/abs/2602.17001v3
- Canonical: https://arxiv.org/abs/2602.17001v3
Trouble viewing inline? Open PDF directly â
Full Text
85,877 characters extracted from source content.
Expand or collapse full text
Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Zhao Tan 1 2 Yiji Zhao 3 Shiyu Wang Chang Xu 4 Yuxuan Liang 5 Xiping Liu â 1 Shirui Pan 2 Ming Jin â 2 Abstract Natural Language Querying for Time Series Databases (NLQ4TSDB) aims to assist non- expert users retrieve meaningful events, intervals, and summaries from massive temporal records. However, existing Text-to-SQL methods are not designed for continuous morphological intents such as shapes or anomalies, while time series models struggle to handle ultra-long histories. To address these challenges, we propose Sonar- TS, a neuro-symbolic framework that tackles NLQ4TSDB via a âSearch-Then-Verifyâ pipeline. Analogous to active sonar, it utilizes a feature index to âpingâ candidate windows via SQL, fol- lowed by generated Python programs to âlock onâ and verify candidates against raw signals. To en- able effective evaluation, we introduce NLQTS- Bench, the first large-scale benchmark designed for NLQ over TSDB-scale histories. Our experi- ments highlight the unique challenges within this domain and demonstrate that Sonar-TS effectively navigates complex temporal queries where tra- ditional methods fail. This work presents the first systematic study of NLQ4TSDB, offering a general framework and evaluation standard to facilitate future research. Our code has been made available athttps://github.com/ Atlamtiz/Sonar-TS. 1. Introduction The volume of time series data is increasing rapidly across domains such as IoT monitoring, financial trading, and AIOps. To handle this scale, specialized Time Series 1 Jiangxi University of Finance and Economics 2 Griffith Uni- versity 3 Yunnan University 4 Microsoft Research Asia 5 The Hong Kong University of Science and Technology (Guangzhou). Corre- spondence to: Xiping Liu<liuxiping@jxufe.edu.cn>, Ming Jin <mingjinedu@gmail.com>. Proceedings of the43 rd International Conference on Machine Learning, Seoul, South Korea. PMLR 306, 2026. Copyright 2026 by the author(s). NLQ SQL Massive TimeSeriesDatabase Multi-scale Feature Tables (Queryable Index) Candidates Verify SQL Search Python Verification Sonar-TS Text-to-SQL Time Series Model Failure: Limited Context NLQ SQL Failure: Morphology Gap Figure 1. Comparison of querying paradigms. While Text-to-SQL fails to express morphological intents and Time Series Models are limited by context length, Sonar-TS adopts a âSearch-Then-Verifyâ pipeline: it uses SQL to search a symbolic index for candidates and Python to verify them on raw data. Databases (TSDBs) have become the standard solution for storage (Pelkonen et al., 2015). However, querying these massive records for meaningful insights remains a signifi- cant barrier for non-expert users. Unlike simple numerical lookups (e.g., âmaximum value in Mayâ), users often pri- oritize morphological characteristics, such as identifying a specific day where data shows âa rapid rise followed by a slow fall.â The profound semantic gap between such abstract natural language descriptions and the continuous numerical data constitutes the fundamental challenge in TSDB querying. Existing attempts to bridge this gap can be broadly cat- egorized into two distinct paradigms. On the one hand, from a database-centric perspective, Text-to-SQL (Pourreza & Rafiei, 2023; Tan et al., 2024; Liu et al., 2025) aims to translate natural language into executable SQL queries. While this field has demonstrated significant success in han- dling complex schema linking within relational databases, it encounters an expressivity bottleneck in the time series domain: standard SQL lacks native primitives to describe continuous morphological concepts (e.g., shapes or trends), making it arduous to formulate qualitative intents using rigid operators. On the other hand, from a data-centric perspec- 1 arXiv:2602.17001v3 [cs.AI] 10 Jun 2026 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases tive, Time Series Question Answering (TSQA) (Jin et al., 2024; Langer et al., 2025; Divo et al., 2025) focuses on aligning textual modalities with raw temporal signals, en- abling models to interpret morphological patterns directly. However, these models face a severe scalability bottleneck. Constrained by finite context windows, end-to-end models cannot ingest the ultra-long-horizon histories (often millions of points) stored in real-world TSDBs. To overcome these limitations, we formally define the task of Natural Language Querying for Time Series Databases (NLQ4TSDB). Unlike standard TSQA which typically operates on short context windows, this task de- mands that a system ground high-level semantic intents into executable operations over massive, unsegmented tempo- ral records. To facilitate rigorous evaluation, we introduce NLQTSBench, a comprehensive benchmark featuring a hierarchical taxonomy spanning four levels of complex- ity: Level 1 tests basic numerical retrieval and windowing; Level 2 focuses on morphological pattern recognition (e.g., shapelets identification); Level 3 evaluates semantic reason- ing over composite trends and causal anomalies; and Level 4 requires holistic insight synthesis for report generation. In this work, we propose Sonar-TS, a neuro-symbolic framework tailored to address the unique challenges of NLQ4TSDB. As illustrated in Figure 1, Sonar-TS reframes the TSDB querying process as a âSearch-Then-Verifyâ pipeline, drawing an analogy to active sonar. Instead of scanning the entire raw history (which is computationally prohibitive) or relying solely on SQL (which lacks mor- phological expressivity), our system first âpingsâ the mas- sive search space using a multi-scale feature index via SQL queries to localize candidate windows. Subsequently, it âlocks onâ to these candidates using generated Python pro- grams to verify the raw signals against the userâs semantic intent. The framework is structured into three key modules: (1) Offline Data Processing, which constructs compact fea- ture tables to render continuous shapes queryable; (2) Online Querying, where an LLM-driven planner synthesizes hy- brid SQL-Python execution plans; and (3) Post-processing, which formats execution artifacts into user-friendly insights and visualizations. Our contributions are summarized as follows: â˘New Problem: We formally define the NLQ4TSDB task, highlighting its necessity in practice, the dual chal- lenges of semantic grounding, and scalability that dif- ferentiate it from traditional Text-to-SQL and TSQA. â˘New Benchmark: We introduce NLQTSBench, the first large-scale benchmark for complex time series question-answering on TSDBs. Distinguished from existing settings that are restricted to short context win- dows, it necessitates active evidence localization over long-horizons rather than passive context processing. â˘Novel Framework: We propose Sonar-TS, a frame- work that orchestrates a âSearch-Then-Verifyâ work- flow. Our experiments show that Sonar-TS handles complex temporal queries where traditional methods fail, laying a foundation for future research in DB- grounded time series analysis. 2. The NLQ4TSDB Problem 2.1. Problem Formulation The goal of NLQ4TSDB is to retrieve insights from a Time Series Database (TSDB) via natural language. For- mally, letDdenote the TSDB instance containing massive timestamped records. Its structure is defined by a schema M i n i=1 , consisting ofnmeasurements (e.g., tables). We define each measurement as a tuple: M i = (n i ,T i ,F i ),(1) wheren i is the measurement name,T i is a set of tags (cate- gorical), andF i is a set of fields (numerical). Input. The input consists of two components: 1. Textual Schema (S), a serialized token sequence of the metadataM i n i=1 , formally defined asS = Serialize(M i n i=1 ). This provides structural context without exposing the raw data inD. 2.Natural Language Query (Q), a sentence specifying the user intent, typically targeting temporal patterns rather than simple relational lookups. Objective. We formulate the task as a two-stage process. A solverffirst synthesizes an executable query planĎ(e.g., SQL or Python code) based on the schema, which is then executed against the instanceD to yield the answer A: Ď = f (Q,S), A = Exec(Ď,D).(2) Output. The answerAcan be a scalar, timestamps, time intervals, or descriptive text, depending on the query intent. 2.2. Challenges To illustrate the unique challenges of NLQ4TSDB, we con- sider a representative query targeting a composite trend: NLQ: âIdentify the specific dates within the last year at which the temperature showed a rapid increase and then maintained a stable plateau.â This intent is easy for a human to understand. However, executing it over a massive TSDB in practice exposes three core challenges. 2 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases C1: The Representation Gap. The query relies on ge- ometric shapes such as ârapid riseâ and âstable plateauâ. A TSDB, in contrast, only stores point-by-point numerical values. SQL is built on strict boolean logic with fixed thresh- olds, so it cannot directly express sequential shapes. For example, defining a ârapid riseâ asWHERE slope > 60 is fragile, because the meaning of a shape depends on its context and varies across series. A clear gap therefore exists between the userâs shape-based intent and the point-based storage of a TSDB. Closing this gap requires an abstraction layer that turns continuous shapes into a discrete, queryable form the database can search. C2: The Context Scale Limit. Recent time series multi- modal models (Xie et al., 2025) can interpret shapes well, but they do not match the scale of real TSDBs. A query over âthe last yearâ may cover millions of raw points, which far exceeds the context window of modern models. Scanning the full history with a sliding window is also too slow for online use. As a result, these models still cannot directly handle TSDB-scale histories. C3: The Semantic Grounding Conflict. Natural language is inherently fuzzy. Users describe patterns with relative terms such as ârapid riseâ or âgradual dropâ. Database search, however, needs exact numerical parameters. When users think at this abstract level, they usually cannot give such numbers. The system must therefore translate the fuzzy words into concrete thresholds before execution. Us- ing static thresholds is not enough, because the meaning of ârapidâ depends on the local data distribution and the historical context. Resolving this conflict requires a method that maps vague descriptions into precise and context-aware numerical boundaries. 3. Related Work NLQ4TSDB is a novel problem closely related to three fields: Text-to-SQL, Time Series Question Answering (TSQA), and Time Series Similarity Search. However, solv- ing NLQ4TSDB task requires three capabilities at once that no single field provides: Morphological Primitives (MP) to process continuous shapes, Massive Scalability (MS) to handle long database horizons, and Natural Language Grounding (NLG) to understand user intents. As shown in Table 1, each prior field covers only a subset of these capabilities, while Sonar-TS unifies all three. We discuss the specific limitations of each field below. Text-to-SQL. Text-to-SQL translates natural language into executable SQL (Li et al., 2023; Qin et al., 2022), evolving from rule-based methods to LLM-driven agentic pipelines. Recent work adopts decomposition and multi-agent strate- gies to scale up. For example, DIN-SQL (Pourreza & Rafiei, 2023) and MAC-SQL (Wang et al., 2025a) split the task Table 1. Capability comparison of existing paradigms against the fundamental requirements of NLQ4TSDB. Abbreviations: MP (Morphological Primitives), MS (Massive Scalability), NLG (Nat- ural Language Grounding). Paradigm / MethodMPMSNLG Text-to-SQLââ TSQA Modelsâââ TS Similarity Searchââ Sonar-TS (Ours)â into sub-problems such as schema linking and results refine- ment; CHASE-SQL (Pourreza et al., 2025) verifies candi- date queries via test-time computation; and CHESS (Talaei et al., 2024) uses hierarchical retrieval to filter irrelevant schema items at industrial scale. However, Text-to-SQL is built on relational algebra and lacks native primitives for shape matching. Concepts like âV-shapeâ or âfluctuationâ cannot be expressed in plain SQL, leaving a semantic gap that pure SQL generation cannot close. Time Series Question Answering. TSQA enables models to perceive and reason over numerical signals, moving be- yond forecasting toward semantic understanding (Chang et al., 2025). Time-LLM (Jin et al., 2024) reprograms LLMs by mapping series into textual prototypes, while ChatTS (Xie et al., 2025) aligns signals with language via multimodal encoders.Benchmarks such as Time- MQA (Kong et al., 2025) and QuAnTS (Divo et al., 2025) further expand the scope of reasoning tasks. However, cur- rent TSQA models are bounded by the Transformer context window, which makes them infeasible for scanning mas- sive, unsegmented histories in real TSDBs. For example, a year of high-frequency monitoring easily contains millions of points, far exceeding the few-thousand-token contexts typical of TSQA models. Time Series Similarity Search. This field aims to find subsequences that match a given query sequence. Existing approaches fall into two broad families: index-accelerated numerical matching, and symbolic compression. For mas- sive datasets, KV-Match (Wu et al., 2019) builds on a custom key-value index, while MS-Index (dâHondt et al., 2025) uses R-trees over Discrete Fourier Transform approximations for efficient Top-kretrieval. Symbolic methods like SAX (Lin et al., 2007) discretize continuous waveforms into discrete string tokens. These techniques are efficient, but they fol- low a âQuery-by-Exampleâ paradigm and require a precise numerical sequence as input. NLQ4TSDB instead follows âQuery-by-Languageâ, where users express intents through abstract linguistic concepts (e.g., ârapid declineâ). This shift from a concrete numerical exemplar to an abstract textual description fundamentally changes the retrieval problem, making existing similarity search indices inapplicable. 3 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Level 1: Basic Operations [Question]:What is the median value of channel 1 in 2021? [Answer]: 0.479 [Question]:Which 10-day period in 2022 had the highest average for channel 2? [Answer]: [2022-02-18 17:15:00 to 2022-02-28 17:00:00] Level 2: Pattern Recognition Sliding WindowAtomic Retrieval [Question]: Find the interval in channel 5 within [Search Range] most similar to the pattern in [Ref Range]. [Answer]: [2021-07-27 12:45:00 to 2021-07-28 03:30:00] Search RangeRef Range Basic Operations 24% Pattern Recognition 31% Semantic Reasoning 36% Insight Synthesis 9% [Question]:Identify the time range of the longest plateau (stable period) in channel 3 within [2022- 09-11 08:00:00 to 2022-09-20 12:00:00]. [Answer]: [2022-09-11 19:15:00 to 2022-09-13 04:00:00] Shape IdentificationPeriodicity Detection [Question]:What is the dominant cycle period (in data points) of channel 4 within [2023-11-05 09:15:00 to 2023-11-08 11:45:00]? [Answer]: 90 Subsequence Matching Level 3: Semantic Reasoning [Question]: Channel 8 is the upstream source of channel 9, identify the time period in 2019 where 9 shows a significant causal anomaly. [Answer]: [2019-08-27 12:45:00 to 2019-09-01 03:30:00] [Question]:Identify the dates in channel 6 during 2023 that exhibit the most significant 'rapid fall followed by a stable plateau' trend. [Answer]: ['2023-06-21â, ..., '2023-02-05'] Composite TrendContextual Anomaly [Question]:Identify the period in channel 7 during 2023 that experienced historically high values. [Answer]: [2023-09-09 to 2023-11-10] Causal Anomaly Level 4: Insight Synthesis [Question]: Analyze the behavior of channel 9 for the period 2020-07. Please use ONLY the following phrases for trend description: rapid rise,gradual rise, rapid fall,gradual fall, steady stable, fluctuating stable. Provide a structured report covering: 1.Trend Segmentation:Describe each stage with precise start/end timestamps using the phrases above. 2.Outlier Audit: Identify only significant outliers that deviate sharply from the local trend. [Answer]: 1.Trend Segmentation:from 2020-07-01 00:00:00 to 2020- 07-14 06:45:00, the trend showed a steady stable; from 2020-07-14 06:45:00 to 2020- 07-20 22:00:00, the trend showed a fluctuating stable; from 2020-07-20 22:00:00 to 2020-07-25 08:15:00, the trend showed a gradual rise; from 2020-07-25 08:15:00 to 2020- 07-31 23:45:00, the trend showed a fluctuating stable. 2.Outlier Audit: A significant spike was detected at 2020-07- 08 00:45:00 (value: 13.61). Figure 2. The hierarchical taxonomy of tasks in NLQTSBench. The benchmark ranges from Level 1 (Basic Operations) which tests numerical filtering, to Level 2 (Pattern Recognition) for morphological grounding, Level 3 (Semantic Reasoning) for logical composition, and finally Level 4 (Insight Synthesis) for narrative reporting. 4. NLQTSBench NLQ4TSDB is a fundamentally new problem. The closest existing proxy is TSQA benchmarks (Kong et al., 2025; Chen et al., 2025), but they typically restrict evaluation to short snippets (often fewer than 500 points). This setting im- plicitly assumes that the relevant evidence has already been perfectly segmented, which misrepresents practical TSDB interactions where users query continuously accumulated, unsegmented histories. To bridge this gap, we introduce NLQTSBench, the first benchmark designed specifically for the NLQ4TSDB prob- lem. In NLQTSBench, the average search space per query spans approximately 12,000 points. This magnitude en- forces a paradigm shift from passive context reading to active, long-horizon evidence localization. 4.1. Task Taxonomy We organize NLQTSBench into a four-level taxonomy, il- lustrated in Figure 2. The hierarchy progresses from atomic numerical operations to holistic reasoning, evaluating how well a solver grounds abstract linguistic concepts into con- tinuous time series at scale. Level 1: Basic Operations. Tests precision in translat- ing natural language constraints into executable numerical filters. It includes (1) Atomic Retrieval, covering statisti- cal calculation, precise localization, and value-based range selection; and (2) Sliding Window, which identifies target intervals across a massive search space. Level 2: Pattern Recognition. Assesses the ability to ground abstract morphological concepts (e.g., V-shape) into continuous numerical series. It includes (1) Shape Identi- fication, recognizing qualitative patterns such as plateaus or spikes; (2) Periodicity Detection, capturing the dominant cycle in oscillating data; and (3) Subsequence Matching, re- trieving periods that morphologically resemble a reference pattern. Level 3: Semantic Reasoning. Evaluates logical com- position and relational reasoning over temporal sequences and inter-channel dependencies. It includes (1) Composite Trend, handling multi-stage transitions such as a rapid rise followed by a slow fall; (2) Contextual Anomaly, diagnos- ing abnormalities relative to local history rather than fixed thresholds; and (3) Causal Anomaly, identifying contradic- tions between correlated series. Level 4: Insight Synthesis. Serves as a composite evalu- ation, requiring the solver to orchestrate lower-level capa- bilities into a cohesive Report Generation workflow that 4 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Table 2. Statistics of NLQTSBench. The dataset comprises 1153 queries spanning four complexity levels. LevelTask Sub-TypeCountAvg. Length L1: Basic Operations Atomic Retrieval216 âź 2k Sliding Window58 L2: Pattern Recognition Shape Identification129 âź 0.6kPeriodicity Detection120 Subsequence Matching111 L3: Semantic Reasoning Composite Trend220 âź 30kContextual Anomaly104 Causal Anomaly95 L4: InsightReport Generation100 âź 3k TotalAll Tasks1153Avg. â 12k sequentially performs trend segmentation and outlier audit- ing within a localized window. Table 2 summarizes the query distribution and context scales across the four levels. Full task definitions and query tem- plates are provided in Appendix A.1. 4.2. Data Construction Pipeline A NLQ4TSDB benchmark requires three ingredients: mas- sive raw histories, natural language queries, and precise ground truths. The first two are straightforward, but ground- truth annotation is the bottleneck. Pinpointing a morpholog- ical boundary across years of data (e.g., the exact moment a âgradual riseâ begins) is highly subjective and prohibitively labor-intensive for human annotators. No existing auto- mated algorithm extracts such boundaries reliably from real- world data either. We therefore adopt a controlled injection strategy: we syn- thesize mathematical patterns that strictly match the linguis- tic descriptions and overlay them onto real backgrounds sam- pled from CausalRivers (Stein et al., 2025), ETTm1 (Zhou et al., 2021), and SMD (Su et al., 2019). This makes labels auditable by construction while preserving the noise and drift of real signals, and follows a paradigm already adopted in recent TSQA work (Xie et al., 2025). The pipeline runs in three stages: template formulation, signal injection, and human visual verification. Full details are in Appendix A.2. 4.3. Benchmark Variants. NLQTSBench is designed for long-horizon querying, but existing TSQA models often operate within small context windows and cannot process such long histories. To en- able a fair comparison with these baselines, we release NLQTSBench-Lite, a compatibility set of 500 samples with fixed 512-point windows, covering three core capabil- ities: Shape Identification, Composite Trend, and Causal Anomaly. We emphasize that NLQTSBench-Lite is solely intended for TSQA baseline comparisons. 5. The Sonar-TS Framework 5.1. Overview No existing paradigm covers all the capabilities required by NLQ4TSDB task. We therefore propose Sonar-TS, the first framework purpose-built for this task. As illustrated in Figure 3, the workflow operates in three stages: â˘Offline Data Processing (Section 5.2). We preprocess native time series into multi-scale Feature Tables that act as a queryable semantic index. These tables store window-level metadata, statistical primitives, and mor- phological tokens to facilitate rapid and approximate evidence localization. â˘Online Querying (Section 5.3). Given a query and the textual database schema, an LLM first plans the task and then generates hybrid SQL and Python programs. The SQL filters candidate windows from the feature tables, while the Python programs verify them against raw slices. This generation is supported by an offline Prompt Cold Start mechanism, which injects a static set of distilled Experiences to guide the LLM with domain-specific heuristics. â˘Post-processing (Section 5.4). This step formats the raw execution artifacts into user-friendly responses, and provides lightweight visualizations for quick hu- man verification. 5.2. Offline Data Processing To avoid costly full scans at query time, we precompute com- pact multi-scale Feature Tables that act as a Queryable Se- mantic Index. The raw TSDB remains the definitive source of truth and is accessed only for exact computations on localized regions. For each numeric channel, we materialize feature rows un- der a hierarchical windowing scheme across multiple gran- ularities (e.g., Year/Month/Day). Each row corresponds to one time window and stores its metadata (e.g., Channel ID) along with two categories of descriptors that jointly support numerical and morphological queries. 1.Statistical Primitives. We compute lightweight statis- tics (e.g.,slope,stdval) as cheap pruning sig- nals. This lets the system prioritize candidate windows with simple SQL (e.g.,ORDER BY stdval DESC LIMIT 1) instead of aggregating over raw points at query time. 2.Morphological Tokens.To accommodate shape- driven intents (e.g., âV-shapeâ), we must transform 5 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Sax_Shape...slopeendstartChannel acead......-0.362020-012019-01channel_1 .................. Sax_Shape ... slopeendstartChannel acead......-0.362020-012019-01channel_1 .................. Visualization Question Offline Data Processing Native Time Series Data Feature Tables ... Online Querying Post-processing Database Schema # Table: data [channel_1, ...] # Table: feature_daily [...] # Table: feature_monthly [...] ... Question Find dates in channel 1 during 2019 daily trend: first rapid fall, then volatile rise, then steady, then gradual fall. Code Generation Task Planning Experiences Execute Results lTime Window lTimestamp lScalar Sub-Steps # Step 1 # Step 2 ... Reward Model Experiences Summarize Experiences Update Trajectory Prompt Cold Start Answer Question Sub-Steps Results SAX...slopeendstartChannel acead......-0.362020-012019-01channel_1 ...............channel_2 Yearly Monthly Daily TagsStatisticalPattern Time Series Database SQLPython Operators Query Tasks Comprehensive Reporting 1.For simple shape detection, use SAX Regex, and... ... Answer Summary [...,'2019-04-28',...] SearchVerify Figure 3. The overview of the Sonar-TS framework. The workflow is organized into three stages: (1) Offline Data Processing constructs compact multi-scale Feature Tables to serve as a queryable index; (2) Online Querying, where the Task Planner and Code Generator synthesize SQL for rapid candidate search and Python for exact verification, guided by domain heuristics distilled from an offline Prompt Cold Start mechanism; and (3) Post-processing translates execution artifacts into a user-friendly interface. continuous numerical shapes into discrete string to- kens. This symbolization is a strict necessity for en- abling standard SQL engines to search massive time series data. We adopt Symbolic Aggregate approXi- mation (SAX) (Lin et al., 2007) as a well-established baseline, providing a transparent and reproducible start- ing point for Sonar-TS. We treat SAX as a Symbolic Search Handle, allowing the system to approximate shapes via standard SQL regex (e.g., approximating a âmonotonic riseâ viaWHERE regexplike(sax, â[ab]+. * [de]+â)). Crucially, SAX is one valid instantiation rather than a hard dependency: our frame- work is agnostic to the tokenization method, and any advanced discrete representation can be integrated. 5.3. Online Querying Querying over TSDBs faces two core challenges: (1) Com- putational Infeasibility: Verifying these intents directly on raw data requires full-history scanning, which is pro- hibitively expensive for online interaction. (2) The Semantic- Signal Mismatch: Usersâ intents often describe high-level morphology (e.g., âsteadyâsharp dropâ) but databases only index low-level raw signals. Expressing such compos- ite intents as a single SQL predicate is often impossible. To resolve these issues, Sonar-TS adopts a Search-Then- Verify workflow that orchestrates explicit collaboration be- tween coarse-grained symbolic database search and fine- grained algorithmic verification. Search-Then-Verify Workflow. The pipeline takes the user query, the database schema (including offline feature tables), and the Experience set as inputs, and proceeds in three sequential steps. Step 1: Task Planning. Complex temporal queries are inherently difficult to execute in a single shot. We employ the backbone LLM as a Task Planner that decomposes the query into an ordered sequence of fine-grained sub-steps, identifying both the logical execution order and the operator types required for each step. Step 2: Code Generation. Based on the plan, the Code Generator instantiates the abstract logic into executable forms via two distinct mechanisms: 1. SQL-based Search: To narrow the massive search space, the Generator writes SQL targeting the of- fline feature tables using SAX tokens as symbolic handles.For instance, to search for a compos- ite trend like ârapid rise, then fall,â it formulates a fuzzy regex (e.g.,WHERE regexplike(sax, â[ab]+. * [de]+. * [ab]+â)) to retrieve approx- imate candidate windows. This strategy efficiently eliminates structurally irrelevant histories, yielding a manageable set of candidate metadata. 2. Operator-based Verification: Because SAX com- pression inevitably introduces information loss, the localized candidates must be rigorously validated. The Generator synthesizes Python programs that fetch the 6 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Table 3. Representative verification primitives in the operator library. Operator SignatureMathematical Grounding detectperiodAutocorrelation Function (ACF) for cyclic behaviors. findbestmatchDynamic Time Warping (DTW) for subsequence matching. detectchangepointsPELT algorithm for structural segmentation. calc trendslopeTheil-Sen estimator + local slope distribution. calccorrelationPearson correlation for causal links. raw data slices corresponding to these candidates and execute exact mathematical checks. Continuing our example, the script appliescalctrendslopeand detectchangepointsto the raw slices. It veri- fies a ârapidâ rise by checking if the candidateâs slope ranks within the top percentiles of the historical slope distribution. To support this, we equip the Genera- tor with a standard library of classic time-series al- gorithms wrapped as executable operators. Table 3 highlights representative operators used for verifica- tion; the comprehensive library and implementation details are provided in our open-source repository. This design ensures that fuzzy linguistic concepts are strictly grounded in established, context-aware mathematics. Step 3: Execution & Self-Correction. The generated SQL and Python codes are executed sequentially. This stage handles runtime failures (e.g., SQL returning empty results or Python syntax errors). If an error occurs, the execution feedback (a traceback or a result summary) is returned to the Code Generator for refinement, forming a closed-loop debugging process that iterates until successful execution or a predefined retry limit is reached. Prompt Cold Start.NLQ4TSDB is knowledge-intensive, requiring domain heuristics. To inject such expertise with- out fine-tuning, Sonar-TS maintains Experiences: compact, high-level insights distilled from past executions (e.g., cor- rect operator usage, effective SAX matching, and avoidance of irregular sampling gaps). At inference, the current Expe- rience set is injected directly into the Planner and Generator prompts as a concise âexpert manual.â Crucially, Experiences are built entirely offline on a profil- ing dataset and never updated at query time, avoiding both fine-tuning cost and the unpredictability of online memory updates. The construction follows a closed-loop âReward- Summarize-Updateâ cycle: first scores each execution; an Experience Summarizer distills 1â3 skills from the execu- tion trajectory (plan, code, reward); and an Experience Up- dater refines the global set via add/merge/delete operations, enforcing a strict cap (e.g., 20 insights) to bound context overhead. Figure 4 shows representative entries, ranging from high-level algorithmic orchestration to low-level syn- tax corrections, each a targeted heuristic rather than generic prompt advice. Snapshot of Injected Experiences â˘For symbolic pattern matching, utilize the 5-level SAX alphabet (âa-bâ for Low, âd-eâ for High). E.g., to detect a âlow plateauâ (bottom out), use the fuzzy SQL regex: SELECT * FROM feature daily WHERE sax REGEXP â.*[a-b]3,.*â â˘When working with timestamps in pandas, ALWAYS convert them immediately after loading: df[âtsâ] = pd.to datetime(df[âtsâ]). Never assume they are datetime objects. Never call .strftime() on a numpyarray without conversion. â˘For structural trend reporting, do not calculate a global slope. Instead, use a divide-and-conquer approach: first apply detect changepoints to decompose the trend into segments, then use calc_trend_slope to quantify the direction of each specificsegment. â˘If Step 1 (SAX filtering) returns an empty result, you MUST automatically fallback to fetching raw data for the entire requested time range. Do not simply return âNo data foundââthe SAX approximation has been too strict. â˘When detecting continuous time periods (Interval Discovery), use dynamic gap detection based on the datasetâs median sampling interval. â˘... (others) Figure 4. Snapshot of representative Injected Experiences. 5.4. Post-processing The Online Querying module returns raw mathematical out- puts (e.g., timestamps, intervals, or scalars) that are not always directly consumable by users. The Post-processing module wraps these outputs into user-facing answers. For text-centric tasks such as Insight Synthesis, an LLM is in- voked to compose a concise summary that integrates the retrieved values into a coherent narrative. In addition, Post- processing optionally produces a lightweight Python visu- alization that renders the relevant time-series context and highlights the retrieved windows, supporting quick visual inspection and human verification. 5.5. Execution Complexity Sonar-TS delegates heavy computation to the database en- gine and Python operators. LetRbe the retry limit,T LLM the LLM call cost,Mthe feature-table rows scanned,K the retrieved candidate windows, andwthe window length. The worst-case online cost is: O R¡ T LLM + M + K¡ f (w) ,(3) wheref (w)is the operator complexity on one window. The key property is decoupling from the series lengthN: the LLM prompt depends only on the schema and a bounded Experience set, and Python verification depends only onK. The termMscales with the feature tables, not raw data, and standard indices keep it efficient. Sonar-TS therefore avoids theO(N )orO(N 2 )scans that limit end-to-end time series models on long histories. 5.6. Implementation Details Sonar-TS is a training-free framework targeting SQL- compatible TSDBs, with DeepSeek-V3 as the default back- bone. Full implementation details, including feature table and hyperparameter configurations, the experience initial- ization protocol, and all prompt templates, are provided in Appendix B. The complete configuration files and operator library are released in our open-source code. 7 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Table 4. Main experimental results on NLQTSBench. Abbreviations: AR (Atomic Retrieval), SW (Sliding Window), SI (Shape Ident.), PD (Periodicity Det.), SM (Subseq. Matching), CT (Composite Trend), CxA (Contextual Anomaly), CsA (Causal Anomaly), IS (Insight Synthesis). Best results are bolded, and the best baseline results are underlined. CategoryMethod L1: Basic OpsL2: Pattern Rec.L3: Semantic ReasoningL4 Avg. ARSWSIPDSMCTCxACsAIS Performance on NLQTSBench-Lite (Short Context) Time Series Models ChatTS-14B--0.1768--0.2431-0.1229-0.1818 ITFormer-7B--0.0736--0.1500-0.1953-0.1529 Time-R1--0.0320--0.1395-0.1878-0.1374 OursSonar-TS--0.2491--0.2680-0.3615-0.3016 Performance on NLQTSBench (Long History) Text-to-SQL Methods MAC-SQL0.47350.04570.04190.39280.05980.00200.03460.0152-0.1611 Xiyan-SQL-32B0.108200.05880.22630.00680.00210.01680.0020-0.0582 Omni-SQL-32B0.42450.00860.0185000.00380.01540-0.0921 OursSonar-TS0.86090.78270.33360.86250.94390.29880.47670.38410.73950.6144 6. Experiments 6.1. Experimental Setup Datasets. No prior benchmark exists for NLQ4TSDB; we therefore evaluate on our own NLQTSBench. For fair com- parison across different baselines, we adopt a dual-track setup: the full benchmark (1,153 queries over massive histo- ries) is used for query-based methods, while NLQTSBench- Lite (500 queries with 512-point windows) accommodates context-limited end-to-end time series models. Baselines. NLQ4TSDB sits at the intersection of Text-to- SQL and time series models, with no direct baseline avail- able; we therefore compare against representatives from both sides. ⢠Time series models: ChatTS (Xie et al., 2025), a mul- timodal framework aligning signals with text features; ITFormer (Wang et al., 2025b), a Transformer-based encoder for temporal modeling; and Time-R1 (Luo et al., 2025), a reasoning-enhanced time series model. â˘Text-to-SQL methods: MAC-SQL (Wang et al., 2025a), a classic multi-agent decomposition frame- work; Xiyan-SQL (Liu et al., 2026) and Omni-SQL (Li et al., 2025), representing leading end-to-end SQL gen- eration models. Evaluation Metrics. NLQTSBench includes nine distinct tasks with diverse output formats, so we adopt format- specific metrics: IoU for time intervals (e.g., Shape Identifi- cation), accuracy for scalars and timestamps (e.g., Atomic Retrieval), F1-score for date sets (e.g., Composite Trend), and a composite score for free-form reports (Insight Syn- thesis). Full definitions and the task-to-metric mapping are provided in Appendix A.3. 6.2. Main Results Table 4 reports the comparative performance on NLQTS- Bench. The results confirm that NLQ4TSDB poses a unique challenge: it requires a synergy of precise morphological grounding and complex logical reasoning, which no existing baseline can effectively solve. Against this backdrop, Sonar- TS achieves consistent improvements across all categories, outperforming every baseline by a large margin. Comparison with Time Series Models (NLQTSBench- Lite). Time series models perform poorly, even on tasks they are expected to solve well, such as Shape Identification (SI). Interestingly, they often score lower on simple SI tasks than on Composite Trend (CT). Qualitative analysis (Sec- tion 6.4) suggests that while these models can recognize general shapes, they struggle with strict semantic filtering: given a query to âIdentify the longest plateauâ, the model effectively locates a plateau but ignores the âlongestâ con- straint. Sonar-TS itself shows reduced accuracy on morphol- ogy tasks (SI, CT) in this short-context setting compared to the long-history benchmark, likely due to information loss from SAX compression on short windows. Comparison with Text-to-SQL Methods (NLQTSBench). Within the Text-to-SQL category, the training-free MAC- SQL outperforms fine-tuned SOTA models like Xiyan-SQL and Omni-SQL. This trend runs contrary to general bench- marks such as BIRD (Li et al., 2023). We attribute this diver- gence to a fundamental paradigm gap: relational querying focuses on discrete record filtering, whereas time series anal- ysis demands reasoning over continuous temporal patterns. SQL baselines therefore struggle on morphology-dependent tasks (e.g., SI, CT). For instance, to identify a âslow rise followed by rapid ascentâ, they typically generate static range constraints (e.g.,WHERE value > threshold) that cannot capture the dynamic rate of change. 8 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Table 5. Ablation study on component contributions. We analyze the impact of removing the Feature Table, Experiences, and the Verification phase. Abbreviations follow Table 4. Cells highlighted inblue indicate tasks most significantly impacted by the ablation. Variant L1: BasicL2: PatternL3: ReasoningL4 Avg. ARSWSIPDSMCTCxACsAIS Sonar-TS0.86090.78270.33360.86250.94390.29880.47670.38410.73950.6144 w/o Self-Correction0.83020.72500.30560.86180.92170.29190.48130.33260.71390.5930 w/o Feature Tables0.86580.69230.15610.88040.93090.04220.49680.39180.71630.5430 w/o Experiences0.84260.55910.11860.83110.91380.06770.25010.36120.34150.4686 w/o Verification 0.82940.18700.29920.01540.03960.28260.08180.05920.02610.2721 6.3. Ablation Study Table 5 reports the contribution of each Sonar-TS compo- nent when ablated. The four components produce quali- tatively different failure modes, ranging from a localized robustness drop to near-total system collapse, as we now discuss in order of increasing impact. Impact of Self-Correction. Removing the self-correction loop primarily affects SW tasks (0.78 â 0.73). Since SW relies on generated Python scripts, this loop is needed to recover from initial syntax or logic errors. The modest overall drop suggests it acts as a robustness refinement rather than a core capability. Impact of Feature Tables.Without Feature Tables, morphology-driven tasks collapse: SI drops0.33 â 0.16 and CT drops0.30 â 0.04, while L1 tasks remain intact. This symbolic index is essential for shape retrieval. Notably, this ablation reduces Sonar-TS to a generic SQL+Python agent, whose collapse shows that agent-only paradigms can- not solve NLQ4TSDB without symbolic indexing. Impact of Experiences. Without Experiences, reasoning- heavy tasks degrade broadly (CxA0.48â 0.25, IS0.74â 0.34), and morphology cues weaken too (SI, CT). This module bridges generic LLM logic and domain heuristics, letting the planner mimic expert analytical workflows. Impact of Verification. Ablating Verification causes near- total collapse (Avg.0.61â 0.27), zeroing out algorithmic tasks such as PD (0.86 â 0.02) and SM (0.94 â 0.04). Verification is the indispensable computational engine for rigorous procedures that cannot be expressed in plain SQL. 6.4. Case Study Figure 5 presents a qualitative analysis of the Shape Iden- tification task, specifically targeting the âlongest plateauâ. Text-to-SQL baselines struggle to express continuous mor- phological traits, often hallucinating rigid numerical filters that fail to capture the geometric pattern. Conversely, time series models correctly recognize typical plateau shapes within short contexts but fail to align with the âlongestâ Query: Identify the index range of the longest plateau(stable period) in channel 94. (Output format: [start_index, end_index]). SELECTMIN(timestamp) ASstart, MAX(timestamp) ASend FROM( SELECTtimestamp FROMl2_t1_data WHERE94= ( SELECT94FROMl2_t1_data WHEREtimestamp BETWEEN'0'AND'512' GROUP BY94 ORDER BYCOUNT(94) DESCLIMIT1) ANDtimestamp BETWEEN'0'AND'512') Time Series Model ďźChatTSďź Text-to-SQL (Xiyan-SQL) Sonar-TS Verify Search SELECTwindow_start, window_end FROMfeature_table WHEREregexp_like(sax, '[a-b]+[c]*[d-e]2,[c]*[a-b]+') [380, 500] Answer SQL defverify_longest(data) Figure 5. Case Study. Text-to-SQL (Left) lacks morphological expressivity, and TS Models (Right) fail the logical constraint. Sonar-TS (Middle) succeeds via Search-Then-Verify. intent, lacking the global reasoning to compare durations. Sonar-TS bridges this gap by first retrieving candidates via fuzzy SAX matching and subsequently employing Python verification to rigorously enforce the constraint, ensuring precise grounding where pure model-based approaches fail. 7. Conclusion In this paper, we formally define the NLQ4TSDB task. To facilitate evaluation, we introduced NLQTSBench, a hier- archical benchmark that necessitates reasoning over long histories. To address this challenge, we proposed Sonar-TS, a neuro-symbolic framework implementing a âSearch-Then- Verifyâ pipeline. By orchestrating coarse-grained symbolic search and fine-grained algorithmic verification, the system effectively bridges the gap between abstract user intents and raw numerical data. Our experiments demonstrate that Sonar-TS successfully handles complex temporal reasoning tasks where traditional paradigms fail. This work serves as a foundational step toward DB-grounded time series in- telligence, offering a robust baseline for future research in semantic indexing and intelligent data monitoring. See Appendix D for a discussion of limitations and future work. 9 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Acknowledgments S. Pan was partially supported by the Australian Re- search Council (ARC) under grants FT210100097 and DP240101547, and the CSIRO â National Science Founda- tion (US) AI Research Collaboration Program. This work was also supported by the NVIDIA Academic Grant in Higher Education and Developer program. Z. Tan acknowl- edges financial support from the China Scholarship Coun- cil (CSC) and the hospitality of Griffith University, where part of this work was carried out during his visiting pe- riod. X. Liu was supported by the National Natural Science Foundation of China (Grant Nos. 62462034, 62562033, 62272205, 62272206) and the Natural Science Founda- tion of Jiangxi Province (Grant Nos. 20232ACB202008, 20242BAB25119). Impact Statement This paper presents a framework for natural language query- ing of time series databases. The primary positive impact is lowering the technical barrier for analysts and operators to retrieve events, intervals, and summaries from TSDBs, which may improve decision-making in domains such as monitoring and operations. However, deploying such systems introduces potential risks. Privacy and confidentiality concerns may arise if the model is applied to sensitive industrial data. While we do not foresee immediate negative societal consequences, we en- courage practitioners to maintain strict access controls and validation protocols when applying this technology to sensi- tive or critical environments. References Chang, C., Shi, Y., Cao, D., Yang, W., Hwang, J., Wang, H., Pang, J., Wang, W., Liu, Y., Peng, W.-C., et al. A sur- vey of reasoning and agentic systems in time series with large language models. arXiv preprint arXiv:2509.11575, 2025. Chen, J., Feng, A., Zhao, Z., Garza, J., Nurbek, G., Qin, C., Maatouk, A., Tassiulas, L., Gao, Y., and Ying, R. Mtbench: A multimodal time series benchmark for tem- poral reasoning and question answering. arXiv preprint arXiv:2503.16858, 2025. dâHondt, J., Kortekaas, T., Papapetrou, O., and Palpanas, T. Ms-index: Fast top-k subsequence search for multivariate time series under euclidean distance. Proceedings of the VLDB Endowment, 19(2):99â112, 2025. Divo, F., Kraus, M., Nguyen, A. Q., Xue, H., Razzak, I., Salim, F. D., Kersting, K., and Dhami, D. S. Quants: Question answering on time series.arXiv preprint arXiv:2511.05124, 2025. Jin, M., Wang, S., Ma, L., Chu, Z., Zhang, J., Shi, X., Chen, P.-Y., Liang, Y., Li, Y.-F., Pan, S., and Wen, Q. Time-llm: Time series forecasting by reprogramming large language models. In International Conference on Learning Repre- sentations, volume 2024, p. 23857â23880, 2024. Kong, Y., Yang, Y., Hwang, Y., Du, W., Zohren, S., Wang, Z., Jin, M., and Wen, Q. Time-MQA: Time series multi- task question answering with context enhancement. In Proceedings of the 63rd Annual Meeting of the Associ- ation for Computational Linguistics (Volume 1: Long Papers), p. 29736â29753, Vienna, Austria, July 2025. Association for Computational Linguistics. ISBN 979-8- 89176-251-0. doi: 10.18653/v1/2025.acl-long.1437. Langer, P., Kaar, T., Rosenblattl, M., Xu, M. A., Chow, W., Maritsch, M., Verma, A., Han, B., Kim, D. S., Chubb, H., et al. Opentslm: Time-series language models for reasoning over multivariate medical text-and time-series data. arXiv preprint arXiv:2510.02410, 2025. Li, H., Wu, S., Zhang, X., Huang, X., Zhang, J., Jiang, F., Wang, S., Zhang, T., Chen, J., Shi, R., Chen, H., and Li, C. Omnisql: Synthesizing high-quality text-to-sql data at scale. Proc. VLDB Endow., 18(11):4695â4709, July 2025. ISSN 2150-8097. doi: 10.14778/3749646.3749723. Li, J., Hui, B., Qu, G., Yang, J., Li, B., Li, B., Wang, B., Qin, B., Geng, R., Huo, N., et al. Can llm already serve as a database interface? a big bench for large-scale database grounded text-to-sqls. Advances in Neural Information Processing Systems, 36:42330â42357, 2023. Lin, J., Keogh, E., Wei, L., and Lonardi, S. Experiencing sax: a novel symbolic representation of time series. Data Mining and knowledge discovery, 15(2):107â144, 2007. Liu, X., Shen, S., Li, B., Ma, P., Jiang, R., Zhang, Y., Fan, J., Li, G., Tang, N., and Luo, Y. A survey of text-to-sql in the era of llms: Where are we, and where are we going? IEEE Transactions on Knowledge and Data Engineering, 2025. Liu, Y., Zhu, Y., Gao, Y., Luo, Z., Li, X., Shi, X., Hong, Y., Gao, J., Li, Y., Ding, B., et al. Xiyan-sql: A novel multi- generator framework for text-to-sql. IEEE Transactions on Knowledge and Data Engineering, 2026. Luo, Y., Zhou, Y., Cheng, M., Wang, J., Wang, D., Pan, T., and Zhang, J. Time series forecasting as reasoning: A slow-thinking approach with reinforced llms. arXiv preprint arXiv:2506.10630, 2025. 10 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Pelkonen, T., Franklin, S., Teller, J., Cavallaro, P., Huang, Q., Meza, J., and Veeraraghavan, K. Gorilla: a fast, scalable, in-memory time series database. Proc. VLDB Endow., 8(12):1816â1827, August 2015. ISSN 2150- 8097. doi: 10.14778/2824032.2824078. Pourreza, M. and Rafiei, D. Din-sql: Decomposed in- context learning of text-to-sql with self-correction. Ad- vances in Neural Information Processing Systems, 36: 36339â36348, 2023. Pourreza, M., Li, H., Sun, R., Chung, Y., Talaei, S., Kakkar, G. T., Gan, Y., Saberi, A., Ozcan, F., and Arik, S. Chase- sql: Multi-path reasoning and preference optimized candi- date selection in text-to-sql. In International Conference on Learning Representations, volume 2025, p. 60385â 60415, 2025. Qin, B., Hui, B., Wang, L., Yang, M., Li, J., Li, B., Geng, R., Cao, R., Sun, J., Si, L., et al. A survey on text-to-sql parsing: Concepts, methods, and future directions. arXiv preprint arXiv:2208.13629, 2022. Stein, G., Shadaydeh, M., Blunk, J., Penzel, N., and Den- zler, J. Causalrivers - scaling up benchmarking of causal discovery for real-world time-series. In International Conference on Learning Representations, volume 2025, p. 64516â64531, 2025. Su, Y., Zhao, Y., Niu, C., Liu, R., Sun, W., and Pei, D. Robust anomaly detection for multivariate time series through stochastic recurrent neural network. In Proceed- ings of the 25th ACM SIGKDD international conference on knowledge discovery & data mining, p. 2828â2837, 2019. Talaei, S., Pourreza, M., Chang, Y.-C., Mirhoseini, A., and Saberi, A. Chess: Contextual harnessing for efficient sql synthesis. arXiv preprint arXiv:2405.16755, 2024. Tan, Z., Liu, X., Shu, Q., Li, X., Wan, C., Liu, D., Wan, Q., and Liao, G.Enhancing text-to-sql capabilities of large language models through tailored promptings. In Proceedings of the 2024 Joint International Confer- ence on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024), p. 6091â6109, 2024. Wang, B., Ren, C., Yang, J., Liang, X., Bai, J., Chai, L., Yan, Z., Zhang, Q.-W., Yin, D., Sun, X., et al. Mac-sql: A multi-agent collaborative framework for text-to-sql. In Proceedings of the 31st International Conference on Computational Linguistics, p. 540â557, 2025a. Wang, Y., Lei, P., Song, J., Hao, Y., Chen, T., Zhang, Y., Jia, L., Li, Y., and Wei, Z. Itformer: Bridging time series and natural language for multi-modal qa with large- scale multitask dataset. In International Conference on Machine Learning, p. 63324â63344. PMLR, 2025b. Wu, J., Wang, P., Pan, N., Wang, C., Wang, W., and Wang, J. Kv-match: A subsequence matching approach supporting normalization and time warping. In 2019 IEEE 35th international conference on data engineering (ICDE), p. 866â877. IEEE, 2019. Xie, Z., Li, Z., He, X., Xu, L., Wen, X., Zhang, T., Chen, J., Shi, R., and Pei, D. Chatts: Aligning time series with llms via synthetic data for enhanced understanding and reasoning. Proc. VLDB Endow., 18(8):2385â2398, April 2025. ISSN 2150-8097. doi: 10.14778/3742728. 3742735. Zhou, H., Zhang, S., Peng, J., Zhang, S., Li, J., Xiong, H., and Zhang, W. Informer: Beyond efficient transformer for long sequence time-series forecasting. In Proceedings of the AAAI conference on artificial intelligence, volume 35, p. 11106â11115, 2021. 11 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases A. Benchmark Details This appendix provides the implementation details of NLQTSBench. We document the query templates used to instantiate concrete questions (Appendix A.1), the construction pipeline that produces ground-truth-annotated samples from these templates (Appendix A.2), and the evaluation metrics used to score solver outputs (Appendix A.3). A.1. Query Templates Every query in NLQTSBench is instantiated from a parameterized template. Each template contains two kinds of slots: structural slots (e.g.,channel,timewindow), which are filled from dataset metadata, and semantic slots (e.g., patternname,superlative), which are drawn from a controlled vocabulary. Semantic slots are constrained so that only meaningful combinations are produced (e.g.,steepestis paired only withspikeorvalley, never with plateau). We list all templates below, grouped by the four levels of the taxonomy. Level 1: Basic Operations Level 1 templates produce queries that map directly to deterministic numerical operations. We distinguish atomic retrieval (a single statistic or extremum) from rolling-window analysis (best window over a moving context). Level 1: Basic Operations Templates Type 1: Atomic Retrieval ⢠Global Aggregation Template: What is theagg value of channelchannel intime? Args:aggâ [âmaximumâ, âminimumâ, âaverageâ, âmedianâ, ârangeâ] ⢠Temporal Localization Template: At what exact timestamp did channelchannelaction intime? Args:actionâ [âreach its maximum valueâ, âfirst rise abovethresholdâ, . . . ] ⢠Interval Discovery Template: Find the longest period where channelchannel remained abovethreshold intime. Args:thresholdâ P 80 (Dynamic 80th percentile of data) Type 2: Rolling Window Analysis ⢠Sliding Window Statistics Template: Whichwindow desc intime had themetric for channelchannel? Args:metricâ [âhighest/lowest averageâ, âhighest varianceâ, âlargest rangeâ]; window descâ Random Integer [3D, 60D] Level 2: Pattern Recognition Level 2 templates target morphological patterns. Each template specifies a target shape (e.g.,plateau,spike) and a qualifier (longest,deepest, etc.) that selects a specific instance from the candidate set. Level 2: Pattern Recognition Templates ⢠Shape Identification Template: Identify the time range of thesuperlativepatternnamein channelchannelwithin timewindow. Args:patternnameâ [âplateauâ, âupward spikeâ, âdeep valleyâ, âstep ascent/descentâ]; superlativeâ [âlongestâ, âhighestâ, âdeepestâ, âlargestâ] ⢠Periodicity Detection Template: What is the dominant cycle period (in data points) of channelchannel withintimewindow? Args: Target Signalâ [âsineâ, âcosineâ, âcompositeâ]; Period Rangeâ Random Integer [30, 120] points 12 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases ⢠Subsequence Matching Template: Analyze the reference pattern inquerywindow. Find the time interval where channelchannel exhibits the most similar pattern within the search contextsearch window. Args: Injected Prototypesâ [âbell curveâ, âstep patternâ, âdouble-peak (M-shape)â, âsharp spikeâ] Level 3: Semantic ReasoningLevel 3 templates extend pattern recognition to longer horizons (typically year-scale) and to cross-channel reasoning. The system must contextualize events against global baselines or infer relational discrepancies between correlated series. Level 3: Semantic Reasoning Templates ⢠Composite Trend Search (Top-K) Template: Identify the top-kdates in channelchannelduringyearthat exhibit the most significant patterndesc trend. Args:patterndescâ [ârapid rise then fallâ, âgradual reversalâ, âstep ascentâ, . . . ]; Injection Intensityâ Linear Decay (ensures strict ranking) ⢠Contextual Anomaly Detection Template: Identify the period in channelchannelduringyearthat experienced the most significant anomalydesc. Args:anomalydescâ [âsevere floodâ (> 3Ď surge), âsevere droughtâ (varianceâ 0)]; Contextâ Full Calendar Year (>30k points) ⢠Causal Anomaly Detection Template: Given that channelupstreamcausesdownstream, identify the time period inyearwhere downstream shows a significant causal anomaly, such as anbreakdesc. Args:break descâ [âinverse trend against sourceâ, âflat line during activityâ]; Mechanismâ Correlation Break Injection Level 4: Insight Synthesis Level 4 contains a single template that asks for a structured narrative report. To make the free-form output deterministically parseable, the prompt enforces a controlled vocabulary for trend descriptions and a fixed two-part schema. Level 4: Insight Synthesis Templates ⢠Trend & Anomaly Audit (Report Generation) Template: Analyze channelchannel for the periodtarget month. Constraint: Use ONLY standardized phrases: [ârapid/gradual riseâ, ârapid/gradual fallâ, âsteady/fluctuating stableâ]. Requirement: Provide a structured report covering: 1. Trend Segmentation (with precise H:M:S timestamps). 2. Significant Outlier Audit (ignoring minor noise). Args: Scenario Generationâ Chained injection of 2â4 distinct primitives (e.g., Linear Trendâ Stableâ Oscillation); Ground Truthâ Structured Fact Sheet defining the exact start/end and type of every stage. A.2. Construction Pipeline This appendix expands the three-stage pipeline summarized in Section 4.2. Background series are sampled from three real-world domains: CausalRivers (Stein et al., 2025), ETTm1 (Zhou et al., 2021), and SMD (Su et al., 2019). Stage 1: Parameterized Template Formulation. We design a small set of parameterized templates that cover common query intents, with the full template list given in Appendix A.1. Each template combines two kinds of slots: structural slots filled from dataset metadata, and semantic slots filled from a controlled vocabulary. Structural slots (e.g.,channel,timewindow) are populated from the datasetâs metadata. Semantic slots (e.g., superlative,patternname) are drawn from a predefined vocabulary under semantic constraints that ensure 13 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases logical coherence (e.g.,steepestpairs only withspikeorvalley, never withplateau). This controlled instantiation expands a small number of base templates into a diverse query set while avoiding nonsensical combinations. Stage 2: Signal Injection. This stage turns an instantiated template into a concrete time series sample. The injection is built from a library of parametric primitives, composed and then planted into a real background window with carefully calibrated amplitude. We elaborate the three steps below. (1) Function lifting. Each morphological descriptor is mapped to a parametric base functionf (t)drawn from a primitive library that currently supports three families: ⢠Transient patterns, modeled by Gaussian kernels for localized events such as spikes or sharp valleys: f spike (t) = A¡ exp âÎť(tâ t 0 ) 2 ,(4) where A controls the peak height, Îť controls the sharpness, and t 0 is the location. ⢠State shifts, modeled by dual-sigmoid activations for plateaus and step-like regimes: f box (t) = Ď(k(tâ t s ))â Ď(k(tâ t e )),(5) whereĎ(¡)is the sigmoid function,[t s ,t e ]defines the support of the plateau, andkcontrols the steepness of the rising and falling edges. ⢠Oscillations, modeled by composite sinusoids with Gaussian noise for periodic patterns: f wave (t) = K X i=1 A i sin(Ď i t + Ď i ) + Îľ(t).(6) Because the primitives are differentiable and parametric, complex scenarios are built by composition. Level 2 uses a single primitive instance to test local pattern recognition. Level 3 either chains two primitives (f rise â f fall ) to form a composite trend, or breaks the correlation between paired channels for causal anomaly detection. Level 4 composes a multi-stage sequence of 2â4 primitives with optional distractors, simulating a full-lifecycle scenario for narrative reporting. (2) Background selection. We retrieve a real-world background windowX bg (t)from the metadata pool, matching the sampledtimewindow. The window then undergoes a stability check based on its local varianceĎ 2 (X bg ): if the variance exceeds an upper bound, native fluctuations are of comparable magnitude to the injection and would obscure the planted pattern. Such windows are rejected, and the pipeline resamples another candidate. This filtering step ensures that the SNR calibration in Step (3) operates on a sensible base. (3) Superimposition with SNR calibration. The synthetic sequence is generated by adding the transformed primitive onto the background: X syn (t) = X bg (t) + ι¡T (f (t)),(7) whereT denotes temporal transformations such as shifting, scaling, and stretching, and Îą is an adaptive gain factor. The key challenge is choosingÎą. A fixed value would be invisible in a highly volatile window and unrealistically large in a stable one. We therefore define the signal-to-noise ratio (SNR) of a candidate injection as the ratio between the energy of the injected signal and the local variance of the background: SNR(Îą) = E h (ι¡T (f (t))) 2 i Ď 2 (X bg ) ,(8) and solve forÎąso that the resulting SNR falls inside a target band (1.0 < SNR < 1.5). Because the denominator is the local variance ofX bg , this forcesÎąto scale with the native noise level, keeping the injected pattern simultaneously salient and distributionally consistent with the surrounding signal. 14 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Figure 6. The human verification interface. Annotators inspect both the global context (top) and the local detail view (bottom, where the injected signal in orange is overlaid on the raw data in blue) to validate the ground truth. Stage 3: Human Visual Verification. Automated checks alone cannot guarantee that a generated query is perceptually solvable. We therefore add a human-in-the-loop audit as the final safeguard. Expert annotators inspect rendered charts for each candidate sample through the interface shown in Figure 6: the global view confirms the injection fits its surrounding regime, while the local view confirms perceptual alignment with the linguistic query. Only samples that clear both the SNR check and human inspection enter the final benchmark. A.3. Evaluation Methods NLQ4TSDB outputs span five formats: scalars, timestamps, intervals, date sets, and structured reports. We pair each format with a tailored metric. Table 6 provides a task-to-metric lookup at the end of this section. 1. Scalars and Timestamps.For scalars (e.g., a periodicity value), exact equality is brittle under floating-point arithmetic. We instead use a relative-accuracy score normalized to the magnitude of the ground truth: Score scalar (y p ,y g ) = max 0, 1â |y p â y g | |y g | + Îľ ,(9) whereÎľ = 10 â9 avoids division by zero. For timestamps, we use a binary hit rate: a prediction is correct if|t pred ât gt |⤠δ, where δ is the sampling resolution (typically 0, i.e., exact match). 2. Time Intervals. For tasks that return a continuous interval (e.g., Sliding Window, Shape Identification, Contextual Anomaly, Causal Anomaly), we evaluate the temporal overlap between the predicted intervalI p and the ground truthI g via Intersection over Union: Score interval (I p ,I g ) = duration(I p ⊠I g ) duration(I p ⪠I g ) ,(10) where duration(¡) is measured in seconds. Disjoint intervals score 0. 15 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases 3. Timestamp Sets.For tasks that return an unordered set of dates (e.g., Top-K composite trends), we treat the prediction D p and ground truth D g as sets and compute F1: Score set (D p ,D g ) = 2¡ Precision¡ Recall Precision + Recall ,(11) where Precision is the fraction of correct dates in the prediction, and Recall is the fraction of ground-truth dates successfully retrieved. 4. Structured Reports.Insight Synthesis (Level 4) returns free-form text. Surface metrics like BLEU and ROUGE cannot judge factual correctness in this setting, so we cannot rely on them. Because our prompt enforces a controlled vocabulary and a strict two-part schema (see Appendix A.1), the output can be deterministically parsed into Trend Segments and Outliers, which are then scored by a composite: Score report = 0.4S trend + 0.3S interval + 0.2S adj + 0.1S outlier ,(12) The four sub-scores measure, respectively: (1)S trend : alignment of trend types (rise vs. fall) via longest common subsequence. (2)S interval : mean IoU over the matched trend segments. (3)S adj : match rate of descriptive adjectives (rapid vs. gradual). (4) S outlier : the detected anomaly timestamps. The weights were calibrated to prioritize correct trend structure over fine-grained adjective matching. Table 6. Task-to-metric lookup for NLQTSBench. LevelSubtaskMetric L1Atomic Retrieval (Global Aggregation)Relative Accuracy L1Atomic Retrieval (Temporal Localization)Hit Rate L1Atomic Retrieval (Interval Discovery)IoU L1Sliding WindowIoU L2Shape IdentificationIoU L2Periodicity DetectionRelative Accuracy L2Subsequence MatchingIoU L3Composite TrendSet F1 L3Contextual AnomalyIoU L3Causal AnomalyIoU L4Insight SynthesisComposite Report Score A.4. NLQTSBench-Lite Statistics We provide the per-task composition of NLQTSBench-Lite in Table 7. The Lite variant is purpose-built as a fixed evaluation suite for context-limited time series baselines (e.g., ChatTS, ITFormer, Time-R1) whose input window cannot accommodate the multi-year histories of the full benchmark. Table 7. Task composition of NLQTSBench-Lite (500 instances in total). LevelSubtask#Instances L2Shape Identification (SI)100 L3Composite Trend (CT)200 L3Causal Anomaly (CsA)200 Total500 The three retained tasks correspond to the three core capabilities that NLQ4TSDB demands: Shape Identification for morphological grounding, Composite Trend for multi-stage temporal reasoning, and Causal Anomaly for cross-channel relational reasoning. Together they form a compact yet representative testbed for evaluating short-context models on the central challenges of the task. 16 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases B. Implementation Details of Sonar-TS B.1. System Configurations It is crucial to note that Sonar-TS is designed as a highly configurable framework. The hyperparameters described below represent our default instantiation for the benchmark evaluation. All configurations can be flexibly adapted to specific downstream applications or industrial deployments. Databases and Backbone Models.The framework fundamentally decouples data storage from analytical reasoning. For the underlying TSDB, our current implementation targets SQL-compatible systems (e.g., InfluxDB). For the backbone LLM, our primary experiments utilize DeepSeek-V3 for both task planning and code generation. To demonstrate consistent efficacy across varying model capacities, we additionally evaluate the framework using the open-weights Qwen family. Multi-scale Feature Tables. To facilitate efficient multi-granular querying, we materialize feature tables aligned with natural temporal hierarchies:Yearly,Monthly, andDailyviews. Each row in these tables summarizes a specific time window w = [t start ,t end ) for a unique time series channel. The schema includes: ⢠Metadata: seriesid, viewtype (e.g., âdailyâ), windowstart, windowend. ⢠Statistical Primitives: minval, maxval, avgval, stdval, and slope. ⢠Morphological Tokens: SAX and SAX len. Statistical Primitives For each window, we precompute a set of lightweight descriptive statistics. While the current version of the NLQ4TSDB benchmark focuses heavily on complex pattern recognition, making simple statistics less central to the primary evaluation tasks, these primitives remain critical for optimizing broader query types. For instance, a query such as âFind the longest daily interval with a continuous upward trendâ can be accelerated significantly by filtering on precomputedslopevalues (e.g.,slope > 0), thereby pruning the search space before accessing raw high-frequency data. Similarly, stdval serves as an efficient proxy for filtering volatile or stable periods. Morphological Tokens (SAX Implementation). To support shape-based retrieval, we implement Symbolic Aggregate approXimation (SAX), transforming complex continuous shapes into discrete string signatures. 1. Piecewise Aggregate Approximation (PAA). We first reduce the dimensionality of the raw time series sequence C =c 1 ,...,c n within a window into a vector of lengthw, denoted as Ě C = Ěc 1 ,..., Ěc w . The choice ofwadapts to the temporal granularity to preserve semantic interpretability: ⢠Yearly View: w = 12, aligning with months. ⢠Monthly View: w is dynamic, equal to the number of days in that specific month (e.g., 28, 30, or 31). ⢠Daily View: w = 24, aligning with hours. The i-th PAA coefficient is computed as the mean of the corresponding segment: Ěc i = w n n w i X j= n w (iâ1)+1 c j (13) 2.Symbolic Mapping. The PAA vector Ě Cis Z-normalized to have a mean of zero and a standard deviation of one. We then map each coefficient Ěc i to a symbols i from an alphabetÎŁof sizeÎą(in our implementation,Îą = 5, ÎŁ = Ⲡa Ⲡ, Ⲡb Ⲡ, Ⲡc Ⲡ, Ⲡd Ⲡ, Ⲡe Ⲡ). The mapping is defined by a set of breakpointsβ =β 0 ,...,β Îą , which divide the area under the Normal distribution N (0, 1) into Îą equiprobable regions. The mapping function is: s i = char(j) if β jâ1 ⤠Ěc i < β j (14) whereβ 0 =ââandβ Îą =â. This results in a discrete signature string Ë C = s 1 s 2 ...s w that robustly encodes the shape of the time series window. Figure 7 illustrates this SAX transformation process across different granularities. 17 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Figure 7. Visualization of Multi-Scale SAX Representations. The framework discretizes time series data across hierarchical granularities to support pattern matching at different resolutions: (Top) The Daily View captures high-frequency local fluctuations; (Middle) The Monthly View summarizes intermediate trends; (Bottom) The Yearly View abstracts long-term seasonality. The colored horizontal bars represent the assigned SAX symbols (from level a to e) overlaid on the raw data (gray line). Experience Initialization (Prompt Cold Start).To construct the initial Prompt Experiences without causing data leakage on the test set, we utilized a separate, hold-out dataset of 110 queries entirely independent of the evaluation benchmark. The âReward-Summarize-Updateâ pipeline was executed on this set to bootstrap the initial knowledge base. Furthermore, the global Experience set is strictly capped at 20 items. This limit ensures that the entire set can be directly injected into the system prompt for every online query without risking context overflow or distracting the LLM. Runtime Self-Correction. To enhance system robustness during the online âExecution & Self-Correctionâ phase, the system employs an automated debugging loop. We bound the maximum retry limit toR = 3. Empirical observations indicate that the majority of recoverable execution errors (e.g., empty SQL results or Python syntax faults) are resolved within this window, and further retries yield diminishing returns. B.2. Prompt Design We implement a structured prompting pipeline to orchestrate the Search-Then-Verify workflow. This process dissociates high-level logical planning from low-level code implementation, featuring a dual-mode code generator capable of iterative self-correction. 1. Task Planner Prompt.The Planner is responsible for selecting the execution mode and the data source. As shown in the prompt below, the model is explicitly guided to distinguish between the âHigh IOâ raw data table (Wide) and the âLow IOâ feature tables (Long) to optimize retrieval efficiency. 18 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Task Planner Prompt You are a Task Planner for Time Series Analysis. Decompose the question into a JSON plan. No code. â DATABASE SCHEMA â database schema 1. Raw Data (data): High I/O cost. Use ONLY when the time range is explicitly known and precise values are needed. 2. Feature Tables (feature *): Low I/O cost. Contains precomputed stats (avg, std) and shape descriptors (sax). Use for searching patterns or scanning large historical ranges. â EXPERIENCES â experiences â User Question â Input Question â PLANNING STRATEGY â Analyze the query constraints to decide the Pipeline Mode: Mode A: DIRECTACCESS (Fetchâ Compute) Criteria: 1. Time range is fixed (e.g., âlast 24hâ, âin 2023â). 2. Task involves calculation on a specific segment. Strategy: Direct SQL query on âdataââ Python Processing. Mode B: SEARCHTHENVERIFY (Pruneâ Verify) Criteria: 1. Time range is UNKNOWN/OPEN (e.g., âFind the period where...â). 2. Logic is MORPHOLOGICAL (e.g., âV-shapeâ) or requires historical context. Strategy: Search âfeature*â filtersâ Get Candidatesâ Python Verification. â Output Format (Strict JSON) â âreasoningâ: âAnalysis of time range constraints and search intentâ, âpipeline modeâ: âDIRECTACCESSâ or âSEARCHTHENVERIFYâ, âstep1retrievalâ: âtarget tableâ: âdataâ or âfeaturedailyâ or âfeaturemonthlyâ, âsql logichintâ: âDescription of the SQL filter/logicâ , âstep 2computationâ: âneedspythonâ: true, âlogicdescriptionâ: âDescription of the math/verification logicâ 2. Code Generator Prompt. Following the plan, the Code Generator constructs the executable queries. It operates in two modes: Generation (synthesizing the initial code) and Refinement (fixing errors based on runtime feedback). In the generation phase, strict environmental constraints and a domain-specific operator library are enforced to ground the modelâs logic. Subsequently, the refinement phase acts as a runtime debugger, allowing the agent to iteratively self-correct against dynamic exceptions (e.g., empty SQL results) that are unpredictable during the initial generation. Code Generation Prompt (Generation Mode) You are the Code Generator. Translate the structured Task Plan into executable Python code. â DATABASE SCHEMA â database schema â EXPERIENCES â experiences 19 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases â User Question â Input Question â TASK PLAN (JSON) â JSON Plan generated by Task Planner â CODE GENERATION STRATEGY â Generate a single Python code block to execute the plan. 1. Execution Environment: You have access to pandas (pd), numpy (np), and scipy. The variable âconnâ is already defined and connected to the database. - DO NOT create a new connection. DO NOT close âconnâ. - Execute SQL using: df = pd.readsqlquery(sql, conn). 2. Operator Library (Module: sonarops): Prioritize using the following pre-defined atomic operators for verification. If a task cannot be solved by these operators, synthesize standard pandas/numpy logic. - detect period(data, maxlag): Estimates the dominant cycle length. - findbestmatch(query, search, metric): Finds the most similar subsequence via DTW. - detectchangepoints(data, penalty): Identifies structural break points (PELT). - calc trendslope(data): Computes robust slope (Theil-Sen) for trend description. - calc correlation(seqa, seqb, lag): Measures statistical relationship between series. â Output Format â Return ONLY the executable Python code block. No markdown explanation. The code must define a final variable finalanswer containing the result. Code Generation Prompt (Refinement Mode) You are the Code Refinement Agent. The previous execution failed. Analyze the error trace and modify the code to make it executable. â SHARED CONTEXT â (Includes Database Schema, Experiences, Input Question, Task Plan, and Code Generation Strategy) â HISTORY: TURN 1 â Code: Previous Python Code Execution Feedback: Error Traceback OR âEmpty Resultâ ... (History stacks up to 3 turns) ... â Output Format â Return ONLY the corrected executable Python code block. No markdown explanation. The code must define a final variable final answer containing the result. 3. Experience Summarizer Prompt.This module acts as a âTechnical Leadâ conducting a post-mortem. It analyzes the full execution trajectoryâincluding the initial plan, the challenges faced (error history), and the final working codeâto extract a single, high-value insight. This ensures that the system learns not just from success, but from the corrections applied during the process. Experience Summarization Prompt You are a Technical Lead conducting a Post-Mortem. Summarize the technical solution. â Question â Input Question 20 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases â Plan â JSON Plan generated by Task Planner â CODE & EXECUTION HISTORY â Full Trace of Code Generations and Execution Feedbacks â Task â Extract ONE concise, reusable technical insight. - How was the task resolved? - Analyze the reasons for success or failure. - Generalize the finding. â Output Format â Insight: [Your 1-sentence summary] 4. Experience Updater prompt To prevent the experience list from growing indefinitely, the Updater functions as a âKnowledge Curator.â It takes the newly extracted insight and merges it into the existing Global Experience Pool. The model is instructed to perform semantic operationsâAdd (if new), Merge (if similar), or Discard (if redundant)âensuring the knowledge base remains compact and highly relevant. Experience Updater Prompt You are the Knowledge Base Curator for Sonar-TS. Manage the global experience list. â EXISTING EXPERIENCES â Current List of N Insights â NEW INSIGHT â Output from Summarizer â UPDATE STRATEGY â Compare the New Insight with the Existing List and apply one operation: 1. ADD: If the insight covers a new edge case. 2. MERGE: If a similar insight exists, combine them into a more robust rule. 3. DISCARD: If the insight is trivial or fully covered. Constraint: Keep the total list size under 20 items to preserve context window. â Output Format â Return the updated list of experiences (JSON list of strings). C. Additional Experiments We present three additional analyses that probe Sonar-TS from different angles: (1) sensitivity to two key parameters, namely the LLM backbone and the SAX alphabet size (Appendix C.1); (2) the internal effectiveness of the Search stage that anchors our Search-Then-Verify workflow (Appendix C.2); and (3) computational overhead relative to a comparable baseline (Appendix C.3). C.1. Parameter Sensitivity We examine the sensitivity of Sonar-TS to two key parameters: the choice of LLM backbone and the SAX alphabet sizeÎą. Sensitivity to LLM Choice.Table 8 reports the performance of Sonar-TS across underlying LLMs of varying scales. As expected, scaling up the model size consistently yields better overall performance, with our default DeepSeek-V3 achieving the highest average score. While the Experiences memory mitigates the zero-shot reasoning burden by providing historical analytical skills, the unconventional âSAX + regexâ querying paradigm still demands strong capabilities from the underlying LLM: the backbone must translate subjective morphological descriptions into precise SAX-based regular expressions. Smaller models (e.g., Qwen3.5-9B) therefore struggle with this morphological-to-symbolic mapping, whereas larger models handle the translation reliably. 21 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Table 8. Sensitivity of Sonar-TS to the LLM backbone. Backbone ModelAvg. Score Qwen3.5-9B0.3598 Qwen3.5-27B0.4817 Qwen3.5-35B0.5359 DeepSeek-V3 (Default)0.6144 Sensitivity to SAX Alphabet Size.Table 9 evaluates the effect of varying the SAX alphabet sizeÎąon morphology tasks (SI, CT). The optimal value isÎą = 5, driven by two factors. First, semantic alignment: natural language typically uses five morphological gradations (e.g., from âvery lowâ to âvery highâ), so settingÎą = 5maps these descriptors directly onto symbolic tokens. Second, resolution trade-off : a larger alphabet (Îą = 7) fractures the search space and complicates robust regex generation, while a smaller alphabet (Îą = 3) lacks the expressive power to capture necessary morphological nuances. Table 9. Sensitivity of morphology tasks to the SAX alphabet size Îą. Alphabet Size (Îą)L2: SIL3: CT Îą = 30.19270.2318 Îą = 5 (Default)0.33360.2988 Îą = 70.28960.2675 C.2. Search Effectiveness A core challenge of NLQ4TSDB is morphological reasoning and retrieval, which Sonar-TS addresses via the Search-Then- Verify workflow. To examine the internal effectiveness of this mechanism, we focus on the morphology-dependent tasks: Shape Identification and Composite Trend. Table 10 reports the intermediate retrieval performance of the initial Search stage on these tasks. The Search stage narrows the search space by orders of magnitude relative to the raw time series (typically containing tens of thousands of points), while maintaining moderate recall. This validates our core hypothesis: symbolic representation enables morphological retrieval. We acknowledge that the current recall indicates room for improvement, which we attribute to two factors. First, the task is inherently hard: translating subjective morphological concepts into strict matching conditions is highly prone to semantic ambiguity. Second, our SAX-based symbolic implementation suffers inevitable information loss during compression, which hinders fine-grained morphological retrieval; we discuss this limitation further in Appendix D. As an initial attempt, these results nonetheless demonstrate the feasibility of our retrieval strategy. Exact candidate counts and recall values may vary with benchmark configuration and future SAX index improvements; we refer readers to our open-source repository for the most up-to-date numbers. Table 10. Internal evaluation of the Search stage, reporting average candidates retrieved and recall. Absolute candidate counts depend on benchmark construction details (e.g., the number of injected positives per query and the temporal scope of each instance). Task CategoryAvg. CandidatesRecall L2: Shape Identification9.30.5482 L3: Composite Trend5.80.4713 C.3. System Overhead Table 11 reports the system overhead of Sonar-TS along four practical metrics: offline construction time for the feature tables, online querying latency, average token consumption per query, and relative storage overhead. We use MAC-SQL as the baseline because its multi-agent collaborative design closely aligns with Sonar-TS, ensuring a fair and architecturally comparable evaluation. Sonar-TS exhibits an online querying latency of roughly 22 seconds and consumes approximately 11k tokens per query. While slightly higher than the Text-to-SQL baseline MAC-SQL, this overhead represents a reasonable trade-off given the 22 Sonar-TS: Search-Then-Verify Natural Language Querying for Time Series Databases Table 11. System overhead and computational cost of Sonar-TS. Time is in seconds (s), token cost is the per-query average, and storage overhead is relative to the raw data size. Reported figures reflect a representative deployment on our experimental setup; concrete values depend on hardware, API latency, and code version. Efficiency MetricMAC-SQLSonar-TS Offline Construction TimeN/A âź83 s Online Querying Latency âź15 s âź22 s Average Token Costâź8k âź11k Storage OverheadN/A11% complexity of NLQ4TSDB. Conceptually, Sonar-TS functions as a superset of Text-to-SQL methods: it retains foundational SQL generation capabilities but additionally orchestrates multi-step task planning, morphological retrieval, and Python code execution. Given these supplementary operations, the modest latency increase remains within an acceptable range for the target use case. As our system continues to evolve, latency and token cost may shift with code optimizations and changes in upstream LLM inference speed; we refer readers to our open-source repository for current framework. D. Limitations and Future Work While Sonar-TS demonstrates the feasibility of the NLQ4TSDB task, several limitations remain. Realism of Data and Queries. Due to the nascent nature of the NLQ4TSDB task, there is a severe scarcity of available datasets. We initially sought to use real-world data but faced significant bottlenecks: manually annotating million-point sequences is prohibitively labor-intensive, and reliable automated labeling algorithms are lacking. Consequently, we relied on a synthetic-injection pipeline (Section 4.2) to guarantee verifiable ground truths. While this ensures an initial testbed, aligning with the true distribution of real-world data and authentic user queries remains a critical necessity. Future work must focus on developing realistic datasets aligned with actual business demands. Information Loss in Symbolic Representation. To enable morphological retrieval over continuous signals, we employ SAX. However, its reliance on rigid temporal and amplitude bins inevitably induces information loss, causing the system to inherently struggle with fine-grained local fluctuations. Future iterations should explore learnable discrete represen- tations. Transitioning from these rigid heuristics to semantics-aware tokenizers could provide the nuanced, high-fidelity representations specifically tailored for complex NLQ4TSDB tasks. Scalability of Experience Injection. Because general LLMs lack the specialized domain knowledge for complex time series querying, we implement a prompt cold start process (Section 5.3) to extract essential analytical skills as Experiences. Currently, to ensure execution stability, we inject a hard limit of 20 items directly into the system prompt. While this pragmatic workaround is effective, it is not a scalable long-term solution. As user intents diversify and databases expand, a static set of skills will inevitably become insufficient. Future work should develop dynamic retrieval modules to scale for increasingly complex analytical scenarios. 23