Query statement generation method and device, electronic equipment and storage medium

By identifying demand intent and combining language models and database schema information to generate query statements, the problem of high error rate in query statement generation with the assistance of artificial intelligence is solved, and the accuracy of query statements and the efficiency of business services are improved.

CN120743928AActive Publication Date: 2025-10-03INSPUR SUZHOU INTELLIGENT TECH CO LTD

Patent Information

Application Number
CN202511224669.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-29
Publication Date
2025-10-03
Estimated Expiration
2045-08-29

AI Technical Summary

Technical Problem

In database query tasks assisted by artificial intelligence technology, the error rate of query statement generation is high, resulting in reduced business service response efficiency.

Method used

By identifying demand intent based on business data, using language models to generate execution logic structures, combining preset database schema information for semantic understanding, outputting intermediate structured data, and ultimately generating accurate query statements.

Benefits of technology

It improves the accuracy of query statements and the response speed of business services, avoids operations on irrelevant or erroneous database objects, and improves the response efficiency of business services.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120743928A_ABST
    Figure CN120743928A_ABST
Patent Text Reader

Abstract

The invention provides a query statement generation method and device, electronic equipment and a storage medium, and relates to the field of artificial intelligence, in particular to the field of computers, the field of databases and the field of deep learning. The query statement generation method comprises the steps of performing intention recognition on a demand text based on business data to obtain a demand intention; in response to the demand intention meeting a preset demand condition, processing the demand intention by using a language model to obtain an execution logic structure, the execution logic structure comprising a plurality of execution logic elements based on structured representation, and a structured relationship among the plurality of execution logic elements representing an execution process of executing the query statement; determining target mode information matched with the text semantics represented by the execution logic element from preset database mode information; performing semantic understanding on the plurality of execution logic elements and the target mode information by utilizing a language model, and outputting a plurality of pieces of intermediate structured data for describing the query statement; and generating a query statement according to the intermediate structured data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence, specifically to the field of computers, databases, and deep learning, and more specifically to a query statement generation method, device, electronic device, and storage medium. Background Art

[0002] With the rapid development of artificial intelligence (AI), database query tasks can be completed with the assistance of AI. This can improve business service response efficiency by using AI-assisted query execution. However, using AI-assisted database query tasks can result in high data query error rates and query execution failures, which can affect the business service experience. Summary of the Invention

[0003] In view of the above problems, the present application provides a query statement generation method, device, electronic device and storage medium.

[0004] According to the first aspect of the present application, a query statement generation method is provided, comprising: performing intent recognition on a demand text based on business data to obtain a demand intent; in response to the demand intent satisfying a preset demand condition, processing the demand intent using a language model to obtain an execution logic structure, wherein the execution logic structure comprises a plurality of execution logic elements based on a structured representation, the execution logic elements representing a target task of executing the query statement or target metadata related to the target task based on text semantics, and the structured relationship between the plurality of the execution logic elements representing the execution process of the query statement; determining target pattern information matching the text semantics represented by the execution logic elements from preset database pattern information; outputting a plurality of intermediate structured data for describing the query statement by performing semantic understanding on the plurality of the execution logic elements and the target pattern information using the language model; and generating the query statement based on the plurality of the intermediate structured data.

[0005] The second aspect of the present application provides a query statement generation device, including: an identification module, which is used to identify the intent of the demand text based on business data to obtain the demand intent; an execution logic structure acquisition module, which is used to process the demand intent using a language model in response to the demand intent satisfying the preset demand conditions to obtain an execution logic structure, wherein the execution logic structure includes multiple execution logic elements based on structured representation, and the execution logic elements represent the target task of executing the query statement or target metadata related to the target task based on text semantics, and the structured relationship between the multiple execution logic elements represents the execution process of executing the query statement; a target pattern information acquisition module, which is used to determine the target pattern information that matches the text semantics represented by the execution logic element from the preset database pattern information; an intermediate structured data acquisition module, which is used to use the language model to perform semantic understanding on the multiple execution logic elements and the target pattern information, and output multiple intermediate structured data for describing the query statement; a query statement generation module, which is used to generate the query statement based on the multiple intermediate structured data.

[0006] The third aspect of the present application provides an electronic device, comprising: one or more processors; a memory for storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the query statement generation method.

[0007] The fourth aspect of the present application further provides a computer-readable storage medium having a computer program or instruction stored thereon, which implements the steps of the query statement generation method when the computer program or instruction is executed by a processor.

[0008] The fifth aspect of the present application further provides a computer program product, including a computer program or instructions, which implements the steps of the above-mentioned query statement generation method when the above-mentioned computer program or instructions are executed by a processor.

[0009] According to an embodiment of the present application, the text semantics of multiple execution logic elements in the execution logic structure are used to represent multiple target tasks corresponding to the query statement, and the execution logic between the multiple target tasks is represented based on the structured relationship between the execution logic elements, thereby clearly and clearly characterizing the execution process of the query statement that matches the execution requirement text through text semantics. In addition, by determining the target pattern information that matches the execution logic element, and semantically understanding the execution logic element and the target pattern information based on the language model, the objects represented by the database pattern information such as tables, columns, and indexes required to execute the target task are clearly determined, so that the output intermediate structured data can accurately represent the multiple target tasks in the execution query statement, and match the target task with the logical process of executing operations on objects such as tables and columns of the database, avoiding the output query statement operating on irrelevant or erroneous database objects due to hallucinations generated by the language model, so that the query statement generated based on the intermediate structured data can improve the accuracy of the query statement and improve the response speed of the business service implemented by executing the query statement. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] The above contents and other objects, features and advantages of the present application will become more apparent through the following description of the embodiments of the present application with reference to the accompanying drawings, in which:

[0011] Figure 1 An application scenario diagram of the query statement generation method according to an embodiment of the present application is shown.

[0012] Figure 2 A flowchart of a query statement generation method according to an embodiment of the present application is shown.

[0013] Figure 3 A schematic diagram of a thinking process topology according to an embodiment of the present application is shown.

[0014] Figure 4 A schematic diagram of an execution logic structure according to an embodiment of the present application is shown.

[0015] Figure 5 A schematic diagram of a query statement generation method according to an embodiment of the present application is shown.

[0016] Figure 6 A structural diagram of a query statement conversion link and a verification link according to an embodiment of the present application is shown.

[0017] Figure 7 A schematic diagram of a checkpoint according to an embodiment of the present application is shown.

[0018] Figure 8 A structural block diagram of a query statement generating device according to an embodiment of the present application is shown.

[0019] Figure 9 A block diagram of an electronic device suitable for implementing a query statement generating method according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0020] Hereinafter, embodiments of the present application will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present application. In the detailed description below, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present application. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessarily confusing the concepts of the present application.

[0021] The terms used herein are only for describing specific embodiments and are not intended to limit this application. The terms "comprise," "include," etc. used herein indicate the presence of the features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.

[0022] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.

[0023] When expressions such as "at least one of A, B, and C, etc." are used, they should generally be interpreted in accordance with the meaning commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).

[0024] In the technical solution of this application, the user information involved (including but not limited to user personal information, user image information, user device information, such as location information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) are all information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of the relevant data comply with relevant laws and standards, take necessary encryption measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0025] With the rapid development of artificial intelligence technology, large language models can be used to generate query statements through semantic understanding of natural language. This reduces the time and workload required by professionals to write queries using programming languages, improving the efficiency of diverse business services such as product transactions and information queries. However, query statements generated based on large language models are difficult to accurately adapt to business service requirements and are prone to query generation errors, resulting in reduced business service response efficiency and difficulty meeting actual business service needs.

[0026] The embodiments of the present application provide a query statement generation method, device, electronic device and storage medium. The query statement generation method includes: performing intent recognition on the demand text based on business data to obtain the demand intent; in response to the demand intent satisfying the preset demand condition, using the language model to process the demand intent to obtain an execution logic structure, the execution logic structure includes multiple execution logic elements based on structured representation, the execution logic elements represent the target task of executing the query statement or target metadata related to the target task based on the text semantics, and the structured relationship between the multiple execution logic elements represents the execution process of the query statement; determining the target pattern information that matches the text semantics represented by the execution logic element from the preset database pattern information; using the language model to perform semantic understanding on multiple execution logic elements and target pattern information, and outputting multiple intermediate structured data for describing the query statement; generating a query statement based on the multiple intermediate structured data.

[0027] According to an embodiment of the present application, by identifying the requirement intent of a requirement text and processing the requirement intent through a language model to obtain an execution logic structure, the textual semantics of multiple execution logic elements in the execution logic structure can be used to represent multiple target tasks corresponding to the query statement, and the execution logic between the multiple target tasks can be represented based on the structured relationship between the execution logic elements. Thus, the execution process of the query statement matching the requirement text can be structured and clearly represented through textual semantics through the execution logic structure. Furthermore, by determining target schema information matching the execution logic elements and semantically understanding the execution logic elements and target schema information based on a language model, the objects represented by database schema information such as tables, columns, and indexes required to execute the target tasks can be clearly determined. The output intermediate structured data can accurately represent the multiple target tasks in the query statement, and the target tasks can be matched with the logical process of executing operations on database tables, columns, and other objects. Thus, query statements can be generated based on the multiple intermediate structured data to match the actual requirements of the requirement text for query statement editing, avoiding the output query statement operating on irrelevant or erroneous database objects due to hallucinations generated by the language model, improving the accuracy of the query statement, and improving the response speed of the business service implemented by executing the query statement.

[0028] Figure 1 An application scenario diagram of the query statement generation method according to an embodiment of the present application is shown.

[0029] like Figure 1 As shown, the application scenario 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 is used as a medium for providing a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired or wireless communication links or optical fiber cables.

[0030] A user may use a first terminal device 101, a second terminal device 102, or a third terminal device 103 to interact with a server 105 via a network 104 to receive or send messages, etc. Various communication client applications may be installed on the first terminal device 101, the second terminal device 102, or the third terminal device 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (for example only).

[0031] The first terminal device 101 , the second terminal device 102 , and the third terminal device 103 may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

[0032] The server 105 may be a server that provides various services, such as a background management server (for example only) that supports websites browsed by users using the first terminal device 101, the second terminal device 102, and the third terminal device 103. The background management server may analyze and process received data such as user requests, and feed back processing results (e.g., web pages, information, or data obtained or generated based on user requests) to the terminal devices.

[0033] It should be noted that the query statement generation method provided in the embodiment of the present application can generally be executed by the server 105. Accordingly, the query statement generation device provided in the embodiment of the present application can generally be set in the server 105. The query statement generation method provided in the embodiment of the present application can also be executed by a server or server cluster that is different from the server 105 and can communicate with the first terminal device 101, the second terminal device 102, the third terminal device 103 and / or the server 105. Accordingly, the query statement generation device provided in the embodiment of the present application can also be set in a server or server cluster that is different from the server 105 and can communicate with the first terminal device 101, the second terminal device 102, the third terminal device 103 and / or the server 105.

[0034] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.

[0035] Figure 2 A flowchart of a query statement generation method according to an embodiment of the present application is shown.

[0036] like Figure 2 As shown, the query statement generation method of this embodiment includes operations S210 to S250.

[0037] In operation S210 , the intent of the demand text is identified based on the business data to obtain the demand intent.

[0038] According to an embodiment of the present application, the demand text may be a text based on a natural language description input by a user through a terminal device. For example, a user may input the demand text by performing interactive operations such as voice interaction and touch interaction through a smart phone.

[0039] According to an embodiment of the present application, business data may be data related to the business type indicated by the user who inputs the demand text. For example, if the business service targeted by the user is a smartphone service, and the user inputs "How long does it take for xx to arrive?", the demand text may be intended to be identified based on the logistics data and sales data related to the smartphone model "xx" as business data.

[0040] In some embodiments, the requirement intent may be information such as text, symbols, etc. that represents the semantic attributes of the requirement in the requirement text. For example, the requirement intent may be the requirement keywords obtained by extracting keywords from the requirement text.

[0041] In some embodiments, a large language model can be used to identify the intent of a requirement text based on business data to obtain the requirement intent. By using a large language model to process the requirement text and output the requirement intent, the requirement intent can more accurately represent the requirement attributes of the semantic representation of the requirement text, thereby further improving the match between the subsequent execution logic structure and the requirements represented by the requirement text.

[0042] In operation S220 , in response to the requirement intention satisfying a preset requirement condition, the requirement intention is processed using a language model to obtain an execution logic structure.

[0043] According to the embodiments of the present application, the preset requirement conditions may indicate that the semantic complexity of the requirement intention representation satisfies the preset complexity conditions, or may also indicate that the semantic clarity and semantic logical coherence of the requirement intention representation meet the preset quality conditions. For another example, the preset requirement conditions may also indicate that the product or business service type that matches the requirement intention matches the business attributes of the business data in the database. The embodiments of the present application do not limit the specific types of preset requirement conditions, and those skilled in the art may design based on actual needs.

[0044] According to embodiments of the present application, the language model may be a trained Large Language Model (LLM), which may have relatively large model parameters and be constructed based on a deep learning model algorithm. Based on these relatively large model parameters, the LLM can perform semantic understanding of textual content, such as demand intent, to generate text, code, files, and other content that matches the training objective or the objective indicated by the prompt information.

[0045] It should be noted that the language model or large language model involved in the embodiments of the present application can be uniformly represented as a large model with a large parameter scale. The large model can perform data processing tasks by processing multimodal information such as images and text, and output execution results.

[0046] According to an embodiment of the present application, the execution logic structure includes a plurality of execution logic elements based on structured representation, and the execution logic elements are based on text semantics to represent the target task of executing the query statement or target metadata related to the target task. For example, the execution logic element can be text such as select, delete, and sum, which are used to indicate the type of operation performed in the target task of the query statement. For another example, the execution logic element can be text such as "A region", "January 2020", etc., which represent the execution conditions of the target task such as time and geographical area. For another example, the execution logic element can also be text such as "Brand A", "Mobile phone", "Sales volume", etc., which are related to the target metadata indicated by the target task in the query statement.

[0047] According to an embodiment of the present application, the execution logic structure is represented based on a structured relationship between multiple execution elements and execution logic elements. The execution logic elements can be represented based on texts such as Chinese and English. The structured relationship between multiple execution logic elements represents the execution process of the query statement. The structured relationship can be represented based on the text grammatical relationship between multiple sentences or words in the text. For example, multiple different execution logic elements can be represented based on multiple paragraphs. For another example, the subject content corresponding to multiple paragraphs can be used as an execution logic element to represent the grammatical structural relationship between the subject content and the execution logic elements in the text of the relevant multiple paragraphs.

[0048] Alternatively, structured relationships can be represented based on edge relationships within a topology graph. For example, the execution logic structure can be a tree topology, with execution logic elements consisting of multiple nodes with edge relationships within the tree topology. Edge relationships between nodes represent the structured relationships between execution logic elements. Each branch subtopology within the tree topology can represent the parallel execution of multiple target tasks within a query statement.

[0049] In operation S230 , target schema information matching the text semantics of the execution logical element representation is determined from the preset database schema information.

[0050] According to an embodiment of the present application, preset database schema information can be used to describe business data-related information such as data tables in a database, data fields contained in the data tables, data types of the data fields, mapping relationships between primary keys and foreign keys, indexes, constraints, etc. The preset database schema information can include preset metadata fields such as the data table name field, column identification fields in the data table, and index fields. Alternatively, the preset database schema information can include preset fields related to operations such as functions, operators, and identifiers that can be executed by query statements.

[0051] In some embodiments, the target schema information can be determined by semantically matching the execution logic element with fields in the preset database schema information. For example, for the execution logic element "sales," the target metadata field "orders.amount" can be determined from the preset database schema information as the target schema information. The target metadata field "orders.amount" represents the table name of the data table corresponding to sales orders in the database.

[0052] In operation S240 , a plurality of intermediate structured data for describing the query statement is output by semantically understanding the plurality of execution logic elements and the target pattern information using a language model.

[0053] In some embodiments, intermediate structured data is used to describe the target tasks in the query statement based on a structured format language, and the attribute information representing the structured relationship, such as the arrangement relationship and hierarchical relationship between multiple intermediate structured data, can represent the execution logic between multiple target tasks.

[0054] According to embodiments of the present application, intermediate structured data can describe a query statement according to a preset configuration format, and the query execution result cannot be generated by directly executing the intermediate structured data. For example, it can be represented based on a preset configuration format such as JSON, YAML, or XML. Embodiments of the present application do not limit the specific format type of the intermediate structured data, as long as it can describe the target task in the query statement.

[0055] In some embodiments, the intermediate structured data may include target schema information with binding relationships (also known as dependency relationships or mapping relationships) and execution logic elements represented in a preset configuration format. For example, the intermediate structured data may be sum(A1 and B1), where "sum" is an execution logic element represented in a preset configuration format, and "A1" and "B1" are data table name fields serving as the target schema information.

[0056] In operation S250 , a query statement is generated according to the plurality of intermediate structured data.

[0057] In some embodiments, the intermediate structured data can be data fields represented in a structured Domain-Specific Language (DSL) format. The intermediate structured data uses structured JSON data fields to represent the logical execution process of the target task in the query statement. This allows multiple intermediate structured data to be used to describe the query execution process, allowing tools such as query builders to process the multiple intermediate structured data and generate a query statement that matches the intent of the requirement document.

[0058] According to an embodiment of the present application, by representing execution logic elements based on text and representing the textual grammatical relationships between the texts of multiple execution logic elements based on structured relationships, the execution logic process of multiple target tasks in a query statement can be more accurately and clearly represented based on the textual semantic logic represented by the execution logic structure. This allows the language model to perform semantic understanding of the multiple execution logic elements and structured relationships in the execution logic structure, so as to more clearly convert the execution process of multiple target tasks in the execution query statement into multiple intermediate structured data that can be used to describe the query statement, thereby avoiding the misunderstanding caused by the language model converting the code content of the query statement by understanding natural language. At the same time, by understanding the matching target pattern information and execution logic elements through the language model, it is possible to avoid the occurrence of mismatches between operation fields and metadata fields in the intermediate structured data output by the language model, or even the illusion that metadata fields such as table names and column names do not exist in the database. This allows the query statement generated based on the multiple intermediate structured data to more accurately represent the actual demand intent of the user input demand text, thereby improving the efficiency of query statement generation and business service response.

[0059] In some embodiments, generating a query statement based on the plurality of intermediate structured data may include: using a language model to process the plurality of intermediate structured data represented by attributes in a domain-specific language format to generate a query statement.

[0060] According to embodiments of the present application, by using a language model to process multiple intermediate structured data represented by domain-specific language format attributes to generate query statements, the language model's relatively large model parameter scale and powerful semantic understanding capabilities can be used to understand the execution process of the query statements represented by the multiple intermediate structured data and output more accurate query statements. This improves the efficiency and accuracy of query statement generation, and further improves the efficiency of business service responses through query execution.

[0061] In one example, the requirement text is "Mobile phone products with a rating less than 3 points or a return rate greater than 10% in region A or region B." By processing the requirement text using a language model, multiple keywords are obtained: region A, region B, mobile phone, rating less than 3 points, and return rate greater than 10%, as multiple requirement intents. By processing these multiple requirement intents using a language model, an execution logic structure based on structured text representation is output. By processing the execution logic structure and the target pattern information matching the execution logic elements using the language model, intermediate structured data represented by domain-specific language format attributes, enclosed by the following symbols " / / ", can be output.

[0062] / / {"operation": "SELECT","columns": [{"name": "product_name", "alias": "Product Name"},{"name": "region", "alias": "Region"},{"name": "avg_rating", "alias": "Average Rating"},{"name": "return_rate", "alias": "Return Rate"}] / / .

[0063] / / "from": {"primary_table": "products","joins": [{"type": "INNERJOIN", "table": "sales_stats", "on": "products.id = sales_stats.product_id"},{"type": "INNER JOIN", "table": "regions", "on": "sales_stats.region_id =regions.id"}]} / / .

[0064] / / "where": ["(regions.name IN ('A region', 'B region'))","products.category= 'Mobile phone'","(sales_stats.avg_rating < 3 OR sales_stats.return_rate > 0.1)"]} / / .

[0065] Among them, "from": {"primary_table": "products", can be expressed as intermediate structured data, where "from" can be the identifier field corresponding to the execution logic element "where to query from", primary_table, and "products" are the target metadata fields corresponding to the execution logic element "product data table".

[0066] By using a language model to process the multiple structured data represented by the domain-specific language format attributes in this example, a corresponding query statement can be generated. This allows the dependencies between identifiers and metadata fields in the query statement to be more accurately represented through multiple intermediate structured data, thereby improving the efficiency and accuracy of query statement generation and enhancing business response efficiency.

[0067] In some embodiments, performing intent recognition on the demand text to obtain the demand intent includes: using a language model to perform intent recognition on the demand text to obtain structured demand content.

[0068] According to an embodiment of the present application, the demand intent includes structured demand content, and the structured demand content includes data attribute items and data content related to the metadata in the query statement. The data attribute item represents the attribute type of the metadata field, and the data content represents the metadata field based on the text. For example, the demand attribute items are "region", "time range", and "indicator type", and the data content associated with the demand attribute items are "region A", "2024", and "return rate" respectively. By expressing the demand intent based on the associated data attribute items and data content in the structured demand content, the semantic model can more accurately understand the demand semantics expressed by the demand text, and accurately convert the demand semantics into intermediate structured data that can represent the target task in the query statement, so as to improve the accuracy of the query statement and the degree of match between the demand semantics and the demand text.

[0069] In one embodiment, the requirement intent may include the following structured requirement content.

[0070] basic_type: "Compare". Complexity: "Medium". normalized_question: "Compare the differences in [mobile phone return rates] between [region A, region B] in [the first half of 2024] and [the second half of 2024]. Keywords: "mobile phone", "return rate". Dimensions: Region: ["Region A", "Region B"]. Time base period: label: "first half of the year". Time comparison period: label: "second half of the year".

[0071] In some embodiments, performing intent recognition on the requirement text to obtain the requirement intent also includes: using a language model to semantically update the requirement text to obtain a target requirement text.

[0072] According to an embodiment of the present application, the target requirement text represents at least one requirement content based on a specified tag, and the target requirement text is used to prompt a language model to perform semantic understanding of the requirement intent based on the associated specified tag and the requirement content.

[0073] For example, if the requirement text is "Compare the mobile phone return rates in Region A and Region B's eastern region in the first half and second half of 2024," the language model outputs the updated target requirement text as: "Compare the difference in [mobile phone return rates] between [Region A's eastern region and Region B's eastern region] in the [first half of 2024] and [second half of 2024]." The "[]" denotes associated designated tags. These designated tags enclose the requirement content to prompt the language model to accurately identify the actual requirement intent expressed in the requirement text. This allows the language model to accurately understand the target requirement text in the requirement intent and output the execution logic elements and structured relationships that accurately describe the target task in the query statement through text. This improves the precision of the intermediate structured data and the accuracy of the query statement, reduces the likelihood of the language model outputting query statements unrelated to the business database due to semantic understanding hallucinations, and improves the query quality.

[0074] In some embodiments, the requirement intent also includes the requirement complexity determined by semantically understanding the requirement text through a language model. The requirement complexity indicates the complexity of executing the query statement. For example, the requirement complexity can represent the complexity of the query statement's execution conditions, operation complexity, metadata data attribute item complexity, etc.

[0075] For example, requirement complexity can represent the number of data attribute items in the requirement content. A greater number of data attribute items indicates that the query statement requires operations on more dimensions and different types of metadata. This can be understood as the greater the number of data attribute items, the higher the requirement complexity.

[0076] In one embodiment, the requirement complexity of a requirement document can be scored based on multiple dimensions, and the requirement complexity score is determined based on the complexity scores corresponding to the multiple dimensions. The requirement complexity score Qcs = Ds + Os + Cs + Ms, which can be understood as requirement complexity = data attribute item score + operation complexity score + condition complexity score + modification score.

[0077] The data attribute score Ds represents the number of specific dimensions of data attribute items explicitly mentioned in the requirement text. For example, if a requirement text includes three different data attribute items: region, time, and product, each additional data attribute item adds one point, with a maximum score of 3. The operation complexity score Os ranges from 0 to 4 and reflects the complexity of the operation requirements implied in the requirement text. For example, the content shown in Table 1 can be used as prompt information to prompt the language model to output the operation complexity score after processing the requirement text.

[0078] Table 1

[0079]

[0080] The condition complexity score Cs ranges from 0 to 3 and represents the complexity of the filter condition in the query statement represented by the requirement text. For example, the content shown in Table 2 can be used as prompt information to prompt the language model to output the condition complexity score after processing the requirement text.

[0081] Table 2

[0082]

[0083] The modified score Ms is used to modify the requirement complexity score and can be set based on experience or calibrated based on historical execution results to determine the modified score value.

[0084] In one embodiment, requirement complexity can also be represented based on a complexity level type. For example, a preset complexity rating scale is queried based on the requirement complexity score. In the preset complexity rating scale, requirement complexity scores of 0 to 3 represent a simple level, requirement complexity scores of 4 to 7 represent a medium level, and requirement complexity scores of 8 to 10 represent a complex level. The complexity level type is used as the requirement complexity.

[0085] In some embodiments, the requirement complexity is used to prompt the language model, and the requirement intent is processed based on a thinking process topology that matches the requirement complexity to obtain an execution logic structure.

[0086] According to an embodiment of the present application, the thinking process topology can represent the thinking tasks that need to be performed in the thinking process of the language model to process the demand intent. The thinking process topology that matches the demand complexity can represent the depth of thinking of the thinking process that matches the complexity level or complexity score of the demand complexity. By executing the processing tasks for the demand intent based on the depth of thinking that matches the demand complexity, the demand complexity can be used as prompt information to prompt the language model to avoid over-thinking for demand intents with lower demand complexity and avoid insufficient depth of thinking for demand intents with higher demand complexity. Therefore, the degree of matching between the execution logic structure and the execution process required by the query statement represented by the demand intent is improved, so as to improve the accuracy of the intermediate structured data in describing the execution process of multiple target tasks in the query statement, and thereby improve the accuracy of query statement generation.

[0087] In some embodiments, the topological complexity of the thought process topology may represent the depth of thought in the thought process. Alternatively, the depth of thought may be represented based on the number of thought tasks in the thought process topology.

[0088] Figure 3 A schematic diagram of a thinking process topology according to an embodiment of the present application is shown.

[0089] like Figure 3 As shown, the thinking process topology 300 includes multiple thinking tasks. Multiple thinking tasks are represented based on circular nodes respectively. The first thinking task can be a task for determining a storage area. The first thinking task indicates determining a storage area that matches the demand intent from a preset storage area as the execution area of ​​the query statement. The second thinking task indicates determining the table name field corresponding to area A according to the demand intent "Area A" and using it as the target metadata field. The third thinking task indicates determining the specific time condition field "2020.1.1 to 2020.6.30" according to the demand intent "the first half of 2020". The fourth thinking task indicates performing function field conversion on the demand intent "sum" to obtain the task of the function editing process.

[0090] According to an embodiment of the present application, using a language model to process demand intent and obtain an execution logic structure may include: based on the complexity of the demand, using a language model to perform task planning on the demand content in the demand intent to determine the thinking process topology; and using a language model to execute multiple thinking tasks based on dependency relationships and output an execution logic structure.

[0091] In some embodiments, multiple thinking tasks in the thinking process topology have dependencies, and the number of thinking tasks matches the complexity of requirements.

[0092] For example, if the complexity of a requirement in a demand intent is a complexity score of 3, the language model can use this complexity as a prompt to perform task planning for multiple related data attributes and data content in the requirement intent, thereby outputting a thought process topology. The number of thought tasks in the thought process topology matches the number of predefined tasks corresponding to a complexity score of 3.

[0093] For example, if the complexity level of a requirement in a demand intent is "medium," the language model can use the complexity level as a prompt to perform task planning for multiple related data attributes and data content in the demand intent, thereby outputting a thought process topology. The number of thought tasks in the thought process topology matches the preset number of tasks corresponding to the "medium" complexity level.

[0094] According to an embodiment of the present application, the complexity and content of the requirements are determined by performing intent recognition on the requirement text, and the language model is prompted according to the complexity of the requirements to perform task planning based on the complexity of multiple target tasks in the query statement represented by the requirement text, so as to avoid overthinking or underthinking about the requirement intent. In this way, the prompting effect of the complexity of the requirements can be used to control the language model to generate a thinking process topology that matches the complexity of the requirements, and to achieve explicit control of the language model to avoid the situation where the text semantics and execution process represented by the execution logical structure do not match the execution process and target tasks of the query statement due to hallucinations, thereby improving the accuracy of query statement generation.

[0095] In one embodiment, the number of thinking tasks in the thinking process topology matches the complexity of the requirements, and the thinking tasks are associated with execution logic elements with the same attributes. For example, a time range thinking task in the thinking process topology is used to output a time attribute element related to the time attribute "September 1, 2020 to September 1, 2023" by processing the requirements "Time: Recent Three Fiscal Years" and "Industry: Management of Professional Ball League Teams" using an instructional language model. Consequently, the thinking tasks associated with each of the multiple attributes in the thinking process topology can be used to output execution logic elements corresponding to each of the multiple attributes. This allows the execution logic elements to more accurately represent the conditional content, data table names, and other metadata fields related to the target task of the query statement through the relatively accurate text content of the execution logic elements, thereby improving the accuracy of the execution logic structure's representation of the query execution process, further improving the efficiency and accuracy of query generation, and improving business response efficiency.

[0096] In some embodiments, the requirement intent meeting a preset requirement condition includes: the requirement complexity being greater than or equal to a preset complexity threshold. For example, the requirement complexity score in the requirement intent is greater than or equal to a preset complexity score threshold, or, for another example, the requirement complexity level in the requirement intent is greater than a preset level type.

[0097] In one example, when the complexity of the requirement is greater than or equal to a preset complexity threshold, the language model is used to process the requirement intent to output an execution logic structure, and intermediate structured data is generated based on the execution logic structure and target pattern information, thereby generating a query statement based on the intermediate structured data. When the complexity of the requirement is less than the preset complexity threshold, it can be determined that the requirement intent does not meet the preset requirement conditions. Therefore, the language model can be used to process a simpler requirement intent and directly output a query statement, thereby improving the efficiency of query statement generation for requirement texts with simpler requirement semantics, and improving the adaptability and flexibility of the query statement generation method provided in the embodiment of the present application for different requirement texts.

[0098] In some embodiments, the execution logic element includes at least one of the following: a time attribute element representing a time condition; a region attribute element representing a region condition; and an indicator type element representing a calculation indicator in a demand intent.

[0099] According to an embodiment of the present application, the time attribute element is a text related to the time field in a preset metadata field. For example, the time attribute element is a text such as "the first half of 2024" or "the first quarter of 2020" that can accurately express the time semantics.

[0100] The regional attribute element is a text related to the regional scope in a preset metadata field. For example, the regional attribute element is text such as "A region" or "A region urban area" that can more accurately represent the regional attribute semantics.

[0101] The indicator type element represents a metadata field related to the indicator type in the preset metadata field. For example, the indicator type element is a text representing the table name and column name fields related to the profit margin indicator type.

[0102] Figure 4 A schematic diagram of an execution logic structure according to an embodiment of the present application is shown.

[0103] like Figure 4 As shown, execution logic structure 400 includes multiple substructures, including an entity element structure 410 and a time attribute element structure 420. Entity element structure 410 includes a first-level execution logic element, "Entity Element Definition," and second-level execution logic elements, "Mobile Phone," "Region A," and "Region B." The dotted lines between the execution logic elements indicate the structural relationships between the execution logic elements. The first-level execution logic elements can indicate, through textual semantics, that multiple execution logic elements in entity element structure 410 are metadata fields related to database objects, such as data tables and indexes, that require the language model to focus on.

[0104] Time attribute element structure 420 includes a first-level execution logic element "time attribute description," a second-level execution logic element "time period comparison," a third-level execution logic element "baseline period: label: first half of 2024; time period range: 2024-01-01 to 2024-06-30," and a third-level execution logic element "target period: label: second half of 2024; time period range: 2024-07-01 to 2024-12-31." The "time attribute description" can use textual semantics to instruct the language model to understand and generate a target task related to the time condition. The "time period comparison" can prompt the language model to understand that the specific task condition of the target task is "comparing data from different time periods." The third-level execution logic element can represent the time boundaries of the specific task condition in "comparing data from different time periods" based on structured relationships. In this way, the time attribute element structure 420 is used to prompt the language model to accurately determine the time attribute conditions of the target task, and combine the semantics of other execution logic elements to construct metadata fields such as table fields and column fields that match the time attribute conditions, so that the intermediate structured data can more accurately represent the execution process of multiple target tasks in the query statement, so as to improve the accuracy of the generated query statement and avoid hallucinations of the language model.

[0105] In one example, a user enters a requirement text: "Compare the mobile phone return rates in Regions A and B in the first and second half of 2024." Intent recognition is performed on the requirement text to obtain the requirement intent. A language model is then used to semantically understand the requirement intent and output an execution logic structure. The content enclosed by "#" ("#") is represented as follows: The content within "()" ("#") represents the function or effect of the execution logic element.

[0106] #operation: COMPARISON (indicates that the query statement operation type required by the requirement text is: comparison) #.

[0107] Attribute element definition (first-level execution logic element). product: attributes: [category] (attribute: type); filters: ["category = 'Mobile Phone'"] (execution logic element indicating business type qualification)#.

[0108] #region: attributes: [name]; filters: ["name IN ('A region', 'B region')"] (indicates the region attribute filter condition). metric:type: RATE (indicates that the metric type is ratio). name: "return_rate" (indicates that the metric type is return rate). calculation: "returned_quantity / total_quantity" (indicates that the logical calculation method for "return rate" is: total returned quantity / total sold quantity)#.

[0109] #Description of temporal attributes. temporal: (indicates the temporal attribute); comparison_type: PERIOD_COMPARISON (indicates period comparison); base__period: (indicates the base period); label: "2024-1H"; range: "2024-01-01 to 2024-06-30" (indicates the boundaries of the temporal attribute condition); aggregation: REQUIRED (indicates that aggregation calculation is required); target_period: (indicates the target period); label: "2024-2H"; range: "2024-07-01 to 2024-12-31" (indicates the specific boundaries of the target period); aggregation: REQUIRED (indicates that aggregation calculation is required). #

[0110] #Logical analysis structure; dimensions: (indicates the logical analysis dimensions); entity: region (entity: region); attribute: name (attribute: name); role: GROUP_KEY (indicates the "grouping" basis in the query statement); values: ["A region", "B region"] (indicates the value field on which "grouping" should be based)#.

[0111] #Logical calculation structure, Projections, type: DIMENSION, source: region.name, alias: "region", type: METRIC, source: metric.return_rate (indicating the indicator type), alias: "Return rate in the first half of the year", context: base_period; (indicating that the content bound to the return rate in the first half of the year is data related to the base period), type: METRIC, source: metric.return_rate, alias: "Return rate in the second half of the year", context: target_period; (indicating that the content bound to the return rate in the second half of the year is data related to the target period)#.

[0112] Calculation feature description; characteristics: aggregation_level: - region- time_period Aggregation by region + time period #.

[0113] It should be noted that the text paragraph relationship or text grammatical structure relationship between different execution logic element lines in this example can represent the structural relationship between execution logic elements. Among them, the string separated by "," ";" and "." can also be understood as the same execution logic element.

[0114] According to the embodiments of the present application, the text semantics represented by each of the multiple execution logic elements in the execution logic structure, and the structured relationships between the multiple execution logic elements based on the text grammatical structure type, can more clearly prompt a language model with strong natural language understanding capabilities to perform text semantic understanding on the execution logic elements and structured relationships of the execution logic structure, and output multiple intermediate structured data that can accurately describe multiple target tasks that match the requirement text, thereby improving the accuracy of the query statement and avoiding the language model from misunderstanding the target task or outputting errors in the logical execution relationship between multiple target tasks due to unclear semantic understanding.

[0115] In some embodiments, determining target schema information that matches the text semantics represented by the execution logic element from preset database schema information may include: performing semantic matching between the execution logic element and the preset database schema information to obtain multiple candidate metadata fields related to the execution logic element; and determining a target metadata field that matches the execution logic element from multiple candidate metadata fields based on the intent semantic matching results between the candidate metadata fields and the requirement intent.

[0116] According to an embodiment of the present application, the candidate metadata field represents a database object in the preset database schema information. For example, the candidate metadata field may represent a database object such as a table or column in the preset database schema information.

[0117] In some embodiments, semantic matching is performed based on the execution logic element and the preset database schema information, which may include calculating the semantic similarity between the execution logic element and the preset metadata field in the preset database schema information based on a similarity algorithm or a neural network algorithm, and determining the preset metadata field that meets the similarity threshold as a candidate metadata field.

[0118] According to an embodiment of the present application, the semantic matching result between the candidate metadata field and the requirement intent may include the semantic matching result between the candidate metadata field and one or more requirement contents in the requirement intent. Alternatively, the semantic matching result may also include the semantic matching result between the candidate metadata field and the updated target requirement text in the requirement intent.

[0119] In some examples, based on the semantic matching results between the candidate metadata fields and the required intent, determining a target metadata field that matches the execution logic element from multiple candidate metadata fields can include assigning corresponding semantic matching weights to the multiple candidate metadata fields based on the semantic matching results, and determining a target metadata field that matches the textual semantics of the execution logic element from the multiple candidate metadata fields based on the semantic matching weights. Thus, by determining the target metadata field that matches the execution logic element and inputting the target metadata field and the execution logic structure into a language model, the language model can be prompted to understand the mapping relationship between the textual semantics of the execution logic element and the target metadata field, thereby avoiding the generation of hallucinations that may lead to incorrect output of metadata fields such as table name fields and column name fields in the output query statement, thereby improving the accuracy of query data generation by outputting accurate intermediate structured data.

[0120] In some embodiments, multiple preset metadata fields in the preset database schema information can be traversed and relevance-ranked based on the semantic similarity between each of the multiple preset metadata fields and the execution logic element to obtain candidate metadata fields whose ranking positions meet the preset position conditions. The candidate metadata fields can then be re-ranked based on the semantic matching results between the requirement intent and the candidate metadata fields to obtain a target metadata field whose ranking position meets the conditions.

[0121] In some embodiments, determining a target metadata field that matches an execution logic element from multiple candidate metadata fields based on the intent semantic matching results between the candidate metadata field and the requirement intent may include: determining, for any target execution logic element from the multiple execution logic elements, the matching weights of the multiple candidate metadata fields based on the intent semantic matching results corresponding to the multiple candidate metadata fields related to the target execution logic element; determining the field matching results between the first target metadata field that matches the other execution logic element and the candidate metadata field; updating the matching weights of the multiple candidate metadata fields based on the field matching results to obtain the target matching weights of the multiple candidate metadata fields; and determining, from the multiple candidate metadata fields, a second target metadata field that matches the target execution logic element based on the multiple target matching weights.

[0122] According to an embodiment of the present application, the other execution logic elements are execution logic elements different from the target execution logic element, the first target metadata field is the currently generated target metadata field, and the first target metadata field matches the other execution logic elements. The specific process of determining the second target metadata field will be described below in conjunction with Examples 1 and 2.

[0123] In Example 1, in the first stage, the target execution logic element is "sales", and the multiple candidate metadata fields matching "sales" are "orders.amount" (representing the order table, the data in the order table is related to the original amount of the order), "transactions.total" (representing the payment table, the data in the payment table is related to the actual payment amount), and "invoices.value" (representing the invoice table, the data in the invoice table is related to the invoice amount).

[0124] In the second stage, by semantically matching "orders.amount," "transactions.total," and "invoices.value" with the demand intent's content [order, department, region A], we obtain matching weights of 0.6, 0.3, and 0.2 for each of the candidate metadata fields. This confirms that the user's demand intent targets data related to the "orders table."

[0125] In the third stage, the target metadata field "orders.region_id" that matches the other execution logic element "A Region" is searched for within the execution logic element. This is then semantically matched against multiple candidate fields, resulting in multiple field similarities as the field matching results. Based on these field similarities, the target matching weights for "orders.amount," "transactions.total," and "invoices.value" are updated to 0.9, 0.07, and 0.03, respectively. Consequently, if the "orders.region_id" that matches the other execution logic element "A Region" indicates the foreign key table field orders, "orders.amount" is selected as the second target metadata field matching the target execution logic element.

[0126] The difference between Example 2 and Example 1 is that the demand intent is "unpaid." Therefore, the target execution logic element "sales" can be matched with "orders.amount," "transactions.total," and "invoices.value," with corresponding matching weights of 0.3, 0.6, and 0.2, respectively. If the first target metadata field matched by other execution logic elements is "transactions.region," the target matching weights for "orders.amount," "transactions.total," and "invoices.value" can be determined to be 0.09, 0.9, and 0.01, respectively. Therefore, "transactions.total" can be determined as the second target metadata field.

[0127] According to an embodiment of the present application, the target schema information includes a target metadata field corresponding to an execution logic element. The execution logic element can be a text-based representation of the metadata to be processed in the target task, and the target metadata field is a metadata field determined from the preset database schema information that matches the execution logic element. For example, if the execution logic element is "sales," the target metadata field that matches "sales" is "order.amount."

[0128] In some embodiments, using a language model to semantically understand multiple execution logic elements and target pattern information to output multiple intermediate structured data for describing query statements may include: based on the target metadata field as prompt information, using the language model to process multiple execution logic elements, outputting associated identifiers and target metadata fields; and determining the intermediate structured data based on the associated identifiers and target metadata fields.

[0129] According to an embodiment of the present application, an identifier may represent a keyword in a query statement. For example, an identifier may be "FROM," "JOIN," "WHERE," "GROUP," and so on. The target metadata field associated with the identifier may be a metadata field corresponding to the keyword in the preset database schema information. For example, the target metadata field may be a table name field corresponding to "FROM," a column name field corresponding to "WHERE," and so on.

[0130] In some embodiments, the intermediate structured data may further include associated function fields and target metadata fields, thereby accurately representing the computing tasks that need to be performed in the query statement based on the intermediate structured data to improve the accuracy of the query statement.

[0131] In some embodiments, matching execution logic elements and target metadata fields can prompt the language model to generate multiple target tasks associated with the identifier in the query statement based on the execution logic relationship between the multiple target tasks indicated by the execution logic structure. This allows the identifier and target metadata fields to be precisely bound according to the textual semantics of the execution logic structure, avoiding errors in the intermediate structured data that are specific to the query statement.

[0132] For example, if the target task is "find the corresponding table", the language model can be instructed to associate the identifier "FROM" with the table name field to form intermediate structured data based on the hint of the table name field that matches the execution logic element "sales".

[0133] For example, if the target task is "find the corresponding column", the language model can be instructed to bind the identifier SELECT with the column name field in the list and the column name field in the WHERE condition based on the hint of the column name field that matches the execution logic element "return order".

[0134] For example, if the target task is "Specify join conditions and columns", the language model can be instructed to bind the table name fields and column name fields corresponding to JOIN and ON respectively according to the prompts of the table fields and column name fields that match the execution logic element "Return Order".

[0135] For example, if the target task is "indicate the value range of metadata", the language model can be instructed to bind the identifier WHERE column to the attribute value field [VALUE] based on the attribute value threshold prompt that matches the execution logic element "return rate".

[0136] In one embodiment, the demand text is: products in the mobile phone category with a rating of less than 3 points or a return rate of more than 10% in region A or region B. Multiple intermediate structured data can be represented as follows, surrounded by "#".

[0137] #{"operation": "SELECT". "columns": [{"name": "product_name", "alias":"Product Name"},{"name": "region", "alias": "Region"},{"name": "avg_rating", "alias": "Average Rating"},{"name": "return_rate", "alias": "Return Rate"}]#.

[0138] #"from": {"primary_table": "products","joins": [{"type": "INNERJOIN", "table": "sales_stats", "on": "products.id = sales_stats.product_id"},{"type": "INNER JOIN", "table": "regions", "on": "sales_stats.region_id =regions.id"}]}#.

[0139] #"where": ["(regions.name IN ('A region', 'B region'))","products.category= 'Mobile phone'","(sales_stats.avg_rating < 3 OR sales_stats.return_rate > 0.1)"]}#.

[0140] In this embodiment, the content of each paragraph can be understood as an intermediate structured data, and the paragraph relationship between multiple intermediate structured data can represent the dependency relationship between the intermediate structured data. The binding relationship between multiple identifiers and target metadata can be represented in the intermediate structured data in a nested manner. For example, in "where":["(regions.name IN ('A region'", "regions.name" and "A region" can be target metadata fields that have a binding relationship with the identifier "where", and "A region" is a target metadata field that has a binding relationship with the identifier "IN".

[0141] According to an embodiment of the present application, by using the target metadata as a hint and using the language model to process multiple execution logic elements and structured relationships in the execution logic structure, the language model can accurately bind the identifiers related to the target task and the target metadata fields while clearly understanding the task attributes and execution logic of multiple target tasks in the query data. For example, it can be achieved that identifiers such as SELECT projection items, FROM tables, JOIN conditions, and WHERE condition items are correctly bound to corresponding target metadata fields such as table fields and index fields. While enabling the intermediate structured data to represent the task attributes of the target task, the database schema information and the execution logic elements are accurately bound, and intermediate structured data that accurately represents the target task is generated by filling in the target metadata fields, thereby greatly reducing the confusion of cross-table query fields and loss of conditions that occur when natural language is converted into query statements, and avoiding the black box illusion of the language model such as confusion of fields with the same name in query statements, the appearance of fictitious metadata fields, and semantic understanding deviations. By using language models to generate complete, detailed, and verifiable intermediate structured data describing query statements, the target metadata fields are used to "fill in the blanks" of multiple target tasks represented by the execution logic structure. This prevents query execution errors caused by mismatches in table name fields, attribute value fields, and other mismatches, thereby improving query accuracy. This creates a highly accurate, interpretable, and self-correcting translation mechanism from natural language to query statements, suitable for applications such as business intelligence, finance, and healthcare that require stringent query accuracy.

[0142] In some embodiments, the language model outputs intermediate structured data by performing the following operations: semantically understanding the task type element that represents the target task type to obtain an identifier that matches the target task type; semantically converting the task entity element that represents the target metadata to determine the target metadata field corresponding to the task entity element; and determining the associated identifier and target metadata field based on the structured relationship between the task type element and the task entity element.

[0143] According to an embodiment of the present application, a task type element representing multiple target task types can represent a function field such as "SUM" based on text, or a condition keyword field such as "WHERE" based on text content. A task entity element can represent text related to the table name field "order.amount" such as "sales amount."

[0144] In one embodiment, multiple intermediate structured data corresponding to the requirement text "Compare the mobile phone return rates in regions A and B in the first half and second half of 2024" can be represented based on the content surrounded by "#" as follows.

[0145] #{"operation": "SELECT","columns": [{"expression": "region_dim.region_name","alias": "Region","type": "DIMENSION","source_logical": "region.name"}#。

[0146] #{"expression": "SUM(returns_fact.returned_quantity) FILTER (WHERE returns_fact.sale_date BETWEEN '2024-01-01' AND '2024-06-30') / NULLIF(SUM(returns_fact.total_quantity)) FILTER (WHERE returns_fact.sale_date BETWEEN '2024-01-01' AND '2024-06-30'), 0)","alias": "(Return Rate in the First Half of the Year)","type": "METRIC","source_logical": "metric.return_rate","context": "base_period"}#。

[0147] #{"expression": "SUM(returns_fact.returned_quantity) FILTER (WHERE returns_fact.sale_date BETWEEN '2024-07-01' AND '2024-12-31') / NULLIF(SUM(returns_fact.total_quantity) FILTER (WHERE returns_fact.sale_date BETWEEN '2024-07-01' AND '2024-12-31'), 0)","alias": "Return Rate in the Second Half of the Year","type": "METRIC","source_logical": "metric.return_rate","context": "target_period"}]#。

[0148] #"from": {"primary_table": "returns_fact","joins": [{"type": "INNERJOIN","table": "product_dim","on": "returns_fact.product_id = product_dim.product_id"," purpose": (indicates applying product filtering conditions)}#.

[0149] #{"type": "INNER JOIN","table": "region_dim","on": "returns_fact.region_id = region_dim.region_id","purpose": (indicates application of regional grouping and filtering)}]}#.

[0150] #"where": ["product_dim.category = 'mobile phone'","region_dim.region_name IN('A region', 'B region')","returns_fact.sale_date BETWEEN '2024-01-01' AND '2024-12-31'"],"group_by": ["region_dim.region_name"]#.

[0151] #"having": [],"order_by": [],"metadata": {"comparison_type": "PERIOD_COMPARISON"," aggregation_level": ["region", "time_period"];"consistency_checks": {" projection_columns_in_group_by ": "PASS (indicates that the grouping column (region_dim. region _name) is in the projection)";"where_columns_in_joins": "PASS (indicates that all WHERE condition reference columns) (product_dim.category, region_dim.region_name, returns_fact.sale_date) are from the FROM / JOIN table";" data_type_validation": {" product_dim.category ": "STRING - Matching value type'mobile phone'","region_dim.region_name": "STRING- Matching value list ('A region','B region')". " returns_fact.sale_date": "DATE ​​(indicates matching date range)}}}}#.

[0152] In this embodiment, paragraphs based on intermediate structured data can represent the structured relationships between intermediate structured data. The intermediate structured data can preserve the textual semantics of the execution logic elements and the execution logic relationships between multiple target tasks, thereby ensuring the correct binding relationship between metadata fields and identifiers, and mapping the execution logic elements based on the intermediate structured data to ensure consistency between the query statement and the required intent. It also allows relevant personnel to adjust and generate updated intermediate structured data by editing the intermediate structured data. By performing semantic conversion on the intermediate structured data, highly accurate query data can be obtained.

[0153] For example, the following query statement surrounded by “#” may be generated based on the multiple intermediate structured data in this embodiment.

[0154] #SELECT.

[0155] region_dim.region_name AS "region"#.

[0156] #SUM(returns_fact.returned_quantity) FILTER (WHERE returns_fact.sale_date BETWEEN '2024-01-01' AND '2024-06-30') / NULLIF(SUM(returns_fact.total_quantity) FILTER (WHERE returns_fact.sale_date BETWEEN '2024-01-01' AND '2024-06-30'), 0) AS "Return rate in the first half of the year"#.

[0157] #SUM(returns_fact.returned_ quantity) FILTER (WHERE returns_fact.sale_date BETWEEN '2024-07-01' AND '2024-12-31') / NULLIF(SUM(returns_fact.total_quantity) FILTER (WHERE returns_fact.sale_date BETWEEN '2024-07-01' AND '2024-12-31'), 0) AS "Return rate in the second half of the year"#.

[0158] #FROM returns_fact. INNER JOIN product_dim ON returns_fact.region_id =product_dim.product_id. INNER JOIN region_dim ON returns_fact.region_id =region_dim.region_id. WHERE product_dim. dim.category='Mobile phone. 'AND region_dim.region_name IN ('A region', 'B region'). AND returns_fact.sale_date BETWEEN '2024-01-01' AND '2024-12-31'GROUP BY region_dim.region_name#.

[0159] It should be noted that the two different character strings separated by “,”, “;” and “.” in the same paragraph in the intermediate structured data, execution logic structure and query statement in the embodiment of the present application can be understood as character strings in different paragraphs in the structured information.

[0160] According to an embodiment of the present application, intermediate structured data is determined based on associated identifiers and target metadata fields. The language model can use the execution process of multiple target tasks represented by the execution logic structure and the target metadata fields that match the execution logic elements as prompts to perform semantic understanding of the task type elements and task entity elements, and output associated identifiers and target metadata fields. This can achieve refined matching of the identifiers and target metadata fields, and output associated identifiers and target metadata fields based on the structured relationship represented by the execution logic structure as a text grammatical structure relationship, so that the intermediate structured data can accurately represent the grammatical structure of the query statement and the execution process of the target task through the associated identifiers and target metadata fields, thereby improving the accuracy of the query statement.

[0161] In some embodiments, the query statement generation method also includes: performing consistency verification on the target metadata field in the intermediate structured data based on the preset metadata field in the preset database model information to obtain a consistency verification result; and verifying the attribute information corresponding to the target metadata field in the intermediate structured data to obtain an attribute compliance verification result.

[0162] In some embodiments, the consistency check result obtained by performing a consistency check on the target metadata field can indicate whether the target metadata field exists in the preset database schema information. This checks whether the identifier bound to the target metadata field in the intermediate structured data conforms to the execution logic of the target task. For example, the consistency check result indicates that the column referenced in the WHERE condition must come from the FROM / JOIN table. For another example, the consistency check result indicates that the grouping column must be in a projection or aggregate function.

[0163] In some embodiments, the attribute compliance check result indicates whether the attribute information corresponding to the target metadata field, such as the attribute value range and attribute value type, matches the preset attribute information set in the preset database model.

[0164] According to an embodiment of the present application, the defect information indicated by the consistency check result and the attribute compliance check result is used to prompt the language model to update the current intermediate structured data, thereby obtaining updated intermediate structured data. The verification results can thus be used to prompt the language model to automatically correct the consistency of object fields such as tables, columns, and indexes with the target metadata fields based on the defects indicated by the verification results, thereby quickly correcting field errors that the language model has outputted in accordance with hallucinations and improving the accuracy of the intermediate structured data.

[0165] In one embodiment, multiple types of checks such as entity binding check, attribute binding check, connection path binding check, value binding and type check, function / operator concretization check, alias management check, integrity check, integrity check and consistency check can be performed on the intermediate structured data. If all the check results are passed, it is determined that the query statements are generated for the multiple intermediate structured data.

[0166] Entity binding validation means: determining that the business entity text (such as "product", "sales") in the intermediate structured data and execution logic elements are mapped to specific database table fields.

[0167] Attribute binding validation means: Map the text of keywords such as representation, projection items, condition items, grouping items, sorting items, and join keys in the execution logic element to specific table columns (Column), thereby resolving text ambiguity that causes mapping to multiple tables or column fields.

[0168] Connection path binding validation involves verifying the specific tables involved in a specific connection, such as INNER / LEFT, and the specific columns used in the connection. Information such as foreign key relationships is used to derive or verify the connection path.

[0169] Value binding and type verification means: bind the constant value represented in the condition string (such as the specific threshold value 10000 corresponding to "High") to the expression and verify whether the value type is compatible with the data type of the bound column. In addition, it is necessary to verify that the comparison object of the numeric column cannot be a string.

[0170] Function / operator specificity verification: Confirm whether the specific use of aggregate functions, comparison operators, etc. is consistent with the column data type (for example, SUM() can only be used for numeric columns).

[0171] Alias ​​management verification: Verify that the alias of a data table or complex expression is the same as the alias in the preset database schema information.

[0172] In some embodiments, the query data generation method may further include: in response to the requirement complexity being less than a preset complexity threshold, determining intent pattern information that matches the text semantics represented by the requirement intent from the preset database pattern information; and using a language model to perform semantic understanding on the requirement intent and intent pattern information, outputting multiple intent intermediate structured data for describing the query statement, and generating a reference query statement based on the multiple intent intermediate structured data.

[0173] According to an embodiment of the present application, determining the intent pattern information that matches the text semantics represented by the requirement intent from the preset database pattern information can include semantically matching the preset database pattern information with multiple requirement intents respectively to obtain the intent pattern information that semantically matches each of the multiple requirement intents. In this way, a binding relationship between the preset database pattern information and the requirement intent can be established, and by using a language model to process the matching intent pattern information and requirement intent, the intent intermediate structured data that can accurately represent the target task execution logic can be output, thereby generating a reference query statement with low requirement text complexity based on multiple intent intermediate structured data.

[0174] According to an embodiment of the present application, the language model can be prompted to generate intermediate structured data of intent by directly determining the intent pattern information that matches the text of the requirement intent when the requirement complexity is less than a preset complexity threshold. This can reduce the computational time delay generated by generating query statements for requirement texts with lower complexity and improve the efficiency of query statement generation.

[0175] In some embodiments, the intent schema information includes an intent metadata field that matches the requirement intent. The intent metadata field may represent objects such as tables and columns in the preset database schema information that match the text content of the requirement intent.

[0176] In some embodiments, using a language model to perform semantic understanding on the requirement intent and intent pattern information, and outputting multiple intent intermediate structured data for describing the query statement may include: using the language model requirement intent and intent metadata fields to perform semantic understanding to obtain associated intent identifiers and intent metadata fields; and determining the intent intermediate structured data based on the associated intent identifiers and intent metadata fields.

[0177] According to an embodiment of the present application, the intent identifier can represent an identifier that matches the textual semantics of the requirement intent. By prompting the language model to perform semantic understanding of the matching requirement intent based on the corresponding intent pattern information, the textual semantics related to the task type of the target task represented in the requirement intent can be converted into an intent identifier, and a binding relationship is established between the intent metadata field that matches the requirement intent and the intent identifier to determine the associated intent identifier and intent metadata field. Thus, the language model can be used to generate intent intermediate structured data by processing the associated intent identifier and intent metadata field, so that the binding relationship between the intent metadata field and the intent identifier in the intent intermediate structured data can match the requirement intent, and accurately represent the grammatical logical relationship and query logical relationship between identifiers such as "WHERE" and table and column fields in the target task of the query statement. This improves the accuracy of the query statement.

[0178] In some embodiments, the query statement generation method may further include: verifying multiple execution logic elements in the execution logic structure based on business data attributes in the business rules related to the requirement text to obtain a semantic verification result; performing an accounting logic rule verification on the dependency relationship between the multiple execution logic elements based on the accounting rules in the business rules to obtain an accounting logic verification result;

[0179] According to embodiments of the present application, the semantic verification result represents the semantic consistency between the execution logic element and the business data attribute. For example, the execution logic element "Product AA" is semantically consistent with the product name attribute "Product AA" in the business data. By using a language model to semantically understand the demand intent based on the metadata field corresponding to the product name attribute in the preset database schema information, an execution logic element that accurately matches the product name attribute can be output.

[0180] For example, the execution logic element "A region" is not semantically consistent with the region name attribute "A city A region" in the business data. The semantic difference between the execution logic element and the business attribute can be indicated based on the semantic verification result.

[0181] According to an embodiment of the present application, the accounting logic verification result indicates whether the structured relationship satisfies the accounting execution logic represented by the accounting rules. For example, the accounting logic verification result can indicate whether the calculation logic process for calculating a company's profit margin, represented by the structured relationship, matches the accounting process indicated by the business rules. If the semantic verification result and the accounting logic verification result indicate that the verification is correct, the structured relationship and execution logic elements corresponding to the accounting logic verification result, as well as the target pattern information, can be input into the language pattern information to generate accurate intermediate structured data.

[0182] In some embodiments, the semantic verification results and the calculation logic verification results each indicate a defect, which prompts the language model to update the current execution logic structure, resulting in an updated execution logic structure. This allows accurate intermediate structured data to be output based on the language model and the updated execution logic structure and target schema information.

[0183] In some embodiments, the demand intent, execution logic structure, intermediate structured data and query statements can all be verified to ensure that the generated query statements can accurately and efficiently execute business services and improve business service response efficiency.

[0184] Figure 5 A schematic diagram of a query statement generation method according to an embodiment of the present application is shown.

[0185] like Figure 5As shown, query statements are generated based on the semantic injection module, the query statement conversion link and the verification link. The semantic injection module is used to store and manage multimodal business data such as images, data tables, texts, and is used to store preset database model information. The first node in the query statement conversion link is used to call the business data as a prompt through the semantic injection module, use the language model to process the demand text, and output the demand intention. The second node in the query statement conversion link is used to call the language model to process the demand intention and obtain the execution logic structure. The third node calls the target pattern information and the execution logic structure through the semantic injection module, uses the language model to perform semantic understanding on the target pattern information and the execution logic structure, and outputs multiple intermediate structured data. The fourth node edits the query statement on multiple intermediate structured data by calling the language model, and outputs the query statement.

[0186] The multiple verification nodes in the verification chain verify the requirement intent, execution logic structure, intermediate structured data, and query statements output by multiple nodes in the query translation chain. If the verification results do not meet the preset verification quality requirements, the defect information indicated by the verification results is returned to each node, allowing the language model to update the requirement intent, execution logic structure, intermediate structured data, and query statements based on the defect information indicated by the verification results.

[0187] The query statement generation method provided by the embodiment of the present application is executed through the double-chain loop structure of the query statement conversion link and the verification link. The business data and the preset database model information can be semantically injected and stored in heterogeneous data based on the semantic injection module to provide each node in the query statement conversion link with the data processing task. And the multiple nodes of the query statement conversion link are matched one by one with the multiple verification nodes of the verification link, and the reliability and accuracy of the query statement generation are guaranteed by the combination of the two links. The multiple nodes of the query statement conversion link use the semantic understanding ability and dynamic business knowledge of the language model to perform hierarchical evolution transformation on the semantics of the query statement, and output intermediate structured data that can accurately describe the query statement. The multiple verification nodes in the verification link perform quantitative evaluation and verification on the structured information output by the query statement conversion link to assist in the optimization of multiple nodes in the conversion link, and timely verify, correct and optimize the information output during the query statement conversion process, thereby improving the generation efficiency and execution efficiency of the query statement.

[0188] Figure 6 A structural diagram of a query statement conversion link and a verification link according to an embodiment of the present application is shown.

[0189] like Figure 6As shown, the query statement conversion chain includes the first conversion layer, the second conversion layer, the third conversion layer, and the fourth conversion layer. The verification chain includes the first verification node, the second verification node, the third verification node, the fourth verification node, and the fifth verification node. In addition, each verification node can also be associated with a corresponding check node. The semantic injection module can include a business background layer, a business concept layer, a business logic layer, a physical logic layer, and a data anchor layer.

[0190] The business background layer is used to manage descriptive information such as the structural information of databases, business data, and other data, and is used to provide the first conversion layer of the query data conversion chain with business data related to the specific business scope of the demand text, such as business data in business fields such as retail e-commerce and supply chain finance.

[0191] The second level, the business concept layer, is used to clearly define or describe business data such as "valid orders," "active users," and "GMV." The business concept layer describes business attributes such as terminology and transactions within the business domain and provides atomic metric definitions for information such as reports and operational analysis reports. The first conversion layer, using the descriptive information from the business concept layer and the business data provided by the business context layer, utilizes language models to understand the intent of the demand text and output demand intent that matches the business terminology and concepts.

[0192] The third level is the business logic layer, which stores business rules, including business execution logic, business domain table division, table and view definitions, and business line content interpretation. For example, business rules such as "return requests must be initiated within 7 days of receipt" and "Gold Membership offers free shipping" are updated and stored in real time. Business rules can also include relevant business process rules, such as order fulfillment rules and risk control and approval process rules.

[0193] This allows the second conversion layer to obtain real-time business rule information from the business logic layer to semantically understand the demand intent and output an execution logic structure that matches the business rules, so that the structured relationship of the execution logic structure can meet the execution logic corresponding to the business rules and make the execution logic elements completely consistent with the specific technical terminology text in the business rules.

[0194] The fourth level is the physical-logical layer, which stores database table metadata. This metadata includes table definitions, field definitions, relationships, data types, and other structural information. The physical-logical layer extracts the database schema information from the database schema and statistical information. The third conversion layer then uses a language model to extract target schema information from the physical-logical layer that matches the execution logic elements, performing semantic understanding and outputting intermediate structured data.

[0195] The fifth layer is the data anchoring layer, which stores sampling point information. This information provides data support for sampling points in query statements, such as the specific numeric type format and string value binding relationships. The fourth conversion layer then uses the language model to interpret the sampling point information and intermediate structured data to perform query transformation tasks and generate query statements. The execution layer executes the query statements and outputs the execution results.

[0196] The multiple semantic layers of the semantic injection module can provide data call support functions for multiple conversion layers in the query data conversion link, and ensure that the lower-layer semantics can retain the upper-layer semantic information, so that the query data conversion link can call multi-level business data and business rules from top to bottom to achieve accurate conversion of query statements.

[0197] The first to fifth verification nodes of the verification link can respectively verify the structured data and query statements output by each conversion layer to ensure data quality.

[0198] The first verification node is used to perform semantic verification on the demand intent. For example, the semantic model can be used to reversely generate a natural language description text from the demand intent, and the semantic similarity between the original demand text and the natural language description text can be calculated. When the semantic similarity is higher than the similarity threshold of 0.92, a qualified verification result is output. Alternatively, the demand intent can be combined to recall key entities in the business data using entity information, and when the recall rate meets the preset recall rate threshold, a qualified verification result is output. In the case of outputting an unqualified verification result, the demand text can be modified to re-instruct the first conversion layer to output the demand intent.

[0199] The second verification node is used to perform execution logic verification on the execution logic structure. For example, it can match the target metadata with pre-set database schema information, or it can verify the execution logic of the execution logic structure according to business rules to verify whether the execution logic structure complies with business rules and metadata constraints. Furthermore, it can verify the existence and time compliance of entities in the execution logic elements. If the verification result does not meet the requirements, the requirement intent can be updated, prompting the second conversion layer to re-output the execution logic structure.

[0200] The third verification node is used to perform metadata binding verification on the intermediate structured data. For example, it can perform association binding verification on the identifier and target metadata field in the intermediate structured data, or it can also include other verification types for the intermediate structured data. If the verification result indicates that the verification is passed, the fourth conversion layer can be instructed to output the query statement. If the verification result fails, the third conversion layer can be instructed to regenerate new intermediate structured data based on the updated execution logic structure until the verification passes.

[0201] The fourth verification node can verify the query statement. For example, this can be done through static syntax verification of the query statement and dynamic verification based on query statement precompilation. Static syntax tree verification can use tools such as sqlglot to check syntax rules, while dynamic verification can generate a detailed execution plan to check for direct physical and logical errors.

[0202] The fifth verification node can verify the execution results of the query statement. For example, it can perform a formal compliance assessment on the execution results based on the preset execution result format. Alternatively, it can set a value range security boundary based on statistical information to intercept abnormal values ​​in the execution results. For example, it can verify abnormal data such as the age of the person in the execution result is over 200 years old, the number of vehicles exceeds the local car ownership, and the number of paid members is greater than the total number of registered users. It can also perform a logical consistency check on the semantics of the execution result and the semantic logical relationship between the requirement text to ensure that the execution result meets the requirements of the requirement text.

[0203] In addition, when each verification node outputs a verification pass result, compliance checks can also be performed based on the corresponding checkpoints, thereby further improving the accuracy and execution efficiency of the query statement.

[0204] Figure 7 A schematic diagram of a checkpoint according to an embodiment of the present application is shown.

[0205] like Figure 7 As shown, a checkpoint can include a check component and a clarification node. The check component receives structured information transmitted by the transformation layer, for example, receiving and checking the requirement intent, execution logic structure, intermediate structured data, and query statements. It detects data with anomalies in the structured information and outputs abnormal status data. Abnormal status data can include metadata fields that do not match the preset database schema information. The checkpoint returns the abnormal status data to the corresponding transformation layer, prompting the transformation layer to update the structured information.

[0206] Furthermore, users can interact with the clarification node through the human-computer interaction module, editing the structured information with anomalies to obtain structured information that meets verification requirements. The edited structured information is returned to the conversion layer to continue the data processing tasks of the next conversion layer in the query statement conversion chain. If the structured data output by the inspection component is normal, the data processing tasks of the next conversion layer can be continued.

[0207] Based on the above query statement generation method, the present application also provides a query statement generation device. Figure 8 The device is described in detail.

[0208] Figure 8 A structural block diagram of a query statement generating device according to an embodiment of the present application is shown.

[0209] like Figure 8 As shown, the query statement generating device 800 of this embodiment includes a recognition module 810 , an execution logic structure obtaining module 820 , a target pattern information obtaining module 830 , an intermediate structured data obtaining module 840 and a query statement generating module 850 .

[0210] The recognition module 810 is used to perform intent recognition on the demand text based on business data to obtain the demand intent.

[0211] The execution logic structure acquisition module 820 is used to respond to the demand intention to meet the preset demand conditions, use the language model to process the demand intention, and obtain the execution logic structure. The execution logic structure includes multiple execution logic elements based on structured representation. The execution logic elements are based on text semantics to represent the target task of executing the query statement or target metadata related to the target task. The structured relationship between multiple execution logic elements represents the execution process of the query statement.

[0212] The target pattern information obtaining module 830 is configured to determine target pattern information that matches the text semantics of the execution logical element representation from the preset database pattern information.

[0213] The intermediate structured data acquisition module 840 is used to output a plurality of intermediate structured data for describing the query statement by using a language model to perform semantic understanding on a plurality of execution logic elements and target pattern information.

[0214] The query statement generating module 850 is configured to generate a query statement according to a plurality of intermediate structured data.

[0215] According to an embodiment of the present application, the target mode information includes a target metadata field corresponding to the execution logic element;

[0216] According to an embodiment of the present application, the intermediate structured data obtaining module includes: a first output unit and a first determination unit.

[0217] The first output unit is configured to process a plurality of execution logic elements using a language model based on the target metadata field as prompt information, and output an associated identifier and the target metadata field.

[0218] The first determining unit is configured to determine the intermediate structured data according to the associated identifier and the target metadata field.

[0219] According to an embodiment of the present application, the language model outputs intermediate structured data by performing the following operations: semantically understanding the task type element that represents the target task type to obtain an identifier that matches the target task type; semantically converting the task entity element that represents the target metadata to determine the target metadata field corresponding to the task entity element; based on the structured relationship between the task type element and the task entity element, determining the associated identifier and target metadata field, wherein the intermediate structured data is determined based on the associated identifier and target metadata field.

[0220] According to an embodiment of the present application, the query statement generating device further includes: a first verification module and a second verification module.

[0221] The first verification module is used to perform consistency verification on the target metadata field in the intermediate structured data based on the preset metadata field in the preset database schema information to obtain a consistency verification result.

[0222] The second verification module is used to verify the attribute information corresponding to the target metadata field in the intermediate structured data to obtain the attribute compliance verification result; wherein, the defect information represented by the consistency verification result and the attribute compliance verification result respectively is used to prompt the language model to update the current intermediate structured data to obtain the updated intermediate structured data.

[0223] According to an embodiment of the present application, the target mode information obtaining module includes: a first obtaining unit and a second determining unit.

[0224] The first obtaining unit is configured to perform semantic matching between the execution logic element and the preset database schema information to obtain a plurality of candidate metadata fields related to the execution logic element, wherein the candidate metadata fields represent database objects in the preset database schema information.

[0225] The second determining unit is used to determine a target metadata field that matches the execution logic element from multiple candidate metadata fields based on the intention semantic matching result between the candidate metadata field and the required intention.

[0226] According to an embodiment of the present application, the second determining unit includes: a first determining subunit, a second determining subunit, a first obtaining subunit, and a third determining subunit.

[0227] The first determination subunit is used to determine the matching weights of multiple candidate metadata fields for any target execution logical element among the multiple execution logical elements based on the intention semantic matching results corresponding to each of the multiple candidate metadata fields related to the target execution logical element.

[0228] The second determination subunit is used to determine the field matching result between the first target metadata field that matches other execution logic elements and the candidate metadata field, wherein the other execution logic elements are execution logic elements different from the target execution logic element, and the first target metadata field is the target metadata field that has been currently generated.

[0229] The first obtaining subunit is configured to update the matching weights of the plurality of candidate metadata fields according to the field matching result, and obtain target matching weights of the plurality of candidate metadata fields.

[0230] The third determining subunit is configured to determine, based on multiple target matching weights, a second target metadata field that matches the target execution logic element from multiple candidate metadata fields.

[0231] According to an embodiment of the present application, the identification module includes an identification unit.

[0232] The recognition unit is used to use a language model to perform intent recognition on the demand text to obtain structured demand content, wherein the structured demand content includes data attribute items and data content related to the metadata in the query statement.

[0233] According to an embodiment of the present application, the identification module further includes an updating unit.

[0234] An updating unit is used to perform semantic updates on the requirement text using a language model to obtain a target requirement text, wherein the target requirement text represents at least one requirement content based on a specified tag, and the target requirement text is used to prompt the language model to perform semantic understanding of the requirement intent based on the associated specified tags and requirement content.

[0235] According to an embodiment of the present application, the requirement intent also includes the requirement complexity determined by semantically understanding the requirement text through a language model, and the requirement complexity indicates the complexity of the execution process of executing the query statement; the requirement complexity is used to prompt the language model to process the requirement intent based on the thinking process topology matching the requirement complexity to obtain the execution logical structure.

[0236] According to an embodiment of the present application, the execution logic structure obtaining module includes: a third determination unit and a second output unit.

[0237] The third determination unit is used to determine the thinking process topology based on the complexity of the requirement by using a language model to perform task planning on the requirement content in the requirement intention, wherein multiple thinking tasks in the thinking process topology have a dependency relationship, and the number of thinking tasks matches the complexity of the requirement.

[0238] The second output unit is used to use the language model to perform multiple thinking tasks based on dependency relationships and output the execution logic structure.

[0239] According to an embodiment of the present application, the requirement intention to meet a preset requirement condition includes: the requirement complexity is greater than or equal to a preset complexity threshold.

[0240] According to an embodiment of the present application, the query statement generating device further includes: an intention pattern information determination module and a semantic understanding module.

[0241] The intention pattern information determination module is used to determine the intention pattern information that matches the text semantics of the requirement intention representation from the preset database pattern information in response to the requirement complexity being less than the preset complexity threshold.

[0242] The semantic understanding module is used to perform semantic understanding using the language model requirement intent and intent pattern information, output multiple intent intermediate structured data used to describe the query statement, and generate a reference query statement based on the multiple intent intermediate structured data.

[0243] According to an embodiment of the present application, the intent pattern information includes an intent metadata field that matches the requirement intent;

[0244] Among them, the semantic understanding module includes: a semantic understanding unit and an intention intermediate structured data determination unit.

[0245] The semantic understanding unit is used to perform semantic understanding using the language model requirement intent and intent metadata fields to obtain the associated intent identifier and intent metadata fields.

[0246] The intent intermediate structured data determination unit is used to determine the intent intermediate structured data based on the associated intent identifier and intent metadata field.

[0247] According to an embodiment of the present application, the query statement generating device further includes: a third verification module and a fourth verification module.

[0248] The third verification module is used to verify multiple execution logic elements in the execution logic structure based on the business data attributes in the business rules related to the requirement text, and obtain semantic verification results. The semantic verification results represent the semantic consistency between the execution logic elements and the business data attributes.

[0249] The fourth verification module is used to perform accounting logic rule verification on the dependency relationship between multiple execution logic elements based on the accounting rules in the business rules to obtain the accounting logic verification result. The accounting logic verification result represents whether the structured relationship satisfies the accounting execution logic represented by the accounting rules; wherein, the defect information represented by the semantic verification result and the accounting logic verification result are used to prompt the language model to update the current execution logic structure to obtain an updated execution logic structure.

[0250] According to an embodiment of the present application, the execution logic element includes at least one of the following: a time attribute element representing a time condition; a region attribute element representing a region condition; and an indicator type element representing a calculation indicator in a demand intention.

[0251] According to an embodiment of the present application, the query statement generation module includes: a generation unit.

[0252] The generation unit is used to use the language model to process multiple intermediate structured data represented by domain-specific language format attributes to generate query statements.

[0253] According to embodiments of the present application, any multiple modules among the identification module 810, the execution logic structure acquisition module 820, the target pattern information acquisition module 830, the intermediate structured data acquisition module 840, and the query statement generation module 850 can be combined into a single module, or any one of these modules can be split into multiple modules. Alternatively, at least part of the functionality of one or more of these modules can be combined with at least part of the functionality of other modules and implemented in a single module. According to embodiments of the present application, at least one of the identification module 810, the execution logic structure acquisition module 820, the target pattern information acquisition module 830, the intermediate structured data acquisition module 840, and the query statement generation module 850 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application-specific integrated circuit (ASIC), or can be implemented in hardware or firmware through any other reasonable means of circuit integration or packaging, or can be implemented in any one of the three implementation methods of software, hardware, and firmware, or any appropriate combination of any of these. Alternatively, at least one of the identification module 810, the execution logic structure acquisition module 820, the target pattern information acquisition module 830, the intermediate structured data acquisition module 840 and the query statement generation module 850 can be at least partially implemented as a computer program module, which can perform the corresponding function when it is run.

[0254] Figure 9 A block diagram of an electronic device suitable for implementing a query statement generating method according to an embodiment of the present application is shown.

[0255] like Figure 9As shown, an electronic device 900 according to an embodiment of the present application includes a processor 901, which can perform various appropriate actions and processes based on programs stored in a read-only memory (ROM) 902 or programs loaded from a storage unit 908 into a random access memory (RAM) 903. The processor 901 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or related chipsets and / or a dedicated microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 901 may also include onboard memory for caching purposes. The processor 901 may include a single processing unit or multiple processing units for performing different actions of the method flow according to the embodiment of the present application.

[0256] Various programs and data required for the operation of the electronic device 900 are stored in the RAM 903. The processor 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. The processor 901 performs various operations of the method flow according to the embodiment of the present application by executing the programs in the ROM 902 and / or the RAM 903. It should be noted that the programs may also be stored in one or more memories other than the ROM 902 and the RAM 903. The processor 901 may also perform various operations of the method flow according to the embodiment of the present application by executing the programs stored in one or more memories.

[0257] According to an embodiment of the present application, electronic device 900 may further include an input / output (I / O) interface 905, which is also connected to bus 904. Electronic device 900 may also include one or more of the following components connected to I / O interface 905: an input section 906 including a keyboard, mouse, etc.; an output section 907 including devices such as a cathode ray tube (CRT), liquid crystal display (LCD), and speakers; a storage section 908 including a hard disk; and a communication section 909 including a network interface card such as a LAN card or modem. Communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to I / O interface 905 as needed. Removable media 911, such as a magnetic disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed in drive 910 as needed, so that computer programs read from the removable media can be installed into storage section 908 as needed.

[0258] This application also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments, or may exist independently and not be incorporated into the device / apparatus / system. The computer-readable storage medium carries one or more programs, and when the one or more programs are executed, the method according to the embodiments of this application is implemented.

[0259] According to an embodiment of the present application, a computer-readable storage medium may be a non-volatile computer-readable storage medium, and may include, for example, but not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present application, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, according to an embodiment of the present application, a computer-readable storage medium may include the ROM 902 and / or RAM 903 described above and / or one or more memories other than ROM 902 and RAM 903.

[0260] The embodiments of the present application also include a computer program product, which includes a computer program containing program code for executing the method shown in the flowchart. When the computer program product is executed in a computer system, the program code is used to enable the computer system to implement the query statement generation method provided in the embodiments of the present application.

[0261] The computer program executes the above functions defined in the system / device of the embodiment of the present application when the processor 901 executes the computer program. According to the embodiment of the present application, the system, device, module, unit, etc. described above can be implemented by a computer program module.

[0262] In one embodiment, the computer program may be stored on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may be transmitted and distributed in the form of a signal on a network medium, downloaded and installed via the communication portion 909, and / or installed from a removable medium 911. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to wireless, wired, or any suitable combination thereof.

[0263] In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 909, and / or installed from a removable medium 911. When the computer program is executed by the processor 901, the above-mentioned functions defined in the system of the embodiment of the present application are performed. According to the embodiment of the present application, the systems, devices, means, modules, units, etc. described above can be implemented by computer program modules.

[0264] According to an embodiment of the present application, the program code for executing the computer program provided by the embodiment of the present application can be written in any combination of one or more programming languages. Specifically, these computer programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages ​​include, but are not limited to, languages ​​such as Java, C++, Python, "C" or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect via the Internet).

[0265] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of the boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0266] Those skilled in the art will appreciate that the features described in the various embodiments of this application may be combined and / or coupled in various ways, even if such combinations or couplings are not explicitly described in this application. In particular, the features described in the various embodiments of this application may be combined and / or coupled in various ways without departing from the spirit and teachings of this application. All such combinations and / or couplings fall within the scope of this application.

[0267] The embodiments of the present application have been described above. However, these embodiments are for illustrative purposes only and are not intended to limit the scope of the present application. Although each embodiment has been described separately above, this does not mean that the measures in each embodiment cannot be advantageously used in combination. Without departing from the scope of the present application, those skilled in the art may make various substitutions and modifications, and these substitutions and modifications should all fall within the scope of the present application.

Claims

1. A query statement generation method, characterized in that: include: Perform intent recognition on the demand text based on business data to obtain the demand intent; In response to the demand intention satisfying a preset demand condition, the demand intention is processed using a language model to obtain an execution logic structure, wherein the execution logic structure includes a plurality of execution logic elements based on a structured representation, the execution logic elements representing a target task of executing the query statement or target metadata related to the target task based on text semantics, and the structured relationships between the plurality of execution logic elements representing an execution process of executing the query statement; Determining target pattern information that matches the text semantics represented by the execution logic element from preset database pattern information; Using the language model to semantically understand the plurality of execution logic elements and the target pattern information, outputting a plurality of intermediate structured data for describing a query statement; The query statement is generated according to the plurality of intermediate structured data.

2. The method according to claim 1, characterized in that The target mode information includes a target metadata field corresponding to the execution logic element; The language model is used to semantically understand the plurality of execution logic elements and the target pattern information, thereby outputting a plurality of intermediate structured data for describing the query statement, including: Based on the target metadata field as prompt information, the language model is used to process the plurality of execution logic elements, and an associated identifier and a target metadata field are output; as well as The intermediate structured data is determined according to the associated identifier and the target metadata field.

3. The method according to claim 1 or 2, characterized in that The language model outputs the intermediate structured data by performing the following operations: Performing semantic understanding on a task type element representing a target task type to obtain an identifier that matches the target task type; Performing semantic conversion on the task entity element representing the target metadata, and determining the target metadata field corresponding to the task entity element; Based on the structured relationship between the task type element and the task entity element, an associated identifier and a target metadata field are determined, wherein the intermediate structured data is determined based on the associated identifier and the target metadata field.

4. The method according to claim 3, characterized in that The method further comprises: Performing a consistency check on the target metadata field in the intermediate structured data based on the preset metadata field in the preset database schema information to obtain a consistency check result; Verifying the attribute information corresponding to the target metadata field in the intermediate structured data to obtain an attribute compliance verification result; The defect information respectively represented by the consistency check result and the attribute compliance check result is used to prompt the language model to update the current intermediate structured data to obtain updated intermediate structured data.

5. The method according to claim 1, wherein Determining target pattern information that matches the text semantics represented by the execution logic element from preset database pattern information includes: Performing semantic matching between the execution logic element and preset database schema information to obtain a plurality of candidate metadata fields related to the execution logic element, wherein the candidate metadata fields represent database objects in the preset database schema information; and According to the intention semantic matching result between the candidate metadata field and the requirement intention, a target metadata field matching the execution logic element is determined from multiple candidate metadata fields, and the target mode information includes the target metadata field.

6. The method according to claim 5, characterized in that Determining a target metadata field that matches the execution logic element from a plurality of candidate metadata fields according to a result of semantic matching between the candidate metadata field and the requirement intent includes: For any target execution logic element among the plurality of execution logic elements, determining a matching weight of each of the plurality of candidate metadata fields according to the intent semantic matching results corresponding to each of the plurality of candidate metadata fields associated with the target execution logic element; Determining a field matching result between a first target metadata field that matches another execution logic element and the candidate metadata field, wherein the other execution logic element is an execution logic element different from the target execution logic element, and the first target metadata field is a currently generated target metadata field; updating the matching weights of the plurality of candidate metadata fields according to the field matching results to obtain target matching weights of the plurality of candidate metadata fields; and Based on the multiple target matching weights, a second target metadata field that matches the target execution logic element is determined from the multiple candidate metadata fields.

7. The method according to claim 1, characterized in that Perform intent recognition on the requirement text to obtain the requirement intent, including: The language model is used to perform intent recognition on the requirement text to obtain structured requirement content, wherein the structured requirement content includes data attribute items and data content related to the metadata in the query statement, and the requirement intent includes the requirement content.

8. The method according to claim 7, characterized in that Perform intent recognition on the requirement text to obtain the requirement intent, which also includes: The requirement text is semantically updated using the language model to obtain a target requirement text, wherein the target requirement text represents at least one requirement content based on a specified tag, and the target requirement text is used to prompt the language model to semantically understand the requirement intention based on the associated specified tag and requirement content.

9. The method according to claim 1 or 7, characterized in that The requirement intent also includes the requirement complexity determined by semantically understanding the requirement text through the language model, where the requirement complexity indicates the complexity of the execution process of executing the query statement; The requirement complexity is used to prompt the language model, and the requirement intention is processed based on a thinking process topology that matches the requirement complexity to obtain the execution logic structure.

10. The method according to claim 9, characterized in that The language model is used to process the requirement intent to obtain an execution logic structure, including: Based on the complexity of the requirement, determining a thinking process topology by performing task planning on the requirement content in the requirement intent using the language model, wherein multiple thinking tasks in the thinking process topology have a dependency relationship, and the number of the thinking tasks matches the complexity of the requirement; and The language model is used to execute a plurality of the thinking tasks based on the dependency relationship, and the execution logic structure is output.

11. The method according to claim 10, characterized in that The requirement intention to meet the preset requirement condition includes: the requirement complexity is greater than or equal to a preset complexity threshold.

12. The method according to claim 9, characterized in that The method further comprises: In response to the requirement complexity being less than a preset complexity threshold, determining, from the preset database pattern information, intention pattern information that matches the textual semantics of the requirement intention representation; and The language model is used to perform semantic understanding on the demand intention and the intention pattern information, output a plurality of intention intermediate structured data for describing the query statement, and generate a reference query statement based on the plurality of intention intermediate structured data.

13. The method according to claim 12, characterized in that The intent pattern information includes an intent metadata field that matches the requirement intent; The semantic understanding is performed using the demand intent and the intent pattern information of the language model to output a plurality of intent intermediate structured data for describing the query statement, including: Using the language model to perform semantic understanding on the demand intent and the intent metadata field to obtain associated intent identifiers and intent metadata fields; and Based on the associated intent identifier and intent metadata field, the intent intermediate structured data is determined.

14. The method according to claim 1, wherein The method further comprises: Verifying the plurality of execution logic elements in the execution logic structure based on the business data attributes in the business rules related to the requirement text to obtain semantic verification results, wherein the semantic verification results represent semantic consistency between the execution logic elements and the business data attributes; performing an accounting logic rule check on the dependency relationship between the plurality of execution logic elements based on the accounting rule in the business rule to obtain an accounting logic check result, wherein the accounting logic check result indicates whether the structured relationship satisfies the accounting execution logic indicated by the accounting rule; The defect information respectively represented by the semantic verification result and the calculation logic verification result is used to prompt the language model to update the current execution logic structure to obtain an updated execution logic structure.

15. The method according to claim 1, wherein The execution logic element includes at least one of the following: Time attribute elements that represent time conditions; Regional attribute elements that characterize regional conditions; Indicator type element that represents the calculated indicator in the requirement intent.

16. The method according to claim 1, wherein Generating the query statement according to the plurality of intermediate structured data includes: The query statement is generated by processing a plurality of intermediate structured data represented by attributes of a domain-specific language format using a language model.

17. A query statement generating device, characterized in that: include: The recognition module is used to identify the intent of the demand text based on business data and obtain the demand intent; an execution logic structure acquisition module, configured to, in response to the requirement intent satisfying a preset requirement condition, process the requirement intent using a language model to obtain an execution logic structure, wherein the execution logic structure includes a plurality of execution logic elements based on a structured representation, wherein the execution logic elements represent a target task of executing the query statement or target metadata related to the target task based on textual semantics, and wherein the structured relationships between the plurality of execution logic elements represent an execution process of executing the query statement; A target pattern information obtaining module is used to determine target pattern information that matches the text semantics represented by the execution logic element from the preset database pattern information; an intermediate structured data acquisition module, configured to utilize the language model to semantically understand the plurality of execution logic elements and the target pattern information, and output a plurality of intermediate structured data for describing the query statement; A query statement generating module is used to generate the query statement according to the plurality of intermediate structured data.

18. An electronic device comprising: one or more processors; a memory for storing one or more computer programs, It is characterized in that the one or more processors execute the one or more computer programs to implement the steps of the method according to any one of claims 1 to 16.

19. A computer-readable storage medium having a computer program or instruction stored thereon, characterized in that: When the computer program or instructions are executed by a processor, the steps of the method according to any one of claims 1 to 16 are implemented.

20. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instructions are executed by a processor, the steps of the method according to any one of claims 1 to 16 are implemented.

Citation Information

Patent Citations

  • Structured query statement generation method and device and computer readable medium

    CN116737762A

  • Adaptive rule-guided large language model generation SQL (Structured Query Language) system

    CN117131070A

  • Method and system for realizing Text2SQL (Structured Query Language)

    CN120470020A

  • Systems and methods for facilitating database queries

    US20240394251A1

Cited By

  • Data query method and device, equipment and storage medium

    CN121117062A

  • Query method and device adaptive to multiple types of databases and storage medium

    CN121524207A

  • Artificial intelligence interactive combined query method and system and electronic equipment

    CN122220483A