Data query method, device and system based on large model and medium
By obtaining the user's natural language problems and permissions, using a large language model to match database tables and fields, generating query statements, and checking unviewable fields based on permissions, it solves the problem of ensuring data security while maintaining query convenience, and realizes efficient and secure data query.
Patent Information
- Application Number
- CN202510105102.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-23
- Publication Date
- 2025-04-18
Smart Images

Figure CN119848080A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing, and in particular to a data query method, device, system and medium based on a large model. Background Art
[0002] In recent years, natural language processing technology has made significant progress, especially the development of large pre-trained language models, which enable machines to better understand and generate human language. These technological advances have made it possible to develop more intuitive and easy-to-use data query systems.
[0003] In the related technology, a data query method based on natural language processing is adopted, which uses a large pre-trained language model to parse and understand the query statement input by the user to obtain the database query statement; execute the generated database query statement, and return the query result to the user. In this way, non-technical personnel in the enterprise management industry can interact with the system through natural language without having to master complex database query languages, which greatly improves the convenience and efficiency of data query. However, there are still deficiencies in ensuring data security, which may cause the risk of data leakage.
[0004] Therefore, how to ensure data security while maintaining query convenience is an urgent problem to be solved by technical personnel in this field. Summary of the invention
[0005] The purpose of the present invention is to provide a data query method, device, system and medium based on a large model, which can ensure data security while maintaining query convenience.
[0006] In a first aspect, a data query method based on a large model is provided, comprising:
[0007] Obtain the user's natural language question and the user's user permissions;
[0008] The natural language question is input into the large language model, and the large language model is used to match a target database table corresponding to the natural language question from multiple database tables according to the natural language question; if the target database table is matched, the large language model is used to match a target field matching the natural language question from multiple fields of the target database table according to the natural language question; if the target field is matched, the large language model is used to generate a query statement according to the target field and database table information of the target database table;
[0009] Determining, according to the user rights, whether the natural language question contains a non-viewable field;
[0010] If the natural language question does not include an unviewable field, a query is performed from the database according to the query statement to obtain a query result; and the query result is returned to the client device corresponding to the user.
[0011] In a preferred example, the present invention can be further configured as follows: if the natural language question contains an unviewable field, the method further includes:
[0012] Correcting the unviewable fields included in the natural language question to obtain a corrected natural language question; accordingly, inputting the natural language question into a large language model, including: inputting the corrected natural language question into the large language model;
[0013] Or, generate rejection information and send it to the client device corresponding to the user.
[0014] In a preferred example, the present invention can be further configured as follows: generating a query statement according to the target field and the database table information of the target database table through the large language model, including:
[0015] Determine whether the target field includes a non-viewable field;
[0016] If the target field does not include an unviewable field, generating a query statement according to the target field and database table information of the target database table through the large language model;
[0017] If the target field does not include an unviewable field, a query statement is generated by the large language model according to the fields in the target field except the unviewable field and database table information of the target database table.
[0018] In a preferred example, the present invention can be further configured to: obtain the user rights of the user, including:
[0019] determining a role of the user;
[0020] According to the role of the user, the user rights corresponding to the role of the user are determined from preset permission information; the preset permission information is a correspondence relationship between multiple roles and multiple rights.
[0021] In a preferred example, the present invention can be further configured as follows:
[0022] Acquire a fine-tuning dataset, where the fine-tuning dataset includes a plurality of fine-tuning natural language questions and respective corresponding fine-tuning query statements;
[0023] Fine-tune the large language model according to the fine-tuning dataset to obtain a fine-tuned large language model;
[0024] The fine-tuned large language model is used to generate query sentences.
[0025] In a preferred example, the present invention can be further configured as follows: querying from the database according to the query statement to obtain query results, including:
[0026] Determine whether there are at least two similar fields in the target database table for the target field of the query statement;
[0027] If not, query the database according to the query statement to obtain the query result;
[0028] If yes, the step of inputting the natural language question into the large language model is performed again to obtain a new query statement;
[0029] Determine whether there are at least two similar fields in the target database table for the target field of the new query statement; if so, obtain a user profile of the user; wherein the user profile is obtained by updating an original user profile according to the user's interactive information, and the original user profile is constructed according to the user's historical query behavior;
[0030] According to the user portrait, matching a final field corresponding to the target field from the at least two similar fields;
[0031] If the final field is matched, the query statement is updated according to the final field, and a query is performed from the database according to the updated query statement to obtain a query result;
[0032] If the final field cannot be matched, the query statement is updated according to the at least two similar fields, and a query is performed from the database according to the updated query statement to obtain a query result.
[0033] In a preferred example, the present invention can be further configured as follows: after obtaining the user's natural language question, the method further includes:
[0034] Performing feature extraction on the natural language question to obtain target feature information corresponding to the natural language question;
[0035] Match similar questions from the user's query library based on target feature information;
[0036] If a similar question is matched, the target query statement corresponding to the similar question is adjusted according to the target feature information to obtain the query statement corresponding to the natural language question;
[0037] If no similar question is matched, the step of inputting the natural language question into a large language model is performed.
[0038] In a second aspect, a device is provided, comprising:
[0039] An acquisition module is used to obtain the user's natural language questions and the user's user permissions;
[0040] A generation module, configured to input the natural language question into a large language model, and match a target database table corresponding to the natural language question from multiple database tables according to the natural language question through the large language model; if the target database table is matched, match a target field matching the natural language question from multiple fields of the target database table according to the natural language question through the large language model; if the target field is matched, generate a query statement according to the target field and database table information of the target database table through the large language model;
[0041] A determination module, used to determine whether the natural language question contains a non-viewable field according to the user authority;
[0042] The query module is used to query the database according to the query statement to obtain the query result if the natural language question does not contain the unviewable field; and return the query result to the client device corresponding to the user.
[0043] In a third aspect, a large model-based data query system is provided, wherein the large model-based data query system comprises a memory and a processor, wherein a computer program is stored in the memory, and the processor executes any one of the methods described in the first aspect when running the computer program.
[0044] In a fourth aspect, a computer-readable storage medium is provided, wherein at least one program code is stored in the computer-readable storage medium, and the program code is loaded and executed by a processor to implement any method as described in the first aspect.
[0045] In a fifth aspect, a computer program product is provided, comprising a computer program or instructions, wherein when the computer program or instructions are executed by a processor, the method described in any one of the first aspects is implemented.
[0046] In summary, the data query method based on the big model provided by the present invention includes the following beneficial technical effects:
[0047] In this solution, the user's natural language question and user authority are obtained to ensure the pertinence and security of the query operation; after the natural language question is input into the large language model, the large language model can intelligently match the target database table from multiple database tables, and match the target field from multiple fields of the target database table; check whether the natural language question contains unviewable fields according to the user authority, if it does not contain unviewable fields, query from the database according to the query statement to obtain the query result, effectively preventing the leakage of sensitive information; greatly reducing manual intervention, improving query efficiency, and at the same time, ensuring data security.
[0048] In addition, the present invention also provides a data query device, system and medium based on a large model, all of which have the above-mentioned beneficial technical effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the embodiments of the present invention or the technical solutions of 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 some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0050] Figure 1 It is a flowchart of a data query method based on a large model provided by an embodiment of the present invention;
[0051] Figure 2 It is a flowchart of another data query method based on a large model provided by an embodiment of the present invention;
[0052] Figure 3 It is a schematic diagram of a process for obtaining a query result provided by an embodiment of the present invention;
[0053] Figure 4 It is a structural schematic diagram of a data query device based on a large model provided by an embodiment of the present invention;
[0054] Figure 5 It is a structural diagram of a data query system based on a large model provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0055] This specific embodiment is merely an explanation of the present invention and is not a limitation of the present invention. After reading this specification, those skilled in the art may make non-creative modifications to the present embodiment as needed, but such modifications are protected by patent law as long as they are within the scope of the present invention.
[0056] It should be noted that in the optional embodiments of the present invention, the object information and other related data involved, when the embodiments of the present invention are applied to specific products or technologies, need to obtain the permission or consent of the object, and the collection, use and processing of the relevant data need to comply with the relevant laws, regulations and standards of the relevant countries and regions. In other words, if the embodiments of the present invention involve data related to the object, it needs to be obtained with the authorization and consent of the object, the authorization and consent of the relevant department, and in compliance with the relevant laws, regulations and standards of the country and region. If personal information is involved in the embodiments, the acquisition of all personal information needs to obtain the consent of the individual. If sensitive information is involved, the separate consent of the information subject needs to be obtained. The embodiments also need to be implemented with the authorization and consent of the object.
[0057] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0058] In addition, the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally means that the associated objects before and after are in an "or" relationship.
[0059] In today's enterprise management industry, balancing data security and efficient query has become a key challenge. To address this problem, the present invention proposes an application method of data permission control based on a large model in the enterprise management industry. This method achieves refined management of sensitive data such as employee information through an innovative permission dynamic adjustment mechanism and efficient natural language processing technology, which not only ensures data security but also improves query efficiency.
[0060] The embodiment of the present invention provides a data query method based on a large model, which can also solve the balance problem between data security and efficient query in the enterprise management industry. The method realizes refined management of data by defining user roles and permissions, using natural language processing technology to parse user query intentions and convert them into query statements, such as SQL (Structured Query Language) query statements, implementing a dynamic permission adjustment mechanism, and using a permission management system to accurately control data access rights.
[0061] Specifically, it includes: defining different user roles and their data access rights; using large pre-trained language models to understand the user's natural language query intent and convert it into structured SQL query statements; implementing a permission management system to filter inaccessible data fields to ensure that query results comply with user permissions; when the model output does not meet expectations, using LoRA (Low-Rank Adaptation) and other fine-tuning techniques to optimize model performance; executing filtered SQL query statements, which can automatically identify the user's query intent and limit the model's output results according to the user's permissions, ensuring that only authorized users can access the corresponding data, ensuring the security and compliance of the results. By integrating natural language processing technology and permission management systems, this invention not only ensures data security, but also improves query efficiency. It can not only help enterprises manage data assets, but also improve employee work efficiency. It is suitable for a variety of enterprise management scenarios.
[0062] The embodiment of the present invention provides a data query method based on a large model, such as Figure 1 As shown, the method provided in the embodiment of the present invention can be executed by a data query system based on a large model. The data query system based on a large model is a server, which can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services. The terminal device can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited to this. The terminal device and the data query system based on a large model can be directly or indirectly connected through wired or wireless communication. The embodiment of the present invention is not limited here. The method includes:
[0063] S101, obtaining a natural language question of a user, and obtaining user permissions of the user;
[0064] The user's natural language question refers to the user's request for a specific query task to the system, and the natural language question includes at least one question. User permissions refer to the scope of permissions granted to the user's corresponding role to access data.
[0065] Among them, through the permission management system, different user roles are defined, such as ordinary employees, department managers, senior managers, etc., and each role corresponds to specific data access rights. The scope of data that can be accessed is set for each role. For example, ordinary employees can only access their personal information and some public information; department managers can access all information of their subordinates; senior managers have more extensive access rights.
[0066] When a user needs to query data, he or she can input a natural language question through the user interface, and the user information can be determined through login, identity authentication and other processes, and then the user authority is determined based on the user information. The natural language question can be input directly by the user through a text input box, or by language input, or by picture input, which is not limited in the embodiment of the present invention.
[0067] S102, inputting the natural language question into the large language model, and matching the target database table corresponding to the natural language question from multiple database tables according to the natural language question through the large language model; if the target database table is matched, matching the target field matching the natural language question from multiple fields of the target database table according to the natural language question through the large language model; if the target field is matched, generating a query statement according to the target field and database table information of the target database table through the large language model;
[0068] In the embodiment of the present invention, after obtaining the natural language question, it is input into a large pre-trained language model to understand the user's query intention, and the understood query intention is converted into a structured SQL query statement. The main implementation process is as follows:
[0069] Table selection: Based on the user's natural language question and all database tables in the database, the big model selects all database tables related to the question as target database tables. For example, if there are 100 database tables in the database, the big model may select 2 database tables related to the natural language question.
[0070] Specifically, each of the multiple database tables has a specific name, each database table contains multiple fields, and each field stores specific information in the database table. The large model determines the target database table from the multiple database tables based on the identification information about the database table in the natural language question. It can be understood that if a match is found, the field is confirmed, and if the target database table is not matched, a prompt message is generated to prompt the user that the relevant content is not recorded in the database.
[0071] Select fields: Based on the user's natural language question, combined with the selected target database table and its related fields, filter out specific fields related to the natural language question as target fields. For example, if there are two target database tables, obtain all fields in the two target database tables, and filter out all target fields related to the question through the large model.
[0072] Specifically, after confirming the target database table, each database table is set with multiple fields. For example, the employees table is a database table that stores employee information, including fields such as employee ID, employee name, employee gender, date of birth, position, date of employment, department number, manager number, email address, phone number, and status. The field list is not fixed and can be added, deleted, or modified according to actual needs. Then, the corresponding actual content is set under each field. All keywords corresponding to the fields in the natural language question are filtered out through the large model to determine the target field.
[0073] The query statement is generated by the large language model according to the database table information of the target field and the target database table. For example, if the natural language question of user a is "check the entry time of employee b in the employees table" or "check the entry time of employee b", user a is a department manager, and employee b is a subordinate of user a, then the target database table is determined to be the employees table, the target fields are employee a and the entry time, and the generated query statement is: SELECT HireDate FROMemployees WHERE name = 'employee b' AND department_manager = 'user a'.
[0074] Furthermore, the target fields can be filtered according to user permissions, and the filtered fields and field comments, and database table information (such as table name) of the target database table can be passed to the big model. The big model generates a query statement based on the question and the field, and the query statement is specifically a statement that can be parsed by the database.
[0075] S103. Determine whether the natural language question contains a non-viewable field according to the user's authority.
[0076] In the embodiment of the present invention, it is determined whether the natural language question contains unviewable fields according to the user's authority; the query can be performed only when the unviewable fields are not contained.
[0077] If the natural language question contains unviewable fields, in one achievable manner, the unviewable fields contained in the natural language question can be corrected to obtain a corrected natural language question; accordingly, the natural language question is input into the large language model, including: inputting the corrected natural language question into the large language model. If the natural language question contains unviewable fields, but there are still viewable fields, the content corresponding to the unviewable fields in the natural language question is removed to generate a corrected natural language question; accordingly, when the query result is fed back to the user, while feeding back the viewable content, it is necessary to remind the user that the unviewable fields contained in the natural language question do not have query permissions.
[0078] If the natural language question contains unviewable fields, in another achievable method, a rejection message can be generated and sent to the user's corresponding client device. If the user's natural language question directly contains unviewable fields, a rejection process is performed and a rejection message is generated to inform the user that he or she has no right to access the information. For example, the manager of department A has no right to view the educational information of employee B in department B. When he or she asks "Please show me employee B's educational information", the system will prompt "No right to view".
[0079] In the embodiment of the present invention, when the natural language question contains unviewable fields, the system can automatically make corrections or generate rejection information. Alternatively, the question is corrected and then the corrected natural language question is input into the large language model again, thereby ensuring the accuracy of the query.
[0080] It is understandable that the embodiment of the present invention does not limit the execution order of S103, and S102 may be executed first and then S103; or S103 may be executed first and then S102. S102 may be executed when the natural language question does not contain the unviewable field, or S102 may be executed regardless of whether the natural language question contains the unviewable field.
[0081] S104: If the natural language question does not include an unviewable field, query the database according to the query statement to obtain a query result; and return the query result to the client device corresponding to the user.
[0082] The database stores a large amount of structured data, including multiple database tables. If the natural language question does not contain unavailable fields, the query statement will be sent to the database. The database will search and filter out qualified data records in the internal target database table according to the instructions in the query statement to form the query results and return them to the user.
[0083] It can be seen that in the embodiment of the present invention, the user's natural language question and user authority are obtained to ensure the pertinence and security of the query operation; after the natural language question is input into the large language model, the large language model can intelligently match the target database table from multiple database tables, and match the target field from multiple fields of the target database table; check whether the natural language question contains unviewable fields according to the user authority, if it does not contain unviewable fields, query the database according to the query statement to obtain the query result, which effectively prevents the leakage of sensitive information; greatly reduces manual intervention, improves query efficiency, and at the same time, ensures data security.
[0084] In the process of implementing data permission control, the present invention particularly adopts the permission management system to accurately control the query fields, rather than relying on the model to directly generate filtered fields, mainly based on the following two important considerations:
[0085] Uncertainty in model output: When a large model processes natural language queries, the answers it generates may be random, which makes it impossible to ensure 100% accurate control of data permissions. If the model output accidentally contains fields that should not be displayed, it may cause the risk of data leakage. This risk can be avoided by controlling through the permission management system to ensure that each query request strictly complies with the preset permission rules.
[0086] The need for real-time and flexibility: Although model fine-tuning can improve the accuracy of answers, this process usually takes a certain amount of time, and during model retraining and deployment, the system may not be able to respond in a timely manner to real-time permission configuration requirements for changes in corporate policies or special circumstances. In contrast, the permission management system can adjust and update permission settings in real time, taking effect immediately, thereby ensuring the real-time and flexibility of permission control. In addition, the use of a permission management system is also conducive to detailed recording, analysis and monitoring of user behavior, facilitating the audit of permission use and tracking of abnormal behavior, and further strengthening data security protection measures. Therefore, the permission management system adopted in the present invention is the key to achieving accurate, efficient and secure data permission control.
[0087] Based on this, the embodiment of the present invention uses a program to perform precise permission control on the queried fields, and filters out the fields that are not allowed to be accessed according to the user's permission level. Check the queried column names to ensure that the current user has the right to view these fields. There are two filtering methods: rejection mechanism and program filtering.
[0088] Rejection mechanism: If the user's question directly contains fields that cannot be viewed, the question will be rejected and the user will be informed that he / she has no right to access this information. For example, the manager of department A has no right to view the educational information of employee B in department B. When he / she asks "Please show me employee B's educational information", the system will prompt "No right to view".
[0089] Program filtering: If the user's question does not directly include unviewable fields, the program will accurately filter the unviewable fields. For example, if the manager of department A does not have the right to view the educational information of employee b in department B, when he asks "Please show me the information of employee b", the system will remove the educational information of employee b that the manager of department A does not have the right to view, and display other viewable information.
[0090] See Figure 2 , Figure 2 1 is a flow chart of another data query method based on a large model provided by an embodiment of the present invention, including:
[0091] Obtain natural language questions sent by users, i.e. user questions;
[0092] Get user permissions;
[0093] Based on all database tables and user questions, use the big model to filter tables related to the questions as target database tables;
[0094] Based on the fields of the target data table and the user's questions, use the big model to filter the fields related to the questions as the target fields;
[0095] Determine whether the user's question specifies fields that cannot be viewed; if so, directly refuse to answer;
[0096] If not specified, the fields that the user does not have permission to are filtered out, and SQL query statements are generated through the large model;
[0097] Execute SQL query statements and display the results to the user.
[0098] Among them, a possible implementation method of an embodiment of the present invention is to generate a query statement through a large language model according to the target field and database table information of the target database table, including: determining whether the target field contains an unviewable field; if the target field does not contain the unviewable field, generating a query statement through the large language model according to the target field and database table information of the target database table; if the target field does not contain the unviewable field, generating a query statement through the large language model according to the fields in the target field except the unviewable field and the database table information of the target database table.
[0099] Among them, according to the user's permissions, it is determined whether the target field contains fields that are not viewable to the user; if not, a query statement is generated according to the target field and database table information of the target database table through the large language model; if yes, all non-viewable fields without viewing permissions are removed from the matching target field, and the remaining viewable fields and database table information of the target database table are used to generate a query statement through the large language model.
[0100] In an embodiment of the present invention, before generating a query statement, the system will perform a permission check on the target field to ensure that it does not contain unviewable fields, thereby further improving the security of the query statement and avoiding information leakage caused by field permission issues.
[0101] A possible implementation method of an embodiment of the present invention is to obtain user rights of a user, including: determining the role of the user; determining the user rights corresponding to the role of the user from preset permission information based on the role of the user; the preset permission information is a correspondence between multiple roles and multiple permissions.
[0102] Among them, the role information of the user is retrieved from the user information database; according to the preset correspondence between the role and the permission, the permissions related to the role corresponding to the user are determined. It can be understood that the role and permissions of the user may be dynamic, so the user permissions may need to be confirmed once regularly, and the user permissions corresponding to the user may be retained within a certain time range to avoid frequent matching and improve query efficiency.
[0103] A possible implementation of the embodiment of the present invention further includes:
[0104] Obtain a fine-tuning dataset, where the fine-tuning dataset includes multiple fine-tuning natural language questions and their corresponding fine-tuning query statements;
[0105] Fine-tune the large language model according to the fine-tuning dataset to obtain a fine-tuned large language model;
[0106] The fine-tuned large language model is used to generate query sentences.
[0107] In the embodiment of the present invention, since the output of the large model has a certain degree of randomness, the output format may not be fixed. At the same time, when there are many fields with similar semantics, it is difficult for the model to distinguish the difference between the fields and the wrong field may be used. Based on the above problems, when the model performance does not meet expectations, fine-tuning technologies such as LoRA can be used to optimize the model performance.
[0108] Specifically, a fine-tuning data set is obtained. The fine-tuning data set may be a natural language question and a corresponding query statement collected during this period of time when the number of times of use reaches a preset number of times during the actual application of the large model. If the accuracy of the feedback is lower than the preset accuracy threshold, the data in these data sets may correspond to the natural language question and the user's query authority, and no filtering is required. In an embodiment of the present invention, the LoRA fine-tuning technology may be used. LoRA is a parameter-efficient fine-tuning method that achieves fine-tuning of model parameters by introducing a low-rank matrix based on a pre-trained large language model. On the basis of the pre-trained large language model, a LoRA layer is added. The LoRA layer will contain a low-rank matrix for adjusting model parameters during the fine-tuning process; the LoRA layer is trained using a fine-tuning data set; the trained LoRA layer is combined with the pre-trained model to obtain a fine-tuned large language model.
[0109] In an embodiment of the present invention, a fine-tuning dataset is used to fine-tune a large language model so that the model can better adapt to specific query scenarios.
[0110] A possible implementation of the present invention is shown in Figure 3 , Figure 3The present invention provides a flowchart of obtaining a query result provided by an embodiment of the present invention. Specifically, querying a database according to a query statement to obtain a query result includes:
[0111] Determine whether there are at least two similar fields in the target database table for the target field of the query statement;
[0112] If not, query the database according to the query statement to obtain the query result;
[0113] If yes, the step of inputting the natural language question into the large language model is performed again to obtain a new query statement;
[0114] Determine whether the target field of the new query statement has at least two similar fields in the target database table; if so, obtain the user's user portrait; wherein the user portrait is obtained by updating the original user portrait based on the user's interactive information, and the original user portrait is constructed based on the user's historical query behavior;
[0115] According to the user profile, match the final field corresponding to the target field from at least two similar fields;
[0116] If the final field is matched, the query statement is updated according to the final field, and the query is performed from the database according to the updated query statement to obtain the query result;
[0117] If the final field cannot be matched, the query statement is updated according to at least two similar fields, and a query is performed from the database according to the updated query statement to obtain a query result.
[0118] In some possible situations, if the target field of the query statement is a date, and there are two similar fields, namely, date of birth and date of employment, in the target database table, it may be that the natural language question is segmented abnormally when extracting and determining the target field. For example, when the user inputs the date of employment of employee b, the target field determined at this time is a date. Therefore, the step of inputting the natural language question into the large language model can be performed again to obtain a new query statement. If there are still similar fields in the target field of the new query statement, the user's user profile is obtained. The user profile is constructed based on user basic information, historical query behavior and other information, and will be dynamically updated according to the user's interactive information. Then, according to the information in the user profile (such as user preferences, historical query records, etc.), the final field that best matches the target field is matched from at least two similar fields. If the final field is successfully matched, the original query statement is updated with the final field, and the database query is executed according to the updated query statement to return the query result. If the final field cannot be matched according to the user profile, the query statement can be updated according to the default strategy (all similar fields are included in the query statement) or the user selection strategy (the user selects a similar field by himself), and the query is executed.
[0119] The construction of user portraits is further elaborated. User historical query behavior includes historical query records of users in the system, such as query fields, query frequency, query time, etc., which reflect the user's query preferences and habits; the initial user portrait is constructed based on these contents. For example, if the user often queries the date of birth, then if multiple similar dates are involved, it can be inferred that the user may want to query the date of birth. Users will have more interactions during actual queries, new query fields, and feedback on query results. The data query system based on the big model regularly collects user interaction information and updates the original user portrait. The update process may include adding new user features, deleting outdated information, etc.
[0120] In an embodiment of the present invention, when a target field of a query statement has a similar field in a target database table, the system can automatically perform a secondary match and match the final field from the similar fields based on the user portrait, thereby improving the accuracy of the query.
[0121] A possible implementation manner of the embodiment of the present invention, after obtaining the user's natural language question, further includes:
[0122] Extract features of natural language questions to obtain target feature information corresponding to the natural language questions;
[0123] Match similar questions from the user's query library based on target feature information;
[0124] If a similar question is matched, the target query statement corresponding to the similar question is adjusted according to the target feature information to obtain the query statement corresponding to the natural language question;
[0125] If no similar question is matched, the step of inputting the natural language question into the large language model is performed.
[0126] The input question is subjected to feature extraction, and the target feature information includes but is not limited to keywords, syntax, and semantics. The extracted feature information is used to search for historical queries similar to the current question in the pre-built query statement library, where the similarity can be calculated based on cosine similarity or Euclidean distance. If a similar question is matched, the target query statement corresponding to the matched similar question is adjusted according to the target feature information. If the similarity reaches 100%, no adjustment is required; otherwise, the target query statement is adjusted by replacing the target field to quickly obtain the required query statement.
[0127] For example, if the natural language question of user a is “check the joining date of employee b in the employees table”, the target query statement is: SELECT HireDate FROM employees WHERE name = 'employee b' AND department_manager = 'user a'.
[0128] The current natural language question of user a is "View the joining date of employee c in the employees table". In this case, you only need to change employee b in the target query statement to employee c, and obtain the query statement: SELECT HireDate FROMemployees WHERE name = 'employee c' AND department_manager = 'user a'.
[0129] In an embodiment of the present invention, before a natural language question is input into a large language model, features are extracted for it first, and similar questions are matched from a user query statement library, so that historical query results can be fully utilized and query statements that meet user intentions can be quickly generated, thereby improving the efficiency of query statement generation.
[0130] Based on any of the above embodiments, the embodiment of the present invention provides a specific solution, including:
[0131] Step 1: User login.
[0132] The user enters the user name and password through the enterprise system interface to log in. The system verifies the user credentials and loads the user's role information into the session.
[0133] Step 2: Submit the request.
[0134] After the user successfully logs in, he can submit a query request through the system interface, for example, enter "I want to view Zhang San's contact number and education level." After the system receives the request, it sends it to the backend for processing.
[0135] Step 3: Select table and fields.
[0136] The system first parses the user's query request to determine the table to be queried. For example, if the request mentions "employee", the system will recognize that the table to be queried is the employees table.
[0137] The system further parses the field information in the request to determine the fields to be queried. In this example, the system identifies the fields to be queried as "Contact Number" and "Education Level".
[0138] Step 4: Field filtering.
[0139] The system filters the identified fields according to the user's role permissions. For example, if the user is a department manager, he can view all the information of his subordinates, including "education level". If the user is an ordinary employee, the system will remove "education level" from the query field because ordinary employees do not have the permission to view other employees' education information. In this process, the fields that are not allowed to be accessed are filtered out according to the user's permissions. This step ensures the security and compliance of the query results.
[0140] Step 5: Generate SQL query statement.
[0141] The system generates an SQL query statement based on the filtered field list. If the user is a department manager, the generated SQL statement may be:
[0142] SELECT contact_number, highest_education FROM employees WHERE name ='Zhang San' AND department_manager = 'User A';
[0143] If the user is an ordinary employee, the generated SQL statement may be:
[0144] SELECT contact_number FROM employees WHERE name = 'Zhang San' ANDemployee_id = user ID;
[0145] Step 6: Execute the query process.
[0146] The system executes the generated SQL query statement and interacts with the database to obtain data. The database returns the query results, and the system displays the results to the user in a user-readable format. For example:
[0147] Zhang San's contact number: 1234567890
[0148] Zhang San's highest education: Master's degree
[0149] It can be seen that in the embodiment of the present invention, a large pre-trained language model is used to parse natural language queries, which improves the accuracy of understanding the query intent. Through the dynamic adjustment mechanism, the user's access rights can be determined in real time according to the query content, which enhances the flexibility and adaptability of the system. The mechanism of filtering fields ensures that only legal fields are used for queries, avoids unnecessary data access, and improves query efficiency. The risk of data leakage caused by uncertainty and randomness of model output is reduced. The instant effectiveness feature of the permission management system meets the needs of the enterprise management industry for rapid changes in permission configuration.
[0150] The following is an introduction to a device provided by an embodiment of the present invention. The device described below and the method described above can be referenced to each other. The device of this embodiment is set in a data query system based on a large model. Figure 4 , Figure 4 : is a structural block diagram of a device according to one embodiment of the present invention, comprising:
[0151] The acquisition module 210 is used to acquire the natural language question of the user and the user authority of the user;
[0152] A generation module 220 is used to input a natural language question into a large language model, and use the large language model to match a target database table corresponding to the natural language question from multiple database tables according to the natural language question; if the target database table is matched, use the large language model to match a target field that matches the natural language question from multiple fields of the target database table according to the natural language question; if the target field is matched, use the large language model to generate a query statement according to the database table information of the target field and the target database table;
[0153] A determination module 230, for determining whether the natural language question contains a non-viewable field according to user permissions;
[0154] The query module 240 is used to query the database according to the query statement to obtain the query result if the natural language question does not contain the unviewable field; and return the query result to the client device corresponding to the user.
[0155] In one achievable manner, if the natural language question contains an unviewable field, the device further includes:
[0156] A first processing module is used to correct the unviewable fields included in the natural language question to obtain a corrected natural language question;
[0157] Accordingly, the generation module 220 is used to: input the corrected natural language question into the large language model;
[0158] The second processing module is used to generate rejection information and send it to the client device corresponding to the user.
[0159] In one achievable manner, the generation module 220 is used to: determine whether the target field includes an unviewable field; if the target field does not include an unviewable field, generate a query statement based on the target field and database table information of the target database table through a large language model; if the target field does not include an unviewable field, generate a query statement based on fields in the target field except the unviewable field and database table information of the target database table through a large language model.
[0160] In one achievable manner, the acquisition module 210 is used to: determine the role of the user; and determine the user rights corresponding to the user role from preset permission information according to the user role; the preset permission information is the correspondence between multiple roles and multiple permissions.
[0161] In one achievable manner, the present invention further includes:
[0162] The fine-tuning module is used to obtain a fine-tuning dataset, which includes multiple fine-tuning natural language questions and their corresponding fine-tuning query statements; fine-tune the large language model according to the fine-tuning dataset to obtain a fine-tuned large language model; and the fine-tuned large language model is used to generate query statements.
[0163] In one achievable manner, the query module 240 is used to determine whether there are at least two similar fields in the target database table to the target field of the query statement; if not, query the database according to the query statement to obtain the query result; if so, execute the step of inputting the natural language question into the large language model again to obtain a new query statement; determine whether there are at least two similar fields in the target database table to the target field of the new query statement; if so, obtain the user portrait of the user; wherein the user portrait is obtained by updating the original user portrait based on the user's interactive information, and the original user portrait is constructed based on the user's historical query behavior; according to the user portrait, match the final field corresponding to the target field from at least two similar fields; if the final field is matched, update the query statement according to the final field, and query the database according to the updated query statement to obtain the query result; if the final field is not matched, update the query statement according to at least two similar fields, and query the database according to the updated query statement to obtain the query result.
[0164] In one achievable manner, the present invention further includes:
[0165] The third processing module is used to extract features of natural language questions and obtain target feature information corresponding to the natural language questions; match similar questions from the user's query statement library based on the target feature information; if similar questions are matched, adjust the target query statement corresponding to the similar questions based on the target feature information to obtain the query statement corresponding to the natural language question; if no similar questions are matched, execute the step of inputting the natural language question into the large language model.
[0166] The present invention provides a data query system based on a large model. Figure 5 As shown, Figure 5 The data query system 300 based on the big model shown includes: at least one processor 301 ( Figure 5 301 and memory 303. The processor 301 and memory 303 are connected, such as through a bus 302. Optionally, the data query system 300 based on the big model may further include a transceiver 304. It should be noted that in actual applications, the transceiver 304 is not limited to one, and the structure of the data query system 300 based on the big model does not constitute a limitation on the embodiment of the present invention.
[0167] The processor 301 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of the present invention. The processor 301 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0168] The bus 302 may include a path to transmit information between the above components. The bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 302 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0169] The memory 303 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.
[0170] The memory 303 is used to store application code for executing the solution of the present invention, and the execution is controlled by the processor 301. The processor 301 is used to execute the application code stored in the memory 303 to implement the content shown in the above method embodiment.
[0171] Figure 5 The data query system based on the big model shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0172] An embodiment of the present invention provides a computer-readable storage medium, in which at least one program code is stored. When the computer-readable storage medium is run on a computer, the computer can execute the corresponding content of the aforementioned method embodiment.
[0173] An embodiment of the present invention provides a computer program product, including a computer program or instructions, which implement the corresponding contents of the aforementioned method embodiment when the computer program or instructions are executed by a processor.
[0174] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0175] The above are only some embodiments of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A data query method based on a large model, characterized in that: include: Obtain the user's natural language question and the user's user permissions; Inputting the natural language question into a large language model, and matching a target database table corresponding to the natural language question from multiple database tables according to the natural language question through the large language model; If a target database table is matched, then matching a target field matching the natural language question from multiple fields of the target database table through the large language model according to the natural language question; If the target field is matched, a query statement is generated according to the target field and database table information of the target database table through the large language model; Determining, according to the user rights, whether the natural language question contains a non-viewable field; If the natural language question does not include an unviewable field, a query is performed from the database according to the query statement to obtain a query result; and the query result is returned to the client device corresponding to the user.
2. The method according to claim 1, characterized in that If the natural language question contains an unviewable field, the method further includes: Correcting the unviewable fields included in the natural language question to obtain a corrected natural language question; accordingly, inputting the natural language question into a large language model, including: inputting the corrected natural language question into the large language model; Or, generate rejection information and send it to the client device corresponding to the user.
3. The method according to claim 1, characterized in that Generate a query statement according to the target field and database table information of the target database table through the large language model, including: Determine whether the target field includes a non-viewable field; If the target field does not include an unviewable field, generating a query statement according to the target field and database table information of the target database table through the large language model; If the target field does not include an unviewable field, a query statement is generated by the large language model according to the fields in the target field except the unviewable field and database table information of the target database table.
4. The method according to claim 1, characterized in that: Get the user's user permissions, including: determining a role of the user; According to the role of the user, the user rights corresponding to the role of the user are determined from preset permission information; the preset permission information is a correspondence relationship between multiple roles and multiple rights.
5. The method according to claim 1, characterized in that Also includes: Acquire a fine-tuning dataset, where the fine-tuning dataset includes a plurality of fine-tuning natural language questions and respective corresponding fine-tuning query statements; Fine-tune the large language model according to the fine-tuning dataset to obtain a fine-tuned large language model; The fine-tuned large language model is used to generate query sentences.
6. The method according to any one of claims 1 to 5, characterized in that: Querying the database according to the query statement to obtain query results includes: Determine whether there are at least two similar fields in the target database table for the target field of the query statement; If not, query the database according to the query statement to obtain the query result; If yes, the step of inputting the natural language question into the large language model is performed again to obtain a new query statement; Determine whether the target field of the new query statement has at least two similar fields in the target database table; if so, obtain a user profile of the user; wherein the user profile is obtained by updating an original user profile according to the user's interactive information, and the original user profile is constructed according to the user's historical query behavior; According to the user portrait, matching a final field corresponding to the target field from the at least two similar fields; If the final field is matched, the query statement is updated according to the final field, and a query is performed from the database according to the updated query statement to obtain a query result; If the final field cannot be matched, the query statement is updated according to the at least two similar fields, and a query is performed from the database according to the updated query statement to obtain a query result.
7. The method according to any one of claims 1 to 5, characterized in that: After obtaining the user's natural language questions, it also includes: Performing feature extraction on the natural language question to obtain target feature information corresponding to the natural language question; Match similar questions from the user's query library based on target feature information; If a similar question is matched, the target query statement corresponding to the similar question is adjusted according to the target feature information to obtain the query statement corresponding to the natural language question; If no similar question is matched, the step of inputting the natural language question into a large language model is performed.
8. A data query device based on a large model, characterized in that: include: An acquisition module is used to obtain the user's natural language questions and the user's user permissions; A generating module, configured to input the natural language question into a large language model, and match a target database table corresponding to the natural language question from a plurality of database tables according to the natural language question through the large language model; If a target database table is matched, then matching a target field matching the natural language question from multiple fields of the target database table through the large language model according to the natural language question; If the target field is matched, a query statement is generated according to the target field and database table information of the target database table through the large language model; A determination module, used to determine whether the natural language question contains a non-viewable field according to the user authority; A query module, configured to query a database according to the query statement to obtain a query result if the natural language question does not contain an unviewable field; The query result is returned to the client device corresponding to the user.
9. A data query system based on a large model, characterized in that: The large model-based data query system includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the method according to any one of claims 1 to 7 when running the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one program code, and the program code is loaded and executed by a processor to implement the method according to any one of claims 1 to 7.
Citation Information
Cited By
Intelligent government affair number asking method, device and equipment based on large model and medium
CN120596509A
Employee information query method, apparatus and device, and storage medium
CN120804141A
Question and answer query method, system and equipment for data table and medium
CN121560925A
Space division scene-oriented data intelligent query method and system
CN121681574A
A data intelligent query method and system for a space division scene
CN121681574B