SQL (Structured Query Language) statement generation method based on large language model, medium and equipment
By combining historical data and preset keyword configuration tables, extracting and matching keywords in the initial statement, calculating statement vectors and similarity, filtering reference statements and inputting large language models, and generating SQL statements, the problem of insufficient accuracy in SQL statement generation is solved, and more efficient and accurate SQL statement generation is achieved.
Patent Information
- Application Number
- CN202411969390.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2044-12-30
AI Technical Summary
The existing technology is difficult to effectively improve the accuracy of SQL statement generation, especially when facing massive historical data and different business scenarios, it lacks a mechanism to utilize historical experience and targeted processing of specific keywords.
By obtaining the historical input database, the initial statements input by the target user, the target scenario and the target table, as well as the target vector transformation model and preset keyword configuration table corresponding to the target scenario, keyword extraction, matching, regular expression acquisition, statement vector calculation and similarity filtering are performed, and finally input to the large language model to generate SQL statements.
Accurately capture key semantic information in natural language, avoid misinterpretation of user intentions by large language models, and improve the accuracy and efficiency of SQL statement generation.
Smart Images

Figure CN119862200A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to a method, medium and device for generating SQL statements based on a large language model. Background Art
[0002] In today's digital age, databases play a core role in information management and data processing in many fields. However, for most non-professional database users, writing SQL statements is a challenging task because SQL syntax is strict and complex and requires familiarity with database structure, various operation commands, and the relationship between data.
[0003] With the continuous development of natural language processing technology, especially the powerful language understanding and generation capabilities of large language models, users expect to be able to easily generate corresponding SQL statements through natural language to lower the threshold for database use and improve the efficiency of data acquisition and operation. However, there are certain limitations to simply relying on large language models to directly convert natural language into SQL statements. For example, the diversity and ambiguity of natural language may lead to deviations in model understanding. In addition, when faced with massive historical data and different business scenarios, there is a lack of effective use of historical experience and targeted processing of specific keywords to improve the accuracy and efficiency of SQL statement generation, resulting in poor accuracy in SQL statement generation.
[0004] Therefore, how to improve the accuracy of SQL statement generation results has become an urgent problem to be solved. Summary of the invention
[0005] In view of the above technical problems, the technical solution adopted by the present invention is a method for generating SQL statements based on a large language model, and the method for generating SQL statements comprises the following steps:
[0006] S10, obtain the historical input database, the initial sentence input by the target user, the target scenario and target table corresponding to the initial sentence, and the target vector conversion model and preset keyword configuration table corresponding to the target scenario, wherein the historical input database includes several historical sentences, the historical sentence vectors corresponding to each historical sentence, and the historical SQL statements, and the preset keyword configuration table includes several custom keywords and the regular expression corresponding to each custom keyword.
[0007] S20, extracting keywords from the initial sentence to obtain a number of target keywords corresponding to the initial sentence.
[0008] S30, matching each target keyword with the preset keyword configuration table to obtain a matching result corresponding to each target keyword, wherein the matching result includes a set consisting of a corresponding custom keyword and a corresponding regular expression.
[0009] S40, obtaining several target regular expressions corresponding to the initial sentence according to the matching results of all target keywords.
[0010] S50, acquiring a sentence vector corresponding to the initial sentence according to a target vector conversion model corresponding to a target scene corresponding to the initial sentence.
[0011] S60, obtaining the similarity between the initial sentence and each historical sentence according to the sentence vector and the historical sentence vector corresponding to each historical sentence.
[0012] S70, based on the comparison between the similarity between the initial sentence and each historical sentence and a preset similarity threshold, a plurality of reference sentences corresponding to the initial sentence are screened out from all historical sentences.
[0013] S80, input the sentence vector, the target table, several target regular expressions corresponding to the initial sentence, several reference sentences corresponding to the initial sentence, and the historical SQL statements corresponding to each reference sentence into the preset large language model to obtain the SQL statement corresponding to the initial sentence.
[0014] The present invention also provides a non-transitory computer-readable storage medium, in which at least one instruction or at least one program is stored, and the at least one instruction or at least one program is loaded and executed by a processor to implement the above-mentioned SQL statement generation method based on a large language model.
[0015] The present invention also provides an electronic device, comprising a processor and the above-mentioned non-transitory computer-readable storage medium.
[0016] The present invention has at least the following beneficial effects: by extracting keywords from the initial sentence and matching it with a preset keyword configuration table to obtain a target regular expression, it is possible to accurately capture key semantic information in natural language, standardize fuzzy and diverse natural language expressions according to established business rules, and avoid incorrect interpretation of user intentions by a large language model; at the same time, by screening out reference sentences that have a high similarity with the initial sentence and are of reference significance for generating current SQL statements from numerous historical sentences, it is helpful for the preset large language model to generate more accurate SQL statements that meet user intentions based on previous similar situations, thereby improving the accuracy of SQL statement generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0018] Figure 1 A flowchart of a method for generating SQL statements based on a large language model provided in the first embodiment of the present invention;
[0019] Figure 2 A schematic diagram of the structure of a SQL statement generation device based on a large language model provided in Embodiment 2 of the present invention. DETAILED DESCRIPTION
[0020] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It is understood that, where appropriate, the above-mentioned terms used to distinguish similar objects can be interchanged so that the present invention can also implement other embodiments other than the above-mentioned illustrated embodiments or described embodiments. In addition, the terms "including" and "having" and any variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0022] Embodiment 1
[0023] The first embodiment provides a method for generating SQL statements based on a large language model. The method for generating SQL statements based on a large language model includes the following steps: Figure 1 As shown:
[0024] S10, obtain the historical input database, the initial sentence input by the target user, the target scenario and target table corresponding to the initial sentence, and the target vector conversion model and preset keyword configuration table corresponding to the target scenario, wherein the historical input database includes several historical sentences, the historical sentence vectors corresponding to each historical sentence, and the historical SQL statements, and the preset keyword configuration table includes several custom keywords and the regular expression corresponding to each custom keyword.
[0025] The initial statement input by the user is a data operation requirement expressed by the user in natural language. The target scenario is a classification definition of the business or operation type in which the initial statement is located. The target table refers to a specific data table in the database related to the requirement expressed by the user through the initial statement.
[0026] For example, the target scenarios can be divided into sales business scenarios, financial business scenarios, human resources business scenarios, etc. according to the business field. They can also be divided into query scenarios, insert scenarios, update scenarios, etc. according to the operation type. In an enterprise management database, the target tables may include employee information tables, sales data tables, department information tables, etc. The description text of the employee information table may introduce "the table contains fields such as employee number, name, department, and entry time. The employee number is the primary key and uniquely identifies each employee."
[0027] The function of the vector conversion model is to convert natural language text into vector representation. Due to the different language characteristics, data relationships and other factors in different preset scenarios, a vector conversion model that is adapted to them is needed to more accurately measure the relationship between natural language text and vector representation, and provide a suitable vector data foundation for the subsequent generation of SQL statements.
[0028] The historical input database is a collection that stores a large amount of past database interaction-related data, including several historical statements, each of which corresponds to a historical statement vector and a corresponding historical SQL statement. The historical statement vector is a digital, computer-friendly representation of the historical statement after vector conversion, which contains information such as the semantics of the historical statement. The historical SQL statement is the SQL code that has been successfully generated and executed based on the corresponding historical statement and complies with the database syntax specification.
[0029] The preset keyword configuration table is a pre-set table containing several custom keywords and the regular expression corresponding to each custom keyword. Custom keywords are important words with specific meanings and database operation directions extracted from a business perspective, such as "entry time" and "leaving time" in human resource management scenarios. Regular expression is a tool for matching and standardizing text formats. The regular expression corresponding to each custom keyword specifies how to accurately identify the keyword and its related expression form in natural language. For example, the regular expression corresponding to "entry time" may be "entry\s+[\s+] time", which is used to match statement expressions such as "entry on January 1, 2024". In this way, key information can be accurately extracted and standardized from texts such as initial statements, assisting in the determination of the generation logic of subsequent SQL statements.
[0030] In a specific implementation, S10 includes the following steps:
[0031] S101, obtaining an initial vector conversion model, description text samples corresponding to a number of preset tables, preset scenes and description vector samples corresponding to each description text sample, and a preset sampling ratio corresponding to each preset scene.
[0032] S102, determining a preset sampling ratio as a target sampling ratio, determining each preset scene as an initial scene, and initializing the number of repetitions N=1.
[0033] S103, sampling from a plurality of description text samples according to a target sampling ratio corresponding to each initial scene, to obtain an Nth description text training sample set, an Nth description text verification sample set, and an Nth number of description text samples corresponding to each initial scene in the Nth description text training sample set.
[0034] S104, training the initial vector conversion model according to the Nth description text training sample set, the Nth description text verification sample set and the description vector sample corresponding to each description text sample, and obtaining the Nth vector conversion model and the Nth accuracy of each initial scene in the Nth vector conversion model.
[0035] S105 , obtaining an Nth degree of adaptation between each initial scene and the Nth vector conversion model according to the Nth number and the Nth accuracy rate corresponding to each initial scene.
[0036] S106, for any initial scene, determine the adaptation result corresponding to the current initial scene according to the comparison result of the Nth adaptation degree corresponding to the current initial scene and the preset degree threshold, wherein the adaptation result includes adaptation, non-matching and to be determined.
[0037] S107: If the adaptation result corresponding to the current initial scene is adaptation, the current initial scene is determined as the first scene, and the Nth vector conversion model is determined as the target vector conversion model corresponding to the current first scene.
[0038] S108: If the adaptation result corresponding to the current initial scene is not suitable, the current initial scene is determined as the second scene.
[0039] S109: If the adaptation result corresponding to the current initial scene is to be determined, the current initial scene is determined as the third scene.
[0040] S110, traverse all initial scenes, obtain all first scenes and the target vector conversion model corresponding to each first scene, all second scenes, all third scenes and the number of scenes corresponding to the third scenes.
[0041] S111, acquiring a target description text sample set corresponding to each second scene according to the preset scene and the description vector sample corresponding to each description text sample.
[0042] S113, training the initial vector conversion model according to the target description text sample set corresponding to each second scene and the description vector sample corresponding to each description text sample, to obtain the target vector conversion model corresponding to each second scene.
[0043] S114, if the number of scenes is greater than 0, update the preset sampling ratio corresponding to each third scene and determine the updated preset sampling ratio as the target sampling ratio, determine each third scene as the initial scene, update N=N+1, and repeat step S103 until the updated number of scenes is equal to 0, and obtain the target vector conversion model corresponding to each preset scene.
[0044] S115, acquiring a target vector conversion model corresponding to the target scene according to the target vector conversion model corresponding to each preset scene.
[0045] The description text sample is used to describe in detail the structure, field meaning, data range and other information of each preset table, which helps to understand the specific composition of the table so as to accurately build the association between the SQL statement and the table.
[0046] The initial vector conversion model is a general vector conversion model that is not optimized for specific scenarios. In the future, training and adjustment will be carried out based on the initial vector conversion model combined with specific data to enable it to adapt to the text-to-vector conversion requirements in different preset scenarios.
[0047] The description vector sample is the correct vector representation of the corresponding description text sample, which is used to guide the model to learn how to accurately convert the description text into a vector. The description vector sample can be obtained by converting the description text sample based on a known vector conversion technology. Among them, those skilled in the art know that any vector conversion technology in the prior art falls within the protection scope of the present invention, and will not be repeated here. For example, the vector conversion technology can be Word2Vec technology.
[0048] During the training process of the initial vector conversion model, the description text samples in the Nth description text training sample set as training samples are input into the initial vector conversion model to assist the initial vector conversion model in learning how to convert the description text samples into vectors, and then the description text samples in the Nth description text verification sample set as verification samples are used for verification, and the difference between the vector output by the model and the corresponding description vector sample is compared. The accuracy of the model conversion in each initial scenario is measured by evaluation indicators such as cosine similarity, and finally the Nth vector conversion model and the Nth accuracy of each initial scenario in the Nth vector conversion model are obtained to reflect the accuracy of the current model in converting text into vectors in the corresponding initial scenario.
[0049] For any initial scene, the corresponding Nth degree of adaptation is compared with the preset degree threshold. If the Nth degree of adaptation is higher than the preset degree threshold, it means that the Nth vector conversion model performs well in the initial scene and the adaptation is ideal. If it is lower than the preset degree threshold, it is considered that the Nth vector conversion model is not very suitable for the initial scene. If it is just near the critical point of the preset degree threshold, it is determined to be in a pending state, and the vector conversion model adapted to the initial scene needs to be further updated and matched.
[0050] For the situation determined as the first scene, the target vector conversion model corresponding to each first scene is determined to complete the work of determining the appropriate model in some scenes.
[0051] For the cases determined to be the second scene, a target description text sample set suitable for retraining is collected and sorted out, and the initial vector conversion model corresponding to each second scene is trained separately to obtain the target vector conversion model corresponding to each second scene.
[0052] For the situation judged as the third scene, the vector conversion model is continuously optimized by updating the sampling ratio, repeating training and other operations until all preset scenes have clear model adaptation judgment results, and finally the target vector conversion model corresponding to each preset scene is obtained.
[0053] The above method of finding a suitable vector conversion model for different preset scenarios through multiple iterative training and evaluation aims to improve the accuracy and effectiveness of subsequent SQL statement conversion so that it can better adapt to diverse business scenarios and natural language input situations.
[0054] By acquiring basic data including the initial vector conversion model, descriptive text samples and their related preset scenarios and description vector samples, preset sampling ratios, etc., and through multiple rounds of iterative operations, each preset scenario and related sample data and vector conversion model are sampled, trained, evaluated and classified, and each initial scenario is divided into an adapted first scenario and its target vector conversion model is determined, an unsuitable second scenario is to be retrained, and a third scenario to be judged is to be further analyzed and optimized, until all preset scenarios obtain an adapted target vector conversion model, which lays a precise and adaptable vector conversion foundation for the subsequent natural language and SQL statement conversion based on the target vector conversion model, improves the depth and accuracy of the understanding of the initial statements corresponding to each scenario in the vector conversion process, thereby improving the accuracy of SQL statement generation and reducing the risk of data errors or business process interference caused by the execution of erroneous SQL statements.
[0055] In a specific implementation, the preset sampling ratio corresponding to each preset scene includes a training sample sampling ratio and a verification sample sampling ratio, and S103 includes the following steps:
[0056] S1031, for any initial scene, according to the sampling ratio of training samples corresponding to the current initial scene, a number of description text samples are sampled from all description text samples corresponding to the current initial scene as training samples, and the Nth number of description text samples corresponding to the current initial scene as training samples is obtained.
[0057] S1032 , according to the sampling ratio of verification samples corresponding to the current initial scene, sample a plurality of description text samples from all description text samples corresponding to the current initial scene as verification samples.
[0058] S1033, traverse all initial scenes, and obtain a number of description text samples as training samples and a number of description text samples as verification samples corresponding to each initial scene.
[0059] S1034: Determine a set of several description text samples corresponding to all initial scenes as training samples as the Nth description text training sample set.
[0060] S1035: Determine a set of several description text samples corresponding to all initial scenes as verification samples as the Nth description text verification sample set.
[0061] As mentioned above, from the descriptive text samples in each initial scenario, training samples and verification samples are reasonably divided according to the corresponding sampling ratios, and finally the overall training sample set and verification sample set are constructed, so as to provide the key data preparation and organizational basis for the subsequent training, verification and gradual optimization of the initial vector conversion model based on the training sample set and the verification sample set, thereby creating a suitable vector conversion model for different preset scenarios, and ensuring the scientificity and rationality of the entire model training process.
[0062] In a specific implementation, S105 includes the following steps:
[0063] S1051, normalize the Nth number corresponding to each initial scene to obtain the normalized Nth number corresponding to each initial scene.
[0064] S1052, input the normalized Nth number and Nth accuracy corresponding to each initial scene into the preset adaptation degree calculation model, and obtain the Nth adaptation degree of each initial scene and the Nth vector conversion model, wherein the Nth adaptation degree is inversely proportional to the corresponding normalized Nth number, and the Nth adaptation degree is directly proportional to the corresponding Nth accuracy.
[0065] Among them, there may be large differences in the number of descriptive text samples extracted as training samples from different initial scenes. This embodiment uses a normalization operation to uniformly convert the quantitative values of different magnitudes into a standard, comparable range, creating conditions for the subsequent accurate measurement of the degree of adaptation. The value range of the Nth number after normalization is [0, 1]. Those skilled in the art know that any normalization method in the prior art with a value range of [0, 1] falls within the protection scope of the present invention, and will not be repeated here. For example, the normalization method in this embodiment can be a Min-Max normalization method.
[0066] When the normalized Nth number corresponding to the initial scene is large, it means that there is relatively sufficient training data for the vector conversion model to learn the text conversion mode related to the initial scene. Correspondingly, the abundant data volume should help the vector conversion model to better capture the rules and improve the accuracy. However, when the Nth accuracy corresponding to the initial scene is low, it means that the vector conversion model cannot effectively extract features and understand semantics for the specific data features of the initial scene, so that the generated vector has a large deviation from the actual expected vector. Therefore, when the normalized Nth number corresponding to the initial scene is large and the Nth accuracy is low, it means that the structural design of the vector conversion model cannot fully adapt to the complexity and diversity of the initial scene data, and cannot effectively utilize the description text samples and corresponding description vector samples under the initial scene. Therefore, the Nth adaptation degree is inversely proportional to the corresponding normalized Nth number, and the Nth adaptation degree is proportional to the corresponding Nth accuracy.
[0067] Among them, the preset adaptation degree calculation model is a weighted sum model. The implementer can set the first weight corresponding to the normalized Nth number and the second weight corresponding to the Nth accuracy rate according to actual conditions, and obtain the Nth adaptation degree of each initial scene and the Nth vector conversion model by weighted summing the normalized Nth number and the Nth accuracy rate.
[0068] As described above, normalization is used to allow the number of training samples to participate in the evaluation on a fair and comparable basis. Then, based on the preset relationship between the degree of adaptation and the normalized Nth number and the Nth accuracy, the degree of adaptation is obtained using the adaptation degree calculation model. This provides a scientific and quantitative basis for the entire process to accurately judge the adaptation status of each initial scenario and the vector conversion model, which helps to improve the accuracy and reliability of constructing a vector conversion model that adapts to different preset scenarios, thereby improving the accuracy of subsequent SQL statement conversion.
[0069] In a specific implementation, the preset degree threshold includes a first degree threshold and a second degree threshold, and S106 includes the following steps:
[0070] S1061: If the Nth adaptation degree corresponding to the current initial scene is less than or equal to the first degree threshold, determine that the adaptation result corresponding to the current initial scene is unmatched.
[0071] S1062: If the Nth adaptation degree corresponding to the current initial scene is greater than or equal to the second degree threshold, it is determined that the adaptation result corresponding to the current initial scene is not adapted.
[0072] S1063: If the Nth adaptation degree corresponding to the current initial scene is less than the second degree threshold and greater than the first degree threshold, it is determined that the adaptation result corresponding to the current initial scene is to be determined.
[0073] Among them, if the Nth adaptation degree corresponding to the current initial scene is less than or equal to the pre-set first degree threshold, it means that the Nth vector conversion model in the initial scene has very poor sample utilization effect, scene semantic understanding accuracy, and the ability to generate expected vectors. In this case, it can be clearly determined that the adaptation result corresponding to the initial scene is unsuitable, that is, the vector conversion model trained together under multiple initial scenes is not suitable for the current initial scene. In this case, a target description text sample set suitable for retraining can be collected and sorted, and the initial vector conversion model corresponding to each second scene can be trained separately to obtain an adapted target vector conversion model.
[0074] If the Nth adaptation degree corresponding to the current initial scene is greater than or equal to the set second degree threshold, it means that the Nth vector conversion model has reached an ideal adaptation state in the current initial scene, and can effectively convert the initial sentence in the current initial scene into a suitable vector, and performs well in terms of accuracy, etc., then the current Nth vector conversion model can be used as the target vector conversion model for the current initial scene.
[0075] If the Nth adaptation degree corresponding to the current initial scene is less than the second degree threshold and greater than the first degree threshold, the adaptation result corresponding to the current initial scene is determined to be pending, and more rounds of analysis and processing are required to determine the adaptability of the current initial scene and the current vector conversion model.
[0076] The specific values of the first degree threshold and the second degree threshold can be set by the implementer according to actual conditions.
[0077] In the above, by setting the first degree threshold and the second degree threshold, the three adaptation results of unmatched, matched, and to be judged are clearly and reasonably divided, which provides a clear judgment standard and classification basis for the evaluation and screening of vector conversion models in different initial scenarios, and can classify and process many initial scenarios in an orderly manner, and adopt corresponding optimization strategies for different adaptation results, which helps to more accurately find a suitable target vector conversion model for each preset scenario, thereby ensuring the accuracy and effectiveness of subsequent SQL statement conversion work.
[0078] In a specific implementation, S10 further includes the following steps:
[0079] S116, obtaining a plurality of preset tables, preset description texts and preset scenes corresponding to each preset table, and a target vector conversion model corresponding to each preset scene.
[0080] S117, performing scene consistency matching on the preset scene corresponding to each preset table and the target scene corresponding to the initial sentence, and obtaining the scene consistency matching result between each preset table and the initial sentence, wherein the scene consistency matching result includes scene consistency and scene inconsistency.
[0081] S118, determining each preset table whose scene consistency matching result is scene consistent as an intermediate table corresponding to the initial sentence.
[0082] S119, acquiring an intermediate description vector corresponding to each intermediate table according to a target vector conversion model corresponding to a preset scene corresponding to a preset description text corresponding to each intermediate table.
[0083] S120, acquiring a sentence vector corresponding to the initial sentence according to a target vector conversion model corresponding to a target scene corresponding to the initial sentence.
[0084] S121, obtaining an intermediate matching degree between the initial sentence and each intermediate table according to the intermediate description vector corresponding to each intermediate table and the sentence vector corresponding to the initial sentence.
[0085] S122, according to the intermediate matching degree between the initial statement and each intermediate table, filter out the target table corresponding to the initial statement from all the intermediate tables.
[0086] Among them, by comparing the preset scenario corresponding to the preset table with the target scenario corresponding to the initial statement, it is judged whether they are consistent at the business or operation type level, so as to determine the scenario consistency between the preset table and the initial statement, and provide a basis for screening out relevant tables that meet the scenario of the initial statement, avoiding the introduction of tables that do not meet the user's demand scenarios to participate in subsequent calculations and analysis.
[0087] By calculating the similarity between the intermediate description vector corresponding to each intermediate table and the statement vector corresponding to the initial statement, it can be used to measure the degree of association between the initial statement and each intermediate table, thereby obtaining the intermediate matching degree between the initial statement and each intermediate table, which serves as the basis for accurately screening out the target table that best matches the initial statement from many intermediate tables, and determining the intermediate table corresponding to the largest intermediate matching degree as the target table corresponding to the initial statement, thereby improving the accuracy and rationality of the generated SQL statement.
[0088] In the above, by first collecting relevant information of the preset table for scene matching to screen out the intermediate table, and then converting the intermediate table description text and the initial statement into vectors and calculating the matching degree respectively, the target table is finally screened out, which provides a key operation object foundation that is closely aligned with user needs for the subsequent use of a large language model to accurately generate SQL statements, ensures the accuracy and rationality of the entire SQL statement generation method, and enables it to better serve the user's needs of converting natural language into SQL statements for database operations.
[0089] In a specific implementation, S10 further includes the following steps:
[0090] S123, obtaining a plurality of historical sentences and a preset scene corresponding to each historical sentence.
[0091] S124, acquiring a historical sentence vector corresponding to each historical sentence according to a target vector conversion model corresponding to a preset scenario corresponding to each historical sentence.
[0092] S20, extracting keywords from the initial sentence to obtain a number of target keywords corresponding to the initial sentence.
[0093] Among them, those skilled in the art know that any keyword extraction method in the prior art falls within the protection scope of the present invention, and will not be described in detail here.
[0094] In the above, several target keywords are extracted from the initial sentence input by the user, and the complex sentence is simplified into a vocabulary set that can reflect the core semantics and key elements, so that these keywords can be used for more accurate matching, analysis and guidance of the generation logic of SQL statements, thereby improving the fit between the final generated SQL statement and the user's true intention.
[0095] S30, matching each target keyword with the preset keyword configuration table to obtain a matching result corresponding to each target keyword, wherein the matching result includes a set consisting of a corresponding custom keyword and a corresponding regular expression.
[0096] In a specific implementation, S30 further includes the following steps:
[0097] S301, for any target keyword, perform word consistency matching between the current target keyword and each custom keyword in the preset keyword configuration table, and obtain word consistency matching results between the current target keyword and each custom keyword, wherein the word consistency matching results include word consistency and word inconsistency.
[0098] S302: For any custom keyword, if the word consistency matching result between the current target keyword and the current custom keyword is word consistency, a set consisting of the current custom keyword and the regular expression corresponding to the current custom keyword is determined as the matching result corresponding to the current target keyword.
[0099] S303, traversing all the custom keywords, if the word consistency matching results between the current target keyword and all the custom keywords are all word inconsistencies, determining an empty set as the matching result corresponding to the current target keyword.
[0100] In the above, by comparing the target keywords with the custom keywords in the preset keyword configuration table one by one, the matching of the target keywords and the custom keywords at the word level is judged, and on this basis, the matching results corresponding to each target keyword are obtained, which lays a solid foundation for the subsequent integration of the matching results of all target keywords, further guiding the SQL statement generation logic based on these results, and improving the accuracy and standardization of SQL statement generation.
[0101] S40, obtaining several target regular expressions corresponding to the initial sentence according to the matching results of all target keywords.
[0102] As described above, regular expressions are used to standardize and reflect the text format and matching rules of key semantic information in the initial statement as a whole, providing a clear pattern basis for accurate processing of relevant semantic elements in the subsequent SQL statement generation link, which helps to accurately convert the initial statement into an SQL statement according to the established business logic.
[0103] S50, acquiring a sentence vector corresponding to the initial sentence according to a target vector conversion model corresponding to a target scene corresponding to the initial sentence.
[0104] S60, obtaining the similarity between the initial sentence and each historical sentence according to the sentence vector and the historical sentence vector corresponding to each historical sentence.
[0105] In the above, by calculating the similarity between the statement vector and the historical statement vector corresponding to each historical statement, the proximity between the initial statement and each historical statement in terms of semantics, data relevance, etc. is quantitatively measured, so that historical statements with reference value for generating the SQL statement corresponding to the current initial statement can be screened out based on the similarity, thereby improving the accuracy of SQL statement generation.
[0106] S70, based on the comparison between the similarity between the initial sentence and each historical sentence and a preset similarity threshold, a plurality of reference sentences corresponding to the initial sentence are screened out from all historical sentences.
[0107] Among them, historical sentences with similarity greater than a preset similarity threshold are determined as several reference sentences corresponding to the initial sentence.
[0108] As described above, based on the comparison results of the similarity between the initial sentence and each historical sentence and the preset similarity threshold, reference sentences with high similarity to the initial sentence and reference significance for the current SQL statement generation are screened out from numerous historical sentences, which helps the preset large language model to generate more accurate SQL statements that meet the user's intentions based on previous similar situations, thereby improving the accuracy of SQL statement generation.
[0109] S80, input the sentence vector, the target table, several target regular expressions corresponding to the initial sentence, several reference sentences corresponding to the initial sentence, and the historical SQL statements corresponding to each reference sentence into the preset large language model to obtain the SQL statement corresponding to the initial sentence.
[0110] In the above, the sentence vector, the target table, several target regular expressions corresponding to the initial sentence, several screened reference sentences, and the historical SQL statements corresponding to each reference sentence are input into the preset large language model together. The powerful language understanding and generation capabilities of the large language model are utilized, and the semantics, structure, historical experience and other information contained in the input content are comprehensively considered to generate SQL statements that meet the initial statement intentions input by the user, thereby realizing the conversion from natural language to database executable statements and improving the generation accuracy of SQL statements.
[0111] In the above, by performing keyword extraction on the initial sentence, several target keywords corresponding to the initial sentence are obtained, each target keyword is matched with the preset keyword configuration table, and the matching result corresponding to each target keyword is obtained. According to the matching results of all target keywords, several target regular expressions corresponding to the initial sentence are obtained, and according to the target vector conversion model corresponding to the target scene corresponding to the initial sentence, the sentence vector corresponding to the initial sentence is obtained, and according to the sentence vector and the historical sentence vector corresponding to each historical sentence, the similarity between the initial sentence and each historical sentence is obtained. According to the comparison between the similarity between the initial sentence and each historical sentence and the preset similarity threshold, several reference sentences corresponding to the initial sentence are screened out from all historical sentences, and the sentence vector, target table, and initial sentence are converted into a target vector. Several target regular expressions corresponding to the statement, several reference statements corresponding to the initial statement, and historical SQL statements corresponding to each reference statement are input into the preset large language model, and the SQL statement corresponding to the initial statement is obtained. The target regular expression is obtained by extracting keywords from the initial statement and matching it with the preset keyword configuration table. This can accurately capture the key semantic information in the natural language, standardize the fuzzy and diverse natural language expressions according to the established business rules, and avoid the large language model's incorrect interpretation of the user's intentions. At the same time, by screening out reference statements with high similarity to the initial statement and reference significance for the current SQL statement generation from many historical statements, it helps the preset large language model to generate more accurate SQL statements that meet the user's intentions based on similar situations in the past, thereby improving the accuracy of SQL statement generation.
[0112] Embodiment 2
[0113] The second embodiment provides a SQL statement generation device based on a large language model. The SQL statement generation device based on a large language model includes: Figure 2 As shown:
[0114] The data acquisition module 21 is used to obtain the historical input database, the initial statement input by the target user, the target scene and target table corresponding to the initial statement, and the target vector conversion model and preset keyword configuration table corresponding to the target scene, wherein the historical input database includes a number of historical statements, a historical statement vector corresponding to each historical statement, and a historical SQL statement, and the preset keyword configuration table includes a number of custom keywords and a regular expression corresponding to each custom keyword.
[0115] The keyword extraction module 22 is used to extract keywords from the initial sentence and obtain a number of target keywords corresponding to the initial sentence.
[0116] The matching result acquisition module 23 is used to match each target keyword with the preset keyword configuration table to obtain the matching result corresponding to each target keyword, wherein the matching result includes a set consisting of the corresponding custom keyword and the corresponding regular expression.
[0117] The target regular expression acquisition module 24 is used to acquire a plurality of target regular expressions corresponding to the initial sentence according to the matching results of all target keywords.
[0118] The sentence vector acquisition module 25 is used to acquire the sentence vector corresponding to the initial sentence according to the target vector conversion model corresponding to the target scene corresponding to the initial sentence.
[0119] The similarity acquisition module 26 is used to acquire the similarity between the initial sentence and each historical sentence according to the sentence vector and the historical sentence vector corresponding to each historical sentence.
[0120] The sentence screening module 27 is used to screen out a number of reference sentences corresponding to the initial sentence from all the historical sentences based on the comparison between the similarity between the initial sentence and each historical sentence and a preset similarity threshold.
[0121] The SQL statement generation module 28 is used to input the statement vector, the target table, several target regular expressions corresponding to the initial statement, several reference statements corresponding to the initial statement, and the historical SQL statements corresponding to each reference statement into the preset large language model to obtain the SQL statement corresponding to the initial statement.
[0122] In a specific implementation, the data acquisition module 21 includes:
[0123] The first data acquisition submodule is used to obtain an initial vector conversion model, description text samples corresponding to a number of preset tables, preset scenes and description vector samples corresponding to each description text sample, and a preset sampling ratio corresponding to each preset scene.
[0124] The data initialization submodule is used to determine the preset sampling ratio as the target sampling ratio, determine each preset scene as the initial scene, and initialize the number of repetitions N=1.
[0125] The first training data acquisition submodule is used to sample from a number of description text samples according to a target sampling ratio corresponding to each initial scene, to obtain the Nth description text training sample set, the Nth description text verification sample set, and the Nth number of description text samples corresponding to each initial scene in the Nth description text training sample set.
[0126] The first model training submodule is used to train the initial vector conversion model according to the Nth description text training sample set, the Nth description text verification sample set and the description vector sample corresponding to each description text sample, and obtain the Nth vector conversion model and the Nth accuracy of each initial scene in the Nth vector conversion model.
[0127] The adaptation degree acquisition submodule is used to obtain the Nth adaptation degree of each initial scene and the Nth vector conversion model according to the Nth number and the Nth accuracy rate corresponding to each initial scene.
[0128] The adaptation result acquisition submodule is used to determine the adaptation result corresponding to the current initial scene for any initial scene based on the comparison result of the Nth adaptation degree corresponding to the current initial scene with the preset degree threshold, wherein the adaptation result includes adaptation, non-adaptation and pending judgment.
[0129] The first scene determination submodule is used to determine the current initial scene as the first scene if the adaptation result corresponding to the current initial scene is adaptation, and determine the Nth vector conversion model as the target vector conversion model corresponding to the current first scene.
[0130] The second scene determination submodule is used to determine the current initial scene as the second scene if the adaptation result corresponding to the current initial scene is not suitable.
[0131] The third scene determination submodule is used to determine the current initial scene as the third scene if the adaptation result corresponding to the current initial scene is to be determined.
[0132] The initial scene traversal submodule is used to traverse all initial scenes, obtain all first scenes and the target vector conversion model corresponding to each first scene, all second scenes, all third scenes and the number of scenes corresponding to the third scenes.
[0133] The second training data acquisition submodule is used to acquire a target description text sample set corresponding to each second scene according to the preset scene and description vector sample corresponding to each description text sample.
[0134] The second model training submodule is used to train the initial vector conversion model according to the target description text sample set corresponding to each second scene and the description vector sample corresponding to each description text sample, so as to obtain the target vector conversion model corresponding to each second scene.
[0135] The data updating submodule is used to update the preset sampling ratio corresponding to each third scene if the number of scenes is greater than 0 and determine the updated preset sampling ratio as the target sampling ratio, determine each third scene as the initial scene, update N=N+1, and repeatedly execute the first training data acquisition submodule until the updated number of scenes is equal to 0, and obtain the target vector conversion model corresponding to each preset scene.
[0136] In a specific implementation, the preset sampling ratio corresponding to each preset scene includes a training sample sampling ratio and a verification sample sampling ratio, and the first training data acquisition submodule includes:
[0137] The training sample acquisition unit is used to sample a number of description text samples as training samples from all description text samples corresponding to the current initial scene according to the training sample sampling ratio corresponding to the current initial scene for any initial scene, and obtain the Nth number of description text samples corresponding to the current initial scene as training samples.
[0138] The verification sample acquisition unit is used to sample a number of description text samples as verification samples from all description text samples corresponding to the current initial scene according to the verification sample sampling ratio corresponding to the current initial scene.
[0139] The scene traversal unit is used to traverse all the initial scenes and obtain a number of description text samples corresponding to each initial scene as training samples and a number of description text samples as verification samples.
[0140] The training sample set determination unit is used to determine a set of several description text samples corresponding to all initial scenes as training samples as the Nth description text training sample set.
[0141] The verification sample set determination unit is used to determine a set of several description text samples corresponding to all initial scenes as verification samples as the Nth description text verification sample set.
[0142] In a specific implementation, the adaptation degree acquisition submodule includes:
[0143] The data normalization unit is used to normalize the Nth quantity corresponding to each initial scene, and obtain the normalized Nth quantity corresponding to each initial scene.
[0144] The adaptation degree acquisition unit is used to input the normalized Nth number and Nth accuracy corresponding to each initial scene into a preset adaptation degree calculation model, and obtain the Nth adaptation degree of each initial scene and the Nth vector conversion model, wherein the Nth adaptation degree is inversely proportional to the corresponding normalized Nth number, and the Nth adaptation degree is directly proportional to the corresponding Nth accuracy.
[0145] In a specific implementation, the preset degree threshold includes a first degree threshold and a second degree threshold, and the adaptation result acquisition submodule includes:
[0146] The first adaptation result obtaining unit is used to determine that the adaptation result corresponding to the current initial scene is not suitable if the Nth adaptation degree corresponding to the current initial scene is less than or equal to the first degree threshold.
[0147] The second adaptation result obtaining unit is configured to determine that the adaptation result corresponding to the current initial scene is not adapted if the Nth adaptation degree corresponding to the current initial scene is greater than or equal to a second degree threshold.
[0148] The third adaptation result obtaining unit is used to determine that the adaptation result corresponding to the current initial scene is to be determined if the Nth adaptation degree corresponding to the current initial scene is less than the second degree threshold and greater than the first degree threshold.
[0149] In a specific implementation, the data acquisition module 21 further includes:
[0150] The second data acquisition submodule is used to acquire a plurality of preset tables, preset description texts and preset scenes corresponding to each preset table, and a target vector conversion model corresponding to each preset scene.
[0151] The consistency matching submodule is used to perform scene consistency matching on the preset scene corresponding to each preset table and the target scene corresponding to the initial sentence, and obtain the scene consistency matching result between each preset table and the initial sentence, wherein the scene consistency matching result includes scene consistency and scene inconsistency.
[0152] The intermediate table screening submodule is used to determine each preset table whose scene consistency matching result is scene consistent as the intermediate table corresponding to the initial statement.
[0153] The intermediate description vector acquisition submodule is used to acquire the intermediate description vector corresponding to each intermediate table according to the target vector conversion model corresponding to the preset scene corresponding to the preset description text corresponding to each intermediate table.
[0154] The sentence vector acquisition submodule is used to convert the model according to the target vector corresponding to the target scene corresponding to the initial sentence, and obtain the sentence vector corresponding to the initial sentence.
[0155] The intermediate matching degree acquisition submodule is used to acquire the intermediate matching degree between the initial sentence and each intermediate table according to the intermediate description vector corresponding to each intermediate table and the sentence vector corresponding to the initial sentence.
[0156] The target table screening submodule is used to screen out the target table corresponding to the initial statement from all the intermediate tables according to the intermediate matching degree between the initial statement and each intermediate table.
[0157] In a specific implementation, the data acquisition module 21 further includes:
[0158] The third data acquisition submodule is used to acquire a plurality of historical sentences and a preset scene corresponding to each historical sentence.
[0159] The historical sentence vector acquisition submodule is used to obtain the historical sentence vector corresponding to each historical sentence according to the target vector conversion model corresponding to the preset scenario corresponding to each historical sentence.
[0160] In a specific implementation, the matching result acquisition module 23 further includes:
[0161] The word consistency matching submodule is used to perform word consistency matching on the current target keyword and each custom keyword in the preset keyword configuration table for any target keyword, and obtain the word consistency matching result between the current target keyword and each custom keyword, wherein the word consistency matching result includes word consistency and word inconsistency.
[0162] The matching result acquisition submodule is used to determine the current custom keyword and the set of regular expressions corresponding to the current custom keyword as the matching result corresponding to the current target keyword if the word consistency matching result between the current target keyword and the current custom keyword is word consistency for any custom keyword.
[0163] The keyword traversal submodule is used to traverse all custom keywords. If the word consistency matching results between the current target keyword and all custom keywords are all word inconsistencies, an empty set is determined as the matching result corresponding to the current target keyword.
[0164] It should be noted that the information interaction, execution process and other contents between the above modules are based on the same concept as the embodiment of the method of the present invention. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0165] Embodiment 3
[0166] Embodiment 3 of the present invention provides a non-transitory computer-readable storage medium, wherein at least one instruction or at least one program is stored in the non-transitory computer-readable storage medium, and the at least one instruction or at least one program is loaded and executed by a processor to implement the steps:
[0167] S10, obtain the historical input database, the initial sentence input by the target user, the target scenario and target table corresponding to the initial sentence, and the target vector conversion model and preset keyword configuration table corresponding to the target scenario, wherein the historical input database includes several historical sentences, the historical sentence vectors corresponding to each historical sentence, and the historical SQL statements, and the preset keyword configuration table includes several custom keywords and the regular expression corresponding to each custom keyword.
[0168] S20, extracting keywords from the initial sentence to obtain a number of target keywords corresponding to the initial sentence.
[0169] S30, matching each target keyword with the preset keyword configuration table to obtain a matching result corresponding to each target keyword, wherein the matching result includes a set consisting of a corresponding custom keyword and a corresponding regular expression.
[0170] S40, obtaining several target regular expressions corresponding to the initial sentence according to the matching results of all target keywords.
[0171] S50, acquiring a sentence vector corresponding to the initial sentence according to a target vector conversion model corresponding to a target scene corresponding to the initial sentence.
[0172] S60, obtaining the similarity between the initial sentence and each historical sentence according to the sentence vector and the historical sentence vector corresponding to each historical sentence.
[0173] S70, based on the comparison between the similarity between the initial sentence and each historical sentence and a preset similarity threshold, a plurality of reference sentences corresponding to the initial sentence are screened out from all historical sentences.
[0174] S80, input the sentence vector, the target table, several target regular expressions corresponding to the initial sentence, several reference sentences corresponding to the initial sentence, and the historical SQL statements corresponding to each reference sentence into the preset large language model to obtain the SQL statement corresponding to the initial sentence.
[0175] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing related hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronization link DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0176] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0177] Embodiment 4
[0178] A fourth embodiment of the present invention provides an electronic device, which includes a processor and the non-transitory computer-readable storage medium in the third embodiment of the present invention.
[0179] The above are only preferred embodiments of the present invention, and are not intended to limit the present invention in any form. Although the present invention has been disclosed as a preferred embodiment as above, it is not intended to limit the present invention. Any technician familiar with the profession can make some changes or modify the technical contents disclosed above into equivalent embodiments without departing from the scope of the technical solution of the present invention. However, any simple modification, equivalent change and modification made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention still fall within the scope of the technical solution of the present invention.
Claims
1. A method for generating SQL statements based on a large language model, characterized in that: The SQL statement generation method comprises the following steps: S10, obtaining a historical input database, an initial sentence input by a target user, a target scenario and a target table corresponding to the initial sentence, and a target vector conversion model and a preset keyword configuration table corresponding to the target scenario, wherein the historical input database includes a number of historical sentences, a historical sentence vector corresponding to each historical sentence, and a historical SQL statement, and the preset keyword configuration table includes a number of custom keywords and a regular expression corresponding to each custom keyword; S20, extracting keywords from the initial sentence to obtain a number of target keywords corresponding to the initial sentence; S30, matching each target keyword with the preset keyword configuration table to obtain a matching result corresponding to each target keyword, wherein the matching result includes a set consisting of a corresponding custom keyword and a corresponding regular expression; S40, obtaining a plurality of target regular expressions corresponding to the initial sentence according to the matching results of all target keywords; S50, acquiring a sentence vector corresponding to the initial sentence according to a target vector conversion model corresponding to a target scene corresponding to the initial sentence; S60, obtaining the similarity between the initial sentence and each historical sentence according to the sentence vector and the historical sentence vector corresponding to each historical sentence; S70, based on the comparison between the similarity between the initial sentence and each historical sentence and a preset similarity threshold, screening out a plurality of reference sentences corresponding to the initial sentence from all historical sentences; S80, input the sentence vector, the target table, several target regular expressions corresponding to the initial sentence, several reference sentences corresponding to the initial sentence, and historical SQL statements corresponding to each reference sentence into the preset large language model to obtain the SQL statement corresponding to the initial sentence.
2. The method for generating SQL statements based on a large language model according to claim 1, characterized in that: S10 includes the following steps: S101, obtaining an initial vector conversion model, description text samples corresponding to a plurality of preset tables, preset scenes and description vector samples corresponding to each description text sample, and a preset sampling ratio corresponding to each preset scene; S102, determining a preset sampling ratio as a target sampling ratio, determining each preset scene as an initial scene, and initializing the number of repetitions N=1; S103, sampling from the plurality of description text samples according to a target sampling ratio corresponding to each initial scene, to obtain an Nth description text training sample set, an Nth description text verification sample set, and an Nth number of description text samples corresponding to each initial scene in the Nth description text training sample set; S104, training the initial vector conversion model according to the Nth description text training sample set, the Nth description text verification sample set, and the description vector sample corresponding to each description text sample, and obtaining the Nth vector conversion model and the Nth accuracy rate of each initial scene in the Nth vector conversion model; S105, obtaining an Nth degree of adaptation between each initial scene and the Nth vector conversion model according to the Nth number and the Nth accuracy rate corresponding to each initial scene; S106, for any initial scene, determining an adaptation result corresponding to the current initial scene according to a comparison result of the Nth adaptation degree corresponding to the current initial scene with a preset degree threshold, wherein the adaptation result includes adaptation, non-adaptation and pending; S107, if the adaptation result corresponding to the current initial scene is adaptation, the current initial scene is determined as the first scene, and the Nth vector conversion model is determined as the target vector conversion model corresponding to the current first scene; S108, if the adaptation result corresponding to the current initial scene is not suitable, determining the current initial scene as the second scene; S109, if the adaptation result corresponding to the current initial scene is to be determined, the current initial scene is determined as the third scene; S110, traversing all initial scenes, obtaining all first scenes and a target vector conversion model corresponding to each first scene, all second scenes, all third scenes, and the number of scenes corresponding to the third scenes; S111, acquiring a target description text sample set corresponding to each second scene according to the preset scene and the description vector sample corresponding to each description text sample; S113, training the initial vector conversion model according to the target description text sample set corresponding to each second scene and the description vector sample corresponding to each description text sample, to obtain a target vector conversion model corresponding to each second scene; S114, if the number of scenes is greater than 0, then updating the preset sampling ratio corresponding to each third scene and determining the updated preset sampling ratio as the target sampling ratio, determining each third scene as the initial scene, updating N=N+1, and repeating step S103 until the updated number of scenes is equal to 0, and obtaining the target vector conversion model corresponding to each preset scene; S115, acquiring a target vector conversion model corresponding to the target scene according to the target vector conversion model corresponding to each preset scene.
3. The method for generating SQL statements based on a large language model according to claim 2, characterized in that: The preset sampling ratio corresponding to each preset scene includes a training sample sampling ratio and a verification sample sampling ratio. S103 includes the following steps: S1031, for any initial scene, according to the sampling ratio of training samples corresponding to the current initial scene, a number of description text samples are sampled from all description text samples corresponding to the current initial scene as training samples, and the Nth number of description text samples corresponding to the current initial scene as training samples is obtained; S1032, according to the sampling ratio of the verification samples corresponding to the current initial scene, sampling from all the description text samples corresponding to the current initial scene to obtain a plurality of description text samples as verification samples; S1033, traversing all initial scenes, obtaining a number of description text samples as training samples and a number of description text samples as verification samples corresponding to each initial scene; S1034, determining a set of a plurality of description text samples corresponding to all initial scenes as training samples as an Nth description text training sample set; S1035: Determine a set of several description text samples corresponding to all initial scenes as verification samples as the Nth description text verification sample set.
4. The method for generating SQL statements based on a large language model according to claim 2, characterized in that: S105 includes the following steps: S1051, normalizing the Nth number corresponding to each initial scene to obtain the normalized Nth number corresponding to each initial scene; S1052, input the normalized Nth number and Nth accuracy corresponding to each initial scene into a preset adaptation degree calculation model, and obtain the Nth adaptation degree of each initial scene and the Nth vector conversion model, wherein the Nth adaptation degree is inversely proportional to the corresponding normalized Nth number, and the Nth adaptation degree is directly proportional to the corresponding Nth accuracy.
5. The method for generating SQL statements based on a large language model according to claim 2, characterized in that: The preset degree threshold includes a first degree threshold and a second degree threshold, and S106 includes the following steps: S1061, if the Nth adaptation degree corresponding to the current initial scene is less than or equal to the first degree threshold, determining that the adaptation result corresponding to the current initial scene is unmatched; S1062: If the Nth adaptation degree corresponding to the current initial scene is greater than or equal to the second degree threshold, determining that the adaptation result corresponding to the current initial scene is not suitable; S1063: If the Nth adaptation degree corresponding to the current initial scene is less than the second degree threshold and greater than the first degree threshold, it is determined that the adaptation result corresponding to the current initial scene is to be determined.
6. The method for generating SQL statements based on a large language model according to claim 2, characterized in that: S10 also includes the following steps: S116, obtaining a plurality of preset tables, preset description texts and preset scenes corresponding to each preset table, and a target vector conversion model corresponding to each preset scene; S117, performing scene consistency matching on the preset scene corresponding to each preset table and the target scene corresponding to the initial sentence, and obtaining a scene consistency matching result between each preset table and the initial sentence, wherein the scene consistency matching result includes scene consistency and scene inconsistency; S118, determining each preset table whose scene consistency matching result is scene consistent as an intermediate table corresponding to the initial sentence; S119, acquiring an intermediate description vector corresponding to each intermediate table according to a target vector conversion model corresponding to a preset scene corresponding to a preset description text corresponding to each intermediate table; S120, acquiring a sentence vector corresponding to the initial sentence according to a target vector conversion model corresponding to a target scene corresponding to the initial sentence; S121, obtaining an intermediate matching degree between the initial sentence and each intermediate table according to the intermediate description vector corresponding to each intermediate table and the sentence vector corresponding to the initial sentence; S122: Filter out a target table corresponding to the initial statement from all the intermediate tables according to the intermediate matching degree between the initial statement and each intermediate table.
7. The method for generating SQL statements based on a large language model according to claim 2, characterized in that: S10 also includes the following steps: S123, obtaining a plurality of historical sentences and a preset scene corresponding to each historical sentence; S124, acquiring a historical sentence vector corresponding to each historical sentence according to a target vector conversion model corresponding to a preset scenario corresponding to each historical sentence.
8. The method for generating SQL statements based on a large language model according to claim 1, characterized in that: S30 also includes the following steps: S301, for any target keyword, performing word consistency matching between the current target keyword and each custom keyword in the preset keyword configuration table, and obtaining a word consistency matching result between the current target keyword and each custom keyword, wherein the word consistency matching result includes word consistency and word inconsistency; S302, for any custom keyword, if the word consistency matching result between the current target keyword and the current custom keyword is word consistency, then determine the set consisting of the current custom keyword and the regular expression corresponding to the current custom keyword as the matching result corresponding to the current target keyword; S303, traversing all the custom keywords, if the word consistency matching results between the current target keyword and all the custom keywords are all word inconsistencies, determining an empty set as the matching result corresponding to the current target keyword.
9. A non-transitory computer-readable storage medium, wherein at least one instruction or at least one program is stored in the non-transitory computer-readable storage medium, characterized in that: The at least one instruction or the at least one program is loaded and executed by the processor to implement the SQL statement generation method based on a large language model as described in any one of claims 1-8.
10. An electronic device, characterized in that: The invention comprises a processor and the non-transitory computer-readable storage medium as claimed in claim 9.
Citation Information
Patent Citations
Ship social method and apparatus, electronic device and readable storage medium
CN109327510A
Method for automatically generating database query statement based on NLP language model
CN116991869A
Method, device, equipment and medium for converting natural language problem into SQL (Structured Query Language) statement
CN117667992A
Method for generating statement from natural language to SQL in business scene based on large model
CN117708162A
Data preparation method, system and device for AIGC interaction analysis and medium
CN118093795A
Cited By
Regular expression synthesis method and device based on big language model demand understanding
CN120950416A