Data query method, device, equipment and product

By using preset industry knowledge bases and large language models to generate structured query statements, the problem of low data query efficiency in traditional business intelligence is solved, and the accuracy and efficiency of data query are improved to adapt to rapidly changing business needs.

CN119166654APending Publication Date: 2024-12-20IFLYTEK CO LTD

Patent Information

Application Number
CN202411168601.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-23
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

Data query efficiency in traditional business intelligence is inefficient, operators need to have high professionalism and business logic understanding, and data visualization display requires additional development work, resulting in inefficiency.

Method used

Through the preset industry knowledge base recall and table knowledge corresponding to data query requests, a large language model is used to generate structured query statements, reducing manual development work and improving data query efficiency.

Benefits of technology

It achieves the accuracy and efficiency of data query, reduces dependence on labor, reduces operational costs, and adapts to rapidly changing business needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166654A_ABST
    Figure CN119166654A_ABST
Patent Text Reader

Abstract

The invention provides a data query method and device, equipment and a product, and the method comprises the steps: recalling knowledge description and table knowledge corresponding to a data query request based on a preset industry knowledge base, and storing knowledge description corresponding to each term in a target scene and description information of each table in the target scene in the industry knowledge base; generating prompt information of data query based on the knowledge description corresponding to the data query request, the table knowledge and the data query request; and generating a structured query statement based on the prompt information through the large language model, and performing data query in a database based on the structured query statement to obtain a data query result. Therefore, the data query efficiency and accuracy can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data query technology, and in particular to a data query method, device, equipment and product. Background Art

[0002] The Business Intelligence (BI) scenario refers to the application of BI technology in the operations of an enterprise or organization to extract valuable information from the enterprise database.

[0003] However, the traditional BI field has high requirements for professionalism in data processing. Operators not only need to have knowledge of database management and Structured Query Language (SQL), but also need to have a full understanding of the company's business logic. Faced with specific analysis needs, operators need to write SQL statements to query data according to the analysis needs in order to accurately extract the required data. In addition, if data visualization is required, further investment is needed in the programming and development of visualization systems or tools. Whenever new display or analysis requirements arise, operators need to perform additional development work, which makes the entire data query process very inefficient. Summary of the invention

[0004] Based on the above technical status, the present application proposes a data query method, device, equipment and product, which can improve data query efficiency.

[0005] In order to achieve the above technical objectives, this application specifically proposes the following technical solutions:

[0006] The first aspect of the present application proposes a data query method, comprising: recalling knowledge descriptions and table knowledge corresponding to a data query request based on a preset industry knowledge base, wherein the industry knowledge base stores knowledge descriptions corresponding to each term in a target scenario, and description information of each table in the target scenario; generating prompt information for a data query based on the knowledge description corresponding to the data query request, the table knowledge and the data query request; generating a structured query statement based on the prompt information through a large language model, and performing a data query in a database based on the structured query statement to obtain a data query result.

[0007] In some implementations, the method further includes: recalling historical query statements and historical data query results related to the data query request based on a preset historical question library, wherein the historical question library stores historical data query requests and their corresponding historical query statements and historical data query results; generating prompt information for the data query based on the knowledge description corresponding to the data query request, the table knowledge and the data query request, including: generating prompt information for the data query based on the data query request, the table knowledge, the knowledge description, the historical query statement and the historical data query result.

[0008] In some implementations, generating a structured query statement based on the prompt information using a large language model includes: generating a query intent based on the prompt information using a large language model; and generating a structured query statement based on the query intent using the large language model.

[0009] In some implementations, the training process of the large language model includes the following steps: training the query intent recognition capability of the basic large model based on data query request samples and corresponding annotated query intents; and training the query statement generation capability of the basic large language model based on query intent samples and corresponding annotated query statements to obtain the large language model.

[0010] In some implementations, the method further includes: optimizing the query intent recognition capability of the basic large language model when it is determined that the query intent recognition accuracy does not reach a preset recognition accuracy; and / or optimizing the query statement generation capability of the basic large language model when it is determined that the query statement generation accuracy does not reach a preset generation accuracy.

[0011] In some implementations, after generating a structured query statement based on the prompt information through a large language model, and performing a data query in a database based on the structured query statement to obtain a data query result, the method further includes: when it is determined that the query duration of the structured query statement exceeds a preset duration, recording the structured query statement as a slow query; if the number of times the structured query statement generated by the large language model is a slow query reaches a preset number, optimizing the structured query statement based on the table structure, table index, table data volume and query plan information of the data query through the large language model to obtain an optimized structured query statement; performing a data query in a database based on the optimized structured query statement through a large language model to obtain a data query result.

[0012] In some implementations, after generating a structured query statement based on the prompt information through a large language model, and performing a data query in a database based on the structured query statement to obtain a data query result, the method further includes: when it is determined that an error occurs in the execution of the structured query statement, optimizing and training the large language model through a data query request sample and an erroneous structured query statement corresponding to the data query request sample and an annotated correct structured query statement; or, when it is determined that an error occurs in the execution of the structured query statement, optimizing and training the large language model through a data query request sample and an erroneous thinking step of the large language model when generating the structured query statement and an annotated correct thinking step.

[0013] In some implementations, before recalling the table knowledge related to the data query request based on a preset industry table knowledge base, the method also includes: obtaining the user's initial question; performing semantic understanding on the initial question to obtain an independent question; and obtaining a data query request based on the independent question.

[0014] In some implementations, the initial question carries the user identifier of the user; semantic understanding is performed on the initial question to obtain an independent question, including: replacing terms in the initial question based on a preset term library to obtain the independent question; or, querying the user's historical questions based on the user identifier, and obtaining the independent question based on the historical questions and the initial question.

[0015] The second aspect of the present application provides a data query method, comprising:

[0016] A third aspect of the present application provides an electronic device, including a memory and a processor;

[0017] The memory is connected to the processor and is used to store programs;

[0018] The processor is used to implement the data query method described in any one of the first aspect and the implementation manner of the first aspect by running the program in the memory.

[0019] In a fourth aspect, the present application proposes a storage medium, on which a computer program is stored. When the computer program is executed by a processor, the data query method described in the first aspect and any one of the implementation methods of the first aspect is implemented.

[0020] In a fifth aspect, the present application proposes a computer program product, including computer program instructions, which, when executed by a processor, enable the processor to implement the data query method described in the first aspect and any one of the implementation methods of the first aspect.

[0021] The data query method, device, equipment and product proposed in the present application recall the knowledge description and table knowledge corresponding to the data query request based on the preset industry knowledge base. The industry knowledge base stores the knowledge description corresponding to each term in the target scenario and the description information of each table; and generates prompt information for data query based on the acquired knowledge description, table knowledge and data query request; and generates structured query statements based on the prompt information through the large language model, and performs data retrieval in the database based on the structured query statement, so as to obtain the required data query results. The knowledge description and table knowledge recalled by the preset industry knowledge base can help the large language model accurately understand the user's query intention, and then generate accurate structured query statements. When performing data query based on the accurate structured query statement, accurate data query results can be obtained. In addition, this method performs data query through the interaction between the user and the large language model, avoiding additional manual development work, thereby improving data query efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the embodiments of the present application 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 application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0023] Figure 1 A flowchart of a data query method provided in an embodiment of the present application;

[0024] Figure 2 A flowchart of an implementation method for generating a structured query statement based on prompt information provided in an embodiment of the present application;

[0025] Figure 3 An overall block diagram of the data query method provided in the embodiment of the present application;

[0026] Figure 4 A schematic diagram of the structure of a data query device provided in an embodiment of the present application;

[0027] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0028] The technical solution proposed in the embodiment of the present application is suitable for data query application scenarios. Adopting the technical solution in the embodiment of the present application can improve the accuracy and efficiency of data query.

[0029] An enterprise database is a collection of enterprise data that is stored, organized, and managed according to a data structure. In business operations, enterprise databases play an important role. As a treasure trove of information, they can quickly and efficiently provide enterprises with real-time industry data and trends, helping enterprises to infer operating status and development direction.

[0030] Solutions in traditional BI scenarios are mainly divided into two categories: one is to develop customized operation and maintenance systems through professional developers to meet specific BI needs; the other is for professional operation and maintenance personnel to directly extract data from the enterprise database, conduct in-depth analysis, and present the results to users.

[0031] In the method of developing and operating systems, professional developers need to have a deep understanding of business scenarios and develop customized query systems and tools for fixed BI problems. This process involves multiple stages such as demand analysis, system design, coding, testing, and deployment, with the goal of building a system that can display predefined analytical indicators. However, this highly customized development model has a long cycle and poor flexibility, making it difficult to quickly respond to changing business needs.

[0032] On the other hand, the operation and maintenance personnel's approach focuses on manual intervention. In this mode, the operation and maintenance personnel need to have a comprehensive and in-depth understanding of all the business processes and related data tables of the enterprise. When users raise specific questions, the operation and maintenance personnel need to manually write SQL query statements, extract the required data from the database, and perform subsequent data cleaning, sorting and analysis, and finally feedback the results to the user. Although this method can meet personalized needs to a certain extent, due to its high dependence on manpower and high requirements for the skills and experience of the operation and maintenance personnel, it is difficult to scale up the processing of large or complex data analysis tasks, and therefore the data query efficiency is low.

[0033] In summary, although the solutions in traditional BI scenarios can solve some fixed or standard analysis needs, they face obvious challenges in coping with the rapidly changing market environment, meeting personalized needs, and improving analysis efficiency. Therefore, a more flexible, efficient and user-friendly BI solution is urgently needed.

[0034] In view of this, the embodiments of the present application propose a new data query method, device, equipment and product, which processes user questions by combining retrieval enhancement technology to accurately understand user query needs. Afterwards, a large language model (hereinafter referred to as the large model) is used to generate and execute SQL query statements based on the retrieval enhancement results, reducing dependence on manual labor, thereby reducing overall operating costs and improving data query accuracy and efficiency.

[0035] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0036] The present application embodiment first proposes a data query method, see Figure 1 As shown, the method includes:

[0037] S101. Recall the knowledge description and table knowledge corresponding to the data query request based on the preset industry knowledge base.

[0038] Wherein, step S101 includes the following steps a1, a2 and a3:

[0039] a1. Get data query request.

[0040] The data query request refers to an independent question that can be understood by the big model after preprocessing the user's initial question. The following steps a11 to a13 can be used to obtain the data query request:

[0041] a11. Get the user's initial question.

[0042] Initial questions usually reflect the user's natural language habits and may contain certain specific terms or expressions that are difficult for large models to understand. For example, users may ask questions such as "How many tourists did our city have in March this year?" or "What are the year-on-year and month-on-month tourism data in our city in March this year?" Or directly ask "What about April this year?".

[0043] In the above examples, "this year", "our city", "year-on-year" and "month-on-month" are expressions of the user's natural language habits or specific terms. The big model cannot understand the meaning of these words. Therefore, the initial question needs to be processed so that it can be understood by the big model. The specific processing process can be seen in the following steps a12 and a13.

[0044] a12. Perform semantic understanding on the initial question to obtain an independent question.

[0045] When asking questions, users may use vague or context-dependent words (such as "this year", "recently", "here", etc.), which may lead to misunderstandings without specific context. In addition, when asking questions, users often assume that the big model already knows some background information, but in fact the big model still needs this information to provide the correct answer. Therefore, it is necessary to convert these words into clear information through semantic understanding (such as converting "this year" to a specific year and converting "here" to an actual geographical location), so as to identify and fill in the gaps in these background information, so that the answers are more in line with the actual needs of users.

[0046] There are many ways to implement step a12, which can be specifically as follows:

[0047] In some embodiments, semantic understanding is performed on the initial question to obtain an independent question, including: terminology replacement is performed on the initial question based on a preset term library to obtain an independent question.

[0048] For example, for the initial question "How many tourists are there in our city in March this year", the two words "this year" and "our city" need to be further clarified. By querying the preset term library, the corresponding replacement words for the two words can be obtained.

[0049] For example, there is a mapping relationship between "this year" and "2024". "My city" can be queried through user location information to obtain a specific place name, such as "Xi'an".

[0050] Based on the above mapping relationship, "this year" is replaced by "2024", and "our city" is replaced by "Xi'an". After the term replacement, the final independent question is "How many tourists will there be in Xi'an in March 2024?"

[0051] In this way, the user's initial question can be effectively converted into an independent question with a clear structure and complete information, thereby facilitating further data query.

[0052] In some embodiments, semantic understanding is performed on the initial question to obtain an independent question, including: querying the user's historical questions based on the user identifier, and obtaining the independent question based on the historical questions and the initial question.

[0053] The user's first question may contain enough information, such as: "How many tourists did our city have in March this year?" However, in subsequent questions, the user may simplify the statement, such as: "What about April?" At this time, it is difficult to determine the user's complete meaning based on this brief statement alone.

[0054] Since users may have established internal connections between different questions, the system needs to combine the current brief question with the previous more detailed historical questions. On this basis, it is inferred that the user's current question is about the situation in April and supplement the missing information. For example, the user's historical question is "How many tourists are there in our city in March this year?", and the current initial question is "What about April?" It can be seen that the user's question cannot be determined by relying solely on "What about April?". Therefore, it is necessary to combine the user's historical questions to generate independent questions.

[0055] Both the initial question and the historical question contain the user's unique ID. Through this ID, the user's past question records can be traced back, that is, "How many tourists did our city have in March 2024?" Combined with the current question, a complete and clear independent question can be obtained, which is "How many tourists did Xi'an have in April 2024."

[0056] In this way, even if the user uses relatively brief expressions when asking questions continuously, their intentions can be accurately understood and accurate data query results can be provided accordingly.

[0057] a13. Obtain data query requests based on independent questions.

[0058] Among them, step a13 specifically includes: slot extraction inspection, follow-up clarification and reconstruction of independent questions. Slot extraction inspection refers to the extraction of all entities in the independent question to identify and extract each slot and its corresponding slot information. Slot information usually contains key elements in the independent question, such as time, place, object, etc.

[0059] Follow-up questions refer to asking users questions about slot information that is unclear or vaguely expressed, in order to further clarify the specific meaning of these slots and further clarify the details of the question. Through this interactive process, we can accurately understand the user's true intention and ensure the accuracy of subsequent queries.

[0060] Reconstructing independent questions means that after obtaining semantically clear slot information, the slot information is combined with the independent question, so as to reconstruct a complete and semantically clear independent question, that is, a data query request. Such constructed questions can more accurately guide the subsequent data query process.

[0061] Through the above steps a11, a12 and a13, not only can the user's query needs be accurately understood, but also it can be ensured that the constructed data query request meets the user's actual intention, thereby improving the accuracy and efficiency of data query.

[0062] After the user's data query request is determined in step a1, step a2 may be performed based on the data query request.

[0063] a2. Recall the knowledge description corresponding to the data query request based on the preset industry knowledge base.

[0064] The industry knowledge base stores the knowledge descriptions corresponding to each term in the target scenario.

[0065] An industry knowledge base is a database that stores professional knowledge about a specific industry or field. It contains a wealth of information and data, and is intended to provide users with an accurate and reliable source of information. In the embodiment of the present application, the industry knowledge base stores knowledge descriptions corresponding to each term in the target scenario. These knowledge descriptions cover a wide range of content, including but not limited to:

[0066] (1) Definition of terms

[0067] Provide basic meaning and explanation of each term to ensure that the big model can accurately understand the meaning of these terms.

[0068] (2) Application scenarios

[0069] Describe the use of the term in a specific context, including the contextual meaning of the term and practical application examples.

[0070] (3) Related terms

[0071] List other terms related to the term to help establish the association between terms and provide a more comprehensive information perspective for the big model.

[0072] (4) Case analysis

[0073] Including real-life cases and examples to show the application of the term in real-world scenarios helps deepen the understanding of the term in large models.

[0074] (5) Statistical information

[0075] Provides statistical data related to terms, such as growth trends, market share, etc., to provide data support for large models.

[0076] (6) Laws and Regulations

[0077] Covers legal regulations and policy information related to terminology to ensure that the big model can understand the latest industry standards.

[0078] (7) Historical evolution

[0079] Record the historical background and development of the term to help the big model understand how the term has evolved over time.

[0080] (8) Glossary of professional terms

[0081] Contains a list of industry-specific terms to ensure that the large model is familiar with and can use these professional terms correctly.

[0082] Through the above content, the industry knowledge base can not only provide detailed explanations of terms, but also help the big model better understand the application of terms in actual scenarios. In this way, it can ensure that the big model accurately understands the user's intention and gives appropriate answers or query results.

[0083] For example, the user's independent question is "What are the year-on-year and month-on-month growth in March 2024?", where "year-on-year" and "month-on-month" are industry terms. In order to help the big model understand the meaning of "year-on-year" and "month-on-month", the explanations of the two terms retrieved from the industry knowledge base can be integrated into knowledge descriptions to ensure that the big model can accurately understand the meaning of "year-on-year" and "month-on-month".

[0084] After the user's data query request is determined in step a1, step a3 may be performed based on the data query request.

[0085] a3. Recall the table knowledge related to the data query request based on the preset industry knowledge base.

[0086] The industry knowledge base also stores description information of each table in the target scenario, including table structure information and table content sample data.

[0087] Among them, table structure information refers to the organization and definition of tables in the database, including the following basic elements: fields, data types, lengths, default values, and constraints. A field is each column in a table. Each field has a unique name that identifies the meaning of the data stored in the column. The data type specifies the type of data that can be stored in the field, such as integers, strings, dates, and times. The length defines the maximum length of data that can be stored in the field. The default value means that when a new record is inserted, if a field is not assigned a value, the default value of the field is used. Constraints are used to ensure the value range or relationship of the data in the table. Common constraints include primary key constraints, unique constraints, foreign key constraints, and check constraints.

[0088] The sample data in the table content provides examples of data actually stored in the table, which can help you understand how to use the fields and the data format. The sample data usually includes the first N rows of actual data in the table, showing the typical values ​​of different fields. Here, N can be a positive integer greater than 1, for example, N can be 3, 4, 5, and so on.

[0089] The big model can determine the table to be queried based on the table knowledge corresponding to the data query request. In other words, the big model can identify which tables contain relevant data such as time, location, and object mentioned in the data query request.

[0090] In this way, the big model can not only understand the user's query intent, but also accurately locate the table containing the required data, thereby effectively performing the data query task. This method can improve the accuracy and efficiency of data query.

[0091] As described above, the knowledge description of each term and the description information of the table are stored in the industry knowledge base. In order to facilitate quick query, a table knowledge base can be built in addition to the industry knowledge base, so that the knowledge description of each term is stored in the industry knowledge base, and the description information of the table is stored in the table knowledge base.

[0092] Continue reading Figure 1 , after step S101, the data query method of this embodiment further includes step S102.

[0093] S102: Generate prompt information for data query based on the knowledge description corresponding to the data query request, the table knowledge and the data query request.

[0094] Specifically, independent questions, knowledge descriptions, and table knowledge are assembled according to prompt templates to generate prompt information, which are then input into a large model to generate SQL statements.

[0095] For example, the prompt template could be as follows:

[0096] "You are a MySQL expert. For the given user independent question, please write a syntactically correct MySQL query statement.

[0097] Please follow the following requirements:

[0098] Try not to query all columns, only the relevant columns needed to answer your question.

[0099] Use backticks (`) to enclose table and column names.

[0100] Do not query non-existent columns, and make sure the column names you use are included in the provided table structure.

[0101] For questions involving time, if it is a relative time (such as today, last year), please use the time function (such as CURDATE(), NOW()) to obtain it; if a specific time is specified (such as 2023, July), use the specific time value directly.

[0102] Please pay attention to the data type and format and convert it if necessary.

[0103] Please give your query results a human-readable nickname.

[0104] Please use the following output format:

[0105] ```sql

[0106] SQL query statement

[0107] ```

[0108] Please use only the following table information:

[0109] {Table structure information and first 3 rows of data example}

[0110] Independent question: {specific independent question information raised by the user}

[0111] Possibly relevant business knowledge:

[0112] {Industry knowledge description}”

[0113] S103: Generate a structured query statement based on the prompt information through the large language model, and perform data query in the database based on the structured query statement to obtain a data query result.

[0114] After obtaining the prompt information, you can use the large language model to generate SQL statements based on the prompt information. For details, refer to Figure 2 , including the following steps S201 and S202:

[0115] S201. Generate query intent based on prompt information through a large language model.

[0116] The query intent refers to determining the table to be queried and the fields to be queried in the table, so as to ensure that the query intent is correct.

[0117] For example, the query intent prompt information can be as follows:

[0118] You are an expert in MySQL database table understanding. Given a user's independent question, knowledge description, and table knowledge, determine the user's query intent and return the table, query conditions, and fields that need to be queried in the user's independent question.

[0119] Please use the following output format:

[0120] Tables to be queried: Table 1, Table 2, .....

[0121] Query conditions: Field 1 of table 1 = 'data value 1' and Field 2 of table 2 i> data value 2.....

[0122] Fields to be queried: Table 1. Field 3, Table 2. Field 4, ...

[0123] Please use only the following table information:

[0124] {Table structure information and first 3 rows of data example}

[0125] Independent question: {Specific independent question}

[0126] Possibly relevant business knowledge:

[0127] {Industry knowledge description}

[0128] S202: Generate a structured query statement based on the query intent using a large language model.

[0129] After obtaining the query intent, you can generate SQL statements based on the query intent to ensure that the query syntax is correct. The following example illustrates the prompt information for generating SQL statements based on query intent.

[0130] For example, the prompt information for generating SQL statements based on query intent can be as follows:

[0131] You are a MySQL expert. Please write a syntactically correct MySQL query statement for the query requirements provided.

[0132] Please follow the following requirements:

[0133] Try not to query all columns, only the columns you need to answer your question.

[0134] Use backticks (`) to enclose table and column names.

[0135] Do not query for non-existent columns, and make sure to use only the column names provided in the following table.

[0136] For questions involving time, if it is a relative time (such as today, last year), use the time function (such as CURDATE(), NOW()) to obtain it; if a specific time is specified (such as 2023, July), use the specific value directly.

[0137] Please pay attention to the data type and format and convert it if necessary.

[0138] Please give your query results an alias that is easier for users to understand.

[0139] Please use the following output format:

[0140] ```sql

[0141] SQL query statement

[0142] Please use only the following table knowledge:

[0143] {Table structure information and first 3 rows of data example}

[0144] Query requirements: {Query intent of the first step}

[0145] Possibly relevant business knowledge:

[0146] {Industry knowledge description}

[0147] The above embodiment introduces the application process of the large model. Before the large model is applied, it needs to be trained. The training process of the large model includes step b1 and step b2:

[0148] b1. Train the query intent recognition capability of the basic large model based on data query request samples and the corresponding annotated query intent.

[0149] The data query request samples may be independent question samples. The labeled query intent is the correct query intent manually labeled for these independent question samples. The loss function used in the training is the cross entropy loss.

[0150] Specifically, by inputting data query samples into the basic big model, the basic big model predicts the query intent based on the data query samples, thereby obtaining the predicted query intent.

[0151] Afterwards, by comparing the difference between the labeled query intent and the predicted query intent, the query intent loss can be determined, and then the parameters of the basic large model are adjusted based on the query intent loss to make it gradually converge, and finally complete the training of query intent recognition capability.

[0152] Among them, the basic large model can choose a larger model to ensure semantic understanding and inductive summary capabilities.

[0153] b2. Based on the query intent samples and the corresponding annotated query sentences, the basic large language model is trained to generate query sentences to obtain a large language model.

[0154] The query intent samples can be the annotated query intent in step b1 or the query intent obtained by other means. The annotated structured query statements are the correct structured query statements annotated manually for the query intent samples. The loss function used in the training process is still the cross entropy loss.

[0155] Specifically, by inputting the query intent sample into the basic large model, the basic large model predicts the corresponding structured query statement based on the query intent sample, thereby obtaining the predicted query statement.

[0156] Afterwards, by comparing the difference between the annotated query and the predicted query, the query loss can be determined. Based on the query loss, the parameters of the basic large model are adjusted to gradually converge, and finally the query generation capability training is completed.

[0157] After completing the query intent recognition capability and query statement generation capability training described in the above embodiment, the performance of these two capabilities can be further verified. If the query intent recognition capability and / or query statement generation capability fail to meet the expected standards, they can be optimized and adjusted.

[0158] Specifically, when it is determined that the query intent recognition accuracy does not reach the preset recognition accuracy, the query intent recognition capability of the basic large language model is optimized; and / or, when it is determined that the query statement generation accuracy does not reach the preset generation accuracy, the query statement generation capability of the basic large language model is optimized.

[0159] In order to verify the query intent recognition capability, this embodiment can use a first test data set (including a data query request sample and its corresponding annotated query intent) to test the trained basic large model, so as to evaluate the accuracy of its query intent recognition. The query intent recognition accuracy can be determined by the accuracy of the test results corresponding to the test data set. If the query intent recognition accuracy does not reach the preset recognition accuracy, continue to train the basic large language model until the query intent recognition accuracy reaches the preset recognition accuracy.

[0160] For the verification of query statement generation capability, the second test data set (including query intent samples and their corresponding annotated query statements) can be used to test the trained basic large model, and the accuracy of the model-generated SQL statements can be determined based on the accuracy in the test results. If the generated accuracy does not reach the preset generation accuracy, it is necessary to continue training the model's SQL statement generation capability until the SQL statement generation accuracy reaches the preset recognition accuracy.

[0161] Based on the above embodiments, SQL statements can be generated through a large model, and data query operations can be performed in the database based on the SQL statements. However, the SQL statements generated by the large model may be inappropriate, which may result in a slow data query speed, thereby affecting the overall data query efficiency. Therefore, the following embodiments can also be used to improve the data query speed. Specifically including: when it is determined that the query duration of the structured query statement exceeds the preset duration, the structured query statement is recorded as a slow query; if the number of times the structured query statement generated by the large language model is a slow query reaches a preset number, the structured query statement is optimized based on the table structure, table index, table data volume and query plan information of the data query by the large language model to obtain an optimized structured query statement; the data query is performed in the database based on the optimized structured query statement by the large language model to obtain a data query result.

[0162] In this embodiment, if an error occurs during the execution of the generated SQL statement, the SQL error correction process will be triggered. In addition, for SQL statements whose execution time exceeds the preset time, such as 5 seconds, they are marked as "slow SQL". When the slow SQL is executed a preset number of times, the SQL optimization process will be triggered. In this optimization process, relevant information including table structure information, table index, table data volume, and SQL execution plan will be provided to the big model. This information is analyzed by the big model to provide an optimized SQL execution plan, or to make specific optimization suggestions, such as creating a new index. After the new index is established, the SQL statement can be re-executed.

[0163] When executing data query operations in the database using structured query statements (SQL) generated by the big model, execution errors may occur. In this case, you can use optimization methods based on SQL statements or optimization methods based on thinking steps to further improve the big model to enhance its ability to generate accurate and effective SQL statements.

[0164] In some implementations, the optimization method based on SQL statements includes: when it is determined that an error occurs in the execution of a structured query statement, optimizing and training a large language model through data query request samples and the erroneous structured query statements corresponding to the data query request samples and the marked correct structured query statements.

[0165] Specifically, after detecting that an SQL statement execution fails, the corresponding data query request samples and the erroneous SQL statements generated by them can be recorded, and the correct SQL statements annotated by experts can be obtained. The data query request samples, erroneous SQL statements and correct SQL statements can be used to allow the large model to learn the differences between erroneous SQL statements and correct SQL statements, thereby improving the correctness of the generated SQL statements.

[0166] In some implementations, the optimization method based on thinking steps includes: when it is determined that an error occurs in the execution of a structured query statement, optimizing and training the large language model through data query request samples and the incorrect thinking steps and marked correct thinking steps of the large language model when generating the structured query statement.

[0167] Similarly, after detecting that an SQL statement execution fails, the big model can be optimized by collecting data query request samples and the thinking steps of the big model in the process of generating SQL statements, as well as the correct thinking steps annotated by experts. These data query request samples, incorrect thinking steps and correct thinking steps can be used to optimize the big model.

[0168] These optimization processes help the big model learn how to avoid errors and gradually improve its ability to generate accurate and effective SQL statements. By continuously iterating and improving the big model in this way, the error rate of generated SQL statements can be gradually reduced in the future.

[0169] The above embodiment introduces a method for recalling knowledge descriptions and table knowledge associated with data query requests from a preset industry knowledge base. These knowledge descriptions and table knowledge provide the necessary semantic understanding information for the big model, which can help the big model understand the user's query intent more accurately. In order to further improve the accuracy of the big model's understanding of the user's query intent, this embodiment can also use a historical question library as auxiliary information to help the big model understand the user's query intent. Specifically including:

[0170] Based on a preset historical question library, historical query statements and historical data query results related to the data query request are recalled. The historical question library stores historical data query requests and their corresponding historical query statements and historical data query results.

[0171] Accordingly, prompt information for data query is generated based on the knowledge description, table knowledge and data query request corresponding to the data query request, including: generating prompt information for data query based on the data query request, table knowledge, knowledge description, historical query statements and historical data query results.

[0172] The historical question library includes past user data query requests and their corresponding processing results, which provides learning resources for the model and helps the big model better understand and predict user query needs. By searching the historical question library, the big model can find historical cases similar to the current query request and refer to the query statements and data query results in these cases. This process not only helps the big model understand the user's query intent more accurately, but also helps it generate more accurate and effective SQL statements, thereby improving data query accuracy and efficiency.

[0173] When searching for historical cases in the historical question library that are similar to the current data query request, the similarity between the current data query request and each historical data query request in the historical question library can be calculated, and the historical case with the highest similarity can be selected as a reference case.

[0174] The similarity between the current data query request and each historical data query request in the historical question library can be determined by using a similarity algorithm or building a relevance model. Similarity algorithms may include cosine distance, Euclidean distance, Manhattan distance, etc. The relevance model can train a neural network based on the relevance of two data query requests and their corresponding annotations to evaluate the relevance between query requests.

[0175] After obtaining the data query results, the data query results and the user's independent questions can be fed back to the big model, so that the big model summarizes the answers the user wants based on the data query results and the user's independent questions, and returns them to the user.

[0176] In summary, the embodiments of the present application solve the BI scenario problems of users by combining the big model with the BI scenario. Figure 3 , which may include:

[0177] (1) Create a session

[0178] A session is built by collecting user information (such as user ID) and context information.

[0179] (2)Term replacement

[0180] Replace the time, place, and specific terms in the user's question with expressions that the big model can understand. For example, if the user's question is "How many tourists are there in our city in March of this year", replace "this year" with "2024", and replace "our city" with "Shanghai", the question becomes "How many tourists are there in Shanghai in March of 2024".

[0181] (3) Constructing independent questions

[0182] Merge all the user's session information. For example, if the last question was "How many tourists will there be in Shanghai in February 2024?", and the current question is "What about March?", the final independent question is "How many tourists will there be in our city in March this year?"

[0183] (4) Intention Judgment

[0184] Determine whether it is the intention of the data query request. If yes, proceed to (5); if no, end.

[0185] (5) Slot inspection

[0186] Slot all entities in independent problems.

[0187] (6) Ask for clarification

[0188] For slots with unclear intentions, such as those missing key information, users will be asked follow-up questions to clarify the semantics of the slots.

[0189] (7) Reconstructing the independent problem

[0190] Combine the clarified slot semantics with the independent question constructed in (3) to reconstruct the semantically clear question.

[0191] (8) Knowledge Recall

[0192] Retrieval enhancement technology is used to recall knowledge related to independent questions in the BI scenario knowledge base based on independent questions. For example, the BI scenario knowledge base stores information about the meaning of star-rated hotels: star-rated hotels indicate a hotel grade greater than level 3.

[0193] (9) Database recall + small sample recall

[0194] Relevant data table information is recalled from the BI question-related database through retrieval enhancement technology, and small sample reference cases are recalled from the historical question library.

[0195] (10) SQL generation

[0196] The constructed independent questions, table structure information, table example data, knowledge and small samples are assembled according to the prompt template and sent to the large model to generate SQL statements.

[0197] (11) Return results

[0198] By executing SQL statements, the SQL execution results and user questions are given to the big model, and the answers the user wants are summarized and returned to the user.

[0199] Corresponding to the above-mentioned data query method, the present application embodiment also proposes a data query device, see Figure 4 , the device comprises:

[0200] The recall unit 401 recalls the knowledge description and table knowledge corresponding to the data query request based on a preset industry knowledge base, wherein the industry knowledge base stores the knowledge description corresponding to each term in the target scenario and the description information of each table in the target scenario;

[0201] A prompt information generating unit 402 generates prompt information for data query based on the knowledge description corresponding to the data query request, the table knowledge and the data query request;

[0202] The generating and querying unit 403 generates a structured query statement based on the prompt information through a large language model, and performs a data query in a database based on the structured query statement to obtain a data query result.

[0203] In some embodiments, the recall unit 401 is also used to perform the following steps: recalling historical query statements and historical data query results related to the data query request based on a preset historical question library, wherein the historical question library stores historical data query requests and their corresponding historical query statements and historical data query results; the prompt information generation unit 402 generates prompt information for the data query based on the knowledge description corresponding to the data query request, the table knowledge and the data query request, specifically including: generating prompt information for the data query based on the data query request, the table knowledge, the knowledge description, the historical query statement and the historical data query result.

[0204] In some embodiments, the generation and query unit 403 generates a structured query statement based on the prompt information through a large language model, specifically including: generating a query intent based on the prompt information through a large language model; generating a structured query statement based on the query intent through the large language model.

[0205] In some embodiments, the training process of the large language model includes the following steps: training the query intent recognition capability of the basic large model based on data query request samples and corresponding annotated query intents; and training the query statement generation capability of the basic large language model based on query intent samples and corresponding annotated query statements to obtain the large language model.

[0206] In some embodiments, the device also includes: an optimization unit 404, which is used to optimize the query intention recognition capability of the basic large language model when it is determined that the query intention recognition accuracy does not reach the preset recognition accuracy; and / or, when it is determined that the query statement generation accuracy does not reach the preset generation accuracy, optimize the query statement generation capability of the basic large language model.

[0207] In some embodiments, the optimization unit 404 is further used to perform the following steps: when it is determined that the query duration of the structured query statement exceeds a preset duration, the structured query statement is recorded as a slow query; if the number of times the structured query statement generated by the large language model is a slow query reaches a preset number, the structured query statement is optimized by the large language model based on the table structure, table index, table data volume and query plan information of the data query to obtain an optimized structured query statement; and data query is performed in a database based on the optimized structured query statement by the large language model to obtain a data query result.

[0208] In some embodiments, the optimization unit 404 is further used to perform the following steps: when it is determined that an error occurs in the execution of the structured query statement, the large language model is optimized and trained through a data query request sample and an erroneous structured query statement corresponding to the data query request sample and a marked correct structured query statement; or, when it is determined that an error occurs in the execution of the structured query statement, the large language model is optimized and trained through a data query request sample and an erroneous thinking step of the large language model when generating the structured query statement and a marked correct thinking step.

[0209] In some embodiments, the device further includes: a semantic understanding unit 405, which is used to perform the following steps: obtaining an initial question from a user; performing semantic understanding on the initial question to obtain an independent question; and obtaining a data query request based on the independent question.

[0210] In some embodiments, the initial question carries the user ID of the user; the semantic understanding unit 405 performs semantic understanding on the initial question to obtain an independent question, specifically including: replacing terms in the initial question based on a preset term library to obtain the independent question; or, querying the user's historical questions based on the user ID, and obtaining the independent question based on the historical questions and the initial question.

[0211] The data query device provided in this embodiment belongs to the same application concept as the data query method provided in the above embodiments of this application, can execute the data query method provided in any of the above embodiments of this application, and has the corresponding functional modules and beneficial effects of executing the data query method. For technical details not fully described in this embodiment, please refer to the specific processing content of the data query method provided in the above embodiments of this application, and will not be repeated here.

[0212] The functions implemented by each unit in the above data query device can be implemented by the same or different processors respectively, and the embodiments of the present application are not limited thereto.

[0213] It should be understood that the units in the above data query device can be implemented in the form of a processor calling software. For example, the device includes a processor, the processor is connected to a memory, and instructions are stored in the memory. The processor calls the instructions stored in the memory to implement any of the above methods or realize the functions of each unit of the device, wherein the processor can be a general-purpose processor, such as a CPU or a microprocessor, etc., and the memory can be a memory in the device or a memory outside the device. Alternatively, the unit in the device can be implemented in the form of a hardware circuit, and the functions of some or all units can be realized by designing the hardware circuit. The hardware circuit can be understood as one or more processors; for example, in one implementation, the hardware circuit is an ASIC, and the functions of some or all of the above units are realized by designing the logical relationship of the components in the circuit; for another example, in another implementation, the hardware circuit can be implemented by PLD, taking FPGA as an example, which can include a large number of logic gate circuits, and the connection relationship between the logic gate circuits is configured by a configuration file, so as to realize the functions of some or all of the above units. All units of the above device can be implemented in the form of a processor calling software, or in the form of a hardware circuit, or in part by a processor calling software, and the remaining part is implemented in the form of a hardware circuit.

[0214] In an embodiment of the present application, a processor is a circuit with the ability to process signals. In one implementation, the processor may be a circuit with the ability to read and run instructions, such as a CPU, a microprocessor, a GPU, or a DSP; in another implementation, the processor may implement certain functions through the logical relationship of a hardware circuit, and the logical relationship of the hardware circuit is fixed or reconfigurable, such as a hardware circuit implemented by an ASIC or PLD, such as an FPGA. In a reconfigurable hardware circuit, the process of the processor loading a configuration document to implement the hardware circuit configuration can be understood as the process of the processor loading instructions to implement the functions of some or all of the above units. In addition, it can also be a hardware circuit designed for artificial intelligence, which can be understood as an ASIC, such as an NPU, TPU, DPU, etc.

[0215] It can be seen that each unit in the above device can be one or more processors (or processing circuits) configured to implement the above method, such as: CPU, GPU, NPU, TPU, DPU, microprocessor, DSP, ASIC, FPGA, or a combination of at least two of these processor forms.

[0216] In addition, all or part of the units in the above device can be integrated together, or can be implemented independently. In one implementation, these units are integrated together and implemented in the form of a SOC. The SOC may include at least one processor for implementing any of the above methods or implementing the functions of each unit of the device. The type of the at least one processor may be different, for example, including a CPU and an FPGA, a CPU and an artificial intelligence processor, a CPU and a GPU, etc.

[0217] An embodiment of the present application further provides a control device, which includes a processor and an interface circuit. The processor in the control device is connected to a data input component via the interface circuit of the control device.

[0218] The data input component specifically refers to a functional component capable of inputting or collecting voice data, such as a microphone, etc.

[0219] The above-mentioned interface circuit can be any interface circuit that can realize the data communication function, for example, it can be a USB interface circuit, a Type-C interface circuit, a serial port circuit, a PCIE circuit, etc.

[0220] The processor in the control device is also a circuit with signal processing capability, which executes the data query method introduced in the above embodiment. The specific implementation of the processor can refer to the above processor implementation, and the embodiment of the present application is not strictly limited.

[0221] Another embodiment of the present application also provides an electronic device, see Figure 5 As shown, the device includes:

[0222] Memory 200 and processor 210;

[0223] The memory 200 is connected to the processor 210 and is used to store programs;

[0224] The processor 210 is used to implement the data query method disclosed in any of the above embodiments by running the program stored in the memory 200.

[0225] Specifically, the electronic device may further include: a bus, a communication interface 220 , an input device 230 and an output device 240 .

[0226] The processor 210, the memory 200, the communication interface 220, the input device 230 and the output device 240 are connected to each other via a bus.

[0227] A bus may include a pathway that transfers information between components of a computer system.

[0228] The processor 210 may be a general-purpose processor, such as a general-purpose central processing unit (CPU), a microprocessor, etc., or an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the scheme of the present invention. It may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0229] The processor 210 may include a main processor, and may also include a baseband chip, a modem, and the like.

[0230] The memory 200 stores a program for executing the technical solution of the present invention, and may also store an operating system and other key services. Specifically, the program may include a program code, and the program code includes a computer operation instruction. More specifically, the memory 200 may include a read-only memory (ROM), other types of static storage devices that can store static information and instructions, a random access memory (RAM), other types of dynamic storage devices that can store information and instructions, a disk storage, a flash, and the like.

[0231] The input device 230 may include a device for receiving data and information input by a user, such as a keyboard, a mouse, a camera, a scanner, a light pen, a voice input device, a touch screen, a pedometer, or a gravity sensor.

[0232] Output device 240 may include devices that allow information to be output to a user, such as a display screen, printer, speaker, etc.

[0233] The communication interface 220 may include any transceiver or the like to communicate with other devices or communication networks, such as Ethernet, Radio Access Network (RAN), Wireless Local Area Network (WLAN), etc.

[0234] The processor 210 executes the program stored in the memory 200 and calls other devices, which can be used to implement each step of any data query method provided in the above embodiments of the present application.

[0235] An embodiment of the present application further proposes a chip, which includes a processor and a data interface, and the processor reads and runs a program stored in a memory through the data interface to execute the embodiment of the data query method introduced in any of the above embodiments.

[0236] In addition to the above methods and devices, an embodiment of the present application may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the data query method described in any of the above embodiments of this specification.

[0237] The computer program product may be written in any combination of one or more programming languages ​​to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages, such as Java, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as an independent software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0238] In addition, an embodiment of the present application may also be a storage medium on which a computer program is stored, and the computer program is executed by a processor to execute the steps of the data query method described in any of the above embodiments of this specification.

[0239] For the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0240] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0241] The steps in the methods of each embodiment of the present application can be adjusted in order, combined and deleted according to actual needs, and the technical features recorded in each embodiment can be replaced or combined.

[0242] The modules and sub-modules in the devices and terminals of the various embodiments of the present application can be combined, divided and deleted according to actual needs.

[0243] In the several embodiments provided in the present application, it should be understood that the disclosed terminals, devices and methods can be implemented in other ways. For example, the terminal embodiments described above are only schematic, for example, the division of modules or submodules is only a logical function division, and there may be other division methods in actual implementation, for example, multiple submodules or modules can be combined or integrated into another module, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.

[0244] The modules or submodules described as separate components may or may not be physically separated, and the components of the modules or submodules may or may not be physical modules or submodules, that is, they may be located in one place, or they may be distributed on multiple network modules or submodules. Some or all of the modules or submodules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0245] In addition, each functional module or submodule in each embodiment of the present application may be integrated into one processing module, or each module or submodule may exist physically separately, or two or more modules or submodules may be integrated into one module. The above-mentioned integrated modules or submodules may be implemented in the form of hardware or in the form of software functional modules or submodules.

[0246] 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.

[0247] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly by hardware, software units executed by a processor, or a combination of the two. The software units 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.

[0248] 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.

[0249] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A data query method, characterized in that: include: Recalling knowledge descriptions and table knowledge corresponding to the data query request based on a preset industry knowledge base, wherein the industry knowledge base stores knowledge descriptions corresponding to each term in a target scenario and description information of each table in the target scenario; Generate prompt information for data query based on the knowledge description corresponding to the data query request, the table knowledge and the data query request; A structured query statement is generated based on the prompt information through a large language model, and data query is performed in a database based on the structured query statement to obtain a data query result.

2. The method according to claim 1, characterized in that The method further comprises: Recalling historical query statements and historical data query results related to the data query request based on a preset historical question library, wherein the historical question library stores historical data query requests and their corresponding historical query statements and historical data query results; Generating prompt information for data query based on the knowledge description corresponding to the data query request, the table knowledge and the data query request, including: Prompt information for data query is generated based on the data query request, the table knowledge, the knowledge description, the historical query statement and the historical data query result.

3. The method according to claim 1 or 2, characterized in that: Generating a structured query statement based on the prompt information through a large language model includes: Generate query intent based on the prompt information through a large language model; A structured query statement is generated based on the query intent using the large language model.

4. The method according to claim 3, characterized in that The training process of the large language model includes the following steps: Based on data query request samples and the corresponding annotated query intents, the basic large model is trained to recognize query intents; as well as, The query statement generation capability of the basic large language model is trained based on the query intent samples and the corresponding annotated query statements to obtain the large language model.

5. The method according to claim 3, characterized in that: The method further comprises: When it is determined that the query intent recognition accuracy does not reach a preset recognition accuracy, optimizing the query intent recognition capability of the basic large language model; and / or, When it is determined that the query statement generation accuracy does not reach the preset generation accuracy, the query statement generation capability of the basic large language model is optimized.

6. The method according to claim 1 or 2, characterized in that: After generating a structured query statement based on the prompt information by using a large language model, and performing a data query in a database based on the structured query statement, and obtaining a data query result, the method further includes: When it is determined that the query duration of the structured query statement exceeds a preset duration, recording the structured query statement as a slow query; If the number of times that the structured query statement generated by the large language model is a slow query reaches a preset number, the structured query statement is optimized by the large language model based on the table structure, table index, table data volume and query plan information of the data query to obtain an optimized structured query statement; A data query is performed in a database based on the optimized structured query statement through a large language model to obtain a data query result.

7. The method according to claim 1 or 2, characterized in that: After generating a structured query statement based on the prompt information by using a large language model, and performing a data query in a database based on the structured query statement, and obtaining a data query result, the method further includes: When it is determined that the structured query statement is executed incorrectly, optimizing and training the large language model through a data query request sample and an erroneous structured query statement corresponding to the data query request sample and an annotated correct structured query statement; or, When it is determined that the structured query statement is executed incorrectly, the large language model is optimized and trained through data query request samples and the incorrect thinking steps and the marked correct thinking steps of the large language model when generating the structured query statement.

8. The method according to claim 1 or 2, characterized in that: Before recalling the table knowledge related to the data query request based on the preset industry table knowledge base, the method further includes: Get the user's initial question; Performing semantic understanding on the initial question to obtain an independent question; A data query request is obtained based on the independent question.

9. The method according to claim 8, characterized in that The initial question carries the user ID of the user; Semantically understand the initial question to obtain independent questions, including: Performing term replacement on the initial question based on a preset term library to obtain the independent question; or, The user's historical questions are queried based on the user identifier, and the independent question is obtained based on the historical questions and the initial question.

10. A data query device, characterized in that: include: A recall module, used to recall knowledge descriptions and table knowledge corresponding to the data query request based on a preset industry knowledge base, wherein the industry knowledge base stores knowledge descriptions corresponding to each term in a target scenario and description information of each table in the target scenario; A first generating module generates prompt information for data query based on the knowledge description corresponding to the data query request, the table knowledge and the data query request; The second generating module is used to generate a structured query statement based on the prompt information through a large language model, and perform data query in a database based on the structured query statement to obtain a data query result.

11. An electronic device, characterized in that: including memory and processor; The memory is connected to the processor and is used to store programs; The processor is configured to implement the method according to any one of claims 1 to 9 by running the program in the memory.

12. A computer program product, characterized in that The method comprises computer program instructions, which, when executed by a processor, cause the processor to implement the method as claimed in any one of claims 1 to 9.

Citation Information

Patent Citations

  • SQL (Structured Query Language) statement generation method and device based on large language model, equipment and medium

    CN117743371A

  • Database query statement generation method and device, equipment and storage medium

    CN118227655A

  • Text2SQL semantic parsing method for domain large language model

    CN118377796A

Cited By

  • Table content retrieval method, program product, equipment and medium

    CN119357314A

  • Data processing method and system of intelligent organization construction system

    CN119597863A

  • Natural language place name query method and device and electronic equipment

    CN120011525A

  • Table analysis and retrieval RAG method and device based on large model and medium

    CN120743935A

  • Query method and device based on large language model, equipment and medium

    CN120910097A