This invention provides a method, apparatus, and storage medium for generating
SQL statements based on context enhancement. The method includes: acquiring enhanced context related to a user-submitted
natural language query; based on the enhanced context, using a large
language model to identify the core data table most relevant to the
natural language query from relevant data tables; obtaining several
data records with the highest
data density from the core data table as data samples; integrating the enhanced context, the structure definition of the core data table, the data samples, and the
natural language query to construct Text-to-
SQL prompts; inputting these prompts into the large
language model to generate an
executable SQL statement. This invention leverages vector
database retrieval of enhanced context, uses a large
language model to parse the user's natural language query and identify relevant core data tables, collects data samples from the core tables according to
data density, constructs Text-to-SQL prompts, and generates an
executable SQL statement through the large language model, achieving reliable responses to complex queries in specialized domains.