Pattern-Based Retrieval for Accurate NL2SQL In-Context Learning

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing generative artificial intelligence models for converting natural language to SQL face challenges in accuracy due to nuanced context understanding, domain-specific knowledge gaps, and computational inefficiencies, leading to inaccuracies and resource-intensive solutions.

Innovation Solution

Implementing in-context learning with pattern-based retrieval techniques, using memory banks of high-quality examples and pattern-based retrieval to guide generative models, enhancing accuracy and efficiency in converting natural language to SQL.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Ease of operation

If generative AI models are used to convert natural language to SQL, then the accessibility and ease of operation are improved, but the accuracy and reliability deteriorate due to context understanding limitations and domain knowledge gaps

Engineering Contradiction:
ImproveNatural language query interfaceVSAvoidSQL generation accuracy
Core Design Contradiction:
Ease of operationVSReliability

Solution Approach 1:

The system performs preliminary actions by retrieving relevant in-context examples from a memory bank before generating SQL queries. These examples provide domain-specific patterns and contextual information that guide the generative model, ensuring accurate SQL generation while maintaining natural language accessibility.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent introduces an intermediary retrieval mechanism that acts as a bridge between natural language queries and SQL generation. This intermediary searches for and retrieves relevant examples from a memory bank, providing contextual guidance to the generative model and improving accuracy without compromising ease of use.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Ease of operation

If traditional text-to-SQL systems are implemented, then the ease of operation is improved, but the computational efficiency and resource consumption worsen

Engineering Contradiction:
ImproveNatural language interfaceVSAvoidQuery processing efficiency
Core Design Contradiction:
Ease of operationVSProductivity

Solution Approach 1:

The system segments the text-to-SQL process into distinct components: a retrieval module that searches the memory bank for relevant examples, and a generation module that uses these examples to produce SQL queries. This segmentation allows each component to specialize, improving overall efficiency while maintaining natural language accessibility.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The retrieval of in-context examples is performed as a preliminary action before SQL generation. This pre-computation step provides the generative model with targeted contextual information, reducing the computational burden during the actual query generation phase and improving processing efficiency.

Inventive Principle:
Principle #10Preliminary action

3Reliability

If in-context examples are retrieved from memory bank, then the SQL generation accuracy is improved, but the computational time and complexity increase

Engineering Contradiction:
ImproveSQL generation accuracyVSAvoidRetrieval and processing time
Core Design Contradiction:
ReliabilityVSLoss of time

Solution Approach 1:

The system retrieves a limited number of top-k most relevant in-context examples from the memory bank rather than processing all available examples. This partial action approach provides sufficient contextual guidance for accurate SQL generation while minimizing the time and computational resources required for retrieval and processing.

Inventive Principle:
Principle #16Partial or excessive action

Data Source

PatentUS20260072909A1In-context learning for nl2SQL with pattern based retrieval
Publication Date: 2026.03.12 ORACLE INT CORP
  • US20260072909A1 patent drawing
  • US20260072909A1 patent drawing
  • US20260072909A1 patent drawing

AI summary

The present disclosure relates to machine learning techniques for In-Context-Learning (ICL) with pattern-based retrieval for the task of converting Natural Language (NL) to Structured Query Language (SQL). Aspects are directed towards acquiring a natural language utterance and a database schema, searching, using at least a portion of the natural language utterance as a key, a memory bank for one or more in-context examples that are relevant to the key, generating a prompt comprising the natural language query, the database schema, and the one or more in-context examples, transmitting the prompt to a first pretrained generative artificial intelligence model, receiving, from the first pretrained generative artificial intelligence model, a logical form corresponding to the natural language utterance based at least in part on the prompt, executing the logical form on a database to obtain a query result, and providing the query result to a user.