CN117708157A - SQL sentence generation method and device - Google Patents

SQL sentence generation method and device Download PDF

Info

Publication number
CN117708157A
CN117708157A CN202311651490.7A CN202311651490A CN117708157A CN 117708157 A CN117708157 A CN 117708157A CN 202311651490 A CN202311651490 A CN 202311651490A CN 117708157 A CN117708157 A CN 117708157A
Authority
CN
China
Prior art keywords
query
service
statement
model
sql
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311651490.7A
Other languages
Chinese (zh)
Inventor
万铮宇
徐向上
贺亮
李劼翔
戚瀚中
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Clp Jinxin Software Shanghai Co ltd
Original Assignee
Clp Jinxin Software Shanghai Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Clp Jinxin Software Shanghai Co ltd filed Critical Clp Jinxin Software Shanghai Co ltd
Priority to CN202311651490.7A priority Critical patent/CN117708157A/en
Publication of CN117708157A publication Critical patent/CN117708157A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2237Vectors, bitmaps or matrices
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/332Query formulation
    • G06F16/3322Query formulation using system suggestions
    • G06F16/3323Query formulation using system suggestions using document space presentation or visualization, e.g. category, hierarchy or range presentation and selection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/3331Query processing
    • G06F16/334Query execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/338Presentation of query results
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/30Semantic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Artificial Intelligence (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a SQL sentence generation method and device, which are used for responding to a service query question input by a user and converting the service query question into a service query vector through a vector conversion model; by utilizing a query mode of a service query vector and a service query problem, a model query statement which can be identified by a statement generation model is constructed by determining a query prompt template applicable to the service query problem in the query mode; and inputting the model query statement into a statement generation model, and generating a query result corresponding to the service query problem and/or an SQL query statement for querying the query result corresponding to the service query problem through the statement generation model. Therefore, the SQL query statement can be generated by utilizing the statement generation model, so that the generation process of the SQL query statement can be simplified, and the generation efficiency of the SQL statement can be improved.

Description

SQL sentence generation method and device
Technical Field
The present invention relates to the field of data processing technologies, and in particular, to a method and an apparatus for generating an SQL statement.
Background
With the increasing maturity of large language models applied in various fields, the large language models are utilized to assist relevant practitioners in various fields to more efficiently and accurately complete work contents, and the large language models become one of the popular research directions in the artificial intelligence industry.
At present, no mature service platform capable of generating SQL codes by using a large model exists in the code generation field, and when the SQL statement code generation requirement exists, the service platform can only rely on developers, and also can complete the development and writing of the SQL statement code by referring to the existing program code and through a rewriting or adjusting mode; for some business personnel or beginners without excessive open experience, under the condition that the beginners do not know the SQL sentence development and writing content deeply, the beginners can only resort to the developer if the beginners have the SQL sentence acquisition requirement, or finish the writing of the SQL sentence after knowing the development foundation of the SQL sentence after spending a great deal of time, so that the development progress is dragged slowly, and the development cost is increased.
Disclosure of Invention
In view of this, an object of the present application is to provide a method and an apparatus for generating an SQL statement, which can utilize a statement generation model to generate an SQL query statement, so that a generating process of the SQL query statement can be simplified, and the generating efficiency of the SQL statement can be improved.
The embodiment of the application provides an SQL sentence generation method, which comprises the following steps:
responding to a service inquiry problem input by a user, and converting the service inquiry problem into a service inquiry vector through a vector conversion model;
Constructing a model query sentence which can be identified by a sentence generation model by determining a query prompt template applicable to the service query problem in the query mode by utilizing the service query vector and the query mode of the service query problem;
and inputting the model query statement into the statement generation model, and generating a query result corresponding to the service query problem and/or an SQL query statement for querying the query result corresponding to the service query problem through the statement generation model.
In a possible implementation manner, when the query manner includes a table query manner, the query manner using the service query vector and the service query question constructs a model query statement that can be identified by the statement generation model by determining a query prompt template applicable to the service query question in the query manner, including:
searching a query database by using the service query vector, and determining whether a historical query problem with the same semantic as the service query problem is recorded in the query database;
if the business query problem exists, determining a first prompt template as a query prompt template applicable to the business query problem in the form query mode;
Integrating the historical query questions and the business query questions into the first prompt template according to the template format of the first prompt template, and constructing a model query statement which can be identified by the statement generation model;
if the business query problem does not exist, determining a second prompt template as a query prompt template applicable to the business query problem in the form query mode;
and filling the business query problem to the corresponding filling position of the second prompt template according to the template format of the second prompt template, and constructing and obtaining a model query sentence which can be identified by the sentence generation model.
In a possible implementation manner, the integrating the historical query problem and the service query problem into the first prompt template according to the template format of the first prompt template, and constructing and obtaining a model query sentence which can be identified by the sentence generation model includes:
acquiring a historical SQL statement corresponding to the historical query problem from the query database;
respectively determining corresponding filling positions of the historical query questions, the historical SQL sentences and the business query questions in the first prompt template by analyzing the template format of the first prompt template;
And filling the historical query questions, the historical SQL sentences and the business query questions to corresponding filling positions of the first prompt templates respectively to obtain model query sentences which can be identified by the sentence generation model.
In one possible implementation, a historical query question having the same semantics as the business query question is determined by:
determining semantic similarity between the business query question and each candidate query question by comparing the business query vector with the candidate query vector of each candidate query question recorded in the query database;
determining candidate query sentences with semantic similarity larger than a similarity threshold as historical query problems with the same semantic as the service query problems;
otherwise, determining that the historical query problem which has the same semantic as the service query problem is not recorded in the query database.
In a possible implementation manner, when the query mode is a non-table query mode, the query mode using the service query vector and the service query question constructs a model query statement that can be identified by the statement generation model by determining a query prompt template applicable to the service query question in the query mode, including:
Determining a third prompt template as a query prompt template applicable to the business query problem in the non-form query mode;
searching a grammar case database by using the service query vector, and determining a plurality of reference query cases matched with the service query vector from the grammar case database;
and integrating the multiple reference query cases and the service query vector into the third prompt template according to the template format of the third prompt template to obtain a model query sentence which can be identified by the sentence generation model.
In one possible implementation manner, the searching the grammar case database by using the service query vector, determining a plurality of reference query cases matched with the service query problem from the grammar case database, includes:
determining semantic similarity between the business query question and each candidate query case by comparing the business query vector with candidate case vectors of each candidate query case recorded in the grammar case database;
and according to the semantic similarity, carrying out descending order arrangement on candidate query cases recorded in the grammar case database, and determining the candidate query cases positioned in the previous preset position as a plurality of reference query cases matched with the business query problem.
In one possible implementation manner, the SQL statement generation method further includes:
and calling a target data table associated with the SQL query statement by executing the SQL query statement, and determining a query result of the service query problem.
In one possible implementation manner, the SQL statement generation method further includes:
and responding to a database updating instruction, and updating a target database indicated by the database updating instruction by utilizing at least one of the service query problem, a query result corresponding to the service query problem and the SQL query statement.
In one possible implementation, the query mode of the service query problem is determined by the following steps:
providing a query configuration interface through a graphical user interface of the terminal equipment; the inquiry configuration interface displays a mode selection item; responding to the mode selection operation applied to the mode selection item, and determining the query mode of the service query problem; and/or the number of the groups of groups,
and determining the query mode of the service query problem by identifying the semantics and/or keywords carried in the service query problem.
The embodiment of the application also provides an SQL sentence generating device, which comprises:
The vector conversion module is used for responding to the service inquiry problem input by a user and converting the service inquiry problem into a service inquiry vector through a vector conversion model;
the query sentence construction module is used for constructing a model query sentence which can be identified by a sentence generation model by determining a query prompt template applicable to the service query problem in the query mode by utilizing the service query vector and the query mode of the service query problem;
the SQL sentence generating module is used for inputting the model query sentence into the sentence generating model, and generating a query result corresponding to the service query problem and/or an SQL query sentence used for querying the query result corresponding to the service query problem through the sentence generating model.
In one possible implementation manner, when the query manner includes a table query manner, the query statement construction module is configured to, when the query manner for using the service query vector and the service query question is used to construct a model query statement that can be identified by the statement generation model by determining a query prompt template applicable to the service query question in the query manner, the query statement construction module is configured to:
Searching a query database by using the service query vector, and determining whether a historical query problem with the same semantic as the service query problem is recorded in the query database;
if the business query problem exists, determining a first prompt template as a query prompt template applicable to the business query problem in the form query mode;
integrating the historical query questions and the business query questions into the first prompt template according to the template format of the first prompt template, and constructing a model query statement which can be identified by the statement generation model;
if the business query problem does not exist, determining a second prompt template as a query prompt template applicable to the business query problem in the form query mode;
and filling the business query problem to the corresponding filling position of the second prompt template according to the template format of the second prompt template, and constructing and obtaining a model query sentence which can be identified by the sentence generation model.
In a possible implementation manner, when the query sentence construction module is configured to integrate the historical query problem and the service query problem into the first prompt template according to the template format of the first prompt template, and construct a model query sentence that can be identified by the sentence generation model, the query sentence construction module is configured to:
Acquiring a historical SQL statement corresponding to the historical query problem from the query database;
respectively determining corresponding filling positions of the historical query questions, the historical SQL sentences and the business query questions in the first prompt template by analyzing the template format of the first prompt template;
and filling the historical query questions, the historical SQL sentences and the business query questions to corresponding filling positions of the first prompt templates respectively to obtain model query sentences which can be identified by the sentence generation model.
In one possible implementation, the query statement construction module is configured to determine a historical query question having the same semantics as the business query question by:
determining semantic similarity between the business query question and each candidate query question by comparing the business query vector with the candidate query vector of each candidate query question recorded in the query database;
determining candidate query sentences with semantic similarity larger than a similarity threshold as historical query problems with the same semantic as the service query problems;
otherwise, determining that the historical query problem which has the same semantic as the service query problem is not recorded in the query database.
In one possible implementation manner, when the query mode is a non-table query mode, the query statement construction module is configured to, when the query mode for using the service query vector and the service query question is used to construct a model query statement that can be identified by the statement generation model by determining a query prompt template applicable to the service query question in the query mode, the query statement construction module is configured to:
determining a third prompt template as a query prompt template applicable to the business query problem in the non-form query mode;
searching a grammar case database by using the service query vector, and determining a plurality of reference query cases matched with the service query vector from the grammar case database;
and integrating the multiple reference query cases and the service query vector into the third prompt template according to the template format of the third prompt template to obtain a model query sentence which can be identified by the sentence generation model.
In one possible implementation manner, the query statement construction module is configured to, when configured to search a grammar case database using the service query vector, determine a plurality of reference query cases matching the service query problem from the grammar case database, the query statement construction module is configured to:
Determining semantic similarity between the business query question and each candidate query case by comparing the business query vector with candidate case vectors of each candidate query case recorded in the grammar case database;
and according to the semantic similarity, carrying out descending order arrangement on candidate query cases recorded in the grammar case database, and determining the candidate query cases positioned in the previous preset position as a plurality of reference query cases matched with the business query problem.
In one possible implementation manner, the SQL statement generation device further includes a statement execution module, where the statement execution module is configured to:
and calling a target data table associated with the SQL query statement by executing the SQL query statement, and determining a query result of the service query problem.
In one possible implementation manner, the SQL statement generation device further includes a data update module, where the data update module is configured to:
and responding to a database updating instruction, and updating a target database indicated by the database updating instruction by utilizing at least one of the service query problem, a query result corresponding to the service query problem and the SQL query statement.
In one possible implementation manner, the SQL statement generating device further includes a manner determining module, where the manner determining module is configured to determine a query manner of the service query problem by:
providing a query configuration interface through a graphical user interface of the terminal equipment; the inquiry configuration interface displays a mode selection item; responding to the mode selection operation applied to the mode selection item, and determining the query mode of the service query problem; and/or the number of the groups of groups,
and determining the query mode of the service query problem by identifying the semantics and/or keywords carried in the service query problem.
The embodiment of the application also provides electronic equipment, which comprises: the system comprises a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, when the electronic device is running, the processor and the memory are communicated through the bus, and the machine-readable instructions are executed by the processor to execute the steps of the SQL statement generation method.
Embodiments of the present application also provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the SQL statement generation method as described above.
According to the SQL sentence generation method and device, the service query questions input by the user are received, and the service query questions are converted into service query vectors; constructing a model query sentence which can be identified by the sentence generation model by determining a query prompt template applicable to the business query problem in a query mode by utilizing the business query vector and the query mode selected by the user; and inputting the model query statement into a statement generation model, and generating a query result corresponding to the service query problem and/or an SQL query statement for querying the query result corresponding to the service query problem through the statement generation model. Therefore, the SQL query statement can be generated by utilizing the statement generation model, so that the generation process of the SQL query statement can be simplified, and the generation efficiency of the SQL statement can be improved; in addition, in order to match the query prompt template which is more suitable for obtaining the expected answer of the service query question, the service query vector of the service query question can be further combined, and the matching of the query prompt template is realized.
In order to make the above objects, features and advantages of the present application more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered limiting the scope, and that other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flowchart of a method for generating SQL statements according to an embodiment of the present disclosure;
FIG. 2 is a schematic diagram of an SQL statement generation process according to an embodiment of the present application;
FIG. 3 is a schematic diagram of a query system according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of an SQL statement generation device according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
For the purposes of making the objects, technical solutions and advantages of the embodiments of the present application more clear, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is apparent that the described embodiments are only some embodiments of the present application, but not all embodiments. The components of the embodiments of the present application, which are generally described and illustrated in the figures herein, may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present application, as provided in the accompanying drawings, is not intended to limit the scope of the application, as claimed, but is merely representative of selected embodiments of the application. Based on the embodiments of the present application, every other embodiment that a person skilled in the art would obtain without making any inventive effort is within the scope of protection of the present application.
According to research, at present, no mature service platform capable of generating SQL (structured query language) codes by using a large model exists in the code generation field, and when the SQL statement code generation requirement exists, development and writing of the SQL statement code can be completed only by relying on developers and referring to the existing program codes in a manner of rewriting or adjusting; for some business personnel or beginners without excessive open experience, under the condition that the beginners do not know the SQL sentence development and writing content deeply, the beginners can only resort to the developer if the beginners have the SQL sentence acquisition requirement, or finish the writing of the SQL sentence after knowing the development foundation of the SQL sentence after spending a great deal of time, so that the development progress is dragged slowly, and the development cost is increased.
Based on this, the embodiment of the application provides an SQL sentence generating method, which can convert a business query question input by a user into a model query sentence which can be identified by a sentence generating model by means of an applicable query prompt template, so that the SQL query sentence used for querying a query result corresponding to the business query question is generated by identifying the model query sentence by using the sentence generating model, thereby simplifying the generating process of the SQL query sentence and improving the writing efficiency of the SQL query sentence.
Referring to fig. 1, fig. 1 is a flowchart of an SQL statement generation method according to an embodiment of the present application. As shown in fig. 1, the method for generating an SQL statement provided in the embodiment of the present application includes:
s101, responding to a service query question input by a user, and converting the service query question into a service query vector through a vector conversion model.
S102, constructing a model query sentence which can be identified by a sentence generation model by determining a query prompt template applicable to the service query problem in the query mode by utilizing the service query vector and the query mode of the service query problem.
S103, inputting the model query statement into the statement generation model, and generating a query result corresponding to the service query problem and/or an SQL query statement for querying the query result corresponding to the service query problem through the statement generation model.
According to the SQL sentence generation method, when a service query question input by a user is received, the service query question is converted into a service query vector form, and a query mode of the service query vector and the service query question is utilized to determine a query prompt template applicable to the service query question; and the service query question is translated into a model query sentence which can be identified by the sentence generation model by means of the query prompt template, so that the SQL query sentence used for querying a query result corresponding to the service query question can be generated by utilizing the sentence generation model under the condition that a user does not need to write codes. Therefore, the generation difficulty of the SQL sentence can be reduced, the generation efficiency of the SQL sentence is provided, the writing efficiency of the SQL query sentence can be further improved, and the aim of assisting a user is fulfilled.
When a user needs to search a related data table by means of SQL query sentences to acquire the query results of the service query questions, if the user cannot independently complete the writing of the SQL query sentences, the user can choose to utilize a sentence generation model to complete the generation of the SQL query sentences; however, for the sentence generation model, the recognizable content has a certain limitation in format, so in order to make the sentence generation model "clear" the generation requirement of the user and realize the generation of the SQL query sentence, the service query problem proposed by the user needs to be converted into the model query sentence recognizable by the sentence generation model.
Here, in order to enable the statement generation model to accurately generate the SQL query statement corresponding to the service query problem and/or the query result of the service query problem, a model query statement that is favorable for the statement generation model to feed back the service query problem may be constructed by means of the query prompt template;
further, considering that the answers (SQL query sentences and/or query results) expected to be obtained by different service query questions have differences, which means that the query prompt templates applicable to the service query questions are different, in order to be able to match the query prompt templates more applicable to obtaining the answers expected by the service query questions, the service query vectors of the service query questions can be further combined to realize the matching of the query prompt templates.
In step S101, after the user inputs the service query question, in response to receiving the service query question input by the user, under the Langchain architecture, the service query question input by the user is converted from "text form" to "vector form" by using the vector conversion model obtained by training in advance, so as to obtain the service query vector of the service query question.
The vector conversion model can be a text2vec model, a bge model, an openai-ada-002 model and the like.
Here, the service query problem can have various query modes so as to realize different service query requirements of users; specifically, the query modes may include a table query mode and a non-table query mode; the form query mode refers to that related information is queried in a data form specified by a user, for example, "please find employees whose annual salary is greater than 10 ten thousand in an employee annual salary form"; the non-tabular query means a query implementing a common SQL syntax, for example, "apply me complaint about the usage of the sum function in SQL".
For different query modes, the applicable query prompt templates are different, so that when the query prompt templates related to the service query problem are matched, not only the service query vector of the service query problem, but also the query mode needs to be further considered.
Here, the user may configure a query manner of the service query problem through an application manner selection operation.
In one embodiment, the query mode of the service query question is determined by:
providing a query configuration interface through a graphical user interface of the terminal equipment; the inquiry configuration interface displays a mode selection item; and responding to the mode selection operation applied to the mode selection item, and determining the query mode of the service query problem selected by the user.
In the step, a user can apply mode selection operation to the mode selection items displayed in the query configuration interface so as to complete the selection of the query mode of the service query problem; specifically, in response to a mode selection operation applied by the user with respect to the mode selection item, determining a query mode corresponding to the mode selection item selected by the user as a query mode of the service query question selected by the user.
In another embodiment, the query mode of the service query problem is determined by identifying keywords carried in the service query problem.
In this step, by means of the text recognition model, the query mode applicable to the service query problem can be determined by recognizing the semantics of the service query problem and/or extracting the form of the keywords carried in the service query problem.
The text recognition model can be a model with functions of semantic recognition, keyword extraction and the like, and the text classification model can be trained by utilizing a sample query problem and a label corresponding to the sample query problem; specifically, taking a sample query problem as an input characteristic, taking a label corresponding to the sample query problem as an output characteristic, and training to obtain a text recognition model; the labels corresponding to the sample query questions may represent semantics and keywords corresponding to the sample query questions.
In step S102, a query prompt template applicable to the service query problem is determined by using the service query vector and the query mode of the service query problem, and a model query sentence which can be identified by the sentence generation model is constructed by backfilling the service query problem to the query prompt template.
Here, when the query mode is a table query mode, it is explained that the user aims to acquire the desired content from the data table, and in order to enable the sentence generation model to accurately determine the answer which meets the user's desire, a query prompt template applicable to the service query problem can be matched by referring to the historical query problem mode, so as to achieve accurate acquisition of the answer;
When the query mode is a non-form query mode, the user is stated to query the common SQL grammar, and at this time, the answer meeting the user's expectations can be accurately determined by referring to the reference query case similar to the service query problem.
In one embodiment, when the query means includes a table query means, step S102 includes:
s1021, searching a query database by using the service query vector, and determining whether a historical query problem with the same semantic as the service query problem is recorded in the query database.
In the step, a historical query question which has accurately obtained an answer (SQL query statement and/or query result) is recorded in a query database, and when the query mode of the service query question comprises a table query mode, a service query vector of the service query question can be utilized to determine whether a user has queried a historical query question which is similar to the service query question and has obtained an accurate answer in the historical search process by searching the query database; that is, it is determined whether a historical query question having the same semantic meaning as the business query question is recorded in the query database.
The query database records the historical query problems matched with the SQL sentences and the historical SQL sentences corresponding to the historical query problems.
Here, it may be determined whether there is a history query question in the query database having the same semantic meaning as the service query question by comparing the service query vector with the candidate query vector of each candidate query question recorded in the query database.
In one embodiment, a historical query question having the same semantics as the business query question is determined by:
and a step a of determining semantic similarity between the business query question and each candidate query question by comparing the business query vector with the candidate query vector of each candidate query question recorded in the query database.
In the step, the service query vector is compared with the candidate query vector of each candidate query question which is recorded in the query database and has accurately obtained the answer, and the semantic similarity between the service query question and each candidate query question is defined by determining the similarity degree between the service query vector and the candidate query vector.
And b, determining candidate query sentences with semantic similarity larger than a similarity threshold as historical query problems with the same semantics as the service query problems.
In the step, a candidate query sentence with the semantic similarity larger than a similarity threshold value with the business query problem in the plurality of candidate query sentences is determined to be a historical query problem with the same semantic as the business query problem.
Here, in order to give accurate reference to the sentence generation model, the candidate query sentence with the largest semantic similarity can be determined as the historical query problem with the same semantic as the service query problem, so that the contribution value of the historical query problem to the sentence generation model can be improved; indirectly, the accuracy of the feedback content of the sentence generation model is improved.
And c, otherwise, determining that the historical query problem which has the same semantic as the service query problem is not recorded in the query database.
S1022, if the service query problem exists, determining the first prompt template as a query prompt template applicable to the service query problem in the form query mode.
In this step, if there is a history query problem in the query database, which has the same semantic meaning as the service query problem, the first prompt template may be determined as a query prompt template applicable to the service query problem in the form query mode, so as to use the first prompt template to realize fusion of the service query problem and the history query problem.
S1023, integrating the historical query questions and the business query questions into the first prompt template according to the template format of the first prompt template, and constructing and obtaining a model query sentence which can be identified by the sentence generation model.
In the step, according to the template format of the first prompt template, the historical query question and the service query question are integrated into the first prompt template to realize fusion of the historical query question and the service query question, so that a model query statement which can be identified by a statement generation model is constructed, and the statement generation model can more accurately feed back the answer of the service query question by taking the historical query question as a reference when generating the answer of the service query question (the query result corresponding to the service query question and/or the SQL query statement used for querying the query result corresponding to the service query question) by using the model query statement.
When the query mode is a table query mode, the user is explained to acquire the expected content from the data table, and at the moment, the answer of the service query question comprises a query result corresponding to the service query question and an SQL query statement for querying the query result corresponding to the service query question;
Corresponding to the above embodiment, when the business query question is "please find staff with annual salary greater than 10 ten thousand in staff annual salary table", the "answer" of the business query question is "relevant information of staff with annual salary greater than 10 ten thousand";
"SQL query statement" for querying the business query question:
select salary,ID
from table
Where salary>100000
when the query mode is a non-form query mode, the user is explained to query the common SQL grammar, and at the moment, the answer of the service query question comprises a query result corresponding to the service query question;
corresponding to the above embodiment, when the service query title is "please complaint me about the usage of the sum function in SQL", the "answer" to the service query question is "total number of sum function return value series".
In one embodiment, step S1023 includes:
s10231, acquiring a historical SQL statement corresponding to the historical query question from the query database.
In the step, when the query mode is a table query mode, the description statement generation model needs to further feed back the SQL query statement corresponding to the service query problem to the user, so that the SQL statement corresponding to the history query problem (i.e. the history SQL statement) needs to be further provided for the statement generation model for reference, and therefore, when the service query problem and the history query problem are integrated, the history SQL statement corresponding to the history query problem is further integrated; at this time, a historical SQL statement corresponding to the historical query question needs to be obtained from the query database.
S10232, respectively determining the corresponding filling positions of the historical query questions, the historical SQL sentences and the business query questions in the first prompt template by analyzing the template format of the first prompt template.
For the first prompt template, in order to ensure that the filled first prompt template can be clearly expressed to the sentence generation model, the service query problem and the history query problem for reference are required to be filled one by one to the corresponding filling position in the first prompt template, so that the sentence generation model is convenient to understand.
In the step, the template format of the first prompt template is analyzed to determine the corresponding filling position of the historical query problem, the corresponding filling position of the historical SQL sentence and the corresponding filling position of the business query problem in the first prompt template.
Illustratively, the first hint template is: please write a section of SQL query statement (business query question) according to the answer (history SQL statement corresponding to history query question) of the question (history query question).
S10233, respectively filling the historical query questions, the historical SQL sentences and the business query questions to the corresponding filling positions of the first prompt templates to obtain model query sentences which can be identified by the sentence generation model.
In the case that no historical query problem with the same semantic meaning as the service query problem exists in the query database, the method indicates that any reference information cannot be provided for the statement generation model; that is, no other information needs to be filled into the query prompt template, and at this time, the calculation amount of the terminal device when reading the query prompt template can be reduced by simplifying the query prompt template.
S1024, if not, determining the second prompt template as the query prompt template applicable to the business query problem in the form query mode.
In this step, if there is no history query problem in the query database that has the same semantic meaning as the service query problem, the second prompt template may be determined as a query prompt template applicable to the service query problem in the form query mode, so that the proposed service query problem is expressed to the sentence generation model by using the second prompt template.
S1025, filling the business query problem to the corresponding filling position of the second prompt template according to the template format of the second prompt template, and constructing and obtaining a model query sentence which can be identified by the sentence generation model.
For the second prompt template, in order to ensure that the filled second prompt template can be clearly expressed to the sentence generation model, the service query problem proposed at this time needs to be filled in the corresponding filling position in the second prompt template so as to facilitate the 'understanding' of the sentence generation model.
In the step, the template format of the second prompting template is analyzed to determine the corresponding filling position of the service query problem in the second prompting template, and the service query problem is filled into the corresponding filling position of the second prompting template to construct a model query sentence which can be identified by the sentence generation model.
Illustratively, the second hint template is: please write a section of SQL query statement (business query question).
In another embodiment, when the query mode is a non-table query mode, step S102 includes:
s1026, determining a third prompt template as a query prompt template applicable to the business query problem in the non-form query mode.
In the step, when the query mode is a non-form query mode, the query result corresponding to the service query problem is described as the purpose of providing the service query problem by the user; at this time, the third prompting template may be determined as a query prompting template to which the service query problem applies in the form query mode, so that the service query problem proposed at this time is expressed to the sentence generating model by using the third prompting template.
S1027, searching a grammar case database by using the service query vector, and determining a plurality of reference query cases matched with the service query problem from the grammar case database.
In the step, a reference query case in which an answer (a corresponding query result) is accurately acquired is recorded in a grammar case database, and when a query mode of a service query problem comprises a non-table query mode, a service query vector of the service query problem can be utilized to determine a reference query case which is similar to a query result sought by the service query problem and in which an accurate query result is acquired by searching the grammar case database; that is, a plurality of reference query cases matching the business query question are determined from the grammar case database.
Here, it may be determined whether the reference query case having the same semantic meaning as the business query problem exists in the syntax case database by comparing the business query vector with the candidate case vector of each candidate query case recorded in the query database.
In one embodiment, step S1027 includes:
s10271, determining semantic similarity between the business query question and each candidate query case by comparing the business query vector with the candidate case vector of each candidate query case recorded in the grammar case database.
In the step, the business query vector is compared with the candidate case vector of each candidate query case which is recorded in the grammar case database and has accurately obtained the query result, and the semantic similarity between the business query problem and each candidate query case is defined by determining the similarity degree between the business query vector and the candidate case vector.
S10272, according to the semantic similarity, the candidate query cases recorded in the grammar case database are arranged in a descending order, and the candidate query cases positioned in the front preset position are determined to be a plurality of reference query cases matched with the business query problem.
In the step, the candidate query cases recorded in the language case database are arranged in a descending order by means of semantic similarity between the service query problem and each candidate query case, the ordering order of each candidate query case is determined, and the candidate query cases with the semantic similarity at the previous preset position are determined to be a plurality of reference query cases matched with the service query problem.
S1028, integrating the plurality of reference query cases and the service query vector into the third prompt template according to the template format of the third prompt template to obtain a model query sentence which can be identified by the sentence generation model.
In the step, according to the template format of the third prompt template, a plurality of reference query cases and service query questions are integrated into the third prompt template to realize fusion between the two, so that a model query statement which can be identified by a statement generation model is constructed, and when the statement generation model generates an answer (a query result corresponding to the service query question) of the service query question by using the model query statement, the query result of the service query question can be fed back more accurately by taking the plurality of reference query cases as references.
Illustratively, the third hint template is: please derive the query result of [ business query problem ] according to [ multiple reference query cases ].
Here, after the SQL query statement of the service query question fed back by the statement generation model is acquired, the query result of the service query question may be acquired by executing the SQL query statement.
In step S103, the constructed model query sentence is input to the sentence generation model, so as to generate a query result corresponding to the service query question and/or an SQL query sentence for querying the query result corresponding to the service query question through the pre-trained sentence generation model.
The sentence generation model is a large language model and can comprise a chatglm model, a llama model, a baichuan model and the like.
Here, training a pre-built large language model by using a plurality of sample query questions, sample query sentences corresponding to each sample query question, sample query results corresponding to each sample query question and sample SQL sentences for querying the sample query results corresponding to each sample query question to obtain a trained sentence generation model; specifically, a plurality of sample query questions and sample query sentences corresponding to each sample query question are used as input features of a large language model, sample query results corresponding to each sample query question and sample SQL sentences used for querying the sample query results corresponding to each sample query question are used as input features of the large language model, a pre-built large language model is trained, and a trained sentence generation model is obtained.
In one embodiment, the SQL statement generation method further includes: and calling a target data table associated with the SQL query statement by executing the SQL query statement, and determining a query result of the service query problem.
In the step, SQL query sentences fed back by the sentence generation model are executed, and a target data table associated with a user when configuring a query mode is called, so that a query result for replying to a service query problem is searched in the target data table.
Here, after the user obtains the query result corresponding to the service query question fed back by the statement generation model and/or the SQL query statement for querying the query result corresponding to the service query question, if the user considers that the obtained answer is more accurate, and can be used as a reference of other users in the subsequent query process, positive feedback can be performed, and the content stored in the target database (query database and/or grammar case database) is updated by using the service query question and the obtained answer (the query result corresponding to the service query question and/or the SQL query statement for querying the query result corresponding to the service query question).
In one embodiment, the SQL statement generation method further includes: and responding to a database updating instruction, and updating a target database indicated by the database updating instruction by utilizing at least one of the service query problem, a query result corresponding to the service query problem and the SQL query statement.
In the step, in response to a database update instruction applied by a user, at least one of a service query problem, a query result corresponding to the service query problem and an SQL query statement is utilized to be stored in a target database indicated by the database update instruction, so that the stored content in the target database is updated and expanded, and the assistance to other users is realized in the subsequent query process.
Specifically, the service query problem, the query result corresponding to the service query problem and the SQL query statement for querying the query result corresponding to the service query problem can be stored in a query database in a vector form; the service query questions and the query results corresponding to the service query questions can also be stored in the grammar case database in the form of vectors.
Referring to fig. 2, fig. 2 is a schematic diagram of an SQL statement generation process according to an embodiment of the present application. As shown in fig. 2, the user triggers the selection of the query mode; when a user queries a service query statement in a form query mode, converting the service query statement into a service query vector; matching historical query questions with the same semantics as the service query questions by using the service query vectors; under the condition of matching the historical query problem, fusing by using a first prompting template to obtain a model query statement; under the condition that the historical query problem is not matched, fusing by using a second prompting template to obtain a model query statement; outputting SQL query sentences corresponding to the business query problems through a sentence generation model; executing SQL query sentences, and calling a target data table to obtain a query result of the service query problem; determining whether a positive feedback operation exists by a user; if yes, storing service query questions, SQL query sentences and query results into a query database; if not, abandoning the storage and ending the flow; when a user queries a service query statement in a non-form query mode, converting the service query statement into a service query vector; searching a grammar case database by using the service query vector, and determining a plurality of reference query cases matched with the service query vector; obtaining a model query statement by using a third prompt template; outputting a query result corresponding to the service query problem through a statement generation model; determining whether a positive feedback operation exists by a user; if yes, saving the service inquiry problem and inquiry result to the grammar case database; if not, the storage is abandoned, and the process is ended.
Referring to fig. 3, fig. 3 is a schematic structural diagram of a query system according to an embodiment of the present application. As shown in fig. 3, a user can select corresponding query modes (form query and non-form query) at the front end of the application, and under the Langchain framework, if the query modes are form query modes, a query database and a sentence generation model (large language model) can be queried to acquire a query result; if the query mode is a non-table query mode, a query result can be obtained through a grammar case database and a sentence generation model (large language model); here, the data table for the table query method is stored in the data center.
According to the SQL sentence generation method, the service query questions input by the user are received in response to the received service query questions, and the service query questions are converted into service query vectors; constructing a model query sentence which can be identified by the sentence generation model by determining a query prompt template applicable to the business query problem in a query mode by utilizing the business query vector and the query mode selected by the user; and inputting the model query statement into a statement generation model, and generating a query result corresponding to the service query problem and/or an SQL query statement for querying the query result corresponding to the service query problem through the statement generation model. Therefore, the SQL query statement can be generated by utilizing the statement generation model, so that the generation process of the SQL query statement can be simplified, and the generation efficiency of the SQL statement can be improved; in addition, in order to match the query prompt template which is more suitable for obtaining the expected answer of the service query question, the service query vector of the service query question can be further combined, and the matching of the query prompt template is realized.
Referring to fig. 4, fig. 4 is a schematic structural diagram of an SQL statement generation device according to an embodiment of the present application. As shown in fig. 4, the SQL statement generation apparatus 400 includes:
a vector conversion module 410, configured to convert a service query question input by a user into a service query vector through a vector conversion model in response to receiving the service query question;
the query sentence construction module 420 is configured to construct a model query sentence that can be identified by the sentence generation model by determining a query prompt template applicable to the service query problem in the query manner by using the service query vector and the query manner of the service query problem;
the SQL statement generation module 430 is configured to input the model query statement into the statement generation model, and generate, by using the statement generation model, a query result corresponding to the service query question and/or an SQL query statement for querying the query result corresponding to the service query question.
Further, when the query mode includes a table query mode, the query statement construction module 420 is configured to, when the query mode for using the service query vector and the service query question is used to construct a model query statement that can be identified by the statement generation model by determining a query prompt template applicable to the service query question in the query mode, the query statement construction module 420 is configured to:
Searching a query database by using the service query vector, and determining whether a historical query problem with the same semantic as the service query problem is recorded in the query database;
if the business query problem exists, determining a first prompt template as a query prompt template applicable to the business query problem in the form query mode;
integrating the historical query questions and the business query questions into the first prompt template according to the template format of the first prompt template, and constructing a model query statement which can be identified by the statement generation model;
if the business query problem does not exist, determining a second prompt template as a query prompt template applicable to the business query problem in the form query mode;
and filling the business query problem to the corresponding filling position of the second prompt template according to the template format of the second prompt template, and constructing and obtaining a model query sentence which can be identified by the sentence generation model.
Further, when the query sentence construction module 420 is configured to integrate the historical query question and the service query question into the first prompt template according to the template format of the first prompt template, and construct a model query sentence that can be identified by the sentence generation model, the query sentence construction module 420 is configured to:
Acquiring a historical SQL statement corresponding to the historical query problem from the query database;
respectively determining corresponding filling positions of the historical query questions, the historical SQL sentences and the business query questions in the first prompt template by analyzing the template format of the first prompt template;
and filling the historical query questions, the historical SQL sentences and the business query questions to corresponding filling positions of the first prompt templates respectively to obtain model query sentences which can be identified by the sentence generation model.
Further, the query statement construction module 420 is configured to determine a historical query question having the same semantic meaning as the business query question by:
determining semantic similarity between the business query question and each candidate query question by comparing the business query vector with the candidate query vector of each candidate query question recorded in the query database;
determining candidate query sentences with semantic similarity larger than a similarity threshold as historical query problems with the same semantic as the service query problems;
otherwise, determining that the historical query problem which has the same semantic as the service query problem is not recorded in the query database.
Further, when the query mode is a non-table query mode, the query statement construction module 420 is configured to, when the query mode for using the service query vector and the service query question is used to construct a model query statement that can be identified by the statement generation model by determining a query prompt template applicable to the service query question in the query mode, the query statement construction module 420 is configured to:
determining a third prompt template as a query prompt template applicable to the business query problem in the non-form query mode;
searching a grammar case database by using the service query vector, and determining a plurality of reference query cases matched with the service query vector from the grammar case database;
and integrating the multiple reference query cases and the service query vector into the third prompt template according to the template format of the third prompt template to obtain a model query sentence which can be identified by the sentence generation model.
Further, when the query sentence construction module 420 is configured to search a grammar case database using the service query vector, and determine a plurality of reference query cases matching the service query problem from the grammar case database, the query sentence construction module 420 is configured to:
Determining semantic similarity between the business query question and each candidate query case by comparing the business query vector with candidate case vectors of each candidate query case recorded in the grammar case database;
and according to the semantic similarity, carrying out descending order arrangement on candidate query cases recorded in the grammar case database, and determining the candidate query cases positioned in the previous preset position as a plurality of reference query cases matched with the business query problem.
Further, the SQL statement generation apparatus 400 further includes a statement execution module (not shown in the figure) for:
and calling a target data table associated with the SQL query statement by executing the SQL query statement, and determining a query result of the service query problem.
Further, the SQL statement generation apparatus 400 further includes a data update module (not shown in the figure), where the data update module is configured to:
and responding to a database updating instruction, and updating a target database indicated by the database updating instruction by utilizing at least one of the service query problem, a query result corresponding to the service query problem and the SQL query statement.
Further, the SQL statement generating device 400 further includes a manner determining module (not shown in the figure), where the manner determining module is configured to determine a query manner of the service query question by:
providing a query configuration interface through a graphical user interface of the terminal equipment; the inquiry configuration interface displays a mode selection item; responding to the mode selection operation applied to the mode selection item, and determining the query mode of the service query problem; and/or the number of the groups of groups,
and determining the query mode of the service query problem by identifying the semantics and/or keywords carried in the service query problem.
The SQL sentence generating device provided by the embodiment of the application responds to the received service query questions input by the user and converts the service query questions into service query vectors; constructing a model query sentence which can be identified by the sentence generation model by determining a query prompt template applicable to the business query problem in a query mode by utilizing the business query vector and the query mode selected by the user; and inputting the model query statement into a statement generation model, and generating a query result corresponding to the service query problem and/or an SQL query statement for querying the query result corresponding to the service query problem through the statement generation model. Therefore, the SQL query statement can be generated by utilizing the statement generation model, so that the generation process of the SQL query statement can be simplified, and the generation efficiency of the SQL statement can be improved; in addition, in order to match the query prompt template which is more suitable for obtaining the expected answer of the service query question, the service query vector of the service query question can be further combined, and the matching of the query prompt template is realized.
Referring to fig. 5, fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application. As shown in fig. 5, the electronic device 500 includes a processor 510, a memory 520, and a bus 530.
The memory 520 stores machine-readable instructions executable by the processor 510, and when the electronic device 500 is running, the processor 510 communicates with the memory 520 through the bus 530, and when the machine-readable instructions are executed by the processor 510, the steps of the SQL statement generation method in the method embodiment shown in fig. 1 can be executed, and the specific implementation can refer to the method embodiment and is not repeated herein.
The embodiment of the present application further provides a computer readable storage medium, where a computer program is stored on the computer readable storage medium, and when the computer program is executed by a processor, the steps of the SQL statement generation method in the method embodiment shown in fig. 1 may be executed, and a specific implementation manner may refer to the method embodiment and will not be described herein.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described systems, apparatuses and units may refer to corresponding procedures in the foregoing method embodiments, and are not repeated herein.
In the several embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. The above-described apparatus embodiments are merely illustrative, for example, the division of the units is merely a logical function division, and there may be other manners of division in actual implementation, and for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some communication interface, device or unit indirect coupling or communication connection, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer readable storage medium executable by a processor. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
Finally, it should be noted that: the foregoing examples are merely specific embodiments of the present application, and are not intended to limit the scope of the present application, but the present application is not limited thereto, and those skilled in the art will appreciate that while the foregoing examples are described in detail, the present application is not limited thereto. Any person skilled in the art may modify or easily conceive of the technical solution described in the foregoing embodiments, or make equivalent substitutions for some of the technical features within the technical scope of the disclosure of the present application; such modifications, changes or substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application, and are intended to be included in the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. The SQL sentence generation method is characterized by comprising the following steps:
responding to a service inquiry problem input by a user, and converting the service inquiry problem into a service inquiry vector through a vector conversion model;
constructing a model query sentence which can be identified by a sentence generation model by determining a query prompt template applicable to the service query problem in the query mode by utilizing the service query vector and the query mode of the service query problem;
and inputting the model query statement into the statement generation model, and generating a query result corresponding to the service query problem and/or an SQL query statement for querying the query result corresponding to the service query problem through the statement generation model.
2. The method for generating SQL statements according to claim 1, wherein when the query means comprises a table query means, the query means for using the service query vector and the service query question constructs a model query statement identifiable by the statement generation model by determining a query hint template to which the service query question applies in the query means, comprising:
Searching a query database by using the service query vector, and determining whether a historical query problem with the same semantic as the service query problem is recorded in the query database;
if the business query problem exists, determining a first prompt template as a query prompt template applicable to the business query problem in the form query mode;
integrating the historical query questions and the business query questions into the first prompt template according to the template format of the first prompt template, and constructing a model query statement which can be identified by the statement generation model;
if the business query problem does not exist, determining a second prompt template as a query prompt template applicable to the business query problem in the form query mode;
and filling the business query problem to the corresponding filling position of the second prompt template according to the template format of the second prompt template, and constructing and obtaining a model query sentence which can be identified by the sentence generation model.
3. The method of claim 2, wherein integrating the historical query question and the business query question into the first prompt template according to the template format of the first prompt template, and constructing a model query sentence that can be identified by the sentence generation model, includes:
Acquiring a historical SQL statement corresponding to the historical query problem from the query database;
respectively determining corresponding filling positions of the historical query questions, the historical SQL sentences and the business query questions in the first prompt template by analyzing the template format of the first prompt template;
and filling the historical query questions, the historical SQL sentences and the business query questions to corresponding filling positions of the first prompt templates respectively to obtain model query sentences which can be identified by the sentence generation model.
4. The SQL statement generation method according to claim 2, wherein the historical query question having the same semantics as the business query question is determined by:
determining semantic similarity between the business query question and each candidate query question by comparing the business query vector with the candidate query vector of each candidate query question recorded in the query database;
determining candidate query sentences with semantic similarity larger than a similarity threshold as historical query problems with the same semantic as the service query problems;
otherwise, determining that the historical query problem which has the same semantic as the service query problem is not recorded in the query database.
5. The method for generating SQL statements according to claim 1, wherein when the query mode is a non-tabular query mode, the query mode using the service query vector and the service query question constructs a model query statement identifiable by a statement generation model by determining a query prompt template to which the service query question applies in the query mode, comprising:
determining a third prompt template as a query prompt template applicable to the business query problem in the non-form query mode;
searching a grammar case database by using the service query vector, and determining a plurality of reference query cases matched with the service query vector from the grammar case database;
and integrating the multiple reference query cases and the service query vector into the third prompt template according to the template format of the third prompt template to obtain a model query sentence which can be identified by the sentence generation model.
6. The SQL statement generation method of claim 5, wherein searching a grammar case database using the business query vector, determining a plurality of reference query cases from the grammar case database that match the business query question, comprises:
Determining semantic similarity between the business query question and each candidate query case by comparing the business query vector with candidate case vectors of each candidate query case recorded in the grammar case database;
and according to the semantic similarity, carrying out descending order arrangement on candidate query cases recorded in the grammar case database, and determining the candidate query cases positioned in the previous preset position as a plurality of reference query cases matched with the business query problem.
7. The SQL statement generation method according to claim 1, wherein the SQL statement generation method further comprises:
and calling a target data table associated with the SQL query statement by executing the SQL query statement, and determining a query result of the service query problem.
8. The SQL statement generation method according to claim 1, wherein the SQL statement generation method further comprises:
and responding to a database updating instruction, and updating a target database indicated by the database updating instruction by utilizing at least one of the service query problem, a query result corresponding to the service query problem and the SQL query statement.
9. The SQL statement generation method according to claim 1, wherein a query manner of the service query question is determined by:
providing a query configuration interface through a graphical user interface of the terminal equipment; the inquiry configuration interface displays a mode selection item; responding to the mode selection operation applied to the mode selection item, and determining the query mode of the service query problem; and/or the number of the groups of groups,
and determining the query mode of the service query problem by identifying the semantics and/or keywords carried in the service query problem.
10. An SQL statement generation device, characterized in that the SQL statement generation device comprises:
the vector conversion module is used for responding to the service inquiry problem input by a user and converting the service inquiry problem into a service inquiry vector through a vector conversion model;
the query sentence construction module is used for constructing a model query sentence which can be identified by a sentence generation model by determining a query prompt template applicable to the service query problem in the query mode by utilizing the service query vector and the query mode of the service query problem;
The SQL sentence generating module is used for inputting the model query sentence into the sentence generating model, and generating a query result corresponding to the service query problem and/or an SQL query sentence used for querying the query result corresponding to the service query problem through the sentence generating model.
CN202311651490.7A 2023-12-04 2023-12-04 SQL sentence generation method and device Pending CN117708157A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311651490.7A CN117708157A (en) 2023-12-04 2023-12-04 SQL sentence generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311651490.7A CN117708157A (en) 2023-12-04 2023-12-04 SQL sentence generation method and device

Publications (1)

Publication Number Publication Date
CN117708157A true CN117708157A (en) 2024-03-15

Family

ID=90147097

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311651490.7A Pending CN117708157A (en) 2023-12-04 2023-12-04 SQL sentence generation method and device

Country Status (1)

Country Link
CN (1) CN117708157A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117992791A (en) * 2024-04-02 2024-05-07 浙江口碑网络技术有限公司 Training method of sentence generation model, sentence generation method, sentence generation system and sentence generation equipment
CN118152522A (en) * 2024-05-10 2024-06-07 腾讯科技(深圳)有限公司 Data query method, device, electronic equipment, storage medium and product

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117992791A (en) * 2024-04-02 2024-05-07 浙江口碑网络技术有限公司 Training method of sentence generation model, sentence generation method, sentence generation system and sentence generation equipment
CN118152522A (en) * 2024-05-10 2024-06-07 腾讯科技(深圳)有限公司 Data query method, device, electronic equipment, storage medium and product

Similar Documents

Publication Publication Date Title
US10262062B2 (en) Natural language system question classifier, semantic representations, and logical form templates
US9740677B2 (en) Methods and systems for analyzing communication situation based on dialogue act information
US11222286B2 (en) Target document template generation
CN108932342A (en) A kind of method of semantic matches, the learning method of model and server
CN111708869B (en) Processing method and device for man-machine conversation
CN110795913B (en) Text encoding method, device, storage medium and terminal
CN117708157A (en) SQL sentence generation method and device
CN111159363A (en) Knowledge base-based question answer determination method and device
US20190340503A1 (en) Search system for providing free-text problem-solution searching
US20220414463A1 (en) Automated troubleshooter
CN110019712A (en) More intent query method and apparatus, computer equipment and computer readable storage medium
Rajput et al. BNOSA: A Bayesian network and ontology based semantic annotation framework
CN111274829A (en) Sequence labeling method using cross-language information
CN113821605A (en) Event extraction method
CN113988071A (en) Intelligent dialogue method and device based on financial knowledge graph and electronic equipment
CN112507089A (en) Intelligent question-answering engine based on knowledge graph and implementation method thereof
CN116974554A (en) Code data processing method, apparatus, computer device and storage medium
CN108170661B (en) Method and system for managing rule text
CN110019714A (en) More intent query method, apparatus, equipment and storage medium based on historical results
CN112732743B (en) Data analysis method and device based on Chinese natural language
CN116049376B (en) Method, device and system for retrieving and replying information and creating knowledge
Han et al. A novel part of speech tagging framework for nlp based business process management
Karpagam et al. Deep learning approaches for answer selection in question answering system for conversation agents
CN116090450A (en) Text processing method and computing device
CN113569578B (en) User intention recognition method and device and computer equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination