NL2SQL Method, Apparatus, Device, and Medium Based on a Preset Industry Large Model
By extracting attributes and indexing the database table data, combining pre-processing and full-text search technology of preset industry big models, the target query mode is dynamically generated, which solves the accuracy problem of traditional NL2SQL solutions when processing complex data and fuzzy queries, and realizes efficient and accurate SQL statement generation.
Patent Information
- Application Number
- CN202510407897.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-06-17
- Estimated Expiration
- 2045-04-02
AI Technical Summary
The traditional NL2SQL solution based on preset industry big models cannot effectively process a large number of attributes and complex values in the database, resulting in the inability to fully pass on the size and complexity of the data set, and the inability to accurately identify the relevant columns or values in natural language queries, resulting in the inaccurate SQL statements.
By extracting attribute names and data types from database table data, value indexes and reverse indexes are constructed; pre-processing and full-text search of query information using preset industry models, dynamically generate target query modes, and adjust SQL statements according to client replies.
Improves the accuracy, accuracy, reliability and adaptability of generating SQL statements, reduces resource consumption, and can better handle complex and fuzzy user queries.
Smart Images

Figure CN119917524B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and particularly to an NL2SQL method, device, equipment and medium based on a preset industry large model. Background Art
[0002] At present, more and more scenarios start to attempt to use a preset industry large model for database query work, that is, NL2SQL, Natural Language to Structured Query Language, which represents the process of converting a natural language query into a structured query language (structured query language, that is, SQL, Structured Query Language).
[0003] For the traditional NL2SQL solution based on a preset industry large model, due to the fact that in actual applications, the data in the database usually has a large number of attributes and complex values. On the one hand, this solution cannot see all the data in the database, including all attributes and complex values, making it impossible to fully transfer the size and complexity of the data set to the LLM (Large Language Model); on the other hand, the preset industry large model in this solution cannot accurately identify 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, this 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 solutions are as follows:
[0005] In a first aspect, the present application provides an NL2SQL method based on a preset industry large model, including:
[0006] Extracting the attribute names and attribute data types of the tabular data in the database, and determining corresponding value indexes and reverse indexes based on the attribute extraction results and a preset index construction strategy;
[0007] When receiving query information sent by a client, preprocessing the query information based on a preset industry large model, and performing full-text retrieval using the preprocessing result and the reverse index to obtain a full-text retrieval result;
[0008] Generate a dynamic pattern by using the preset industry large model, the full-text retrieval result, the query information, and the intent recognition result corresponding to the query information determined based on the preset industry large model, so as to obtain a target query pattern, and feedback the target query pattern to the client;
[0009] Based on the received client response information, determine whether the current query pattern correction trigger condition is satisfied. When the judgment result is negative, determine the target SQL statement based on the preset industry large model, the query information, and the target query pattern.
[0010] Optionally, the extraction of the attribute name and attribute data type from the table data in the database, and the determination of the corresponding value index based on the attribute extraction result and the preset index construction strategy include:
[0011] By traversing the table data structure in the database, extract the attribute name and attribute data type based on the header information in the table data to obtain the attribute extraction result;
[0012] Classify the attribute name information in the attribute extraction result based on the preset attribute classification rule and the attribute data type information in the attribute extraction result to obtain the classification result;
[0013] Extract the unique values in the classification result to obtain the unique value set;
[0014] Construct an index based on the unique value set to obtain the value index.
[0015] Optionally, the determination of the corresponding reverse index based on the attribute extraction result and the preset index construction strategy includes:
[0016] Trigger the corresponding synonym generation operation based on the attribute name information to obtain the synonym set;
[0017] Construct an index based on the unique value set, the attribute name information, the attribute data type information, and the synonym set to determine the reverse index.
[0018] Optionally, the preprocessing of the query information based on the preset industry large model, and the full-text retrieval using the preprocessing result and the reverse index include:
[0019] Extract the key entity, database operation, and query filter condition from the query information based on the preset industry large model to obtain the information extraction result;
[0020] Perform full-text retrieval based on the preset multi-way retrieval strategy, the information extraction result, and the reverse index to obtain the full-text retrieval result.
[0021] Optionally, performing full-text retrieval based on the preset multi-way retrieval strategy, the information extraction result, and the inverted index to obtain a full-text retrieval result, including:
[0022] Performing keyword matching based on the information extraction result and the inverted index, and determining a first retrieval result by using the keyword matching result;
[0023] Encoding the information extraction result and the inverted index through a vectorization model, storing the encoding result in a vector database, and retrieving data in the vector database based on a correlation threshold to obtain a second retrieval result;
[0024] Determining the full-text retrieval result based on the first retrieval result and the second retrieval result.
[0025] Optionally, performing dynamic mode generation through the preset industry large model, the full-text retrieval result, the query information, and an intent recognition result corresponding to the query information determined based on the preset industry large model, including:
[0026] Obtaining an intent recognition result corresponding to the query information determined based on the preset industry large model;
[0027] Determining a target static prompt from pre-specified static prompt information based on the intent recognition result;
[0028] Performing dynamic mode generation through the preset industry large model, the full-text retrieval result, the query information, and the target static prompt to obtain a target query mode, and feeding back the target query mode to the client based on a preset interaction method.
[0029] Optionally, after determining whether the current satisfies the query mode correction trigger condition based on the received client reply information, further including:
[0030] If the judgment result indicates that the current satisfies the query mode correction trigger condition, performing full-text retrieval based on the client reply information, the preprocessing result, and the inverted index to obtain a new full-text retrieval result;
[0031] Performing dynamic mode generation through the preset industry large model, the new full-text retrieval result, the query information, and the intent recognition result to obtain a new target query mode, and feeding back the new target query mode 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, configured to extract the attribute name and attribute data type from the tabular data in the database, and determine the corresponding value index and reverse index based on the attribute extraction result and a preset index construction strategy;
[0034] A full-text retrieval module, configured to, when receiving query information sent by a client, preprocess the query information based on a preset industry large model, and perform full-text retrieval using the preprocessing result and the reverse index to obtain a full-text retrieval result;
[0035] A pattern generation module, configured to perform dynamic pattern generation through the preset industry large model, the full-text retrieval result, the query information, and an intent recognition result corresponding to the query information determined based on the preset industry large model to obtain a target query pattern, and feedback the target query pattern to the client;
[0036] A statement determination module, configured to determine whether the current query mode correction trigger condition is satisfied based on the client reply information received, and when the determination result is negative, determine a target SQL statement based on the preset industry large model, the query information, and the target query pattern.
[0037] In a third aspect, the present application provides an electronic device, including:
[0038] A memory, configured to store a computer program;
[0039] A processor, configured to execute the computer program to implement the steps of the foregoing NL2SQL method based on a preset industry large model.
[0040] In a fourth aspect, the present application provides a computer-readable storage medium, configured to store a computer program, and when the computer program is executed by a processor, the steps of the foregoing NL2SQL method based on a preset industry large model are implemented.
[0041] It can be seen that in this application, the attribute names and attribute data types of the table data in the database are extracted, and the corresponding value index and reverse index are determined based on the attribute extraction results 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 large model, and full-text retrieval is performed using the preprocessing result and the reverse index to obtain the full-text retrieval result; dynamic mode generation is performed through the preset industry large model, the full-text retrieval result, the query information, and the intention recognition result corresponding to the query information determined based on the preset industry large model to obtain the target query mode, and the target query mode is fed back to the client; it is judged whether the current satisfies the query mode correction trigger condition based on the received client reply information, and when the judgment result is negative, the target SQL statement is determined based on the preset industry large model, the query information, and the target query mode. That is, in this application, first, the attribute names and attribute data types in the table data in the database are extracted, and then the value index and reverse index are constructed using the extraction results. After that, the received query information is preprocessed through the preset industry large 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 result, the preset industry large model, and the intention recognition result and fed back to the client. If the client reply information does not satisfy the query mode correction trigger condition, the target SQL statement can be determined using the preset industry large model, the query information, and the target query mode. In this way, the accuracy, reliability, and adaptability of generating the 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 technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the accompanying drawings required for use in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only the embodiments of the present invention, and for those of ordinary skill in the art, other accompanying drawings can be obtained according to the provided accompanying drawings without creative efforts.
[0043] Figure 1 It is a flowchart of an NL2SQL method based on a preset industry large model provided by this application;
[0044] Figure 2 It is a schematic diagram of a specific NL2SQL process based on a preset industry large model provided by this application;
[0045] Figure 3 It is a schematic diagram of a full-text retrieval process provided by this application;
[0046] Figure 4 It is a schematic diagram of the structure of an NL2SQL device based on a preset industry large model provided by this application;
[0047] Figure 5 A structural diagram of an electronic device provided for this application. Specific implementation manners
[0048] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0049] For the traditional NL2SQL solution based on a preset industry large model, in actual applications, the data in the database usually has a large number of attributes and complex values. On the one hand, this 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 large model in this solution cannot accurately identify relevant columns or values from the user's natural language queries (which often contain unclear or ambiguous field names or data items). As a result, this solution cannot correctly generate SQL statements that meet the user's query requirements. Therefore, this application provides an NL2SQL solution based on a preset industry large model, which can effectively improve the accuracy, reliability, and adaptability of generating SQL statements and reduce resource consumption.
[0050] See Figure 1 As shown, the embodiments of the present invention disclose an NL2SQL method based on a preset industry large model, including:
[0051] Step S11: Extract the attribute names and attribute data types of the tabular 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.
[0052] Combined with Figure 2 As shown, in this embodiment, attribute extraction is first performed, that is, the attribute names and corresponding data types are extracted from the tabular data input from the database. This process generates a list containing all attributes and their data types by traversing the tabular data structure. That is, by traversing the tabular data structure in the database, attribute name extraction and attribute data type extraction are performed based on the header information in the tabular data to obtain the attribute extraction result. Specifically, assuming that the tabular data used is T, each header in T needs to be traversed, and the name of the header is recorded as the attribute name A and the data type of the header is recorded as the attribute data type D. This process lays the foundation for subsequent query processing and data index establishment. The whole process from input to output of this step can be expressed as: .
[0053] Further, after the attributes are extracted, the processed attributes in the foregoing steps need to be divided into categorical and non-categorical attributes. Categorical attributes refer to attributes containing discrete data, while non-categorical attributes are attributes containing continuous data. That is, based on the preset attribute classification rules and the attribute data type information in the attribute extraction result, the attribute name information (i.e., attribute name A) in the attribute extraction result is classified to obtain a classification result. This step of attribute classification helps to efficiently retrieve and organize information, and the classified categorical attributes will be further processed to improve the accuracy of queries. The whole process from input to output can be expressed as: 。
[0054] In this embodiment, after the attribute classification is completed, the unique values in the classification result 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 the 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 the 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 dataset, enabling the system to more accurately process user queries and return correct results even when faced with complex or ambiguous queries. At the same time, due to the existence of the index, the retrieval efficiency can be greatly improved. The whole 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 level": ["primary school", "junior high school", "senior high school", "university", "graduate student"]}.
[0055] Meanwhile, in order to enhance the flexibility, accuracy, and generalization of queries, in this embodiment, synonyms are also generated for the extracted attribute name A, and the generated synonym set is represented by S. The whole process from input to output of this step can be expressed as: 。Further, in order to establish a fast query structure for the entire tabular data, this structure can quickly locate relevant data when the user queries. It not only includes the unique value M generated by the value index, but also integrates the attribute name A, the data type D, and the synonyms S generated for the attributes. This step synthesizes the results of all the foregoing operations. This index allows this embodiment to quickly and accurately retrieve and locate relevant attributes and values according to the user's query keywords for subsequent database query generation. The whole process from input to output of this step can be expressed as: That is, in this embodiment, corresponding synonym generation operations are triggered based on the attribute name information to obtain a synonym set; and an index is constructed based on the unique value set, attribute name information, attribute data type information, and synonym set to determine the reverse index I. The pseudo-process 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 school"), ("educational level", "academic degree level"), "str", "academic degree"].
[0067] Step S12: When the query information sent by the client is received, preprocess the query information based on a preset industry large model, and perform full-text retrieval using the preprocessing result and the reverse index to obtain a full-text retrieval result.
[0068] Combined with 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 in the figure, for the full-text retrieval of multiple paths, in this embodiment, keyword matching is performed based on the information extraction result and the inverted index, and the first retrieval result is determined using the keyword matching result; the information extraction result and the inverted index are encoded by a vectorization model, the encoded result is stored in a vector database, and the data in the vector database is retrieved based on a relevance threshold to obtain a second retrieval result; the full-text retrieval result is determined based on the first retrieval result and the second retrieval result. That is, on the one hand, retrieval based on text recall is performed. This process is to find the occurrences of the words in the question Q in the inverted index I. In the retrieval based on the inverted index I in the question, since the key information of the question Q has been extracted in the previous step to obtain the information extraction result K, this process performs a matching retrieval based on the information extraction result K of the question Q and the inverted index I. Specifically, it is directly completed through keyword matching. It is judged whether the content in K is in I. If it is, the matching is successful and recorded. Eventually, all the field information of the exact match can be obtained. On the other hand, retrieval based on semantic recall is also performed. This process is to perform matching based on the semantics of K of the user query Q and the semantics of the inverted index I. Specifically, through a vectorization model, the inverted index I and the information extraction result K are encoded and stored in a vector database, and then retrieval is performed by setting a relevance threshold to obtain several table header attributes most relevant to the user. Finally, the two retrieval results obtained 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 the user's question to the data fields. The whole process from input to output of this step can be expressed as: 。
[0071] Step S13: Generate a target query pattern through the preset industry large model, the full-text retrieval result, the query information, and the intent recognition result corresponding to the query information determined based on the preset industry large model, and feedback the target query pattern to the client.
[0072] Combined with Figure 2As shown in the figure, in this embodiment, to generate a field value situation that conforms to the user's question, based on the full-text search result F, using the user's question Q and the full-text search result F as inputs, according to the intent recognition result corresponding to the query information determined based on the preset industry large model, and using the prompt technology to require the preset industry large model to dynamically generate a query pattern, which can reflect the fields and data values that may be involved in the user's query Q. This dynamically generated pattern is different in each user's question and changes dynamically according to the user's question, which helps the preset industry large model to more accurately understand and interpret the user's query, and finally generate a more accurate SQL or other forms of database queries. That is, obtain the intent recognition result corresponding to the query information determined based on the preset industry large model; determine the target static prompt from the pre-specified static prompt information based on the intent recognition result; perform dynamic pattern generation through the preset industry large model, full-text search result, query information, and target static prompt to obtain the target query pattern , and feedback the target query pattern to the client based on the preset interaction method.
[0073] It should be noted that there are two different recognizable intents in intent recognition. Therefore, different pre-prepared static prompts need to be formulated according to the different intents to which the user's question belongs. Generating a dynamic pattern through static prompts can greatly affect the functional direction of the large language model and ensure that the semantic and syntactic database query languages generated by the model are valid and follow the conventions of the database query language structure. For example: the user's question Q is: "What is the price of the cauliflower product reported on August 14, 2020?". The dynamic pattern can be: product, price, time. Then, by constructing a specific prompt and inputting Q and D into the preset industry large model, a possible prompt is: "I will give you a question and the names of the possible table fields, and please output the possible conditions and value situations used in the SQL statement". The output may be: product = "cauliflower", time = "August 14, 2020", price. The whole process from input to output can be expressed as: . Then the code for the process from preprocessing to dynamic pattern generation can be as follows:
[0074] Input: user question Q, reverse index I;
[0075] Output: dynamic pattern 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] An index determination module 11 is configured to extract the attribute names and attribute data types from the tabular data in the database, and determine the corresponding value index and reverse index based on the attribute extraction results and a preset index construction strategy;
[0093] A full-text retrieval module 12 is configured to, when receiving query information sent by a client, preprocess the query information based on a preset industry large model, and perform full-text retrieval using the preprocessing results and the reverse index to obtain a full-text retrieval result;
[0094] A pattern generation module 13 is configured to perform dynamic pattern generation through the preset industry large model, the full-text retrieval result, the query information, and an intent recognition result corresponding to the query information determined based on the preset industry large model to obtain a target query pattern, and feedback the target query pattern to the client;
[0095] A statement determination module 14 is configured to determine whether the current situation meets the trigger condition for query pattern correction based on the client reply information received, and when the determination result is negative, determine a target SQL statement based on the preset industry large model, the query information, and the target query pattern.
[0096] Among them, for the more specific working processes of the above-mentioned various modules, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details will not be elaborated herein.
[0097] It can be seen that in this application, first, the attribute names and attribute data types in the tabular data in the database are extracted, and then the value index and reverse index are constructed using the extraction results. Then, the received query information is preprocessed through a preset industry large model to perform full-text retrieval in combination with the reverse index. Then, a target query pattern is determined based on the full-text retrieval result, the preset industry large model, and the intent recognition result and fed back to the client. If the client reply information does not meet the trigger condition for query pattern correction, the target SQL statement can be determined using the preset industry large model, the query information, and the target query pattern. In this way, the accuracy, reliability, and adaptability of generating SQL statements can be effectively improved, and resource consumption can be reduced.
[0098] In some specific embodiments, the index determination module 11 may specifically include:
[0099] An attribute extraction unit is configured to, by traversing the tabular data structure in the database, extract the attribute names and attribute data types based on the header information in the tabular data to obtain attribute extraction results;
[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 set of unique values;
[0102] A value index determination unit, configured to construct an index based on the set of unique values to obtain a value index.
[0103] In some specific embodiments, the NL2SQL device based on a preset industry large model may specifically include:
[0104] A synonym generation unit, configured to trigger a corresponding synonym generation operation based on the attribute name information to obtain a set of synonyms;
[0105] A reverse index determination unit, configured to construct an index based on the set of unique values, the attribute name information, the attribute data type information, and the set of synonyms to determine a reverse index.
[0106] In some specific embodiments, the full-text retrieval module 12 may specifically include:
[0107] An information extraction unit, configured to extract key entities, database operations, and query filtering conditions from the query information based on a preset industry large model to obtain an information extraction result;
[0108] A full-text retrieval unit, configured to perform full-text retrieval based on a preset multi-way retrieval strategy, the information extraction result, and the reverse index to obtain a full-text retrieval result.
[0109] In some specific embodiments, the full-text retrieval unit may specifically include:
[0110] A first retrieval subunit, configured to perform keyword matching based on the information extraction result and the reverse index, and use the keyword matching result to determine a first retrieval result;
[0111] A second retrieval subunit, configured to encode the information extraction result and the reverse index through a vectorization model, store the encoding result in a vector database, and retrieve data in the vector database based on a correlation threshold to obtain a second retrieval result;
[0112] A full-text retrieval result determination subunit, configured to determine a full-text retrieval result based on the first retrieval result and the second retrieval result.
[0113] In some specific embodiments, the pattern generation module 13 may specifically include:
[0114] An intent recognition result acquisition unit, configured to acquire an intent recognition result corresponding to the query information determined based on a preset industry large model;
[0115] A static prompt information extraction unit, configured to determine a target static prompt from pre-specified static prompt information based on the intent recognition result;
[0116] A query mode determination unit, configured to perform dynamic mode generation through the preset industry large model, the full-text retrieval result, the query information, and the target static prompt to obtain a target query mode, and feedback the target query mode to the client based on a preset interaction method.
[0117] In some specific embodiments, the NL2SQL device based on a preset industry large model may specifically further include:
[0118] A full-text retrieval result update unit, configured to perform full-text retrieval based on the client reply information, the preprocessing result, and the reverse index to obtain a new full-text retrieval result if the judgment result indicates that the current meets the query mode correction trigger condition;
[0119] A mode feedback unit, configured to perform dynamic mode generation through the preset industry large model, the new full-text retrieval result, the query information, and the intent recognition result to obtain a new target query mode, and feedback the new target query mode to the client.
[0120] Furthermore, an embodiment of the present application also discloses an electronic device, Figure 5 It is a structural diagram of an electronic device 20 shown according to an exemplary embodiment, and the content in the figure cannot be considered as any limitation on the scope of use of the present application.
[0121] Figure 5 It is a structural schematic diagram of an electronic device 20 provided by 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. Among them, the memory 22 is used to store a computer program, and the computer program 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 foregoing 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 operating voltages 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 external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and no specific limitation is imposed thereon herein; the input / output interface 25 is used to obtain external input data or output data to the outside, and the specific interface type thereof can be selected according to specific application requirements, and no specific limitation is imposed herein.
[0123] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, a random access memory, a magnetic disk, an optical disk, etc., and the resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be transient storage or permanent storage.
[0124] Among them, the operating system 221 is used to manage and control each hardware device and the computer program 222 on the electronic device 20, and it can be Windows Server, Netware, Unix, Linux, etc. In addition to the computer program capable of implementing the NL2SQL method based on a preset industry large model executed by the electronic device 20 disclosed in any of the foregoing embodiments, the computer program 222 can further include computer programs capable of performing other specific tasks.
[0125] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the NL2SQL method based on a preset industry large model disclosed above is implemented. For the specific steps of this method, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details are not described herein again.
[0126] In this specification, the various embodiments are described in a progressive manner, and the key point of each embodiment is to illustrate the differences from other embodiments. The same or similar parts among the various 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 description of the method part.
[0127] Those skilled in the art can further realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of the examples have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0128] The steps of the methods or algorithms described in combination with the embodiments disclosed in this document can be implemented directly in hardware, software modules executed by a processor, or a combination of both. The software modules can be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium well-known in the technical field.
[0129] Finally, it should also be noted that in this document, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising a..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.
[0130] The technical solutions provided in this application have been introduced in detail above. Specific examples are used in this document to elaborate on the principles and implementation manners of this application. The description of the above embodiments is only used to help understand the method and its core idea of this application; at the same time, for those of ordinary skill in the art, according to the idea of this application, there will be changes in the specific implementation manners and application scopes. In summary, the content of this specification should not be construed as a limitation to this 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; Determine whether the query mode modification trigger condition is currently met based on the received client response information, and when the determination result is no, determine the target SQL statement based on the preset industry big model, the query information and the target query mode; 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: Based on the preset industry big model, the query information is subjected to key entity, database operation and query filter condition extraction to obtain information extraction results; the database operation includes screening operation, sorting operation and aggregation operation; 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; 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; Determine a full-text search result based on the first search result and the second search result; 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.
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 big model according to any one of claims 1 to 3, 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.
5. 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; A statement determination module, 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; The full-text search module comprises: 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; the database operations include screening operations, sorting operations and aggregation operations; A full-text search unit, used for 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; The full-text retrieval unit comprises: 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; 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; A full-text search result determination subunit, used to determine a full-text search result based on the first search result and the second search result; The pattern generation module comprises: 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; 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; 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.
6. 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 4.
7. 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 4.
Citation Information
Patent Citations
Context learning-based database query generation method and system and storage medium
CN119669265A
Process for delivering responses to queries expressed in natural language based on a dynamic document corpus
WO2024228712A1