Data query method and device, storage medium and electronic equipment
By users inputting simple text information on the target interface, keyword escaping and large language model processing are used to generate and de-escape database operation statements, which solves the problem of difficulty in balancing data query convenience and flexibility in the existing technology, and achieves Efficient and secure data query experience.
Patent Information
- Application Number
- CN202411294663.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2025-01-17
AI Technical Summary
The existing technology is difficult to take into account the convenience and flexibility of database data query at the same time, resulting in poor user experience.
By the user inputting simple text information on the target interface, the keyword set is obtained and escaped into a safe keyword set, text prompt information is generated, the large language model is called for processing, the database operation statement is generated, and de-escaped. Query, display query results.
It achieves the convenience and flexibility of data query, lowers the user threshold, improves user experience, and realizes data query without leaking sensitive information.
Smart Images

Figure CN119322835A_ABST
Abstract
Description
Technical Field
[0001] The present specification relates to the field of computer technology, and more specifically, to a data query method, device, storage medium and electronic device in the field of computer technology. Background Art
[0002] In the related art, there are two main ways to implement data query in the database. The first way is to integrate the query statement in the UI (User Interface) control, such as a virtual button, and the user can trigger the data query and obtain the required data by clicking it. Although the first way is convenient, it requires developers to prepare UI controls in advance, which limits its application in various user scenarios. The second way requires users to master the knowledge of database query statements and manually enter the query statement in the input box to obtain data. The second way is highly flexible and allows users to customize query statements, but it has high requirements on users. They need to have knowledge of database queries and manually enter statements, which brings inconvenience to users. In short, the related technologies for database data query face the problem of difficulty in balancing convenience and flexibility at the same time. Summary of the invention
[0003] This specification provides a data query method, device, storage medium and electronic device, which can take into account the convenience and flexibility of data query and effectively improve the user experience.
[0004] In a first aspect, a data query method is provided, the method comprising:
[0005] In response to first text information input by a user on a target interface, obtaining a first keyword set from the first text information;
[0006] Determine at least one target structural element among a plurality of structural elements of the data table to be queried, wherein the structural elements are divided into table names and field names;
[0007] Translating the first category of keywords corresponding to the target structural element in the first keyword set into second category of keywords to obtain a second keyword set;
[0008] Generate text prompt information based on the second keyword set, and call a preset target large language model to process the text prompt information to obtain a first database operation statement returned by the target large language model, wherein the first database operation statement includes the second category of keywords;
[0009] Reverse-translate the second-category keywords in the first database operation statement into the first-category keywords to obtain a second database operation statement;
[0010] A database storing the data table is queried based on the second database operation statement to obtain a query result, second text information is generated based on the query result, and the second text information is displayed on the target interface.
[0011] In combination with the first aspect, in some possible implementations, the step of escaping the first category of keywords corresponding to the target structural element in the first keyword set into second category keywords to obtain the second keyword set includes: obtaining a keyword escape table, wherein the keyword escape table records a mapping relationship between the first category of keywords and the second category of keywords; based on the keyword escape table, escaping the first category of keywords corresponding to the target structural element in the first keyword set into second category keywords to obtain the second keyword set; the step of escaping the second category of keywords in the first database operation statement into the first category of keywords to obtain the second database operation statement includes: based on the keyword escape table, escaping the second category of keywords in the first database operation statement into the first category of keywords to obtain the second database operation statement.
[0012] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, determining at least one target structural element among multiple structural elements of the data table to be queried includes: determining the table name as the target structural element among the multiple structural elements of the data table; and / or determining a preset sensitive field name as the target structural element among the multiple structural elements of the data table.
[0013] In combination with the first aspect and the above-mentioned implementation manner, in some possible implementation manners, the calling a preset target large language model to process the text prompt information to obtain a first database operation statement returned by the target large language model includes: calling a preset target large language model to process the text prompt information to obtain a third database operation statement returned by the target large language model; if the third database operation statement does not meet a preset verification condition and the number of calls to the target large language model does not reach a preset call number threshold, updating the text prompt information based on the third database operation statement so that the updated text prompt information includes the corrected prompt information corresponding to the third database operation statement, and returning to execute the calling of the preset target large language model to process the text prompt information to obtain the third database operation statement returned by the target large language model; if the third database operation statement meets the preset verification condition, determining the third database operation statement as the first database operation statement.
[0014] In combination with the first aspect and the above-mentioned implementation manner, in some possible implementation manners, the verification condition includes a first verification condition, a second verification condition, and a third verification condition; after the calling of the preset target large language model to process the text prompt information and obtaining the third database operation statement returned by the target large language model, it also includes: if the third database operation statement conforms to the user's operation authority on the database, it is determined that the third database operation statement satisfies the first verification condition; if the third category of keywords in the third database operation statement are consistent with the first category of keywords after negation, it is determined that the third database operation statement satisfies the second verification condition, wherein the third category of keywords is obtained by the target large language model processing the second category of keywords in the text prompt information; if the operation type of the third database operation statement on the database is a data query operation, it is determined that the third database operation statement satisfies the third verification condition.
[0015] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, generating text prompt information based on the second keyword set includes: obtaining a text prompt template, wherein the text prompt template includes a scene description, a database operation statement structure prompt, and multiple placeholders, and the placeholders are divided into table name placeholders, field name placeholders, and query modifier placeholders; filling the keywords in the second keyword set into the placeholders in the text prompt template respectively to obtain the text prompt information.
[0016] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the filling of the keywords in the second keyword set into the placeholders in the text prompt template to obtain the text prompt information includes: if there are fourth-category keywords in the second keyword set, there are multiple target field names in the data table, and the data of the fourth-category keywords are calculated based on a preset algorithm for the data of each of the multiple target field names, then in the second keyword set, the fourth-category keywords are converted into fifth-category keywords corresponding to each of the target field names, and sixth-category keywords corresponding to the query modifiers constructed based on the preset algorithm are added to obtain a third keyword set; the keywords in the third keyword set are filled into the placeholders in the text prompt template to obtain the text prompt information.
[0017] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the step of obtaining a first keyword set from the first text information in response to the first text information input by the user in the target interface includes: obtaining intent information from the first text information in response to the first text information input by the user in the target interface; if the intent information is a data query intent, obtaining the first keyword set from the first text information.
[0018] In a second aspect, a data query device is provided, the device comprising:
[0019] an acquisition unit, configured to acquire a first keyword set from first text information input by a user on a target interface;
[0020] A determination unit, used to determine at least one target structural element among a plurality of structural elements of the data table to be queried, wherein the structural elements are divided into table names and field names;
[0021] a translation unit, configured to translate the first category of keywords corresponding to the target structural element in the first keyword set into second category of keywords to obtain a second keyword set;
[0022] a calling unit, configured to generate text prompt information based on the second keyword set, and call a preset target large language model to process the text prompt information to obtain a first database operation statement returned by the target large language model, wherein the first database operation statement includes the second category of keywords;
[0023] a reverse semantics unit, configured to reverse semantics of the second category of keywords in the first database operation statement into the first category of keywords, so as to obtain a second database operation statement;
[0024] A query unit is used to query the database storing the data table based on the second database operation statement to obtain a query result, generate second text information based on the query result, and display the second text information on the target interface.
[0025] In a third aspect, a computer-readable storage medium is provided, which stores a computer program code. When the computer program code runs on a computer, the computer executes the method in the first aspect or any possible implementation of the first aspect.
[0026] According to a fourth aspect, an electronic device is provided, comprising: a processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the steps of the above method.
[0027] In a fifth aspect, a computer program product is provided, which includes: a computer program code, which, when executed on a computer, enables the computer to execute the method in the first aspect or any possible implementation of the first aspect.
[0028] Based on the embodiments of this specification, first, the user only needs to input a simple first text message in the target interface to trigger subsequent data queries, without the need for the user to master complex database query syntax, which lowers the threshold for use and improves the convenience of data queries. Secondly, by translating the first category of keywords in the first keyword set into the second category of keywords corresponding to the target structural elements, text prompt information is generated based on the second keyword set, and the target large language model can be safely called in combination with the text prompt information. Finally, after obtaining the first database operation statement returned by the target large language model, the second database operation statement can be reversed to obtain the second database operation statement. The query and subsequent processing are based on the second database operation statement, and the second text information generated based on the query results can be displayed on the target interface. Through the above scheme, the convenience and flexibility of data query can be taken into account, and the user experience is effectively improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 This is an application scenario diagram of a data query method provided by an embodiment of this specification;
[0030] Figure 2 It is a flowchart of a data query method provided by an embodiment of this specification;
[0031] Figure 3 It is a flowchart of a data query method provided by an embodiment of this specification;
[0032] Figure 4 It is a flowchart of calling a target large language model provided by an embodiment of this specification;
[0033] Figure 5 This is a flowchart of generating text prompt information provided by an embodiment of this specification;
[0034] Figure 6 is a schematic diagram of a process for obtaining a first keyword set provided by an embodiment of this specification;
[0035] Figure 7 It is a swimming lane diagram of a data query provided by an embodiment of this specification;
[0036] Figure 8 It is a structural diagram of a data query device provided in an embodiment of this specification;
[0037] Fig. 9It is a structural schematic diagram of an electronic device provided in an embodiment of this specification. DETAILED DESCRIPTION
[0038] The technical solutions in this specification will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of this specification, unless otherwise specified, " / " means or, for example, A / B can mean A or B: "and / or" in the text 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 mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of this specification, "multiple" means two or more than two.
[0039] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.
[0040] In the related art, there are two main ways to query data in the database:
[0041] The first method is to integrate the query statement into the UI control. For example, the UI control can be a virtual button. Users can trigger the corresponding data query action by clicking these virtual buttons to obtain the required data. Although this method provides convenience for users, it requires developers to prepare relevant UI controls in advance, which actually limits its application capabilities in various user scenarios.
[0042] Method 2 requires users to master the relevant knowledge of database query statements and manually enter the query statement in the database query input box to obtain the required data. Although this method provides high flexibility and allows users to customize query statements according to actual needs, it also places high demands on users, that is, users must have certain database query knowledge and need to manually enter query statements, which undoubtedly brings inconvenience to users.
[0043] Simply put, the technology for users to query data in databases faces the problem of finding a balance between convenience and flexibility.
[0044] In response to the problems in the related art, the embodiments of this specification propose: First, the user only needs to input a simple first text message in the target interface to trigger subsequent data queries, without the need for the user to master complex database query syntax, which lowers the usage threshold and improves the convenience of data queries. Secondly, by translating the first category of keywords in the first keyword set into the second category of keywords corresponding to the target structural elements, text prompt information is generated based on the second keyword set, and the target large language model can be safely called in combination with the text prompt information. Finally, after obtaining the first database operation statement returned by the target large language model, the second database operation statement can be obtained by reverse translation. The query and subsequent processing based on the second database operation statement can display the second text information generated based on the query results on the target interface. Through the above scheme, the convenience and flexibility of data query can be taken into account, and the user experience is effectively improved.
[0045] See also Figure 1 , Figure 1 This is an application scenario diagram of a data query method provided by an embodiment of this specification. Figure 1 As shown, the data query method provided in the embodiment of this specification can be applied to an electronic device, and the electronic device can be a device with a data query function, such as a personal computer, a smart phone, a tablet computer, a server, etc. The electronic device provides a target interface, and the user can enter a first text message in the target interface, and the first text message indicates the content that the user needs to query. After a series of processing processes based on the first text message, the target interface will display a second text message, and the second text message contains the content that the user needs to query.
[0046] by Figure 1 For example, the first text message includes the text content "Please help me with the number of impressions and clicks of advertising project A"; the second text message includes the text content "OK, according to your requirements, the following results are found: advertising project A; the number of impressions is 5678 times; the number of clicks is 1234 times".
[0047] based on Figure 1 The application scenario shown below will be combined with Figure 2 - Figure 7 , the data query method provided in the embodiments of this specification is introduced in detail.
[0048] See also Figure 2 , is a flow chart of a data query method provided in the embodiment of this specification. Figure 2 As shown, the method of the embodiment of this specification may include the following steps S102 to S114.
[0049] S102: In response to first text information input by a user on a target interface, obtaining a first keyword set from the first text information.
[0050] Specifically, the target interface involved in this embodiment can support at least one input method, such as an input box, voice input or other input methods, to ensure that the user can easily input the first text information on the target interface.
[0051] The first text information input by the user is often a colloquial expression, which may include daily language, industry terms or phrases with specific meanings. In addition, the first text information may express multiple intentions of the user.
[0052] Before performing a data query, it is first necessary to determine the user's true intention. In a possible implementation, the first text information can be analyzed and processed to determine whether the user's intention is a data query intention. In a possible implementation, in response to a specific operation of the user on the target interface, it is determined whether the user's intention is a data query intention. For example, the user clicks a "query data" virtual button on the target interface, thereby clarifying that the user's intention is a data query intention.
[0053] In response to the first text information input by the user in the target interface, and determining the user's data query intention, keywords can be extracted from the first text information to form a first keyword set. These keywords are closely related to the industry in which the user is located. Taking the advertising industry as an example, if the user is an advertising agency, they may want to query the relevant data of the advertising project or the advertising effect. Therefore, the first text information may contain advertising industry-related terms such as "number of impressions", "number of clicks", "consumption events", "conversion rate", etc. In order to accurately extract these industry-related keywords, in a possible implementation method, a pre-trained auxiliary large language model can be used to extract keywords from the first text information to obtain a first keyword set. It can be understood that the auxiliary large language model is a model based on deep learning. Through the input and learning of a large amount of advertising industry text, it gradually masters the characteristics of industry terms and keywords. Once the training is completed, the auxiliary large language model can quickly and accurately identify keywords related to the advertising industry.
[0054] It should be noted that the above application in the advertising industry is only an example, and the solution of this embodiment can also be applied to the education industry, medical industry or other industries.
[0055] S104, determining at least one target structural element among multiple structural elements of the data table to be queried, wherein the structural elements are divided into table names and field names.
[0056] Specifically, a data table is a structure used to store data in a database, which consists of rows and columns. The table name of a data table is its unique identifier in the database. In a data table, each row represents a record, and each column represents a field in a record. A field is the basic unit used to store a specific type of data in a data table, and it has a unique field name for identification and reference. In the data table to be queried, the table name is a structural element, and any field name is also a structural element.
[0057] The data in the database usually has security requirements, and some sensitive table names or field names should not be disclosed. Therefore, in order to ensure that sensitive table names or field names are not disclosed in the process of calling the target large language model, it is necessary to predetermine at least one target structure element, which is used to guide keyword escape. For example, the table name of the data table is determined as the target structure element; or, the table name and at least one field name of the data table are determined as the target structure element; or, at least one field name of the data table is determined as the target structure element.
[0058] S106: Translate the first category keywords corresponding to the target structural element in the first keyword set into second category keywords to obtain a second keyword set.
[0059] Specifically, the first category of keywords involved in this embodiment refers to keywords in the first keyword set that directly correspond to the target structural element, and the first category of keywords includes sensitive table names or field names. The second category of keywords are keywords that have been escaped, and it is understandable that the second category of keywords will not directly reflect sensitive table names or field names, so they will not leak sensitive information, but can play the same role as the first category of keywords in constructing database operation statements.
[0060] S108: Generate text prompt information based on the second keyword set.
[0061] Specifically, the text prompt information involved in this embodiment is used to prompt the target large language model to construct a database operation statement that is compatible with the user's data query intention. Therefore, the text prompt information at least includes keywords in the second keyword set, and text content used to prompt the target large language model to construct a database operation statement based on the keywords in the second keyword set.
[0062] In a possible implementation, the keywords in the second keyword set are filled into a preset text prompt template to obtain text prompt information. This method provides a structured approach to generate text prompt information, ensuring the integrity and accuracy of the information, so that the generated text prompt information is grammatical and logical.
[0063] In a possible implementation, natural language processing technology is used to convert the keywords in the second keyword set into text prompt information that is close to human language expression. This method can generate more understandable text prompt information, which helps the target large language model to more accurately capture the user's data query intention. Through natural language processing technology, we can perform semantic analysis and grammatical adjustments on keywords, so that the generated text prompts are more in line with human language habits.
[0064] In a possible implementation, a pre-trained deep learning model can be used to receive keywords in the second keyword set as input and output text prompt information. It is understandable that the deep learning model needs to be iteratively trained based on a training set containing keyword samples and text prompt information samples, and after iterative training, it learns the ability to generate text prompt information based on keywords and has a certain generalization ability.
[0065] S110, calling a preset target large language model to process the text prompt information to obtain a first database operation statement returned by the target large language model, wherein the first database operation statement includes the second category of keywords.
[0066] Specifically, in the process of calling the target large language model, the text prompt information can be passed as a parameter to the calling API (Application Programming Interface) of the target large language model. After receiving the text prompt information, the target large language model will process the text prompt information. Finally, the target large language model will return the constructed first database operation statement, which contains the second category of keywords.
[0067] It should be noted that the reason why the target large language model can process text prompt information, construct and return database operation statements is mainly due to its powerful natural language processing capabilities and deep learning mechanism. The target large language model is trained based on massive text data. It has mastered rich language knowledge and structure and can accurately understand the contextual prompt content in text prompt information.
[0068] In some possible implementations, by fine-tuning the parameters of the target large language model, the ability of the target large language model in constructing database operation statements can also be improved.
[0069] In some possible implementations, the target large language model is a large language model for public use, such as ChatGPT (optional versions include version 3.5, version 4.0 or higher).
[0070] S112, reverse the meaning of the second category keywords in the first database operation statement into the first category keywords to obtain a second database operation statement.
[0071] Specifically, since the second-category keywords do not directly reflect the table name or field name in the data table, the first database operation statement cannot be directly used for data query, and the second-category keywords in the first database operation statement need to be reversed to the first-category keywords to obtain the second database operation statement containing the first-category keywords. The first-category keywords directly reflect the table name or field name in the data table, so the second database operation statement can be directly used for data query.
[0072] The unseparation method in step S112 needs to correspond to the escape method in step S106.
[0073] In combination with the above step S106, the following are optional escape and un-escape methods:
[0074] Method 1: Based on the preset keyword escape table, escape the first category keywords into the second category keywords. When the reverse meaning is needed, reverse the second category keywords into the first category keywords based on the keyword escape table.
[0075] Method 2: Use a preset escape function to escape the first category keywords into the second category keywords. When the escape function is needed, the corresponding escape function can be used to escape the second category keywords into the first category keywords.
[0076] Method 3: Use preset encoding rules (such as 64-bit basic encoding, referred to as Base64 encoding) to escape the first category keywords into the second category keywords. When reverse interpretation is required, the corresponding decoding rules (such as 64-bit basic decoding, referred to as Base64 decoding) can be used to reverse the second category keywords into the first category keywords.
[0077] It is understandable that the above-mentioned escape and reverse escape methods are only examples. In fact, other escape and reverse escape methods can also be used, which are not listed here one by one.
[0078] S114, querying a database storing a data table based on the second database operation statement to obtain a query result, generating second text information based on the query result, and displaying the second text information on the target interface.
[0079] Specifically, firstly, a connection is established with the database based on predetermined database connection information, wherein the database connection information includes the address, port number, user name, and password of the database. Then, the constructed second database operation statement is executed on the database, and the second database operation statement should clearly specify the data table (indicated by the table name), the field (indicated by the field name) to be queried, and other possible query conditions (indicated by the query modifier).
[0080] After the second database operation statement is executed, the query result will be obtained. The query result includes the data that the user wants to query. It is understandable that the query result exists in the form of a data set, which, although accurate and structured, may appear rough and difficult to understand for ordinary users.
[0081] To this end, the second text information may be generated based on the query result. The following is an optional method for generating the second text information:
[0082] Method 1: Generate the second text information by defining a second text template and filling the query result into the second text template as a variable.
[0083] Method 2: Use natural language processing technology to convert the query results into second text information described in natural language.
[0084] Method three: Dynamically splice the query results into the second text information through a pre-written dynamic splicing program.
[0085] It is understandable that the above second text information generation method is only an example, and other second text information generation methods can actually be used, which are not listed here one by one.
[0086] After the second text information is generated, the second text information can be further displayed on the target interface, and the second text information clearly shows the data that the user needs to query.
[0087] It should be noted that the database operation statements appearing in this embodiment can be constructed based on SQL (Structured Query Language), PL / SQL (Procedural Language extensions to SQL), NoSQL (Not Only SQL, non-relational database query language) or other languages, without limitation.
[0088] In this embodiment, first, the user only needs to input a simple first text message in the target interface to trigger subsequent data queries, without the need for the user to master complex database query syntax, which reduces the threshold for use and improves the convenience of data queries. Secondly, by translating the first category of keywords in the first keyword set into the second category of keywords corresponding to the target structural elements, text prompt information is generated based on the second keyword set, and the target large language model can be safely called in combination with the text prompt information. Finally, after obtaining the first database operation statement returned by the target large language model, the second database operation statement can be reversed to obtain the second database operation statement. The query and subsequent processing based on the second database operation statement can display the second text information generated based on the query result on the target interface. Through the above scheme, the convenience and flexibility of data query can be taken into account, and the user experience is effectively improved.
[0089] See also Figure 3 , which is a flow chart of a data query method provided in an embodiment of the present application, such as Figure 3 As shown, the method of the embodiment of the present application may include the following steps S201-S216.
[0090] S202: In response to first text information input by a user in a target interface, obtain a first keyword set from the first text information.
[0091] For details, see the implementation of step S202. Figure 2 The explanation of step S102 in the illustrated embodiment will not be repeated here.
[0092] S204, determining a table name as a target structure element among multiple structure elements of the data table to be queried; and / or determining a preset sensitive field name as a target structure element among multiple structure elements of the data table; wherein the structure elements are divided into table names and field names;
[0093] Specifically, the data in the database usually has security requirements, and some sensitive table names or field names should not be disclosed. Therefore, in order to ensure that sensitive table names or field names are not disclosed in the process of calling the target large language model, it is necessary to determine in advance at least one target structural element among the multiple structural elements of the data table to be queried, and the target structural element is used to guide keyword escape. For example, the table name of the data table is determined as the target structural element; or, the table name of the data table and at least one sensitive field name are determined as the target structural element; or, at least one sensitive field name of the data table is determined as the target structural element. It can be understood that the sensitive field names are predetermined, and all the field names in the above data table may be sensitive field names; or only some of the field names may be sensitive field names, while other field names are not sensitive field names.
[0094] To facilitate understanding of the solution of this embodiment, an example based on an advertisement delivery scenario is provided below:
[0095] Suppose there is a data table named "Advertising", which contains static fields and dynamic fields. Static fields generally do not change during the implementation of an advertising project, such as the advertising project ID, the merchant ID that commissions advertising, and the advertising billing model. Dynamic fields generally change during the implementation of an advertising project, such as the number of impressions, number of clicks, consumption amount, conversion events, etc.
[0096] According to step S204, in this "advertising placement" data table, the table name "advertising placement" can be determined as a target structure element. At the same time, considering the security of the data, some sensitive field names can also be determined as target structure elements. For example, "merchant identifier for entrusted advertising placement" is a sensitive field name because it may involve the merchant's privacy information. Therefore, before calling the target large language model for query, the table name "advertising placement" and the sensitive field name "merchant identifier for entrusted advertising placement" need to be transferred to ensure that these sensitive information will not be leaked.
[0097] S206, obtaining a keyword escape table, wherein the keyword escape table records a mapping relationship between the first category of keywords and the second category of keywords;
[0098] S208: Translate the first category of keywords corresponding to the target structural element in the first keyword set into second category of keywords based on the keyword translation table to obtain a second keyword set.
[0099] Specifically, this embodiment introduces a pre-set keyword escape table. Before transferring the keyword, it is necessary to obtain the keyword escape table.
[0100] In a possible implementation, the keyword escape table includes at least two columns, one of which is used to store first-category keywords and the other is used to store corresponding second-category keywords. In other words, each row in the keyword escape table represents a mapping relationship, characterizing the association between a first-category keyword and a second-category keyword.
[0101] Furthermore, the first keyword set is traversed, and for any keyword traversed, if the keyword is a first-category keyword corresponding to the target structural element, the corresponding second-category keyword is found according to the keyword escape table, and the second-category keyword is added to the second keyword set; if the keyword is not a first-category keyword corresponding to the target structural element, the keyword is directly added to the second keyword set without being escaped.
[0102] In this way, it can be ensured that all first-category keywords corresponding to the target structural elements are safely converted to second-category keywords, while other non-sensitive keywords remain unchanged. Finally, the obtained second keyword set will be used for subsequent data query and processing, thereby achieving flexible query and utilization of data without leaking sensitive information.
[0103] S210, generating text prompt information based on the second keyword set;
[0104] S212, calling a preset target large language model to process the text prompt information, and obtaining a first database operation statement returned by the target large language model, wherein the first database operation statement includes the second category of keywords.
[0105] Specifically, the implementation of step S210 and step S212 is shown in Figure 2 The explanation of step S108 and step S110 in the illustrated embodiment will not be repeated here.
[0106] S214: reverse the translation of the second category keywords in the first database operation statement into the first category keywords based on the keyword translation table to obtain a second database operation statement.
[0107] Furthermore, all keywords in the first database operation statement are traversed, and for any keyword traversed, if the keyword is a second-category keyword, the corresponding first-category keyword is found according to the keyword escape table, and the keyword is replaced with the corresponding first-category keyword in the first database operation statement; if the keyword is not a second-category keyword, the keyword is directly retained in the first database operation statement. After traversing all keywords in the first database operation statement, in fact, all second-category keywords in the first database operation statement are replaced with corresponding first-category keywords, that is, the second database operation statement is obtained.
[0108] In this way, it can be ensured that the second-category keywords in the second database operation statement are safely reversed to the first-category keywords. The first-category keywords can directly reflect the table name or field name of the data table, so the second database operation statement can be used for query operations.
[0109] S216, querying a database storing a data table based on the second database operation statement to obtain a query result, generating second text information based on the query result, and displaying the second text information on the target interface.
[0110] For details, see the implementation of step S216. Figure 2 The explanation of step S114 in the illustrated embodiment will not be repeated here.
[0111] In this embodiment, firstly, by introducing a keyword escape table, the safe escape of sensitive first-category keywords is achieved, which effectively prevents the leakage of sensitive information when calling the target large language model for query, and enhances the security of data. Secondly, the convenience and flexibility of data query are taken into account. Users only need to enter simple first text information in the target interface to trigger the subsequent data query process, without having to master complex database query syntax, which reduces the threshold for use. At the same time, by generating easy-to-understand second text information and displaying it in the target interface, users can clearly obtain the required data, further improving user satisfaction and usage experience.
[0112] See also Figure 4 , provides a flow chart of calling a target large language model in an embodiment of the present application. Among them, the verification condition includes a first verification condition, a second verification condition, and a third verification condition. Figure 4 As shown, the method of the embodiment of the present application may include the following steps S301-S312, wherein steps S301-S312 may be used as Figure 2 The refinement of step S110 in the illustrated embodiment.
[0113] S302, calling a preset target large language model to process the text prompt information, and obtaining a third database operation statement returned by the target large language model.
[0114] Specifically, the method of calling the target large language model in step S302 can be found in Figure 2 The explanation of step S110 in the illustrated embodiment is not repeated here. It is worth noting that after calling the target large language model to process the text prompt information, the target large language model returns a third database operation statement, wherein the third database operation statement is an unverified database operation statement, which may have problems such as excessive operation permissions, table name errors, field name errors, and injection attacks against the database.
[0115] After step S302 is executed, step S304, step S306, and step S308 are respectively executed to verify whether the third database operation statement meets the first verification condition, the second verification condition, and the third verification condition.
[0116] S304: If the third database operation statement complies with the user's database operation authority, determine that the third database operation statement meets the first verification condition; if the third database operation statement does not comply with the user's database operation authority, determine that the third database operation statement does not meet the first verification condition.
[0117] Specifically, the database involved in this embodiment may store data of multiple different users. For the data query behavior of the current user, it is necessary to obtain the user's operation authority for the database, and verify whether the third database operation statement complies with the user's operation authority for the database. Among them, the user's operation authority for the database refers to the scope and restrictions of a series of operations that the user is authorized to perform in the database. Specifically, the user's operation authority for the database defines the specific content of the data that the user can query, modify, delete or insert, including the data table that the user can access and the specific fields in the data table.
[0118] If the data tables and fields involved in the third database operation statement are consistent with the data tables and specific fields in the data tables that the user can access as defined by the user's database operation permissions, then it can be determined that the third database operation statement meets the first verification condition. Conversely, if the data tables and fields involved in the third database operation statement do not meet the data tables and specific fields in the data tables that the user can access as defined by the user's database operation permissions, then it can be determined that the third database operation statement does not meet the first verification condition.
[0119] S306, if the third category of keywords in the third database operation statement are consistent with the first category of keywords after the reverse meaning, it is determined that the third database operation statement meets the second verification condition, wherein the third category of keywords are obtained by processing the second category of keywords in the text prompt information by the target large language model; if the third category of keywords in the third database operation statement are inconsistent with the first category of keywords after the reverse meaning, it is determined that the third database operation statement does not meet the second verification condition.
[0120] Specifically, the third database operation statement is obtained by processing the text prompt information by the target large language model. Ideally, the third database operation statement should completely include the second category of keywords in the text prompt information. However, due to the complexity of the target large language model and the limitations of the training data, the target large language model may introduce some errors when processing the text prompt information. These errors may cause the second category of keywords to be changed in the generated third database operation statement, such as synonym replacement, semantic approximation or format adjustment. Therefore, in order to ensure accuracy, the third database operation statement needs to be further verified.
[0121] More specifically, in the third database operation statement, the third category keywords are obtained by processing the second category keywords in the text prompt information by the target large language model, so the keywords at the position where the second category keywords should be stored are the third category keywords. If the first category keywords are obtained after the third category keywords are reversed (that is, the third category keywords are consistent with the first category keywords after the reversed meaning), then it can be determined that the third database operation statement meets the second verification condition; if the first category keywords cannot be obtained after the third category keywords are reversed (that is, the third category keywords are inconsistent with the first category keywords after the reversed meaning), then it can be determined that the third database operation statement does not meet the second verification condition.
[0122] S308: If the operation type of the third database operation statement on the database is a data query operation, determine that the third database operation statement meets the third verification condition; if the operation type of the third database operation statement on the database is not a data query operation, determine that the third database operation statement does not meet the third verification condition.
[0123] Specifically, an injection attack against a database refers to inserting malicious database operation codes to trick the database into performing unauthorized operations. These malicious codes may be spliced into legitimate query statements, thereby bypassing identity authentication and accessing, modifying, or deleting data in the database. In order to prevent injection attacks against a database, it is necessary to verify the operation type of the third database operation statement.
[0124] More specifically, the third database operation statement is analyzed. If the operation type of the third database operation statement on the database is a data query operation, then it can be determined that the third database operation statement meets the third verification condition; if the operation type of the third database operation statement on the database is a data insertion operation, a data deletion operation or other operations, rather than a data query operation, then it can be determined that the third database operation statement does not meet the third verification condition.
[0125] To facilitate understanding of the present embodiment, examples of step S304, step S306, and step S308 are provided below:
[0126] For the example of step S304: Assume that the current user can only query the two fields of "displays" and "clicks" in the "advertising" data table, where "advertising", "displays" and "clicks" are all first-category keywords expressed in Chinese. If the third database operation statement is "SELECT show,click FROM ad WHERE adid='ABC';", where "show" represents "displays", "click" represents "clicks", "ad" represents "advertising", and "adid" represents "advertising project identifier", it can be seen that this third database operation statement complies with the user's operating permissions for the database (only specific fields can be queried), and therefore meets the first verification condition. If the third database operation statement is "SELECT*FROM ad;", then this third database operation statement attempts to query all fields, which exceeds the user's operating permissions, and therefore does not meet the first verification condition.
[0127] For the example of step S306: Assume that the second-category keyword in the text prompt information is "show", and "show" represents the first-category keyword "number of displays". Ideally, the third database operation statement should contain "show". If the third database operation statement is "SELECT show FROM ad WHERE adid='ABC';", the third-category keyword "show" is obtained by processing the second-category keyword "show" by the target large language model, and can be associated with the first-category keyword "number of displays" after reverse meaning, so the second verification condition is met. If the third database operation statement is "SELECT shov FROM ad WHERE adid='ABC';", the third-category keyword "shov" is obtained by processing the second-category keyword "show" by the target large language model. Obviously, an error occurred during the processing, and the third-category keyword "shov" cannot be reversed to obtain the first-category keyword "number of displays", so the second verification condition is not met.
[0128] For example of step S308: If the third database operation statement is "SELECT show FROM ad WHERE adi d = 'ABC';", this is a data query operation, and therefore the third verification condition is satisfied. If the third database operation statement is "INSERT INTO ad(show) VALUES(100);", this is a data insertion operation, not a data query operation, and therefore the third verification condition is not satisfied.
[0129] After step S304, step S306, and step S308 are all executed, step S310 or step S312 is selectively executed.
[0130] S310: If the third database operation statement does not meet the preset verification condition, and the number of calls to the target large language model does not reach the preset call number threshold, the text prompt information is updated based on the third database operation statement, so that the updated text prompt information includes the corrected prompt information corresponding to the third database operation statement, and the call to the preset target large language model is returned to process the text prompt information, so as to obtain the third database operation statement returned by the target large language model.
[0131] Specifically, when the third database operation statement fails to pass any of the verification conditions in steps S304, S306, and S308, it is necessary to further determine whether the number of calls to the target large language model has reached a preset call number threshold. The preset call number threshold is used to prevent the target large language model from being called in an infinite loop without being able to obtain a database operation statement that meets all the verification conditions. If the number of calls does not reach the preset call number threshold, the text prompt information can be updated based on the current third database operation statement.
[0132] The goal of the update process is to make the text prompt information contain more context information or to modify the prompt information so that the target large language model can generate a more accurate database operation statement the next time it is processed. The modified prompt information can indicate that the third database operation statement generated this time needs to be modified, which helps the target large language model to better understand the updated text prompt information and generate a third database operation statement that meets the verification conditions.
[0133] After the update process of the text prompt information is completed, the target large language model is called again to process the updated text prompt information and obtain a new third database operation statement. This new third database operation statement will be verified again through step S304, step S306, and step S308 until it meets all preset verification conditions or the number of calls to the target large language model reaches a preset call number threshold.
[0134] It is understandable that if the number of calls to the target large language model reaches the preset call number threshold and the third database operation statement that satisfies all verification conditions is not obtained, then the relevant abnormal prompt information can be displayed on the user interface. Among them, the abnormal prompt information can prompt that the query cannot be made, the query is abnormal, or prompt the user to re-enter the first text information.
[0135] S312: If the third database operation statement meets a preset verification condition, determine the third database operation statement as the first database operation statement.
[0136] Specifically, when the third database operation statement passes verification in steps S304, S306, and S308, it can be considered that the third database operation statement is safe and meets the user's data query intention. At this time, the third database operation statement can be determined as the first database operation statement.
[0137] In this embodiment, through the first verification condition, that is, verifying whether the third database operation statement complies with the user's operation authority on the database, unauthorized data access and operation are effectively prevented, and data security is enhanced. The second verification condition ensures that the third category of keywords in the third database operation statement can be consistent with the original first category of keywords after reverse meaning, avoiding errors that may be introduced by the target large language model during the processing process, and improving the accuracy of data query. The third verification condition limits the operation type of the third database operation statement to data query operation, effectively preventing injection attacks on the database, and further improving the security of the database. In summary, in the process of calling the target large language model to perform database query, the scheme of this embodiment introduces multiple verification conditions, which can significantly improve the security and accuracy of data query.
[0138] See also Figure 5 , provides a schematic diagram of a process for generating text prompt information in an embodiment of the present application, such as Figure 5 As shown, the method of the embodiment of the present application may include the following steps S402-S404, wherein steps S402-S404 may be used as Figure 2 The refinement of step S108 in the illustrated embodiment.
[0139] S402, obtaining a text prompt template, wherein the text prompt template includes a scenario description, a database operation statement structure prompt, and a plurality of placeholders, wherein the placeholders are divided into a table name placeholder, a field name placeholder, and a query modifier placeholder;
[0140] S404: Fill the keywords in the second keyword set into the placeholders in the text prompt template respectively to obtain text prompt information.
[0141] Specifically, the text prompt template involved in this embodiment is a preset structured text, which includes a scenario description, a structural prompt of a database operation statement, and a plurality of placeholders. The scenario description is a general description of the database operation that the user wants to perform, which helps the target large language model understand the context in which the user wants to perform the database operation. The structural prompt of the database operation statement provides a general statement framework to guide the target large language model on how to construct the database operation statement. Placeholders are special positions in the text prompt template, which are used to be replaced by specific keywords in subsequent steps to form complete text prompt information.
[0142] In the text prompt template, placeholders are divided into three types: table name placeholders, field name placeholders, and query modifier placeholders. Table name placeholders are used to indicate which data table the database operation will be performed on; field name placeholders are used to indicate which fields in the data table the operation will involve; query modifier placeholders are used to provide additional query conditions or operation modifications, such as sorting, grouping, etc.
[0143] Further, the keywords in the second keyword set provided by the user are respectively filled into the placeholders in the text prompt template, thereby obtaining complete text prompt information. It can be understood that the keywords in the second keyword set represent the data tables, fields and possible query modifiers that the user wants to query.
[0144] During the filling process, appropriate keywords are filled into corresponding placeholders according to the type of placeholder and the semantics of the keywords in the second keyword set. For example, the keyword representing the table name of the data table is filled into the table name placeholder, the keyword representing the field name is filled into the field name placeholder, and the keyword representing the query modifier is filled into the query modifier placeholder. In this way, the text prompt template is converted into a specific text prompt information that reflects the user's data query intention.
[0145] In a possible implementation, the above step S404 is further refined to include the following steps:
[0146] If there are fourth-category keywords in the second keyword set, there are multiple target field names in the data table, and the data of the fourth-category keywords are calculated based on a preset algorithm for the data of each target field name in the multiple target field names, then in the second keyword set, the fourth-category keywords are converted into fifth-category keywords corresponding to each target field name, and sixth-category keywords corresponding to the query modifiers constructed based on the preset algorithm are added to obtain a third keyword set;
[0147] The keywords in the third keyword set are respectively filled into the placeholders in the text prompt template to obtain text prompt information.
[0148] Specifically, if the second keyword set includes fourth-category keywords, and there are multiple target field names in the data table, and the data of these fourth-category keywords are obtained by calculating the data of each target field name in the multiple target field names based on a preset algorithm, then a series of processing operations are required.
[0149] First, in the second keyword set, these fourth-category keywords are converted. The goal of the conversion is to replace them with fifth-category keywords corresponding to the target field names. These fifth-category keywords actually represent specific field names in the data table, which are directly related to the calculation results of the fourth-category keywords.
[0150] Secondly, in addition to the conversion of keywords, new keywords need to be added to the second keyword set. These new keywords are the sixth category keywords corresponding to the query modifiers constructed based on the preset algorithm. Query modifiers play an important role in database operations. They can specify how to perform calculation operations on data. By adding this type of sixth category keywords, necessary calculation instructions can be provided for subsequent database operations.
[0151] After completing the above conversion and addition operations, a new keyword set is obtained, namely the third keyword set. The keywords in the third keyword set include both the fifth category keywords that directly correspond to the field names of the data table and the sixth category keywords corresponding to the query modifiers built based on the preset algorithm. The third keyword set provides a complete and accurate data basis for generating text prompt information.
[0152] Finally, the keywords in the third keyword set are respectively filled into the placeholders in the text prompt template. The text prompt template is a preset structured text, which contains a scenario description, a structural prompt of a database operation statement, and multiple placeholders. These placeholders play the role of marking positions in the text prompt template, and they will be replaced by specific keywords in subsequent steps. By filling the keywords in the third keyword set into these placeholders, a complete text prompt information that reflects the user's data query intention can be obtained.
[0153] To facilitate understanding of this embodiment, an example is provided below:
[0154] Assume that the user wants to query the click-through rate of a certain advertising item in the "Advertising Delivery" data table. The fourth-category keyword corresponding to the click-through rate is "ClickRate", and this click-through rate is calculated based on the data corresponding to the target field names "Number of Impressions" and "Number of Clicks" in the "Advertising Delivery" data table. Then, the fourth-category keyword "ClickRate" can be replaced with the fifth-category keyword "show" corresponding to the target field name "Number of Impressions" and the fifth-category keyword "click" corresponding to the target field name "Number of Clicks".
[0155] Add the sixth category keywords " / " and "AS" corresponding to the query modifier built based on the preset algorithm (clicks divided by impressions equals click-through rate), where " / " is used to perform the calculation of clicks divided by impressions, and "AS" is used to name the calculation result "ClickRate". Fill these keywords into the placeholders in the text prompt template to get a complete text prompt information.
[0156] Based on this text prompt information, a simple database query statement can be generated to query the click rate, specifically: "SELECT click / show AS ClickRate FROM ad WHERE adid='ABC';", where "ad" represents the table name "advertising placement" and "adid" represents the field name "advertising project identifier".
[0157] In this database query statement, "click" and "show" correspond to the "Number of Clicks" and "Number of Shows" fields in the data table, and "ClickRate" is the calculated click rate. Through this database query statement, even if there is no field in the database that directly represents the click rate, you can still query and obtain data related to the click rate.
[0158] In this embodiment, by converting the fourth category of keywords into the fifth category of keywords corresponding to the target field name, it is ensured that the text prompt information can accurately reflect the specific field that the user wants to query, avoiding query errors caused by keyword mismatches. At the same time, by adding the sixth category of keywords corresponding to the query modifiers built based on the preset algorithm, the content of the text prompt information is enriched, so that it can contain complex calculation logic and query modifiers, thereby supporting the generation of more complex database query statements and meeting the user's diverse data query needs. In summary, this embodiment improves the accuracy and flexibility of data queries by optimizing the generation process of text prompt information, and provides users with a better data query experience.
[0159] See also Figure 6 , which provides a schematic diagram of a process for obtaining a first keyword set in an embodiment of the present application, such as Figure 6 As shown, the method of the embodiment of the present application may include the following steps S502-S504, and steps S502-S504 may be used as Figure 2 The refinement of step S102 in the illustrated embodiment.
[0160] S502, in response to first text information input by a user on a target interface, acquiring intention information from the first text information;
[0161] S504: If the intention information is a data query intention, obtain a first keyword set from the first text information.
[0162] Specifically, this embodiment is based on the in-depth application of natural language processing (NLP) technology, especially intent recognition technology. In one possible implementation, a pre-trained auxiliary large language model can be used for intent recognition. The auxiliary large language model is a model based on deep learning. It gradually masters the characteristics of the terminology and intent of the target industry by inputting and learning a large amount of text in the target industry. Once the training is completed, the auxiliary large language model can quickly and accurately recognize the intent of the first text information input by the user, thereby obtaining the user's intent information.
[0163] If the intent information is a data query intent, then keywords related to the data query can be further extracted from the first text information to form a first keyword set. For details on obtaining the first keyword set, see Figure 2 The explanation of step S102 in the illustrated embodiment will not be repeated here. It is understandable that if the intention information is a data modification intention or other intention, it will trigger the execution of an action different from data query.
[0164] In this embodiment, the pre-trained auxiliary large language model is used to perform intent recognition on the first text information input by the user, so that the user's intent information can be quickly and accurately obtained. If the intent information is a data query intent, keywords related to the data query are further extracted from the first text information to form a first keyword set. This process not only ensures that the keyword set is highly matched with the user's actual query needs, but also avoids interference from irrelevant information, thereby improving the accuracy and efficiency of subsequent database queries.
[0165] Based on the above Figure 1 Application scenarios, and Figure 2 - Figure 6 The method of the embodiment shown provides a solution for implementing data query by combining the user end, the server end and the large language model (target large language model). Figure 7 , Figure 7 is a swimming lane diagram of a data query provided by an embodiment of this specification. Among them, the execution subject of the embodiment of this specification is an electronic device, and its identity can be Figure 7 The user side in Figure 7 The server in .
[0166] The user terminal displays a target interface, and the user inputs the first text information through the target interface. The user terminal transmits the first text information to the service terminal.
[0167] The server performs intent recognition on the first text information to obtain intent information. If the intent information is a data query intent, keywords are extracted from the first text information to form a first keyword set. Among multiple structural elements of the data table to be queried, at least one target structural element is determined, where the structural elements are divided into table names and field names; the first category of keywords corresponding to the target structural element in the first keyword set are translated into second category keywords to obtain a second keyword set; and text prompt information is generated based on the second keyword set.
[0168] The server calls the target large language model to process the text prompt information and obtains the third database operation statement returned by the target large language model; if the third database operation statement does not meet the preset verification condition (i.e., fails to pass the verification), and the number of calls to the target large language model does not reach the preset call number threshold, then the text prompt information is updated based on the third database operation statement, so that the updated text prompt information includes the corrected prompt information corresponding to the third database operation statement, and continues to call the preset target large language model to process the text prompt information, and obtains the third database operation statement returned by the target large language model. This cycle is repeated until the third database operation statement does not meet the preset verification condition and the number of calls to the target large language model reaches the preset call number threshold, or until the third database operation statement meets the preset verification condition.
[0169] If the third database operation statement does not meet the preset verification condition and the number of calls to the target large language model reaches the preset call number threshold, the server will return an abnormal prompt information to the user, and the user will display the abnormal prompt information on the target interface. The abnormal prompt information may indicate that the query cannot be made, the query is abnormal, or the user is prompted to re-enter the first text information.
[0170] When the third database operation statement meets a preset verification condition, the third database operation statement is determined as the first database operation statement.
[0171] Furthermore, the server reverses the second-category keyword in the first database operation statement into the first-category keyword to obtain a second database operation statement; based on the second database operation statement, the server queries the database storing the data table to obtain a query result, generates a second text message based on the query result, and returns the second text message to the user end. Accordingly, the user end displays the second text message on the target interface.
[0172] Based on the above Figure 1 The following will combine the application scenarios Figure 8 The data query device provided in the embodiment of the present application is introduced in detail. It should be noted that: Figure 8 The data query device in the present application is used to execute Figure 2 - Figure 7 For the convenience of explanation, only the part related to the embodiment of the present application is shown. For the specific technical details not disclosed, please refer to the present application. Figure 2 - Figure 7 Specifically, the data query device 1 may include an acquisition unit 11, a determination unit 12, an escape unit 13, a call unit 14, an un-escape unit 15, and a query unit 16, as follows:
[0173] The acquisition unit 11 is configured to acquire a first keyword set from the first text information in response to the first text information input by the user on the target interface;
[0174] A determination unit 12, configured to determine at least one target structural element from a plurality of structural elements of the data table to be queried, wherein the structural elements are divided into table names and field names;
[0175] The translation unit 13 is used to translate the first category of keywords corresponding to the target structural element in the first keyword set into the second category of keywords to obtain a second keyword set;
[0176] The calling unit 14 is used to generate text prompt information based on the second keyword set, and call a preset target large language model to process the text prompt information to obtain a first database operation statement returned by the target large language model, wherein the first database operation statement includes the second category of keywords;
[0177] The reverse meaning unit 15 is used to reverse the meaning of the second category keywords in the first database operation statement into the first category keywords to obtain a second database operation statement;
[0178] The query unit 16 is used to query the database storing the data table based on the second database operation statement to obtain a query result, generate second text information based on the query result, and display the second text information on the target interface.
[0179] Optionally, the escape unit 13 is further used to: obtain a keyword escape table, wherein the keyword escape table records the mapping relationship between the first category of keywords and the second category of keywords; based on the keyword escape table, escape the first category of keywords corresponding to the target structural elements in the first keyword set into second category keywords to obtain a second keyword set; the un-escape unit 15 is further used to: based on the keyword escape table, un-escape the second category of keywords in the first database operation statement into first category keywords to obtain a second database operation statement.
[0180] Optionally, the determination unit 12 is further used to: determine the table name as the target structure element among multiple structure elements of the data table; and / or determine the preset sensitive field name as the target structure element among multiple structure elements of the data table.
[0181] Optionally, the calling unit 14 is further used to: call a preset target large language model to process the text prompt information, and obtain a third database operation statement returned by the target large language model; if the third database operation statement does not meet the preset verification conditions, and the number of calls to the target large language model does not reach a preset call number threshold, update the text prompt information based on the third database operation statement, so that the updated text prompt information includes the corrected prompt information corresponding to the third database operation statement, and return to execute the call to the preset target large language model to process the text prompt information, and obtain the third database operation statement returned by the target large language model; if the third database operation statement meets the preset verification conditions, determine the third database operation statement as the first database operation statement.
[0182] Optionally, the verification condition includes a first verification condition, a second verification condition, and a third verification condition; the calling unit 14 is also used to: if the third database operation statement complies with the user's operation authority on the database, determine that the third database operation statement satisfies the first verification condition; if the third category of keywords in the third database operation statement are consistent with the first category of keywords after negation, determine that the third database operation statement satisfies the second verification condition, wherein the third category of keywords are obtained by processing the second category of keywords in the text prompt information by the target large language model; if the operation type of the third database operation statement on the database is a data query operation, determine that the third database operation statement satisfies the third verification condition.
[0183] Optionally, the calling unit 14 is also used to: obtain a text prompt template, wherein the text prompt template includes a scene description, a database operation statement structure prompt and multiple placeholders, and the placeholders are divided into table name placeholders, field name placeholders and query modifier placeholders; fill the keywords in the second keyword set into the placeholders in the text prompt template respectively to obtain text prompt information.
[0184] Optionally, the calling unit 14 is also used for: if there are fourth-category keywords in the second keyword set, there are multiple target field names in the data table, and the data of the fourth-category keywords are calculated based on a preset algorithm for the data of each target field name in the multiple target field names, then in the second keyword set, the fourth-category keywords are converted into fifth-category keywords corresponding to each target field name, and sixth-category keywords corresponding to the query modifiers constructed based on the preset algorithm are added to obtain a third keyword set; the keywords in the third keyword set are respectively filled into the placeholders in the text prompt template to obtain text prompt information.
[0185] Optionally, the acquisition unit 11 is further used to: in response to first text information input by a user in the target interface, acquire intent information from the first text information; if the intent information is a data query intent, acquire a first keyword set from the first text information.
[0186] In this embodiment, first, the user only needs to input a simple first text message in the target interface to trigger subsequent data queries, without the need for the user to master complex database query syntax, which reduces the threshold for use and improves the convenience of data queries. Secondly, by translating the first category of keywords in the first keyword set into the second category of keywords corresponding to the target structural elements, text prompt information is generated based on the second keyword set, and the target large language model can be safely called in combination with the text prompt information. Finally, after obtaining the first database operation statement returned by the target large language model, the second database operation statement can be reversed to obtain the second database operation statement. The query and subsequent processing based on the second database operation statement can display the second text information generated based on the query result on the target interface. Through the above scheme, the convenience and flexibility of data query can be taken into account, and the user experience is effectively improved.
[0187] See also Fig. 9 , is a schematic diagram of the structure of an electronic device provided in the embodiment of this specification. Fig. 9 As shown, the electronic device 1000 may include: at least one processor 1001, such as a CPU, at least one network interface 1004, an input / output interface 1003, a memory 1005, and at least one communication bus 1002. The communication bus 1002 is used to realize the connection and communication between these components. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (non-volatile memory), such as at least one disk storage. The memory 1005 may optionally be at least one storage device located away from the aforementioned processor 1001. As shown in FIG. Fig. 9 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, an input and output interface module, and a data query application.
[0188] exist Fig. 9 In the electronic device 1000 shown, the input-output interface 1003 is mainly used to provide an input interface for the user and obtain data input by the user.
[0189] In one embodiment, the processor 1001 may be used to call a data query application stored in the memory 1005, and specifically perform the following operations:
[0190] In response to first text information input by a user on a target interface, obtaining a first keyword set from the first text information;
[0191] Determine at least one target structural element among multiple structural elements of the data table to be queried, wherein the structural elements are divided into table names and field names;
[0192] Translating the first category of keywords corresponding to the target structural elements in the first keyword set into the second category of keywords to obtain a second keyword set;
[0193] Generate text prompt information based on the second keyword set, and call a preset target large language model to process the text prompt information to obtain a first database operation statement returned by the target large language model, wherein the first database operation statement includes the second category of keywords;
[0194] Reverse the meaning of the second category keywords in the first database operation statement into the first category keywords to obtain a second database operation statement;
[0195] A database storing a data table is queried based on the second database operation statement to obtain a query result, second text information is generated based on the query result, and the second text information is displayed on the target interface.
[0196] Optionally, when the processor 1001 executes the reverse translation of the first category of keywords corresponding to the target structural elements in the first keyword set into second category keywords to obtain the second keyword set, the processor 1001 specifically performs the following operations: obtaining a keyword translation table, wherein the keyword translation table records a mapping relationship between the first category of keywords and the second category of keywords; based on the keyword translation table, the first category of keywords corresponding to the target structural elements in the first keyword set are translated into second category keywords to obtain the second keyword set; when the processor 1001 executes the reverse translation of the second category of keywords in the first database operation statement into first category keywords to obtain the second database operation statement, the processor 1001 specifically performs the following operations: based on the keyword translation table, the second category of keywords in the first database operation statement are reversed into first category keywords to obtain the second database operation statement.
[0197] Optionally, when the processor 1001 determines at least one target structural element among multiple structural elements of the data table to be queried, it specifically performs the following operations: determining the table name as the target structural element among the multiple structural elements of the data table; and / or determining a preset sensitive field name as the target structural element among the multiple structural elements of the data table.
[0198] Optionally, when the processor 1001 executes the call to the preset target large language model to process the text prompt information and obtains the first database operation statement returned by the target large language model, the following specific operations are performed: calling the preset target large language model to process the text prompt information to obtain a third database operation statement returned by the target large language model; if the third database operation statement does not meet the preset verification condition and the number of calls to the target large language model does not reach the preset call number threshold, updating the text prompt information based on the third database operation statement so that the updated text prompt information includes the corrected prompt information corresponding to the third database operation statement, and returning to execute the call to the preset target large language model to process the text prompt information to obtain the third database operation statement returned by the target large language model; if the third database operation statement meets the preset verification condition, determining the third database operation statement as the first database operation statement.
[0199] Optionally, the verification condition includes a first verification condition, a second verification condition, and a third verification condition; after the processor 1001 executes the call to the preset target large language model to process the text prompt information and obtains the third database operation statement returned by the target large language model, the following specific operations are performed: if the third database operation statement complies with the user's operation authority on the database, it is determined that the third database operation statement satisfies the first verification condition; if the third category of keywords in the third database operation statement are consistent with the first category of keywords after negation, it is determined that the third database operation statement satisfies the second verification condition, wherein the third category of keywords are obtained by processing the second category of keywords in the text prompt information by the target large language model; if the operation type of the third database operation statement on the database is a data query operation, it is determined that the third database operation statement satisfies the third verification condition.
[0200] Optionally, when executing to generate text prompt information based on the second keyword set, the processor 1001 specifically performs the following operations: obtaining a text prompt template, wherein the text prompt template includes a scene description, a database operation statement structure prompt, and multiple placeholders, and the placeholders are divided into table name placeholders, field name placeholders, and query modifier placeholders; filling the keywords in the second keyword set into the placeholders in the text prompt template respectively to obtain text prompt information.
[0201] Optionally, when the processor 1001 executes the operation of filling the keywords in the second keyword set into the placeholders in the text prompt template to obtain text prompt information, the following specific operations are performed: if there are fourth-category keywords in the second keyword set, there are multiple target field names in the data table, and the data of the fourth-category keywords are calculated based on a preset algorithm for the data of each target field name in the multiple target field names, then in the second keyword set, the fourth-category keywords are converted into fifth-category keywords corresponding to each target field name, and a sixth-category keyword corresponding to a query modifier constructed based on the preset algorithm is added to obtain a third keyword set; the keywords in the third keyword set are filled into the placeholders in the text prompt template to obtain text prompt information.
[0202] Optionally, when the processor 1001 obtains a first keyword set from the first text information in response to the first text information input by the user in the target interface, the processor 1001 specifically performs the following operations: in response to the first text information input by the user in the target interface, obtain intent information from the first text information; if the intent information is a data query intent, obtain a first keyword set from the first text information.
[0203] In this embodiment, first, the user only needs to input a simple first text message in the target interface to trigger subsequent data queries, without the need for the user to master complex database query syntax, which reduces the threshold for use and improves the convenience of data queries. Secondly, by translating the first category of keywords in the first keyword set into the second category of keywords corresponding to the target structural elements, text prompt information is generated based on the second keyword set, and the target large language model can be safely called in combination with the text prompt information. Finally, after obtaining the first database operation statement returned by the target large language model, the second database operation statement can be reversed to obtain the second database operation statement. The query and subsequent processing based on the second database operation statement can display the second text information generated based on the query result on the target interface. Through the above scheme, the convenience and flexibility of data query can be taken into account, and the user experience is effectively improved.
[0204] The present specification also provides a computer storage medium that can store multiple program instructions, which are suitable for being loaded and executed by a processor as described above. Figure 2 - Figure 7 The method steps of the embodiment shown in the figure can be found in the specific implementation process. Figure 2 - Figure 7 The specific description of the illustrated embodiment will not be repeated here.
[0205] The embodiment of the present specification also provides a computer program product, which stores at least one instruction, and the at least one instruction is loaded and executed by a processor as described above. Figure 2 - Figure 7 The data query method of the embodiment shown in the figure can be found in the specific execution process. Figure 2 - Figure 7 The specific description of the illustrated embodiment will not be repeated here.
[0206] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0207] The above disclosure is only the preferred embodiment of this specification, which certainly cannot be used to limit the scope of rights of this specification. Therefore, equivalent changes made according to the claims of this specification are still within the scope covered by this specification.
Claims
1. A data query method, comprising: In response to first text information input by a user on a target interface, obtaining a first keyword set from the first text information; Determine at least one target structural element among a plurality of structural elements of the data table to be queried, wherein the structural elements are divided into table names and field names; Translating the first category of keywords corresponding to the target structural element in the first keyword set into second category of keywords to obtain a second keyword set; Generate text prompt information based on the second keyword set, and call a preset target large language model to process the text prompt information to obtain a first database operation statement returned by the target large language model, wherein the first database operation statement includes the second category of keywords; Reverse-translate the second-category keywords in the first database operation statement into the first-category keywords to obtain a second database operation statement; A database storing the data table is queried based on the second database operation statement to obtain a query result, second text information is generated based on the query result, and the second text information is displayed on the target interface.
2. According to the method of claim 1, the step of converting the first-category keywords corresponding to the target structural element in the first keyword set into second-category keywords to obtain the second keyword set comprises: Obtaining a keyword escape table, wherein the keyword escape table records a mapping relationship between the first category of keywords and the second category of keywords; Translating the first category of keywords corresponding to the target structural element in the first keyword set into second category of keywords based on the keyword transliteration table to obtain the second keyword set; The step of reverse-interpreting the second-category keywords in the first database operation statement into the first-category keywords to obtain a second database operation statement includes: The second-category keyword in the first database operation statement is reversed into the first-category keyword based on the keyword escape table to obtain the second database operation statement.
3. The method according to claim 1, wherein determining at least one target structural element from a plurality of structural elements in the data table to be queried comprises: Among the plurality of structural elements of the data table, determining the table name as the target structural element; and / or, Among the multiple structural elements of the data table, a preset sensitive field name is determined as the target structural element.
4. According to the method of claim 1, the calling of a preset target large language model to process the text prompt information to obtain a first database operation statement returned by the target large language model comprises: Calling a preset target large language model to process the text prompt information to obtain a third database operation statement returned by the target large language model; If the third database operation statement does not meet the preset verification condition, and the number of calls to the target large language model does not reach the preset call number threshold, the text prompt information is updated based on the third database operation statement, so that the updated text prompt information includes the corrected prompt information corresponding to the third database operation statement, and the call to the preset target large language model is returned to process the text prompt information to obtain the third database operation statement returned by the target large language model; If the third database operation statement meets the preset verification condition, the third database operation statement is determined as the first database operation statement.
5. The method according to claim 4, wherein the verification condition comprises a first verification condition, a second verification condition, and a third verification condition; and after the calling of the preset target large language model to process the text prompt information and obtaining the third database operation statement returned by the target large language model, the method further comprises: If the third database operation statement complies with the user's operation authority for the database, determining that the third database operation statement satisfies the first verification condition; If the third category of keywords in the third database operation statement are consistent with the first category of keywords after negation, it is determined that the third database operation statement meets the second verification condition, wherein the third category of keywords are obtained by processing the second category of keywords in the text prompt information by the target large language model; If the operation type of the third database operation statement on the database is a data query operation, it is determined that the third database operation statement satisfies the third verification condition.
6. The method according to claim 1, wherein generating text prompt information based on the second keyword set comprises: Acquire a text prompt template, wherein the text prompt template includes a scenario description, a database operation statement structure prompt, and a plurality of placeholders, wherein the placeholders are divided into a table name placeholder, a field name placeholder, and a query modifier placeholder; The keywords in the second keyword set are respectively filled into the placeholders in the text prompt template to obtain the text prompt information.
7. The method according to claim 6, wherein the step of filling the keywords in the second keyword set into the placeholders in the text prompt template to obtain the text prompt information comprises: If there are fourth-category keywords in the second keyword set, there are multiple target field names in the data table, and the data of the fourth-category keywords are calculated based on a preset algorithm for the data of each of the multiple target field names, then in the second keyword set, the fourth-category keywords are converted into fifth-category keywords corresponding to each of the target field names, and sixth-category keywords corresponding to the query modifiers constructed based on the preset algorithm are added to obtain a third keyword set; The keywords in the third keyword set are respectively filled into the placeholders in the text prompt template to obtain the text prompt information.
8. The method according to claim 1, wherein in response to first text information input by a user on a target interface, obtaining a first keyword set from the first text information comprises: In response to first text information input by a user on a target interface, acquiring intent information from the first text information; If the intent information is a data query intent, the first keyword set is obtained from the first text information.
9. A data query device, comprising: an acquisition unit, configured to acquire a first keyword set from first text information input by a user on a target interface; A determination unit, used to determine at least one target structural element among a plurality of structural elements of the data table to be queried, wherein the structural elements are divided into table names and field names; a translation unit, configured to translate the first category of keywords corresponding to the target structural element in the first keyword set into second category of keywords to obtain a second keyword set; a calling unit, configured to generate text prompt information based on the second keyword set, and call a preset target large language model to process the text prompt information to obtain a first database operation statement returned by the target large language model, wherein the first database operation statement includes the second category of keywords; a reverse semantics unit, configured to reverse semantics of the second category of keywords in the first database operation statement into the first category of keywords, so as to obtain a second database operation statement; A query unit is used to query the database storing the data table based on the second database operation statement to obtain a query result, generate second text information based on the query result, and display the second text information on the target interface.
10. A computer-readable storage medium storing a computer program code, wherein when the computer program code is executed, the method according to any one of claims 1 to 9 is implemented.
11. An electronic device, comprising: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the steps of the method as claimed in any one of claims 1 to 8.
12. A computer program product having at least one instruction stored thereon, wherein when the at least one instruction is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.