A query condition conversion method and device for adaptive AI output correction
By receiving natural language input from users, dynamically constructing system prompts and performing logical operator position correction, the problem of incorrect logical operator positions when multiple query conditions are connected in a large language model is solved, thereby improving system performance and the accuracy of query results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- XIAN GRAPE CITY SOFTWARE CO LTD
- Filing Date
- 2026-03-03
- Publication Date
- 2026-05-08
AI Technical Summary
When multiple query conditions require logical operators to be connected, the large language model incorrectly places the logical operators on the previous expression, resulting in syntactically correct but logically incorrect output results, which affects the accuracy of the query results.
By receiving natural language input from users, the system dynamically constructs system prompts, obtains a JSON-formatted array of query conditions, performs logical operator position correction to ensure correct logical operator positions, converts it into an internal query condition data structure, and executes a database query.
It significantly reduced system response time, lowered API call costs, improved the smoothness of user interaction and system performance, and ensured that query results were consistent with user intent.
Smart Images

Figure CN121764953B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of the intersection of artificial intelligence and natural language processing, and in particular to a method and apparatus for adaptive AI output correction of query conditions transformation. Background Technology
[0002] With advancements in Large Language Model (LLM) technology, numerous application systems leverage it to convert user natural language input into structured query conditions, thereby optimizing human-computer interaction. This technology is widely used in database query scenarios. For example, after a user inputs a complex natural language description, the system needs to convert it into a structured query condition expression to execute the query.
[0003] In existing technologies, prompt word engineering is often used. This involves designing system prompt words to guide a large language model to generate output results that meet the expected format. The prompt words will explain the output format requirements.
[0004] However, large language models exhibit systematic behavioral biases in practical applications. When multiple query conditions require logical operators to connect, large language models consistently place the logical operators on the preceding expression. This not only results in syntactically correct but logically incorrect outputs but also leads to erroneous query results that contradict user intent, severely impacting system performance and user experience. Summary of the Invention
[0005] In this embodiment of the application, an adaptive AI output correction query condition transformation method is provided to solve the problem that when multiple query conditions need to be connected by logical operators, the large language model always sets the logical operator on the previous expression, which not only results in grammatically correct but logically incorrect output results, but also leads to incorrect query results.
[0006] In a first aspect, embodiments of this application provide a query condition transformation method for adaptive AI output correction. The method includes: receiving user natural language input, whereby the user natural language includes multiple query conditions for a target table and the logical relationships between the query conditions; dynamically constructing system prompts based on the field metadata of the currently queried target table; sending the system prompts along with the user natural language to a large language model, obtaining a JSON-formatted query condition array returned by the large language model, and using the query condition array as the return result; wherein the query condition array is transmitted and / or stored as a string; extracting the JSON string containing the query conditions from the return result, and converting the JSON string into a JSON string according to JSON parsing rules. The system generates an array of query condition objects. It then performs logical operator position correction on this array. This correction includes: sequentially traversing the array of query condition objects; setting the logical relation of the first query condition to null; for the second and subsequent query conditions, reading the logical operator value of the previous query condition and using it as the logical relation between the current and previous conditions; converting the query condition array after logical operator position correction into an internal system query condition data structure to obtain the converted query conditions; and finally, using the converted query conditions to execute a database query, retrieving data records that meet the query conditions, and returning the query results to the user.
[0007] In one possible implementation, before performing logical operator position correction processing on the query condition object array, the following steps are included: determining whether the logical operator of the first query condition in the condition object array is empty; if not empty, performing logical operator position correction processing on the query condition object array; if empty, skipping the logical operator position correction processing and directly converting the query condition array into the system's internal query condition data structure to obtain the converted query conditions; using the converted query conditions to perform a database query operation, obtaining data records that meet the query conditions, and returning the query results to the user.
[0008] In one possible implementation, the system prompt includes a list of all fields in the target table for which a query operation is performed, a list of comparison operators applicable to each field, a list of logical operators used to connect query conditions, and output format requirements.
[0009] In one possible implementation, extracting the JSON string containing the query conditions from the returned results and converting the JSON string into an array of query condition objects according to JSON parsing rules includes: extracting the JSON string containing the query conditions from the returned results using regular expression matching, where the matching rule is: finding JSON strings in the returned results that begin and end with square brackets, and that the JSON string contains one or more JSON objects, to convert the JSON string into an array of query condition objects according to JSON parsing rules; the array of query condition objects includes: a first operand representing database field names, comparison operators, a second operand representing comparison values, logical operators, and parentheses representing the priority of nested query conditions; wherein, logical operators only take effect when the current query condition is not the first query condition in the query condition array.
[0010] In one possible implementation, the step of converting the query condition array after performing logical operator position correction processing into an internal system query condition data structure to obtain the converted query conditions includes: mapping field identifiers in the first operand to internal system column names; converting comparison operator strings to internal system enumeration values; converting the corrected logical operators to internal system query condition relationship enumeration values; converting parentheses strings to parenthesis level values to represent priority grouping of query condition expressions; and converting comparison values in the second operand, which are in array format containing comparison operators, into comma-separated string format.
[0011] One possible implementation also includes: presenting the array of query conditions after the logical operator position correction to the user in a visual manner; after the user views and modifies the query conditions, the system determines the query conditions to be executed, executes the database query operation according to the query conditions confirmed by the user, obtains the data records that meet the query conditions, and returns the query results to the user.
[0012] Secondly, embodiments of this application provide an adaptive AI output correction query condition conversion device, which includes: a receiving module for receiving user natural language input, wherein the user natural language includes multiple query conditions for a target table and the logical relationships between the query conditions; a construction module for dynamically constructing system prompt words based on the field metadata of the currently queried target table; a sending module for sending the system prompt words and the user natural language together to a large language model, obtaining a JSON-formatted query condition array returned by the large language model, and using the query condition array as the return result; wherein the query condition array is transmitted and / or stored in string form; and a first conversion module for extracting the JSON string containing the query conditions from the return result, and converting the JSON string according to JSON parsing rules. The system converts the query condition array into a query condition object array. A processing module performs logical operator position correction on the query condition object array. This logical operator position correction includes: sequentially traversing the query condition object array; setting the logical relationship of the first query condition to null; and for the second and subsequent query conditions, reading the logical operator value of the previous query condition and using it as the logical relationship between the current query condition and the previous query condition. A second conversion module converts the query condition array after logical operator position correction into an internal system query condition data structure to obtain the converted query conditions. A retrieval module uses the converted query conditions to perform a database query operation, retrieves data records that meet the query conditions, and returns the query results to the user.
[0013] Thirdly, embodiments of this application provide an adaptive AI output correction query condition transformation server, including a memory and a processor; the memory is used to store computer-executable instructions; the processor is used to execute the computer-executable instructions to implement the method described in the first aspect or any possible implementation of the first aspect.
[0014] Fourthly, embodiments of this application provide a computer-readable storage medium storing executable instructions, which, when executed by a computer, enable the method described in the first aspect or any possible implementation thereof.
[0015] One or more technical solutions provided in this application embodiment have at least the following technical effects: This application embodiment provides a query condition transformation method for adaptive AI output correction. This method receives user natural language input, dynamically constructs system prompt words based on target table field metadata, and sends these along with the user's natural language to a large language model. It then obtains a JSON-formatted query condition array and transmits and stores it. The JSON string in the array is extracted and converted into a query condition object array. Logical operator position correction processing is performed on this array. The logical relationship of the first query condition is set to empty, and subsequent query conditions read the logical operator value of the previous query condition as the logical relationship with that previous query condition. The corrected array is converted into an internal system data structure, which is used to execute a database query to obtain and return data records that meet the conditions. The logical operator position correction processing in this application is completed in one go during the parsing phase. It eliminates the need for the large language model to regenerate every time a logical operator position is detected as not meeting expectations, avoiding repeated execution of the entire API call process, including network transmission and model inference. This efficient processing method significantly reduces system response time and API call costs. In user interaction scenarios, it can provide users with a more timely and smooth query experience, effectively improving the overall performance and response efficiency of the system. This solves the problem that when multiple query conditions need to be connected by logical operators, the large language model always sets the logical operator on the previous expression, which not only results in syntactically correct but logically incorrect output results, but also leads to incorrect query results. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments of this application or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 A flowchart illustrating an adaptive AI output correction query condition transformation method provided in this application embodiment;
[0018] Figure 2 A schematic diagram of an adaptive AI output correction query condition conversion device provided in an embodiment of this application;
[0019] Figure 3 This is a schematic diagram of an adaptive AI output correction query condition transformation server provided in an embodiment of this application. Detailed Implementation
[0020] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0021] The following description of some technologies involved in the embodiments of this application is provided to aid understanding and should be considered merely exemplary. Therefore, those skilled in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this application. Similarly, for clarity and brevity, some descriptions of well-known functions and structures are omitted in the following description.
[0022] In database query scenarios, users can input complex natural language descriptions into a large language model, which the system needs to convert into structured query conditions. Existing technologies guide the large language model to generate output that conforms to the expected format through prompt engineering. For example, the prompts explicitly require that logical operators (such as "AND" and "OR") should be set on the latter condition to connect the former condition.
[0023] In practical applications, large language models exhibit systematic behavioral biases. Regardless of how the prompt words are optimized, the large language model consistently sets the logical operators incorrectly on the preceding condition (e.g., "condition A and condition B" is output as "the logical operator for condition A is AND, and the logical operator for condition B is null"). Incorrect placement of logical operators prevents subsequent parsing processes from correctly handling the conditional relationships. If this bias is not corrected, the query results will be completely inconsistent with the user's intent (e.g., "A and B or C" is executed as "A or B and C").
[0024] This application provides a query condition transformation method for adaptive AI output correction, such as... Figure 1 As shown, the method includes steps S101 to S107. Wherein, Figure 1 This is merely one execution order shown in the embodiments of this application, and does not represent the only execution order of a query condition transformation method for adaptive AI output correction. Where the final result can be achieved, Figure 1 The steps shown can be performed in parallel or in reverse order.
[0025] S101: Receive user natural language input, which includes multiple query conditions for the target table and the logical relationships between the query conditions.
[0026] Specifically, the system receives user descriptions in natural language through a user interface. User input is unstructured natural language text, which does not need to follow specific grammatical rules, but must contain a clear query intent. The system uses Natural Language Processing (NLP) technology to initially parse the user input, identifying the query conditions it contains, including field names, comparison values, and comparison operators.
[0027] S102: Dynamically construct system suggestion words based on the field metadata of the target table currently being queried.
[0028] The system prompts include a list of all fields in the target table to be used in the query, a list of comparison operators applicable to each field, a list of logical operators used to connect query conditions, and output format requirements.
[0029] Specifically, the list of all fields in the target table used for query operations includes information such as the identifier, display name, data type, and whether it is a list field for all queryable fields in the target table. The comparison operator list is dynamically generated based on the field type. For example, for text and date type fields, corresponding comparison operators will be adapted respectively. The logical operator list can be "AND" or "OR". The large language model is required to output the query conditions in JSON array format, with each query condition containing the following fields: op1 (first operand) indicates the field identifier; op2 (second operand) indicates the comparison value; compareOperator indicates the comparison operator; logicalOperator indicates the logical operator; leftBracket (left bracket) / rightBracket (right bracket) indicates bracket precedence.
[0030] S103: Send the system prompt words along with the user's natural language to the large language model, obtain the query condition array in JSON format returned by the large language model, and return the query condition array as the result. The query condition array is transmitted and / or stored as a string.
[0031] Specifically, each element in the query condition array represents a query condition. The query condition array is processed as a string, which can be reliably transmitted via network protocols during transmission; it can be stored in a database or file for subsequent parsing and use.
[0032] S104: Extract the JSON string containing the query conditions from the returned results, and convert the JSON string into an array of query condition objects according to the JSON parsing rules.
[0033] Extract the JSON string containing the query conditions from the returned results, and convert the JSON string into an array of query condition objects according to JSON parsing rules, including the following:
[0034] The JSON string containing the query conditions in the returned results is extracted using regular expression matching. The matching rule is: find the JSON string that starts with square brackets and ends with square brackets in the returned results, and the JSON string contains one or more JSON objects, so as to convert the JSON string into an array of query condition objects according to the JSON parsing rules.
[0035] Specifically, beginning with and ending with square brackets means beginning with square brackets "[" and ending with square brackets "]".
[0036] The query condition object array includes: a first operand representing the database field name, comparison operators, a second operand representing the comparison value, logical operators, and parentheses indicating the precedence of nested query conditions. Logical operators only take effect if the current query condition is not the first query condition in the query condition array.
[0037] Specifically, the first operand (op1) represents the database field name, i.e., the field identifier, which specifies the specific field in the database table that the query condition targets. For example, when querying employee information, "op1" could be field names such as "name," "gender," or "date of birth." The comparison operator (compareOperator) specifies the comparison method between the field and the comparison value in the query condition. Common comparison operators include "equalsTo," "not equalsTo," "greater than," and "less than." Comparison operators allow for precise definition of the filtering rules for the query conditions. The second operand (op2) represents the comparison value, i.e., the specific numerical value or string compared to the database field. For example, when the query condition is "gender equals male," the value of "op2" is "male"; when the query condition is "age greater than 20," the value of "op2" is 20. The logical operator (logicalOperator) connects multiple query conditions, defining the logical relationship between them. Common logical operators include "AND" and "OR." It's important to note that logical operators only take effect when the current query condition is not the first condition in the query condition array. For example, in the query condition array [condition 1, condition 2, condition 3], conditions 2 and 3 need to be logically connected to the previous condition using logical operators, while condition 1, as the starting condition, has no preceding condition to logically connect to it. Parentheses (left and right) are used to indicate the priority of nested query conditions. Using left and right parentheses, the calculation order between multiple query conditions can be clearly defined, enabling complex query logic. For example, nested query conditions like "(condition 1 AND condition 2) OR condition 3" can accurately express their priority relationship using parentheses.
[0038] S105: Perform logical operator position correction processing on the array of query condition objects.
[0039] The logical operator position correction process includes: sequentially traversing the array of query condition objects; for the first query condition in the array, setting its logical relation to null; for the second and subsequent query conditions, reading the logical operator value of the previous query condition and using it as the logical relation between the current query condition and the previous query condition.
[0040] Specifically, the array of query condition objects is traversed, and each query condition object in the array is processed sequentially. When processing the first query condition, since it has no preceding condition, its logical relation is set to empty. This means that when constructing the final query expression, the first condition serves as the starting condition and does not require logical operators to connect other conditions. When processing the second and subsequent query conditions, for the currently processed query condition object, the logical operator value of its preceding query condition is read. This logical operator value is used as the logical relation between the current query condition and the preceding query condition. In this way, the forward association logical operators output by the large language model are converted into expected backward association logical operators.
[0041] Taking the scenario of querying "all male employees born after January 1, 1990, or whose start date is within this week" in an enterprise human resource management system as an example, this article details the process of logical operator position correction. The array of query condition objects returned by the large language model is as follows.
[0042] [{"op1":"gender",
[0043] "op2":"male",
[0044] "compareOperator":"EqualsTo","logicalOperator":"And","leftBracket":"(","rightBracket":""},
[0045] {"op1":"Date of Birth",
[0046] "op2":"1990 / 01 / 01","compareOperator":"GreaterThan","logicalOperator":"Or","leftBracket":"","rightBracket":")"},
[0047] {"op1":"Date of Joining",
[0048] "op2":"ThisWeek","compareOperator":"KeyFilter","logicalOperator":"","leftBracket":"","rightBracket":""}].
[0049] KeyFilter stands for Keyword Filtering.
[0050] The output above reveals a problem with the logical operator placement in the large language model. In multi-condition expressions, logical operators are incorrectly placed on the preceding condition. For example, the logical operator for condition 1 (gender equal to male) is "AND," indicating its relationship with subsequent conditions; the logical operator for condition 2 (birth date greater than 1990 / 01 / 01) is "OR," indicating its relationship with subsequent conditions; and the logical operator for condition 3 (employment date this week) is empty.
[0051] The logical operator position correction process is as follows: Condition 1 (index 0): This is the first query condition; there is no preceding condition. Correction result: Set its logical relation to null. Do not use the "AND" logical operator value set by condition 1 itself. Condition 2 (index 1): A preceding condition (condition 1) exists. Read the logical operator value of condition 1: "AND". Correction result: Set the logical relation of condition 2 to "AND", indicating that condition 2 and condition 1 have an "AND" relationship. Condition 3 (index 2): A preceding condition (condition 2) exists. Read the logical operator value of condition 2: "OR". Correction result: Set the logical relation of condition 3 to "OR", indicating that condition 3 and condition 2 have an "OR" relationship.
[0052] The information related to the array of query condition objects after the correction process is as follows.
[0053] Condition 1: Column name "Gender", Comparison type = EqualsTo. Comparison value = "Male". Logical relation = null (first query condition). Left parenthesis level = 1. Right parenthesis level = 0. Condition 2: Column name "Date of Birth". Comparison type = GreaterThan. Comparison value = "1990 / 01 / 01". Logical relation = And (AND with the previous condition). Left parenthesis level = 0. Right parenthesis level = 1. Condition 3: Column name "Date of Employment". Comparison type = KeyFilter. Comparison value = ThisWeek. Logical relation = Or (OR with the previous condition). Left parenthesis level = 0. Right parenthesis level = 0.
[0054] It should be noted that the column names above are the first operand (op1). The comparison type above is a comparison operator (compareOperator). The comparison value above is the second operand (op2). The logical relationship above is a logical operator (logicalOperator). The left and right bracket levels above are parentheses (leftBracket and rightBracket).
[0055] Based on the corrected query conditions, the system can construct a database query statement that matches the user's intent. Since conditions 1 and 2 are enclosed in parentheses, their logical expression is equivalent to: (Gender = 'Male' AND Date of Birth > '1990 / 01 / 01') OR (Start Date within this week). This perfectly matches the user's intent to query "condition A and condition B or condition C", avoiding query result deviations caused by incorrect logical operator placement.
[0056] Before performing logical operator position correction on the array of query condition objects, the following content is also included.
[0057] Determine if the logical operator of the first query condition in the array of condition objects is empty.
[0058] If not empty, perform logical operator position correction on the array of query condition objects.
[0059] If the array is empty, the logical operator position correction process is skipped, and the query condition array is directly converted into the system's internal query condition data structure to obtain the converted query conditions. The converted query conditions are then used to execute the database query, retrieve the data records that meet the query conditions, and return the query results to the user.
[0060] S106: Convert the query condition array after performing logical operator position correction into the system's internal query condition data structure to obtain the converted query conditions.
[0061] The query condition array after logical operator position correction is converted into an internal system query condition data structure to obtain the converted query conditions, including the following:
[0062] Map the field identifiers in the first operand to internal column names.
[0063] Specifically, the mapping table between field identifiers (Field IDs) and internal column names (ColumnName) is obtained from the system metadata. The corrected query condition array is traversed, and the op1 (first operand) field value (e.g., "gender", "date of birth") of each query condition is converted into an internal column name (e.g., gender, birth_date) using the mapping table. For example, input: op1="gender". Mapping table: {"gender":"gender"}. Output: ColumnName="gender".
[0064] Convert the strings of comparison operators into system-internal enumeration values.
[0065] Specifically, for example, compareOperator="EqualsTo" is converted to the enumeration value EQUAL.
[0066] The corrected logical operators are converted into enumerated values of query condition relationships within the system.
[0067] Specifically, for example, logicalOperator="And" is converted to the enumeration value AND.
[0068] Convert the string in parentheses into a parenthesis hierarchy number, which is used to represent the priority grouping of query condition expressions.
[0069] Specifically, define the numerical representation rules for bracket levels, such as "(" (right bracket) corresponds to level +1, "")" (left bracket) corresponds to level -1.
[0070] Convert the comparison values in the second operand, which are arrays containing comparison operators, to comma-separated strings.
[0071] Specifically, for comparison operators (such as In and NotIn), check if the comparison value is in array format. If it is, convert it to a comma-separated string format to suit the system's internal data format requirements. For example, for the In operator, convert the array format (such as ["A","B"]) to a comma-separated string (such as "A,B").
[0072] S107: Execute a database query operation using the transformed query conditions, retrieve data records that meet the query conditions, and return the query results to the user.
[0073] This application also includes the following.
[0074] The array of query conditions, after the logical operator position correction is performed, is presented to the user in a visual manner.
[0075] After the user views and modifies the query conditions, the system executes the database query based on the user's confirmed query conditions, retrieves the data records that meet the query conditions, and returns the query results to the user.
[0076] This application embodiment also provides an adaptive AI output correction query condition conversion device 200, such as... Figure 2 As shown, the device includes: a receiving module 201, a building module 202, a sending module 203, a first conversion module 204, a processing module 205, a second conversion module 206, and an acquisition module 207.
[0077] The receiving module 201 is used to receive user natural language input, which includes multiple query conditions for the target table and the logical relationships between the query conditions.
[0078] The construction module 202 is used to dynamically construct system suggestion words based on the field metadata of the target table currently being queried.
[0079] The sending module 203 is used to send the system prompt words along with the user's natural language to the large language model, obtain the query condition array in JSON format returned by the large language model, and return the query condition array as the result. The query condition array is transmitted and / or stored as a string.
[0080] The first conversion module 204 is used to extract the JSON string containing the query conditions in the returned result and convert the JSON string into an array of query condition objects according to the JSON parsing rules.
[0081] Processing module 205 performs logical operator position correction processing on the query condition object array. The logical operator position correction processing includes: sequentially traversing the query condition object array; for the first query condition in the array, setting its logical relation to null; for the second and subsequent query conditions, reading the logical operator value of the previous query condition and using it as the logical relation between the current query condition and the previous query condition.
[0082] The second conversion module 206 is used to convert the query condition array after the execution of logical operator position correction processing into the system's internal query condition data structure to obtain the converted query conditions.
[0083] The acquisition module 207 is used to perform database query operations using the transformed query conditions, obtain data records that meet the query conditions, and return the query results to the user.
[0084] Some modules in the apparatus described in this application can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, classes, etc., that perform a specific task or implement a specific abstract data type. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0085] The apparatus or module described in the above embodiments can be implemented by a computer chip or physical entity, or by a product with a certain function. For ease of description, the above apparatus is described by dividing it into various modules according to their functions. When implementing the embodiments of this application, the functions of each module can be implemented in one or more software and / or hardware. Of course, a module that implements a certain function can also be implemented by combining multiple sub-modules or sub-units.
[0086] The methods, apparatus, or modules described in this application can be implemented in a computer-readable program code manner. The controller can be implemented in any suitable manner, for example, as a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of a memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code manner, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included within it for implementing various functions can also be considered as structures within the hardware component. Alternatively, the device used to implement various functions can be viewed as either a software module that implements the method or a structure within a hardware component.
[0087] like Figure 3 As shown in the figure, this application embodiment also provides an adaptive AI output correction query condition conversion server, including a memory 301 and a processor 302; the memory 301 is used to store computer-executable instructions; the processor 302 is used to execute computer-executable instructions to implement the adaptive AI output correction query condition conversion method described above in this application embodiment.
[0088] This application also provides a computer-readable storage medium storing executable instructions. When a computer executes the executable instructions, it can implement the adaptive AI output correction query condition transformation method described above in this application.
[0089] As can be seen from the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary hardware. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, or it can be embodied in the process of data migration. The computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, mobile terminal, server, or network device, etc.) to execute the methods described in the embodiments of this application.
[0090] The various embodiments described in this specification are presented in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on its differences from other embodiments. All or part of this application can be used in numerous general-purpose or special-purpose computer system environments or configurations.
[0091] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit this application. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of this application.
Claims
1. A query condition transformation method for adaptive AI output correction, characterized in that, include: Receive natural language input from the user, which includes multiple query conditions for the target table and the logical relationships between the query conditions; Based on the field metadata of the target table being queried, dynamically construct system suggestion words; The system prompts and the user's natural language are sent to the large language model. The large language model returns a JSON-formatted array of query conditions, which is then used as the return result. The query condition array is transmitted and / or stored as a string. Extract the JSON string containing the query conditions from the returned results, and convert the JSON string into an array of query condition objects according to the JSON parsing rules; Perform logical operator position correction processing on the array of query condition objects; The logical operator position correction process includes: sequentially traversing the array of query condition objects; for the first query condition in the array of condition objects, setting its logical relationship to null; for the second and subsequent query conditions in the array of condition objects, reading the logical operator value of the previous query condition and using it as the logical relationship between the current query condition and the previous query condition. The query condition array after logical operator position correction is converted into the system's internal query condition data structure to obtain the converted query conditions. The database query is executed using the transformed query conditions to retrieve data records that meet the query conditions, and the query results are returned to the user.
2. The query condition transformation method for adaptive AI output correction according to claim 1, characterized in that, Before performing logical operator position correction on the array of query condition objects, the following steps are also included: Determine if the logical operator of the first query condition in the array of condition objects is empty; If not empty, perform logical operator position correction processing on the array of query condition objects; If the value is empty, skip the logical operator position correction process and directly convert the query condition array into the system's internal query condition data structure to obtain the converted query conditions. Use the converted query conditions to execute the database query operation, obtain the data records that meet the query conditions, and return the query results to the user.
3. The query condition transformation method for adaptive AI output correction according to claim 1, characterized in that, The system prompts include a list of all fields in the target table that will be used for the query, a list of comparison operators applicable to each field, a list of logical operators used to connect the query conditions, and output format requirements.
4. The query condition transformation method for adaptive AI output correction according to claim 1, characterized in that, The extracted results contain a JSON string representing the query conditions. This JSON string is then converted into an array of query condition objects according to JSON parsing rules, including: The JSON string containing the query conditions in the returned result is extracted using regular expression matching. The matching rule is: find the JSON string that starts with square brackets and ends with square brackets in the returned result, and the JSON string contains one or more JSON objects, so as to convert the JSON string into an array of query condition objects according to the JSON parsing rules. The query condition object array includes: a first operand representing the database field name, a comparison operator, a second operand representing the comparison value, logical operators, and parentheses representing the priority of nested query conditions; among them, logical operators only take effect if the current query condition is not the first query condition in the query condition array.
5. The adaptive AI output correction query condition transformation method according to claim 4, characterized in that, The process of converting the query condition array after logical operator position correction into an internal system query condition data structure to obtain the converted query conditions includes: Map the field identifiers in the first operand to internal column names; Convert the comparison operator string into the system's internal enumeration value; The corrected logical operators are converted into enumerated values of query condition relationships within the system. Convert the string in parentheses into a parenthesis hierarchy number, which is used to represent the priority grouping of query condition expressions; Convert the comparison values in the second operand, which are arrays containing comparison operators, to comma-separated strings.
6. The query condition transformation method for adaptive AI output correction according to claim 1, characterized in that, Also includes: The query condition array after logical operator position correction is presented to the user in a visual format; After the user views and modifies the query conditions, the system executes the database query based on the user's confirmed query conditions, retrieves the data records that meet the query conditions, and returns the query results to the user.
7. A query condition transformation device for adaptive AI output correction, characterized in that, The device performs the method as described in any one of claims 1 to 6, including: The receiving module is used to receive user natural language input, which includes multiple query conditions for the target table and the logical relationships between the query conditions. The build module is used to dynamically construct system suggestion words based on the field metadata of the target table currently being queried; The sending module is used to send the system prompt words along with the user's natural language to the large language model, obtain the query condition array in JSON format returned by the large language model, and return the query condition array as the result; wherein, the query condition array is transmitted and / or stored in string form; The first conversion module is used to extract the JSON string containing the query conditions from the returned results and convert the JSON string into an array of query condition objects according to the JSON parsing rules; The processing module is used to perform logical operator position correction processing on the query condition object array. The logical operator position correction processing includes: traversing the query condition object array in sequence, setting the logical relationship of the first query condition in the condition object array to empty; for the second and subsequent query conditions in the condition object array, reading the logical operator value of the previous query condition and using it as the logical relationship between the current query condition and the previous query condition. The second conversion module is used to convert the query condition array after the execution of logical operator position correction processing into the system's internal query condition data structure to obtain the converted query conditions. The retrieval module is used to perform database query operations using the transformed query conditions, retrieve data records that meet the query conditions, and return the query results to the user.
8. A query condition transformation server for adaptive AI output correction, characterized in that, Including memory and processor; The memory is used to store computer-executable instructions; The processor is configured to execute the computer-executable instructions to implement the method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores executable instructions, which, when executed by a computer, enable the implementation of the method as described in any one of claims 1-6.
Citation Information
Patent Citations
SQL (Structured Query Language)-based code conversion method and device, equipment and medium
CN117632999A
Method and device for generating SQL (Structured Query Language) based on natural language, and computer equipment
CN119106043A