Search

CN-121764953-B - Query condition conversion method and device for self-adaptive AI output deviation correction

CN121764953BCN 121764953 BCN121764953 BCN 121764953BCN-121764953-B

Abstract

The application discloses a query condition conversion method and device for self-adaptive AI output correction, and relates to the technical field of intersection of artificial intelligence and natural language processing. The method comprises the steps of receiving user natural language input, dynamically constructing system prompt words based on target form field metadata, sending the system prompt words to a large language model together with the user natural language, obtaining a JSON format query condition array, and transmitting and storing the JSON format query condition array. And extracting the JSON character strings from the array and converting the JSON character strings into an inquiry condition object array, performing logic operator position deviation correction processing on the inquiry condition object array, setting the first inquiry condition logic relation to be null, and reading the previous logic operator value as the logic relation with the previous inquiry condition by the subsequent inquiry condition. And converting the array subjected to deviation correction into a data structure in the system, and executing database inquiry by using the array to acquire and return the data record meeting the conditions. The problem that the query result is wrong due to the fact that a large language model sets a logic operator on a previous expression is solved.

Inventors

  • HU SEN

Assignees

  • 西安葡萄城软件有限公司

Dates

Publication Date
20260508
Application Date
20260303

Claims (9)

  1. 1. The query condition conversion method for self-adaptive AI output deviation correction is characterized by comprising the following steps: Receiving user natural language input, wherein the user natural language comprises a plurality of query conditions aiming at a target table and logic relations among the query conditions; dynamically constructing a system prompt word based on field metadata of a currently queried target table; the system prompt word and the user natural language are sent to a large language model, a query condition array in a JSON format returned by the large language model is obtained, and the query condition array is used as a return result, wherein the query condition array is transmitted and/or stored in a character string form; extracting a JSON character string containing query conditions from the returned result, and converting the JSON character string into a query condition object array according to a JSON analysis rule; performing logical operator position correction processing on the query condition object array; The logical operator position correction processing comprises traversing the query condition object array in sequence, setting the logical relation of the first query condition of the condition object array to be null, and reading the logical operator value of the previous query condition as the logical relation between the current query condition and the previous query condition for the second and subsequent query conditions of the condition object array; converting the query condition array after the logic operator position deviation correction processing into a query condition data structure in the system to obtain a converted query condition; And executing database query operation by using the converted query conditions, acquiring data records conforming to the query conditions, and returning the query results to the user.
  2. 2. The adaptive AI output-deskewing query condition conversion method of claim 1, further comprising, prior to performing logical operator position deskewing processing on the query condition object array: Judging whether a logic operator of a first query condition of the condition object array is empty or not; If not, executing logic operator position deviation rectifying processing on the query condition object array; If the query condition is empty, skipping the position deviation correction processing of the logic operator, directly converting the query condition array into a query condition data structure in the system to obtain the converted query condition, executing database query operation by using the converted query condition to obtain a data record conforming to the query condition, and returning the query result to the user.
  3. 3. The adaptive AI-output-deskew query condition conversion method of claim 1 wherein the system hint words include a list of all fields in the target table that perform the query operation, a list of comparison operators for each field, a list of logical operators for concatenating the query conditions, and output format requirements.
  4. 4. The adaptive AI output-correcting query condition conversion method of claim 1, wherein the extracting the JSON string containing the query condition in the returned result, converting the JSON string into an array of query condition objects according to JSON parsing rules, comprises: Extracting a JSON character string containing query conditions in a return result by adopting a regular expression matching mode, wherein the matching rule is that the JSON character string beginning with a square bracket and ending with the square bracket is searched from the return result, and the JSON character string contains one or more JSON objects so as to convert the JSON character string into a query condition object array according to a JSON analysis rule; The array of query condition objects includes a first operand for representing a database field name, a comparison operator, a second operand for representing a comparison value, a logical operator, and parentheses for representing a priority of nested query conditions, wherein the logical operator is effective only if the current query condition is not the first query condition in the array of query conditions.
  5. 5. The adaptive AI-output-deskew query condition conversion method of claim 4, wherein converting the array of query conditions after performing the logical operator position deskew processing into a query condition data structure within the system to obtain converted query conditions, comprises: mapping field identifiers in the first operand to column names inside the system; Converting the character string of the comparison operator into an enumeration value inside the system; Converting the logic operator after deviation correction processing into an enumeration value of query condition relation in the system; Converting the character strings of the parentheses into the values of the hierarchy of the parentheses, and using the values of the brackets to represent priority groups of the query conditional expressions; and converting the comparison value containing the array format of the comparison operator in the second operand into comma separated character string format.
  6. 6. The adaptive AI output-deskewing query condition conversion method of claim 1, further comprising: The query condition array after the logical operator position deviation correction is executed is visually presented to a user; The user checks and modifies the query conditions, then determines the executed query conditions, and the system executes database query operation according to the query conditions confirmed by the user, acquires data records conforming to the query conditions, and returns the query results to the user.
  7. 7. A query condition conversion apparatus for adaptive AI output correction, the apparatus performing the method of any one of claims 1 to 6, comprising: The receiving module is used for receiving user natural language input, wherein the user natural language comprises a plurality of query conditions aiming at the target table and logic relations among the query conditions; the construction module is used for dynamically constructing system prompt words based on field metadata of the currently queried target table; The system comprises a sending module, a receiving module and a receiving module, wherein the sending module is used for sending a system prompt word and a user natural language to a large language model together, obtaining a query condition array in a JSON format returned by the large language model, and taking the query condition array as a return result; the first conversion module is used for extracting a JSON character string containing query conditions in the returned result and converting the JSON character string into a query condition object array according to a JSON analysis rule; The processing module is used for executing logical operator position correction processing on the query condition object array, wherein the logical operator position correction processing comprises traversing the query condition object array in sequence, setting the logical relationship of the first query condition of the condition object array to be null, and reading the logical operator value of the previous query condition as the logical relationship between the current query condition and the previous query condition for the second and subsequent query conditions of the condition object array; the second conversion module is used for converting the query condition array subjected to the logical operator position deviation correction processing into a query condition data structure in the system so as to obtain converted query conditions; and the acquisition module is used for executing database query operation by using the converted query conditions, acquiring data records conforming to the query conditions and returning the query results to the user.
  8. 8. The query condition conversion server for self-adaptive AI output deviation correction is characterized by comprising a memory and a processor; the memory is used for storing computer executable instructions; the processor is configured to execute the computer-executable instructions to implement the method of any of claims 1-6.
  9. 9. A computer-readable storage medium, wherein the computer-readable storage medium stores executable instructions, a computer capable of implementing the method of any one of claims 1-6 when executing the executable instructions.

Description

Query condition conversion method and device for self-adaptive AI output deviation correction Technical Field The application relates to the technical field of intersection of artificial intelligence and natural language processing, in particular to a query condition conversion method and device for self-adaptive AI output deviation correction. Background With the advancement of Large Language Model (LLM) technology, many application systems convert user natural language input into structured query conditions by means of the Large Language Model (LLM) technology so as to optimize human-computer interaction, and the large language model is widely applied in database query scenes. For example, after a user enters a complex natural language description, the system needs to convert it into a structured query conditional expression to execute the query. In the prior art, a prompt word engineering is mostly adopted, a large language model is guided to generate an output result conforming to an expected format through a design system prompt word, and the prompt word can explain the requirement of the output format. However, there is a systematic behavior bias in practical application of large language models. When multiple query conditions are connected by using logical operators, the large language model always sets the logical operators on the previous expression, so that not only is the grammar of an output result correct but the logic is not consistent, but also the query result is wrong, which is contrary to the intention of a user, and the system performance and the user experience are seriously affected. Disclosure of Invention In the embodiment of the application, by providing a query condition conversion method for self-adaptive AI output deviation correction, the problem that when a plurality of query conditions are connected by a logic operator, a large language model always sets the logic operator on a previous expression, so that the grammar of an output result is correct but the logic is not consistent, and the query result is wrong is solved. In a first aspect, an embodiment of the present application provides a query condition conversion method for adaptive AI output correction, where the method includes receiving user natural language input, where the user natural language includes a plurality of query conditions for a target table and a logical relationship between the query conditions, dynamically constructing a system hint word based on field metadata of the target table currently queried, sending the system hint word and the user natural language to a large language model, obtaining a query condition array in JSON format returned by the large language model, and taking the query condition array as a return result, where the query condition array transmits and/or stores in a string form, extracts a JSON string containing the query condition in the return result, converts the JSON string into a query condition object array according to JSON parsing rules, performs logical operator position correction processing on the query condition object array, where the logical operator position correction processing includes sequentially traversing the query condition object array, setting the logical relationship of the first query condition of the condition object array to be null, reading a logical value of the previous query condition array for the second and subsequent query conditions of the condition object array, taking the first query condition as a query condition, converting the current query condition and the query condition as a query condition, and performing the query operator structure after the query operator is converted into a query condition, and obtaining the query operator structure after the query condition is converted, and the query operator is converted into a query condition. In one possible implementation manner, before executing the logic operator position correction processing on the query condition object array, the method further comprises the steps of judging whether a logic operator of a first query condition of the query condition object array is null, if not, executing the logic operator position correction processing on the query condition object array, if so, skipping execution of the logic operator position correction processing, directly converting the query condition array into a query condition data structure in the system to obtain converted query conditions, executing database query operation by using the converted query conditions, obtaining data records conforming to the query conditions, and returning query results to a user. In one possible implementation, the system prompt word includes all the field lists for performing the query operation, the comparison operator list applicable to each field, the logic operator list for connecting the query condition and the output format requirement in the target table. In one possible implementation, the method for extra