The invention discloses an NL2
SQL question and answer method and
system based on an entity recognition small model and a large
language model, and the
system comprises an intention recognition module which is used for searching a related
knowledge base according to a user question, inputting the large
language model through constructing a cue word, judging the
natural language intention of a user, and triggering a subsequent
branch module; the entity recognition module is used for extracting key entities and related knowledge in a
natural language of a user as components of cue words through a Bert model-based fine-tuning trained entity recognition small model in an NL2
SQL model; the table selection module is used for vectorizing a
natural language input by a user, retrieving keywords of a data table, matching similar questions and corresponding
SQL examples in a sample
library, and constructing cue words for a large
language model to select a target data table; the
large model cue word construction module is used for designing and optimizing a cue word template, and introducing a related
knowledge module and a reference example module into a traditional role, task and constraint structure; the SQL statement execution and check error correction module is used for
processing the generated SQL statement, if an error is reported, a new prompt word is constructed based on error information, a user problem and the SQL, check error correction is performed through a large language model, and execution is performed again for at most three times; according to the invention, more efficient and accurate NL2SQL service is provided for the user.