Hermes: A Text-to-SQL solution at Swiggy

Amaresh Marripudi, Rutvik Reddy29 Jul 2024

Problem

Product managers, business teams and data scientists at Swiggy need specific numbers, such as the P95 of customer claims in a cohort of restaurants in one region. To get one, they search for a dashboard, write SQL themselves (which needs table knowledge, access and SQL skills) or ask an analyst. This takes from minutes to days, so some questions are never asked or get proxy answers. A first text-to-SQL version on a general LLM matched online benchmarks but fell short on real queries, because tables, columns and metrics are numerous and look alike across businesses.

Example from the article: "What was the average rating last week in Bangalore for orders delivered 5 mins earlier than promised?" returns the SQL and its result in Slack.

Solution in brief

Hermes is a Slack bot with a separate knowledge base per business unit (a "charter"). A staged pipeline finds the relevant metrics, then columns and tables, then similar verified queries. It builds one compact prompt for GPT-4o, runs the SQL and returns errors to the model for a limited number of retries.

Questions this case answers
  • How to let non-technical users get accurate answers from a large data warehouse in natural language when generic text-to-SQL breaks on similar tables and company-specific metric definitions
  • How to ground an LLM that writes SQL in curated metadata and verified reference queries so it selects the right tables and columns
  • How to let business users get numbers from company data by asking a question in Slack?
  • How to make a text-to-SQL model pick the right tables and columns when the company has thousands of similar ones?

Tools and methods

  • GPT-3.5 variants (V1), GPT-4o (V2) — generate the SQL
  • Knowledge base per charter — metrics, tables, columns, reference queries
  • Embedding-based vector lookup — find columns and few-shot queries
  • Slack, AWS Lambda, Databricks job — interface, middleware, execution
Continue reading — it's free

Google or a one-time email code. No password.