# US 2026/0093695 A1 · Method and system for templatization and retrieval of domain knowledge for enterprise text-to-sql semantic parsing

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2026/0093695 A1
- Document ID: US20260093695A1
- Status: Published application
- Kind: A1
- Application number: 19/335,178
- Filed: 2025-09-22
- Published: 2026-04-02
- Earliest claimed: 2024-10-02
- Assignees: Tata Consultancy Services Limited
- Applicants: Tata Consultancy Services Limited
- Inventors: Shabbirhussain Hamid BHAISAHEB; Manasi Samarth PATWARDHAN; Aseem ARORA; Lovekesh VIG; Sunita SARAWAGI
- Web page: https://patentgrep.com/patent/US20260093695A1

## CPC

- G06F 16/24522: {Translation of natural language queries to structured queries}
- G06F 16/3344: {using natural language analysis}
- G06F 16/2425: {Iterative querying; Query formulation based on the results of a preceding query}
- G06F 16/24535: {of sub-queries or views}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Existing approaches for templatization and retrieval of domain knowledge for SQL queries for the enterprise databases have the disadvantages that they do not understand the context of natural language query and retrieve the most suitable templatized domain statement for SQL query generation. Embodiments disclosed herein provide a method and system for templatization and retrieval of domain knowledge for enterprise text-to-SQL semantic parsing. In this approach, the system generates the templatized domain statements for the domain database, the templatized domain statements assist in understanding the natural language query and guides the model for generating the SQL query and retrieve the most suitable templatized domain statement for any natural language query to guide the trained model to generate the associated SQL query.

## Claims

### Claim 1

A processor implemented method, comprising:
receiving, via one or more hardware processors, a) at least one query in natural language, b) a database schema, and c) a database meta data from domain specific data source;
pre-processing, via the one or more hardware processors, the at least one query to obtain a pre-processed at least one query;
segmenting, via the one or more hardware processors, the pre-processed at least one query into one or more sets, each comprising one or more sub-queries;
computing, via the one or more hardware processors, an embedding for each of the one or more sub-queries in the one or more sets;
computing, via the one or more hardware processors, a similarity metric between the embedding of the one or more sub-queries in the one or more sets, and an embedding of a natural language part of a plurality of templatized domain statements;
computing, via the one or more hardware processors, a weighted set score for each of the one or more sets using the one or more sub-queries in the one or more sets and the similarity metric, wherein the weighted set score represents extent of similarity of the at least one query with each of the plurality of templatized domain statements;
retrieving, via the one or more hardware processors, one or more of the plurality of templatized domain statements based on the weighted set score; and
generating, via the one or more hardware processors, a SQL query for the at least one query in natural language, using the database schema, the database meta data, and the retrieved one or more templatized domain statements.

### Claim 2 (depends on 1)

The method of claim 1, wherein the pre-processing comprises replacing a numerical value and a date to a predefined fixed integer.

### Claim 3 (depends on 1)

The method of claim 1, wherein segmenting the pre-processed at least one query into the one or more sets comprising the one or more sub-queries comprises:
creating, via the one or more hardware processors, a list of a plurality of individual words in the pre-processed at least one query;
generating, via the one or more hardware processors, the one or more sets comprising a plurality of combinations of the one or more sub-queries in the one or more sets by iterating through the list of a plurality of individual words, and joining two or more of the plurality of individual words;
iteratively generating, via the one or more hardware processors, the one or more sub-queries until all of the plurality of individual words are used in at least one of the one or more sets, wherein each of the one or more sets comprises one or more sub-queries of same or different length of plurality of individual words, and wherein each of the one or more sub-queries among the one or more sets and each of the one or more set among the one or more sets are unique; and
generating, via the one or more hardware processors, the one or more sub-queries in the one or more sets until the one or more sub-queries are matching with the at least one query in natural language.

### Claim 4 (depends on 1)

The method of claim 1, wherein computing the weighted set score by using the length of sub-query representing number of words in the sub-query and the one or more similarity metric is represented as:
Set_Score=Σ(length of sub-string (number of words))*(Max. similarity score with a templatized domain statement),
where, the length of sub-string is the number of words in the one or more sub-queries, and the Max. similarity score with a templatized domain statement is the similarity metric of the one or more sub-queries in the one or more sets.

### Claim 5 (depends on 1)

The method of claim 1, wherein generating the plurality of templatized domain statements comprises:
receiving, via the one or more hardware processors, a) one or more domain statements for a given domain, in natural language, and b) a domain specific database schema comprising name of a plurality of tables, columns, data types, and representative strings corresponding to one or more entities stored in each column;
selecting, via the one or more hardware processors, one or more few shot exemplars from a training dataset comprising a natural language query and a plurality of associated SQL queries;
generating, via the one or more hardware processors, the natural language part of each of the plurality of templatized domain statement by applying a trained model on the one or more few shot exemplars, the one or more domain statements, and the domain specific database schema;
generating, via the one or more hardware processors, a SQL logic for the natural language part of each of the plurality of the templatized domain statements by applying the trained model on the one or more few shot exemplars, the one or more domain statements, the database schema, and the generated natural language part of each of the plurality of templatized domain statements;
validating, via the one or more hardware processors, the natural language part of each of the plurality of templatized domain statements and associated SQL logic for consistency using the trained model, wherein,
if the validation is inconsistent, the SQL logic associated with the natural language part of each of the plurality of templatized domain statements is updated using the trained model, and wherein
if validation is consistent, the templatized domain statement along with the SQL logic are generated by using the trained model for combining the natural language part of each of the plurality of templatized domain statements and the SQL logic, based on the one or more few shot exemplar; and
computing, via the one or more hardware processors, the embedding of the natural language part of the plurality of templatized domain statements, wherein the computed embedding is stored in a database.

### Claim 6

A system, comprising:
one or more hardware processors;
a communication interface; and
a memory storing a plurality of instructions, wherein the plurality of instructions cause the one or more hardware processors to:
receive a) at least one query in natural language, b) a database schema, and c) a database meta data from domain specific data source;
pre-process the at least one query to obtain a pre-processed at least one query;
segment the pre-processed at least one query into one or more sets, each comprising one or more sub-queries;
compute an embedding for each of the one or more sub-queries in the one or more sets;
compute a similarity metric between the embedding of the one or more sub-queries in the one or more sets, and an embedding of a natural language part of a plurality of templatized domain statements;
compute a weighted set score for each of the one or more sets using the one or more sub-queries in the one or more sets and the similarity metric, wherein the weighted set score represents extent of similarity of the at least one query with each of the plurality of templatized domain statements;
retrieve one or more of the plurality of templatized domain statements based on the weighted set score; and
generate a SQL query for the at least one query in natural language, using the database schema, the database meta data, and the retrieved one or more templatized domain statements.

### Claim 7 (depends on 6)

The system of claim 6, wherein the pre-processing comprises replacing a numerical value and a date to a predefined fixed integer.

### Claim 8 (depends on 6)

The system of claim 6, wherein the one or more hardware processors are configured for segmenting the pre-processed at least one query into the one or more sets comprising the one or more sub-queries, comprises:
creating a list of a plurality of individual words in the pre-processed at least one query;
generating the one or more sets comprising a plurality of combinations of the one or more sub-queries in the one or more sets by iterating through the list of a plurality of individual words, and joining two or more of the plurality of individual words;
iteratively generating the one or more sub-queries until all of the plurality of individual words are used in at least one of the one or more sets, wherein each of the one or more sets comprises one or more sub-queries of same or different length of plurality of individual words, and wherein each of the one or more sub-queries among the one or more sets, and each of the one or more set among the one or more sets are unique; and
generating the one or more sub-queries in the one or more sets until the one or more sub-queries are matching with the at least one query in natural language.

### Claim 9 (depends on 6)

The system of claim 6, wherein the one or more hardware processors are configured for computing the weighted set score by using the length of sub-query representing number of words in the sub-query and the one or more similarity metric is represented as:
Set_Score=Σ(length of sub-string (number of words))*(Max. similarity score with a templatized domain statement),
where, the length of sub-string is the number of words in the one or more sub-queries, and the Max. similarity score with a templatized domain statement is the similarity metric of the one or more sub-queries in the one or more sets.

### Claim 10 (depends on 6)

The system of claim 6, wherein the one or more hardware processors are configured for generating the plurality of templatized domain statements, comprises:
receiving, a) one or more domain statements for a given domain, in natural language, and b) a domain specific database schema comprising a name of a plurality of tables, columns, data types, and representative strings corresponding to one or more entities stored in each column;
selecting one or more few shot exemplars from a training dataset comprising a natural language query and a plurality of associated SQL queries;
generating the natural language part of each of the plurality of templatized domain statement by applying a trained model on the one or more few shot exemplars, the one or more domain statements, and the domain specific database schema;
generating a SQL logic for the natural language part of each of the plurality of the templatized domain statements by applying the trained model on the one or more few shot exemplars, the one or more domain statements, the database schema, and the generated natural language part of each of the plurality of templatized domain statements;
validating the natural language part of each of the plurality of templatized domain statements and associated SQL logic for consistency using the trained model, wherein,
if validation is inconsistent, the SQL logic associated with the natural language part of each of the plurality of templatized domain statements is updated using the trained model, wherein
if validation is consistent, the templatized domain statement along with the SQL logic are generated by using the trained model for combining the natural language part of each of the plurality of templatized domain statements and the SQL logic, based on the one or more few shot exemplar; and
computing the embedding of the natural language part of the plurality of templatized domain statements, wherein the computed embedding is stored in a database.

### Claim 11

One or more non-transitory machine-readable information storage mediums comprising one or more instructions which when executed by one or more hardware processors cause:
receiving a) at least one query in natural language, b) a database schema, and c) a database meta data from domain specific data source;
pre-processing the at least one query to obtain a pre-processed at least one query;
segmenting the pre-processed at least one query into one or more sets, each comprising one or more sub-queries;
computing an embedding for each of the one or more sub-queries in the one or more sets;
computing a similarity metric between the embedding of the one or more sub-queries in the one or more sets, and an embedding of a natural language part of a plurality of templatized domain statements;
computing a weighted set score for each of the one or more sets using the one or more sub-queries in the one or more sets and the similarity metric, wherein the weighted set score represents extent of similarity of the at least one query with each of the plurality of templatized domain statements;
retrieving one or more of the plurality of templatized domain statements based on the weighted set score; and
generating a SQL query for the at least one query in natural language, using the database schema, the database meta data, and the retrieved one or more templatized domain statements.

### Claim 12 (depends on 11)

The one or more non-transitory machine readable information storage mediums of claim 11, wherein the pre-processing comprises replacing a numerical value and a date to a predefined fixed integer.

### Claim 13 (depends on 11)

The one or more non-transitory machine readable information storage mediums of claim 11, wherein segmenting the pre-processed at least one query into the one or more sets comprising the one or more sub-queries comprises:
creating a list of a plurality of individual words in the pre-processed at least one query;
generating the one or more sets comprising a plurality of combinations of the one or more sub-queries in the one or more sets by iterating through the list of a plurality of individual words, and joining two or more of the plurality of individual words;
iteratively generating, the one or more sub-queries until all of the plurality of individual words are used in at least one of the one or more sets wherein each of the one or more sets comprises one or more sub-queries of same or different length of plurality of individual words and wherein each of the one or more sub-queries among the one or more sets and each of the one or more set among the one or more sets are unique; and
generating the one or more sub-queries in the one or more sets until the one or more sub-queries are matching with the at least one query in natural language.

### Claim 14 (depends on 11)

The one or more non-transitory machine readable information storage mediums of claim 11, wherein computing the weighted set score by using the length of sub-query representing number of words in the sub-query and the one or more similarity metric is represented as:
Set_Score=Σ(length of sub-string (number of words))*(Max. similarity score with a templatized domain statement),
where, the length of sub-string is the number of words in the one or more sub-queries, and the Max. similarity score with a templatized domain statement is the similarity metric of the one or more sub-queries in the one or more sets.

### Claim 15 (depends on 11)

The one or more non-transitory machine readable information storage mediums of claim 11, wherein generating the plurality of templatized domain statements comprises:
receiving a) one or more domain statements for a given domain, in natural language, and b) a domain specific database schema comprising name of a plurality of tables, columns, data types, and representative strings corresponding to one or more entities stored in each column;
selecting one or more few shot exemplars from a training dataset comprising a natural language query and a plurality of associated SQL queries;
generating the natural language part of each of the plurality of templatized domain statement by applying a trained model on the one or more few shot exemplars, the one or more domain statements, and the domain specific database schema;
generating a SQL logic for the natural language part of each of the plurality of the templatized domain statements by applying the trained model on the one or more few shot exemplars, the one or more domain statements, the database schema, and the generated natural language part of each of the plurality of templatized domain statements;
validating the natural language part of each of the plurality of templatized domain statements and associated SQL logic for consistency using the trained model, wherein,
if the validation is inconsistent, the SQL logic associated with the natural language part of each of the plurality of templatized domain statements is updated using the trained model, and wherein
if validation is consistent, the templatized domain statement along with the SQL logic are generated by using the trained model for combining the natural language part of each of the plurality of templatized domain statements and the SQL logic, based on the one or more few shot exemplar; and
computing the embedding of the natural language part of the plurality of templatized domain statements, wherein the computed embedding is stored in a database.
