Banyan Intelligence Logo
Banyan
Updated: Apr 29, 2024

Beyond Text-to-SQL: Harnessing the Power of Function Calling for Time Series Data Insights

Sumant Shetty6 min read
Cover image for Beyond Text-to-SQL: Harnessing the Power of Function Calling for Time Series Data Insights

In today's data-driven world, time series data has become the lifeblood of countless enterprises. From monitoring application performance and IoT sensor streams to analyzing financial markets and user behavior, the ability to extract timely insights from time-stamped data is paramount. As this data deluge grows, the need for intuitive and efficient query interfaces becomes increasingly critical. Natural-language interfaces, powered by Large Language Models (LLMs), offer a promising avenue to democratize data access and empower users of all technical backgrounds to ask questions and get answers directly from their data.

While Text-to-SQL has emerged as a popular approach for natural-language database querying, its application to complex time-series data—especially within star-schema warehouses—presents significant hurdles. Translating nuanced time-series questions into accurate and performant SQL can quickly become a maze of intricate joins and specialized aggregations.

In this post we explore those limitations and introduce a more powerful alternative: Function Calling. We'll examine three different approaches we've tested and show how they unlock expressiveness and efficiency for faster insights.

The Challenge: Querying Time-Series Star Schemas with Natural Language

Key pain points where Text-to-SQL falls short:

Challenge 1 — Complex Joins

Even a simple question like "What is the average CPU utilization for servers in the US-West region over the last hour?" can require multiple joins across fact and dimension tables. Generating that SQL reliably from free-form language is error-prone.

Challenge 2 — Time-Series Aggregations

Databases such as TimescaleDB provide specialised functions like time_bucket(), first() and last(). Text-to-SQL models rarely surface these capabilities, resulting in slower queries and missed features.

Challenge 3 — Nuanced Analytical Intents

Concepts like "trend analysis" or "significant increases" are difficult to encode directly in SQL. Capturing that intent in a Text-to-SQL pipeline quickly becomes brittle.

Our Solution: Function Calling for Time-Series Data

Function Calling shifts responsibility: instead of generating raw SQL, the LLM calls vetted functions (APIs) that encapsulate business logic and schema specifics. We tested three strategies:

  1. Filtered Table + Code Execution – maximal flexibility; post-processing happens in Python or notebooks.
  2. Comprehensive Structured Calls – nested query dictionaries that translate directly into SQL server-side.
  3. Intent-Based Calls – our preferred middle ground, mapping common analytical intents to concise function signatures.

Benefits of Function Calling

  • Greater expressiveness for specialised time-series analysis
  • Lower latency and data transfer by fetching exactly what is needed
  • User-friendly intents that mirror natural questioning
  • A future-proof pathway to embed advanced analytics & ML workflows

By embracing Function Calling, organisations can move beyond the constraints of Text-to-SQL and empower everyone to gain deeper, faster insights from their time-series data.