NL2SQL method, device and equipment based on preset industry large model and medium

By extracting the attributes of database table data and building indexes, combining preset industry models for full-text search and dynamic pattern generation, the problem that traditional NL2SQL solutions cannot accurately identify complex database data is solved, and more efficient and accurate SQL statement generation is achieved.

CN119917524AActive Publication Date: 2025-05-02SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD

Patent Information

Application Number
CN202510407897.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-02
Publication Date
2025-05-02
Estimated Expiration
2045-04-02

AI Technical Summary

Technical Problem

The traditional NL2SQL solution based on preset industry models cannot accurately identify the attributes and values ​​of complex data in the database, resulting in the inability to correctly generate SQL statements that meet user query needs.

Method used

By extracting attribute names and data types of database table data, value indexes and reverse indexes are constructed; pre-processing and full-text searches are used for query information using preset industry models, target query modes are dynamically generated, and SQL statements are adjusted according to client replies.

Benefits of technology

Improves the accuracy, accuracy, reliability and adaptability of generating SQL statements, reduces resource consumption, and can better handle complex and fuzzy user queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119917524A_ABST
    Figure CN119917524A_ABST
Patent Text Reader

Abstract

The invention discloses an NL2SQL method, device and equipment based on a preset industry large model and a medium, and relates to the technical field of computers, and the method comprises the steps that attribute names and attribute data types are extracted from table data in a database, and a value index and a reverse index are determined based on an attribute extraction result; when query information is received, the query information is preprocessed based on a preset industry large model, and full-text retrieval is carried out by utilizing a preprocessing result and the reverse index; performing dynamic mode generation through a preset industry large model, the full-text retrieval result and an intention recognition result corresponding to query information determined based on the preset industry large model, and feeding back an obtained target query mode to the client; and when it is determined that the query mode correction triggering condition is not met currently based on the received client reply information, determining a target SQL statement based on a preset industry large model, the query information and the target query mode. According to the method, the accuracy and the reliability of generating the SQL statement can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to an NL2SQL method, device, equipment and medium based on a preset industry big model. Background Art

[0002] Currently, more and more scenarios are beginning to try to use preset industry big models for database queries, which is NL2SQL, Natural Language to Structured Query Language, which means the process of converting natural language queries into structured query language (Structured Query Language, i.e. SQL, Structured Query Language).

[0003] For the traditional NL2SQL solution based on the preset industry large model, in actual application, the data in the database usually has a large number of attributes and complex values. On the one hand, the solution cannot see all the data in the database, including all attributes and complex values, so it cannot fully pass the size and complexity of the data set to the LLM (LargeLanguage Model); on the other hand, the preset industry large model in the solution cannot accurately identify the relevant columns or values ​​from the user's natural language query (which often contains unclear or ambiguous field names or data items). As a result, the solution cannot correctly generate SQL statements that meet the user's query requirements. Summary of the invention

[0004] In view of this, the purpose of the present invention is to provide an NL2SQL method, device, equipment and medium based on a preset industry large model, which can effectively improve the accuracy, reliability and adaptability of generating SQL statements and reduce resource consumption. The specific scheme is as follows:

[0005] In a first aspect, the present application provides an NL2SQL method based on a preset industry big model, including:

[0006] Extract attribute names and attribute data types from table data in the database, and determine corresponding value indexes and reverse indexes based on the attribute extraction results and the preset index building strategy;

[0007] When receiving the query information sent by the client, preprocessing the query information based on the preset industry model, and performing full-text search using the preprocessing result and the reverse index to obtain the full-text search result;

[0008] Dynamically generate a model through the preset industry big model, the full-text search result, the query information, and the intention recognition result corresponding to the query information determined based on the preset industry big model to obtain a target query model, and feed back the target query model to the client;

[0009] Based on the received client response information, it is determined whether the query mode modification trigger condition is currently met, and when the judgment result is no, the target SQL statement is determined based on the preset industry big model, the query information and the target query mode.

[0010] Optionally, extracting attribute names and attribute data types from table data in the database, and determining corresponding value indexes based on the attribute extraction results and a preset index building strategy, includes:

[0011] By traversing the table data structure in the database, the attribute name and attribute data type are extracted based on the header information in the table data to obtain the attribute extraction result;

[0012] Classifying the attribute name information in the attribute extraction result based on a preset attribute classification rule and the attribute data type information in the attribute extraction result to obtain a classification result;

[0013] Extracting unique values ​​from the classification results to obtain a unique value set;

[0014] An index is constructed based on the unique value set to obtain a value index.

[0015] Optionally, a corresponding reverse index is determined based on the attribute extraction result and a preset index building strategy, including:

[0016] triggering a corresponding synonym generation operation based on the attribute name information to obtain a synonym set;

[0017] An index is constructed based on the unique value set, the attribute name information, the attribute data type information, and the synonym set to determine a reverse index.

[0018] Optionally, the query information is preprocessed based on a preset industry macro model, and full-text search is performed using the preprocessing result and the reverse index, including:

[0019] Extract key entities, database operations, and query filtering conditions from the query information based on a preset industry big model to obtain information extraction results;

[0020] A full-text search is performed based on a preset multi-path search strategy, the information extraction result and the reverse index to obtain a full-text search result.

[0021] Optionally, the performing a full-text search based on a preset multi-path search strategy, the information extraction result, and the reverse index to obtain a full-text search result includes:

[0022] Performing keyword matching based on the information extraction result and the reverse index, and determining a first search result using the keyword matching result;

[0023] Encoding the information extraction result and the reverse index through a vectorization model, storing the encoding result in a vector database, and searching the data in the vector database based on a correlation threshold to obtain a second search result;

[0024] A full-text search result is determined based on the first search result and the second search result.

[0025] Optionally, the generating a dynamic model by using the preset industry macro model, the full-text search result, the query information, and the intention recognition result corresponding to the query information determined based on the preset industry macro model includes:

[0026] Obtaining an intent recognition result corresponding to the query information determined based on a preset industry macro model;

[0027] Determining a target static prompt from pre-specified static prompt information based on the intention recognition result;

[0028] Dynamic pattern generation is performed through the preset industry macro model, the full-text search results, the query information and the target static prompt to obtain a target query pattern, and the target query pattern is fed back to the client based on a preset interaction method.

[0029] Optionally, after determining whether the query mode modification trigger condition is currently met based on the received client reply information, the method further includes:

[0030] If the judgment result indicates that the query mode modification trigger condition is currently met, a full-text search is performed based on the client reply information, the preprocessing result and the reverse index to obtain a new full-text search result;

[0031] Dynamic pattern generation is performed through the preset industry big model, the new full-text search results, the query information and the intention recognition results to obtain the new target query pattern, and the new target query pattern is fed back to the client.

[0032] In a second aspect, the present application provides an NL2SQL device based on a preset industry large model, including:

[0033] An index determination module is used to extract attribute names and attribute data types from table data in the database, and determine corresponding value indexes and reverse indexes based on the attribute extraction results and a preset index building strategy;

[0034] A full-text search module is used to pre-process the query information based on a preset industry model when receiving the query information sent by the client, and perform a full-text search using the pre-processing result and the reverse index to obtain a full-text search result;

[0035] A pattern generation module, used to generate a dynamic pattern through the preset industry big model, the full-text search result, the query information, and the intention recognition result corresponding to the query information determined based on the preset industry big model, so as to obtain a target query pattern, and feed back the target query pattern to the client;

[0036] The statement determination module is used to determine whether the query mode modification trigger condition is currently met based on the received client reply information, and when the judgment result is no, determine the target SQL statement based on the preset industry big model, the query information and the target query mode.

[0037] In a third aspect, the present application provides an electronic device, including:

[0038] Memory, used to store computer programs;

[0039] A processor is used to execute the computer program to implement the steps of the aforementioned NL2SQL method based on a preset industry big model.

[0040] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the steps of the aforementioned NL2SQL method based on a preset industry big model.

[0041] It can be seen that in this application, the attribute name and attribute data type are extracted from the table data in the database, and the corresponding value index and reverse index are determined based on the attribute extraction result and the preset index construction strategy; when the query information sent by the client is received, the query information is preprocessed based on the preset industry model, and the preprocessing result and the reverse index are used to perform full-text search to obtain the full-text search result; dynamic mode generation is performed through the preset industry model, the full-text search result, the query information, and the intention recognition result corresponding to the query information determined based on the preset industry model to obtain the target query mode, and the target query mode is fed back to the client; based on the received client reply information, it is determined whether the query mode modification trigger condition is currently met, and when the judgment result is no, the target SQL statement is determined based on the preset industry model, the query information and the target query mode. That is, in this application, the attribute name and attribute data type in the table data in the database are first extracted, and then the value index and reverse index are constructed using the extraction result. After that, the received query information is preprocessed by the preset industry model to perform full-text search in combination with the reverse index. Then, the target query mode is determined based on the full-text search results, the preset industry model, and the intent recognition results, and then fed back to the client. If the client's reply information does not meet the query mode correction trigger condition, the preset industry model, query information, and target query mode can be used to determine the target SQL statement. In this way, the precision, accuracy, reliability, and adaptability of the generated SQL statement can be effectively improved, and resource consumption can be reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0043] Figure 1 A flow chart of the NL2SQL method based on a preset industry large model provided for this application;

[0044] Figure 2 A specific NL2SQL process diagram based on a preset industry large model provided for this application;

[0045] Figure 3 A schematic diagram of a full-text search process provided for this application;

[0046] Figure 4 A schematic diagram of the structure of an NL2SQL device based on a preset industry large model provided for this application;

[0047] Figure 5 A structural diagram of an electronic device provided for this application. DETAILED DESCRIPTION

[0048] 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 ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0049] For the traditional NL2SQL solution based on a preset industry big model, in actual application, the data in the database usually has a large number of attributes and complex values. On the one hand, the solution cannot see all the data in the database, including all attributes and complex values, so that the size and complexity of the data set cannot be fully passed to the LLM; on the other hand, the preset industry big model in the solution cannot accurately identify the relevant columns or values ​​from the user's natural language query (which often contains unclear or ambiguous field names or data items). As a result, the solution cannot correctly generate SQL statements that meet the user's query requirements. To this end, the present application provides an NL2SQL solution based on a preset industry big model, which can effectively improve the precision, accuracy, reliability and adaptability of generated SQL statements, and reduce resource consumption.

[0050] See also Figure 1 As shown, the embodiment of the present invention discloses an NL2SQL method based on a preset industry big model, including:

[0051] Step S11: extract attribute names and attribute data types from table data in the database, and determine corresponding value indexes and reverse indexes based on the attribute extraction results and a preset index building strategy.

[0052] Combination Figure 2 As shown, in this embodiment, attribute extraction is first performed, that is, the attribute name and the corresponding data type are extracted from the table data input into the database. This process generates a list containing all attributes and their data types by traversing the table data structure. That is, by traversing the table data structure in the database, attribute name extraction and attribute data type extraction are performed based on the header information in the table data to obtain the attribute extraction result. Specifically, assuming that the table data used is T, it is necessary to traverse each header in T, record the name of the header as the attribute name A and the data type of the header as the attribute data type D. This process lays the foundation for subsequent query processing and data index establishment. The entire process of this step from input to output can be expressed as: .

[0053] Furthermore, after the attributes are extracted, the attributes processed in the above steps need to be divided into categorical attributes and non-categorical attributes. Categorical attributes refer to attributes containing discrete data, while non-categorical attributes refer to attributes containing continuous data. That is, the attribute name information (i.e., attribute name A) in the attribute extraction result is classified based on the preset attribute classification rules and the attribute data type information in the attribute extraction result to obtain the classification result. The attribute classification in this step helps to efficiently retrieve and organize information, and the classified categorical attributes will be further processed to improve the accuracy of the query. The whole process from input to output can be expressed as: .

[0054] In this embodiment, after completing the attribute classification, the unique values ​​in the classification results are extracted to obtain a unique value set. An index is constructed based on the unique value set to obtain a value index. Specifically, each classification attribute C in each classification result is traversed, and a set M of all unique values ​​in each classification attribute C is extracted. The extracted unique values ​​are stored in an index, which is used for subsequent query matching and pattern generation. This index can be quickly accessed during the query process to find data points that match the values ​​mentioned in the user query. The value index ensures that each query term can be accurately mapped to the relevant data points in the classification data set, which enables the system to process user queries more accurately and return correct results even when facing complex or fuzzy queries. At the same time, due to the existence of the index, the retrieval efficiency can be greatly improved. The entire process from input to output of this step can be expressed as: M=Value_index(C). It should be understood that an example of a value index is: {"education":["primary school", "junior high school", "high school", "university", "graduate student"]}.

[0055] At the same time, in order to enhance the flexibility, accuracy and generalization of the query, this embodiment also generates synonyms for the extracted attribute name A, and the generated synonym set is represented by S. The whole process of this step from input to output can be expressed as: . Further, in order to establish a fast query structure for the entire table data, this structure can quickly locate relevant data when the user queries. It not only contains the unique value M generated by the value index, but also integrates the attribute name A, data type D, and synonym S generated for the attribute. This step combines the results of all the above operations. This index allows this embodiment to quickly and accurately retrieve and locate relevant attributes and values ​​based on the user's query keywords for subsequent database query generation. The entire process of this step from input to output can be expressed as: That is, this embodiment triggers the corresponding synonym generation operation based on the attribute name information to obtain a synonym set; and performs index construction based on the unique value set, attribute name information, attribute data type information, and synonym set to determine the reverse index I. The pseudo-flow of the above five operations from attribute extraction to reverse index construction can be shown as follows:

[0056] Input: table data T;

[0057] Output: reverse index I;

[0058] process:

[0059] ① ;

[0060] ② ;

[0061] ③ :

[0062] ;

[0063] ④ ;

[0064] ⑤ ;

[0065] return I;

[0066] Specifically, an example of a reverse index is: [("primary school", "junior high school", "senior high school", "university", "graduate student"), ("education level", "education level"), "str", "education level"].

[0067] Step S12: When query information sent by the client is received, the query information is preprocessed based on the preset industry macro model, and a full-text search is performed using the preprocessing result and the reverse index to obtain a full-text search result.

[0068] Combination Figure 2As shown, in this embodiment, it is necessary to process the user's questions to facilitate the subsequent matching of user questions with indexes. This operation is crucial to improve the efficiency of keyword matching and lay the foundation for accurate information retrieval or results based on the extracted keywords. That is, in this embodiment, the query information is extracted based on the preset industry big model for key entities, database operations, and query filtering conditions to obtain information extraction results. Specifically, after obtaining the query information (that is, question Q) sent by the client, it is necessary to extract key entities, operations, and conditions for question Q. The key entities can be column names or possible values ​​in the table. The operations include common database operations (such as filtering, sorting, aggregation, etc.), and the conditions are filtering criteria (such as greater than, less than, equal to a certain value). Among them, the preset industry big model can be a big model for the data governance industry, or a big model for other industries. Specifically, the preset industry big model is used to perform entity recognition and extraction of key information, and the information extraction result K obtained will be used for subsequent matching with the reverse index I. The entire process of the extraction operation from input to output can be expressed as: .

[0069] Furthermore, since the amount of data in the database is very large when used by users, it is impossible for the model to obtain all the data, so the generated SQL cannot reflect the full picture of the data. Therefore, after completing the preprocessing, the present embodiment designs a full-text search to avoid the drawback that the traditional method cannot obtain the overall data. The full-text search enables the preset industry large model to see the key information of all the data. Not only does it not miss any valid information, but also because the storage space is greatly reduced, it can significantly improve the retrieval efficiency. The full-text search designed in this embodiment is a query based on multi-way retrieval, which is based on the previously generated reverse index I. The reverse index I is a sufficient condition for full-text search. That is, a full-text search will be performed based on the preset multi-way retrieval strategy, information extraction results and reverse index to obtain a full-text search result.

[0070] Specific, combined Figure 3As shown, regarding the multi-way full-text search, in this embodiment, keyword matching is performed based on the information extraction result and the reverse index, and the first search result is determined using the keyword matching result; the information extraction result and the reverse index are encoded through a vectorization model, the encoding result is stored in a vector database, and the data in the vector database is retrieved based on a correlation threshold to obtain a second search result; the full-text search result is determined based on the first search result and the second search result. That is, on the one hand, a search based on text recall is performed. This process is to find the words in question Q that appear in the reverse index I. In the question, a search is performed based on the reverse index I. Since the key information of question Q has been extracted in the previous steps to obtain the information extraction result K, this process is based on the information extraction result K of question Q and the reverse index I for matching and searching. Specifically, it is completed directly through keyword matching to determine whether the content in K is in I. If so, the match is successful and recorded, and finally all field information of the precise match can be obtained. On the other hand, a search based on semantic recall is also performed. This process is to match based on the semantics of K of the user query Q and the semantics of the reverse index I. Specifically, through the vectorization model, the reverse index I and the information extraction result K are encoded and stored in the vector database. Then, by setting the relevance threshold for retrieval, several header attributes that are most relevant to the user can be obtained. Finally, the two retrieval results are combined and all the results are saved as the final full-text retrieval result F. Through full-text retrieval, this step completes the matching process from user questions to data fields. The entire process from input to output of this step can be expressed as: .

[0071] Step S13, dynamically generate a model through the preset industry big model, the full-text search results, the query information and the intention recognition results corresponding to the query information determined based on the preset industry big model to obtain a target query model, and feed back the target query model to the client.

[0072] Combination Figure 2As shown, in this embodiment, in order to generate a field value that meets the user's question, based on the full-text search result F, the user question Q and the full-text search result F are used as input, and according to the intention recognition result corresponding to the query information determined based on the preset industry big model, the preset industry big model is required to dynamically generate a query pattern using prompt technology. The pattern can reflect the fields and data values ​​that may be involved in the user query Q. This dynamically generated pattern is different every time the user asks a question, and it changes dynamically according to the user's question, which helps the preset industry big model to more accurately understand and interpret the user query, and ultimately generate more accurate SQL or other forms of database queries. That is, obtain the intention recognition result corresponding to the query information determined based on the preset industry big model; determine the target static prompt from the pre-specified static prompt information based on the intention recognition result; and generate a dynamic pattern through the preset industry big model, full-text search results, query information, and target static prompts to obtain the target query pattern. , and feeds back the target query pattern to the client based on the preset interaction method.

[0073] It should be noted that there are two different identifiable intents in intent recognition, so different pre-made static prompts need to be formulated according to the different intents of the user's questions. Generating dynamic patterns through static prompts can greatly affect the functional direction of large language models and ensure that the model generates semantically valid and grammatically correct database query languages. These queries follow the conventions of the database query language structure. For example: User question Q is: "What is the price of cauliflower products reported on August 14, 2020?". Dynamic pattern It can be: product, price, time. Then, by constructing a specific prompt, Q and D are input into the preset industry model. One possible prompt is: "I will give you a question and the names of the table fields that may be used. Please output the possible conditions and values ​​used in the SQL statement." The output may be: product = "cauliflower", time = "August 14, 2020", price. The whole process from input to output of this step can be expressed as: The code for the process from preprocessing to dynamic model generation can be as follows:

[0074] Input: user question Q, reverse index I;

[0075] Output: dynamic mode D';

[0076] process:

[0077] ;

[0078] ;

[0079] ;

[0080] ;

[0081] return ;

[0082] After that, the generated dynamic model Feedback is given to users in an interactive manner, allowing them to confirm and correct errors, dynamically adjust the generated dynamic model, ensure that the generated dynamic model is credible, and thus improve the accuracy of generated SQL.

[0083] It should be understood that the intent recognition of query information is specifically the recognition and classification of the intent of query information. Users always have specific intents for query information in the database. This embodiment classifies intents into two categories: querying specific information and statistical analysis. For example, "How tall is Xiao Ming?" This belongs to the intent of querying specific information; and "How much taller is Xiao Ming than Xiao Hong?", "What is the tallest person in Xiao Ming's class?", and so on are all intentions of statistical analysis. As shown in Table 1 below:

[0084] Table 1

[0085]

[0086] This operation is specifically completed through the preset industry big model. After getting the user's question Q, the definition of intent and the question are handed over to the preset industry big model, allowing the preset industry big model to determine the intent of the user's question. After intent recognition, the characteristics of different intents can be conveniently used to generate SQL in a targeted manner. For example, if the preset industry big model determines that the intent is "query specified information", then you can know that the final query is the information of certain specific fields. The keywords after select in SQL can guide the model to generate header field information. If the preset industry big model determines that the intent is "statistical analysis", then you can know that the keywords after select involve some secondary calculations and other operations, which can guide the preset industry big model to generate in the direction of secondary calculations. Intent recognition is to control the direction of iteration of the preset industry big model generation through artificial classification, thereby significantly improving the correctness of SQL statements. The entire process of this step from input to output can be expressed as: .

[0087] Step S14: determine whether the query mode modification trigger condition is currently met based on the received client response information, and when the judgment result is no, determine the target SQL statement based on the preset industry big model, the query information and the target query mode.

[0088] It should be understood that after receiving the client's reply about the target query mode, that is, after the client's reply information, it is determined whether the query mode modification trigger condition is currently met. If not, the question Q is handed over to the preset industry model to generate SQL statements. If it is satisfied, that is, if the user thinks that the query result is not ideal, the user can provide further prompts or conditions through the reply, and then the mode can be automatically adjusted and the query can be regenerated in this embodiment. This adjustment can be performed in an iterative manner until the system generates a query result that meets the user's expectations. That is, if the judgment result shows that the query mode modification trigger condition is currently met, a full-text search is performed based on the client reply information, the preprocessing results, and the reverse index to obtain a new full-text search result; dynamic mode generation is performed through the preset industry model, the new full-text search result, the query information, and the intention recognition result to obtain a new target query mode, and the new target query mode is fed back to the client.

[0089] In summary, the NL2SQL solution described in this embodiment has the following beneficial effects: High-precision SQL generation: Through full-text retrieval and dynamic mode, the ambiguity in user queries is reduced, and the accuracy of queries is greatly improved. User control over the results: The dynamic adjustment and feedback of the introduced users can control the direction of result generation. Wide adaptability: This embodiment provides a generation framework that is suitable for tabular data queries in various fields, especially when processing large and complex data sets. Low resource consumption: Through intelligent index generation and dynamic mode optimization, it can run efficiently on small and medium-sized hardware, reducing dependence on computing resources. Improved the model's ability to handle complex queries.

[0090] It can be seen that in the embodiment of the present application, the attribute name and attribute data type in the table data in the database are first extracted, and then the extraction results are used to construct a value index and a reverse index. Afterwards, the received query information is preprocessed by a preset industry big model to perform a full-text search in combination with the reverse index. Then, the target query mode is determined based on the full-text search results, the preset industry big model and the intent recognition results, and fed back to the client. If the client reply information does not meet the query mode correction trigger condition, the preset industry big model, the query information and the target query mode can be used to determine the target SQL statement. In this way, the precision, accuracy, reliability and adaptability of the generated SQL statement can be effectively improved, and resource consumption can be reduced.

[0091] See also Figure 4 As shown, the embodiment of the present application also discloses a NL2SQL device based on a preset industry large model, including:

[0092] The index determination module 11 is used to extract the attribute name and attribute data type from the table data in the database, and determine the corresponding value index and reverse index based on the attribute extraction result and the preset index construction strategy;

[0093] The full-text search module 12 is used for preprocessing the query information based on the preset industry model when receiving the query information sent by the client, and performing full-text search using the preprocessing result and the reverse index to obtain the full-text search result;

[0094] A pattern generation module 13 is used to generate a dynamic pattern through the preset industry big model, the full-text search result, the query information, and the intention recognition result corresponding to the query information determined based on the preset industry big model, so as to obtain a target query pattern, and feed back the target query pattern to the client;

[0095] The statement determination module 14 is used to determine whether the query mode modification trigger condition is currently met based on the received client response information, and when the judgment result is no, determine the target SQL statement based on the preset industry big model, the query information and the target query mode.

[0096] Among them, for more specific working processes of the above-mentioned modules, please refer to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.

[0097] It can be seen that in this application, the attribute names and attribute data types in the table data in the database are first extracted, and then the extraction results are used to build value indexes and reverse indexes. Afterwards, the received query information is preprocessed by the preset industry big model to perform full-text retrieval in combination with the reverse index. Then, the target query mode is determined based on the full-text retrieval results, the preset industry big model and the intention recognition results, and fed back to the client. If the client reply information does not meet the query mode correction trigger condition, the preset industry big model, query information and target query mode can be used to determine the target SQL statement. In this way, the precision, accuracy, reliability and adaptability of the generated SQL statement can be effectively improved, and resource consumption can be reduced.

[0098] In some specific embodiments, the index determination module 11 may specifically include:

[0099] The attribute extraction unit is used to extract the attribute name and the attribute data type based on the header information in the table data by traversing the table data structure in the database to obtain the attribute extraction result;

[0100] An information classification unit, configured to classify the attribute name information in the attribute extraction result based on a preset attribute classification rule and the attribute data type information in the attribute extraction result to obtain a classification result;

[0101] A unique value extraction unit, configured to extract unique values ​​from the classification result to obtain a unique value set;

[0102] The value index determining unit is used to construct an index based on the unique value set to obtain a value index.

[0103] In some specific embodiments, the NL2SQL device based on the preset industry big model may specifically include:

[0104] A synonym generation unit, used to trigger a corresponding synonym generation operation based on the attribute name information to obtain a synonym set;

[0105] The reverse index determination unit is used to construct an index based on the unique value set, the attribute name information, the attribute data type information and the synonym set to determine a reverse index.

[0106] In some specific embodiments, the full-text search module 12 may specifically include:

[0107] An information extraction unit, used to extract key entities, database operations and query filtering conditions from the query information based on a preset industry macro model to obtain information extraction results;

[0108] The full-text search unit is used to perform a full-text search based on a preset multi-path search strategy, the information extraction result and the reverse index to obtain a full-text search result.

[0109] In some specific embodiments, the full-text search unit may specifically include:

[0110] A first search subunit, configured to perform keyword matching based on the information extraction result and the reverse index, and determine a first search result using the keyword matching result;

[0111] A second retrieval subunit is used to encode the information extraction result and the reverse index through a vectorization model, store the encoding result in a vector database, and search the data in the vector database based on a correlation threshold to obtain a second retrieval result;

[0112] The full-text search result determination subunit is used to determine the full-text search result based on the first search result and the second search result.

[0113] In some specific embodiments, the pattern generation module 13 may specifically include:

[0114] An intention recognition result acquisition unit, used to acquire an intention recognition result corresponding to the query information determined based on a preset industry macro model;

[0115] A static prompt information extraction unit, configured to determine a target static prompt from pre-specified static prompt information based on the intention recognition result;

[0116] The query mode determination unit is used to generate a dynamic mode through the preset industry model, the full-text search results, the query information and the target static prompt to obtain a target query mode, and feed back the target query mode to the client based on a preset interaction method.

[0117] In some specific embodiments, the NL2SQL device based on the preset industry big model may further include:

[0118] A full-text search result updating unit, configured to perform a full-text search based on the client reply information, the preprocessing result and the reverse index to obtain a new full-text search result if the judgment result indicates that the query mode modification trigger condition is currently met;

[0119] A pattern feedback unit is used to generate a dynamic pattern through the preset industry big model, the new full-text search result, the query information and the intention recognition result to obtain the new target query pattern, and feed back the new target query pattern to the client.

[0120] Furthermore, the present application also discloses an electronic device. Figure 5 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram cannot be regarded as any limitation on the scope of use of the present application.

[0121] Figure 5 A schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the NL2SQL method based on a preset industry large model disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0122] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0123] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0124] The operating system 221 is used to manage and control the hardware devices and computer program 222 on the electronic device 20, which can be Windows Server, Netware, Unix, Linux, etc. In addition to the computer program that can be used to complete the NL2SQL method based on the preset industry big model executed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include computer programs that can be used to complete other specific tasks.

[0125] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the aforementioned disclosed NL2SQL method based on a preset industry large model is implemented. The specific steps of the method can refer to the corresponding contents disclosed in the aforementioned embodiment, and will not be repeated here.

[0126] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0127] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0128] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0129] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article 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, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0130] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technicians in this field, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A NL2SQL method based on a preset industry large model, characterized in that: include: Extract attribute names and attribute data types from table data in the database, and determine corresponding value indexes and reverse indexes based on the attribute extraction results and the preset index building strategy; When receiving the query information sent by the client, preprocessing the query information based on the preset industry model, and performing full-text search using the preprocessing result and the reverse index to obtain the full-text search result; Dynamically generate a model through the preset industry big model, the full-text search result, the query information, and the intention recognition result corresponding to the query information determined based on the preset industry big model to obtain a target query model, and feed back the target query model to the client; Based on the received client response information, it is determined whether the query mode modification trigger condition is currently met, and when the judgment result is no, the target SQL statement is determined based on the preset industry big model, the query information and the target query mode.

2. The NL2SQL method based on a preset industry large model according to claim 1 is characterized in that: The extracting of attribute names and attribute data types from the table data in the database, and determining corresponding value indexes based on the attribute extraction results and a preset index building strategy, includes: By traversing the table data structure in the database, the attribute name and attribute data type are extracted based on the header information in the table data to obtain the attribute extraction result; Classifying the attribute name information in the attribute extraction result based on a preset attribute classification rule and the attribute data type information in the attribute extraction result to obtain a classification result; Extracting unique values ​​from the classification results to obtain a unique value set; An index is constructed based on the unique value set to obtain a value index.

3. The NL2SQL method based on a preset industry large model according to claim 2 is characterized in that: Determine the corresponding reverse index based on the attribute extraction results and the preset index building strategy, including: triggering a corresponding synonym generation operation based on the attribute name information to obtain a synonym set; An index is constructed based on the unique value set, the attribute name information, the attribute data type information, and the synonym set to determine a reverse index.

4. The NL2SQL method based on a preset industry large model according to claim 1 is characterized in that: The preprocessing of the query information based on the preset industry macro model and the full-text search using the preprocessing result and the reverse index include: Extract key entities, database operations, and query filtering conditions from the query information based on a preset industry big model to obtain information extraction results; A full-text search is performed based on a preset multi-path search strategy, the information extraction result and the reverse index to obtain a full-text search result.

5. The NL2SQL method based on a preset industry large model according to claim 4 is characterized in that: The full-text search is performed based on the preset multi-path search strategy, the information extraction result and the reverse index to obtain the full-text search result, including: Performing keyword matching based on the information extraction result and the reverse index, and determining a first search result using the keyword matching result; Encoding the information extraction result and the reverse index through a vectorization model, storing the encoding result in a vector database, and searching the data in the vector database based on a correlation threshold to obtain a second search result; A full-text search result is determined based on the first search result and the second search result.

6. The NL2SQL method based on a preset industry big model according to claim 1 is characterized in that: The dynamic model generation is performed by using the preset industry macro model, the full-text search result, the query information, and the intention recognition result corresponding to the query information determined based on the preset industry macro model, including: Obtaining an intent recognition result corresponding to the query information determined based on a preset industry macro model; Determining a target static prompt from pre-specified static prompt information based on the intention recognition result; Dynamic pattern generation is performed through the preset industry macro model, the full-text search results, the query information and the target static prompt to obtain a target query pattern, and the target query pattern is fed back to the client based on a preset interaction method.

7. The NL2SQL method based on a preset industry big model according to any one of claims 1 to 6, characterized in that: After determining whether the query mode modification trigger condition is currently met based on the received client reply information, the method further includes: If the judgment result indicates that the query mode modification trigger condition is currently met, a full-text search is performed based on the client reply information, the preprocessing result and the reverse index to obtain a new full-text search result; Dynamic pattern generation is performed through the preset industry big model, the new full-text search results, the query information and the intention recognition results to obtain the new target query pattern, and the new target query pattern is fed back to the client.

8. An NL2SQL device based on a preset industry large model, characterized in that: include: An index determination module is used to extract attribute names and attribute data types from table data in the database, and determine corresponding value indexes and reverse indexes based on the attribute extraction results and a preset index building strategy; A full-text search module is used to pre-process the query information based on a preset industry model when receiving the query information sent by the client, and perform a full-text search using the pre-processing result and the reverse index to obtain a full-text search result; A pattern generation module, used to generate a dynamic pattern through the preset industry big model, the full-text search result, the query information, and the intention recognition result corresponding to the query information determined based on the preset industry big model, so as to obtain a target query pattern, and feed back the target query pattern to the client; The statement determination module is used to determine whether the query mode modification trigger condition is currently met based on the received client reply information, and when the judgment result is no, determine the target SQL statement based on the preset industry big model, the query information and the target query mode.

9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the NL2SQL method based on a preset industry big model as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: Used to store a computer program, which, when executed by a processor, implements the NL2SQL method based on a preset industry big model as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method and device for retrieving and processing information

    CN102103610A

  • Personalized information retrieval method and apparatus

    CN105045875A

  • Query method and device, electronic equipment and storage medium

    CN115878661A

  • Data retrieval method, device and system, electronic equipment and readable storage medium

    CN118093962A

  • Database index optimization method and system, database, electronic equipment and medium

    CN118733698A

Cited By

  • Retrieval question and answer method and device for table, medium, equipment and program product

    CN120429310A