Natural language to SQL (Structured Query Language) method and device based on large language model and medium
By generating data model lexicon and identifying data model information in natural language, combined with the understanding and analysis of large language models, the semantic understanding and context analysis problems of natural language to SQL are solved, and the accuracy of SQL generation and database syntax compatibility are improved.
Patent Information
- Application Number
- CN202510094623.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-21
- Publication Date
- 2025-05-16
AI Technical Summary
The prior art is difficult to understand the semantics and context of natural language in the process of natural language conversion to SQL, resulting in poor accuracy in generating SQL, especially in the syntax compatibility of complex queries and different databases.
By connecting to preset database tables, obtaining database table information, generating data model lexicon, and identifying data model names, field names and field values in natural languages, grouping them and assembling them, and input them to the large language model for understanding and analysis to generate corresponding SQL statements.
Overcome interferences such as part of the word, position and inverted sentences, truly understand the content of user query, improve the accuracy of SQL generation in natural language, and solve the problem of syntax compatibility of different databases.
Smart Images

Figure CN120011392A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of large language models, and specifically to a natural language to SQL conversion method, device and medium based on a large language model. Background Art
[0002] Chat BI, also known as search BI, is a business intelligence product that uses conversational interaction. Unlike traditional BI tools that create dashboards and reports by dragging components, Chat BI allows users to query data through natural language. This interactive method makes the data analysis process more intuitive, flexible and efficient. Users only need to enter natural language questions similar to those used to interact with search engines, and the system will quickly parse and return the corresponding data analysis results.
[0003] The core technical problem of Chat BI conversational analysis products is natural language to SQL conversion. How to understand the semantics and context of natural language and generate correct and executable SQL has become a key and difficult problem in this field. At present, the ability to convert natural language to SQL in the Chat BI field is still insufficient. There are mainly three ways of converting this technology in the industry, and these three ways still have certain technical defects:
[0004] 1. Forming SQL based on word segmentation rule matching: This method relies on the type and position of natural language word segmentation. Based on the type of word segmentation, such as field name, field value, logical word, etc., and the positional relationship between them, SQL is formed through logical reasoning. This method is easy to implement, but lacks understanding of natural language semantics and context. This method is suitable for simple queries. For complex natural languages, the accuracy of generating SQL in this way is poor.
[0005] 2. Forming SQL based on machine learning training data structure: This method uses the basic model to train natural language, table structure, and generated SQL data to form a dedicated natural language to SQL deep learning model. However, this method requires a large amount of training data and is highly dependent on data. Different training data will generate very different SQL.
[0006] 3. Generate SQL based on the big language model: This method is to inform the big model of natural language and table structure and let it generate SQL based on the prompt words. This method only generates SQL based on the table structure information and relies on the reasoning ability of the big model, but the big model cannot recognize the specific value information in the database table. Summary of the invention
[0007] In order to solve the above problems, the present application proposes a method, a device and a medium, wherein the method includes:
[0008] The method comprises the following steps: obtaining database table information by connecting to a preset database table, and generating a data model vocabulary according to the database table information; obtaining a target natural language, and identifying a data model name, a field name, and a field value in the target natural language; grouping the field names and field values according to the data model names to obtain a plurality of field groups; assembling the plurality of field groups with prompt words, and inputting the assembled prompt words and context information into a large language model; and understanding and analyzing the prompt words and the context information through the large language model to obtain an SQL statement corresponding to the target natural language.
[0009] In one example, the field names and field values are grouped according to the data model name to obtain multiple field groups, specifically including: determining the field names and field values identified in the target natural language; determining the data models corresponding to the field names and the field values respectively; and assigning the field names and field values corresponding to the same data model to the same group to obtain multiple field groups.
[0010] In one example, the method of acquiring a target natural language and identifying a data model name, field name, and field value in the target natural language specifically includes: identifying the target natural language to obtain a single natural language character set corresponding to the target natural language, and unsuccessfully identified characters; performing fuzzy matching on the unsuccessfully identified characters; performing an incremental shift method on a single natural language character within the single natural language character set to obtain a plurality of natural language character combinations; and acquiring data model vocabulary attributes of the plurality of natural language character combinations, wherein the data model vocabulary attributes include a data model name, field name, and field value.
[0011] In one example, obtaining the data model vocabulary attributes of the multiple natural language character combinations specifically includes: selecting any natural language character combination from the multiple natural language character combinations as a target character combination; searching and matching the target character combination in the data model vocabulary to obtain a matching character combination and an unmatched character combination; replacing the matching character combination with a preset symbol to obtain a processed target natural language character; performing natural language word segmentation on the target natural language character to obtain a natural language word segmentation result; replacing the preset symbol in the natural language word segmentation result with a vocabulary identification word corresponding to the matching character combination in the data model vocabulary, and storing the data model vocabulary attributes corresponding to the vocabulary identification word.
[0012] In one example, the assembling of prompt words for the multiple field groups specifically includes: receiving a functional prompt word adding request from a user, and sending a preset functional prompt word library to the user based on the functional prompt word adding request; receiving a functional prompt word selected by the user, and assembling the multiple field groups in the preset positions of the functional prompt word.
[0013] In one example, after assembling the multiple field groups in the preset positions of the function prompt words, the method further includes: obtaining the structure of the data model corresponding to the multiple field groups and assembling the data model prompt words; the data model prompt words include the name of the data model, the included field names and the field types; determining the structure of the data model corresponding to the multiple field groups to assemble the data model prompt words, the data model prompt words include the name of the data model, the included field names and the field types; determining the field names identified in the multiple field groups to add synonym prompt words for the field names; determining the field values identified in the multiple field groups to add the field name prompt words to which the field values belong; determining the database table connected to the data model corresponding to the matching text combination to add the type prompt words for the database table.
[0014] In one example, the method connects to a preset database table, obtains database table information, and generates a data model vocabulary based on the database table information, specifically including: generating a data model based on the database table information; the data model includes the structure of the preset database table, including field names, field types, and field values contained in each field; generating a table name vocabulary based on the table name of the data model; generating a character field name vocabulary and a numeric field name vocabulary based on the field names and field types contained in the data model; generating a field value vocabulary based on the field values contained in the data model; header fields of the data model vocabulary: matching value, belonging field, belonging digital model, and belonging character type.
[0015] In one example, after the prompt word and the context information are understood and analyzed by the large language model to obtain the SQL statement corresponding to the target natural language, the method further includes: performing SQL data retrieval on the database through the SQL statement to obtain SQL retrieved data; assembling the prompt words on the SQL retrieved data to obtain the prompt words of the data retrieval result; and inputting the prompt words of the data retrieval result into the large prediction model for analysis to obtain the analysis summary corresponding to the target natural language.
[0016] The present application also provides a natural language to SQL device based on a large language model, comprising: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute: obtaining database table information by connecting to a preset database table, and generating a data model vocabulary based on the database table information; obtaining a target natural language, and identifying a data model name, a field name, and a field value in the target natural language; grouping the field names and field values according to the data model names to obtain a plurality of field groups; assembling the plurality of field groups with prompt words, and inputting the assembled prompt words and context information into the large language model; understanding and analyzing the prompt words and the context information through the large language model to obtain an SQL statement corresponding to the target natural language.
[0017] The present application also provides a non-volatile computer storage medium storing computer executable instructions, wherein the computer executable instructions are configured to: obtain database table information by connecting to a preset database table, and generate a data model vocabulary based on the database table information; obtain a target natural language, and identify a data model name, a field name, and a field value in the target natural language; group the field names and field values based on the data model name to obtain a plurality of field groups; assemble the plurality of field groups with prompt words, and input the assembled prompt words and context information into a large language model; and understand and analyze the prompt words and the context information through the large language model to obtain an SQL statement corresponding to the target natural language.
[0018] The method proposed in this application can bring the following beneficial effects: it overcomes the interference of word parts, positions, inverted sentences, and irregular languages, can truly understand the content that users want to query, and generate corresponding SQL based on the data structure, thereby improving the accuracy of natural language to generate SQL. It also solves the grammatical compatibility problem of natural language to generate SQL for different databases. There are certain differences in the grammars of different databases, and different databases have different grammars and functions. The present invention can generate corresponding SQL according to different databases by taking advantage of the large model. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0020] Figure 1A flowchart of a natural language to SQL conversion method based on a large language model in an embodiment of the present application;
[0021] Figure 2 A schematic diagram of structural information stored in a data model vocabulary library in an embodiment of the present application;
[0022] Figure 3 This is a schematic diagram of word segmentation using an incremental movement method in an embodiment of the present application;
[0023] Figure 4 This is a schematic diagram of label substitution in the embodiment of the present application;
[0024] Figure 5 This is a schematic diagram of an example data model structure in a prompt word assembly process in an embodiment of the present application;
[0025] Figure 6 This is a schematic diagram of example field information in a prompt word assembly process in an embodiment of the present application;
[0026] Figure 7 This is a schematic diagram of the overall process of obtaining an intelligent analysis summary in an embodiment of the present application;
[0027] Figure 8 This is a structural diagram of a natural language to SQL device based on a large language model in an embodiment of the present application. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0029] The technical solutions provided by various embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0030] Figure 1 A flowchart of a natural language to SQL conversion method based on a large language model provided for one or more embodiments of this specification. The method can be applied to different databases, the process can be executed by a computing device in the corresponding field, and some input parameters or intermediate results in the process allow manual intervention and adjustment to help improve accuracy.
[0031] The analysis method involved in the embodiments of the present application can be implemented by a terminal device or a server, and the present application does not impose any special restrictions on this. For the convenience of understanding and description, the following embodiments are described in detail by taking a server as an example.
[0032] It should be noted that the server can be a single device or a system composed of multiple devices, that is, a distributed server, and this application does not make any specific limitations on this.
[0033] like Figure 1 As shown, the embodiment of the present application provides a natural language to SQL method based on a large language model, including:
[0034] S101: acquiring database table information by connecting to a preset database table, and generating a data model vocabulary according to the database table information.
[0035] In one embodiment, in the process of generating SQL from natural language, the creation of a data model and the generation of a corresponding vocabulary and data structure are the first steps. At this time, it is necessary to connect to different databases, and the information of the database table can be loaded by connecting to the database to generate a data model. The data model contains the structure of the table in the database, including field names, field types, and field values contained in each field. A data model vocabulary is generated based on the information of the data model, including generating a table name vocabulary based on the table name in the data model, generating a character field name vocabulary and a numeric field name vocabulary based on the fields of the table structure in the data model, and generating a field value vocabulary based on the field value. The structural information stored in the specific vocabulary is as follows: Figure 2 shown.
[0036] S102: Acquire a target natural language, and identify a data model name, a field name, and a field value in the target natural language.
[0037] First, the target natural language needs to be recognized to obtain a single natural language character set corresponding to the target natural language and unsuccessfully recognized characters. Figure 3 As shown, a single natural language character in a single natural language character set is subjected to an incremental movement method to obtain multiple natural language character combinations, and then the data model thesaurus attributes of the multiple natural language character combinations are obtained, and the data model thesaurus attributes include data model names, field names, and field values. Specifically, the incremental movement method is used to loop each Chinese character, and each Chinese character combination that is looped is searched for a match in the data model thesaurus. The matched Chinese character combination is enclosed in curly brackets, and the matched words are taken out from the thesaurus, and the thesaurus words and corresponding attribute values are stored. The Chinese character combination enclosed in curly brackets is replaced with a label. After the label is replaced, traditional natural language word segmentation is performed, such as stammering word segmentation and Hanlp word segmentation, and the label is replaced with a word recognized by the thesaurus and the relevant attributes are stored. Fuzzy matching is performed on the unsuccessfully recognized characters; and fuzzy matching is performed again on the unmatched word segmentations using algorithms such as Levenshtein distance and cosine similarity.
[0038] S103: Grouping the field names and field values according to the data model name to obtain a plurality of field groups.
[0039] Before calling the large model to generate SQL, it is necessary to assemble prompt words. At this time, according to the matching and identification of the natural language and the data model in 102, the identified field names and field values can be grouped, and the field names and field values belonging to the same data model can be grouped together.
[0040] S104: Assembling the plurality of field groups with prompt words, and inputting the assembled prompt words and context information into the large language model.
[0041] Next, we assemble the prompt words of the large model. For each group of data after grouping, we assemble the prompt words as follows:
[0042] First, add functional prompt words to inform the big model that the intention is to generate SQL based on natural language. For example: "Please write a SQL for BI analysis based on the table structure I gave you. The SQL needs to include necessary fields and the fields are enclosed in double quotes. Numeric fields need to be aggregated. Do not translate Chinese field names or provide textual explanations."
[0043] Then get the structure of the data model and assemble the data model prompt. The data model prompt includes the name of the data model, the names of the fields included, and the field types. Its format is: data model name (field 1 varchar, field 2 varchar, ..., field n decimal)
[0044] Then, for the recognized field names, add synonymous hints, for example: field ddje: sales, field xsml: gross profit.
[0045] Then, for the recognized field value, add the prompt word of the corresponding field name. For example, Shanghai, the corresponding field is: xsdq.
[0046] Finally, you can add a prompt for the database type for the database to which the data model is connected. For example: Database type: ORACAL.
[0047] Next, we will use a simple example to illustrate the specific assembly process of the prompt word. Assume that the data model is as follows Figure 5 As shown in the figure, assuming that the input natural language is: "Please help me find the sales volume in Shanghai?", then the two fields of Shanghai and sales volume are matched. The information of these two fields in the vocabulary is as follows Figure 6 As shown, the assembly prompts are as follows:
[0048] Please help me check the sales of each sales region? Please write an SQL to do BI analysis according to the table structure I gave you. The necessary fields need to be included in the SQL and the fields need to be enclosed in double quotes. Numeric fields should be aggregated. Do not translate the Chinese field names or explain them in words. The table structure of the first database table: BI_YvwEc07l (cpdlvarchar, xsdq varchar, ddje decimal, xsml decimal); field cpdl: product category, field xsdq: sales region, field ddje: sales, field xsml: gross profit. Shanghai, the corresponding field is: xsdq, database type: PGSQL.
[0049] The present invention supports the access of multiple large models, and can access the large models according to Base-Url, Apikey, Secret Access Key and select the corresponding model.
[0050] S105: The prompt word and the context information are understood and analyzed by the large language model to obtain an SQL statement corresponding to the target natural language.
[0051] The assembled prompt words and context information are input to the big model, which understands and analyzes the prompt words and context information and outputs the results. The SQL information in the results is extracted, and the input natural language and the results output by the big model are added to the context information. This is for Chat BI's multi-round dialogue. The big model generates SQL from natural language based on the context.
[0052] In one embodiment, Figure 7 As shown, SQL information can be extracted based on the results returned by the large model, and the database can be connected to execute SQL data acquisition. The extracted data is reassembled into prompt words and input into the large model to analyze the data and form an intelligent analysis summary.
[0053] The present invention overcomes the interference of word parts of speech, positions, inverted sentences, and irregular languages, truly understands the content that users want to query, and generates corresponding SQL based on the data structure. At the same time, it solves the accuracy problem of natural language generation of SQL, and can understand natural language generation of SQL based on the semantics and context of natural language. SQL can be generated based on the context of multiple rounds of dialogue and context. It also solves the grammatical compatibility problem of natural language generation of SQL for different databases. There are certain differences in the grammar of different databases, and different databases have different grammars and functions. The present invention can generate corresponding SQL based on different databases using the advantages of large models. On this basis, the advantages of large models can also be used to analyze and summarize the data generated by Chat BI to form an intelligent analysis summary.
[0054] like Figure 8 As shown, the embodiment of the present application also provides a natural language to SQL device based on a large language model, including:
[0055] at least one processor; and,
[0056] a memory communicatively connected to the at least one processor; wherein,
[0057] The memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to:
[0058] The method comprises the following steps: obtaining database table information by connecting to a preset database table, and generating a data model vocabulary according to the database table information; obtaining a target natural language, and identifying a data model name, a field name, and a field value in the target natural language; grouping the field names and field values according to the data model names to obtain a plurality of field groups; assembling the plurality of field groups with prompt words, and inputting the assembled prompt words and context information into a large language model; and understanding and analyzing the prompt words and the context information through the large language model to obtain an SQL statement corresponding to the target natural language.
[0059] The embodiment of the present application further provides a non-volatile computer storage medium storing computer executable instructions, wherein the computer executable instructions are configured as follows:
[0060] The method comprises the following steps: obtaining database table information by connecting to a preset database table, and generating a data model vocabulary according to the database table information; obtaining a target natural language, and identifying a data model name, a field name, and a field value in the target natural language; grouping the field names and field values according to the data model names to obtain a plurality of field groups; assembling the plurality of field groups with prompt words, and inputting the assembled prompt words and context information into a large language model; and understanding and analyzing the prompt words and the context information through the large language model to obtain an SQL statement corresponding to the target natural language.
[0061] Each embodiment in this application is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0062] The devices and media provided in the embodiments of the present application correspond one-to-one to the methods. Therefore, the devices and media also have similar beneficial technical effects as the corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the devices and media will not be repeated here.
[0063] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0064] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0065] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0066] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0067] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0068] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0069] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include transitory media such as modulated data signals and carrier waves.
[0070] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0071] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A natural language to SQL conversion method based on a large language model, characterized in that: include: By connecting to a preset database table, obtaining database table information, and generating a data model vocabulary according to the database table information; Acquire a target natural language, and identify a data model name, a field name, and a field value in the target natural language; According to the data model name, the field names and field values are grouped to obtain a plurality of field groups; Assembling prompt words for the plurality of field groups, and inputting the assembled prompt words and context information into the large language model; The prompt word and the context information are understood and analyzed by the large language model to obtain an SQL statement corresponding to the target natural language.
2. The method according to claim 1, characterized in that The field names and field values are grouped according to the data model name to obtain multiple field groups, specifically including: Determine the field name and field value identified in the target natural language; Determine the data models corresponding to the field names and the field values respectively; The field names and field values corresponding to the same data model are grouped together to obtain multiple field groups.
3. The method according to claim 1, characterized in that: The acquiring of the target natural language and identifying the data model name, field name, and field value in the target natural language specifically includes: Recognize the target natural language to obtain a single natural language character set corresponding to the target natural language and unsuccessfully recognized characters; Performing fuzzy matching on the unsuccessfully recognized characters; Performing an incremental shift method on the individual natural language characters in the individual natural language character set to obtain a plurality of natural language character combinations; The data model word library attributes of the plurality of natural language character combinations are obtained, wherein the data model word library attributes include a data model name, a field name, and a field value.
4. The method according to claim 3, characterized in that The step of obtaining the data model vocabulary attributes of the plurality of natural language character combinations specifically includes: Select any one of the multiple natural language character combinations as a target character combination; Search and match the target character combination in the data model vocabulary to obtain matching character combinations and unmatched character combinations; The matching text combination is replaced by a preset symbol to obtain a processed target natural language text; Performing natural language word segmentation on the target natural language text to obtain a natural language word segmentation result; The preset symbols in the natural language word segmentation result are replaced with the vocabulary recognition words corresponding to the matching character combination in the data model vocabulary, and the data model vocabulary attributes corresponding to the vocabulary recognition words are stored.
5. The method according to claim 4, characterized in that The step of assembling prompt words for the plurality of field groups specifically includes: receiving a functional prompt word adding request from a user, and sending a preset functional prompt word library to the user according to the functional prompt word adding request; A function prompt word selected by a user is received, and the plurality of field groups are assembled in preset positions of the function prompt word.
6. The method according to claim 5, characterized in that After assembling the plurality of field groups in the preset positions of the function prompt words, the method further comprises: Acquire the structure of the data model corresponding to the plurality of field groups, and assemble the data model prompt words; the data model prompt words include the name of the data model, the included field names and field types; Determine the structure of the data model corresponding to the plurality of field groups to assemble a data model prompt word, wherein the data model prompt word includes a name of the data model, names of included fields, and field types; Determining the field names identified in the plurality of field groups to add synonym prompt words for the field names; Determine the identified field values in the plurality of field groups to add a field name prompt word to which the field value belongs; Determine the database table connected to the data model corresponding to the matching character combination, and add a type hint word for the database table.
7. The method according to claim 1, characterized in that The method of obtaining database table information by connecting to a preset database table and generating a data model vocabulary according to the database table information specifically includes: Generate a data model based on the database table information; the data model includes the structure of the preset database table, including field names, field types and field values contained in each field; Generate a table name vocabulary according to the table name of the data model; Generate a character field name dictionary and a numeric field name dictionary according to the field names and field types included in the data model; Generate a field value vocabulary according to the field values included in the data model; The header fields of the data model vocabulary include: matching value, belonging field, belonging digital model and belonging character type.
8. The method according to claim 1, characterized in that After the prompt word and the context information are understood and analyzed by the large language model to obtain the SQL statement corresponding to the target natural language, the method further includes: Through the SQL statement, SQL data is retrieved from the database to obtain SQL retrieved data; Assembling the prompt words for the SQL retrieved data to obtain the prompt words for the retrieved data result; The data acquisition result prompt words are input into the large prediction model for analysis to obtain an analysis summary corresponding to the target natural language.
9. A natural language to SQL device based on a large language model, characterized in that: include: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to execute: By connecting to a preset database table, obtaining database table information, and generating a data model vocabulary according to the database table information; Acquire a target natural language, and identify a data model name, a field name, and a field value in the target natural language; According to the data model name, the field names and field values are grouped to obtain a plurality of field groups; Assembling prompt words for the plurality of field groups, and inputting the assembled prompt words and context information into the large language model; The prompt word and the context information are understood and analyzed by the large language model to obtain an SQL statement corresponding to the target natural language.
10. A non-volatile computer storage medium storing computer executable instructions, characterized in that: The computer executable instructions are configured to: By connecting to a preset database table, obtaining database table information, and generating a data model vocabulary according to the database table information; Acquire a target natural language, and identify a data model name, a field name, and a field value in the target natural language; According to the data model name, the field names and field values are grouped to obtain a plurality of field groups; Assembling prompt words for the plurality of field groups, and inputting the assembled prompt words and context information into the large language model; The prompt word and the context information are understood and analyzed by the large language model to obtain an SQL statement corresponding to the target natural language.
Citation Information
Cited By
Context management method and device of large language model, medium, equipment and product
CN120337906A
Database mapping file conversion method and system based on large model
CN120631967A
Data processing method and device for project management, equipment and storage medium
CN120744094A
Data processing method, device and equipment for project management and storage medium
CN120744094B
Large language model intelligent number asking method suitable for electric quantity data query scene
CN120892452A