Database query guidance methods, devices, media and equipment for multi-granularity metadata

By combining multi-granularity metadata semantic networks and large language models, the user's query intent is gradually clarified, solving the SQL misalignment problem in fuzzy queries, improving the accuracy and efficiency of query transformation, and reducing the difficulty for users to understand the database structure.

CN123115180APending Publication Date: 2026-11-17EAST CHINA BRANCH OF STATE GRID CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611142274.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-30
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing natural language query conversion systems lack intent analysis when faced with fuzzy queries, resulting in a significant mismatch between the generated SQL and the user's true intent, which reduces the accuracy and efficiency of database interaction.

Method used

By constructing a multi-granularity metadata semantic network and conducting fuzzy quantitative evaluation, combined with a large language model, the user's query intent is gradually clarified, natural language query suggestions are generated, and the query is converted into a structured query language when it is clear.

Benefits of technology

It improves the accuracy of query conversion and interaction efficiency in fuzzy query scenarios, lowers the threshold for users to understand the underlying database structure, and reduces invalid queries and interaction costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123115180A_ABST
    Figure CN123115180A_ABST
Patent Text Reader

Abstract

This disclosure relates to the field of natural language processing technology, and provides a method, apparatus, medium, and device for guiding database queries using multi-granularity metadata. The method includes: abstracting the metadata of a relational database into a multi-granularity hierarchical structure and generating natural language descriptions using a large language model; constructing a multi-granularity metadata semantic network database; enabling natural language query tasks to perform fuzzy quantitative evaluation based on this semantic network, distinguishing between fuzzy and clear queries; for fuzzy queries, generating natural language query suggestions and receiving supplementary information from the user to iteratively update the query task until it is converted into a clear query, thereby reducing erroneous parsing caused by unclear user query intent; for clear queries, directly generating structured query language and returning the execution result. This embodiment improves the accuracy and interaction efficiency of converting natural language queries to structured query language, and lowers the barrier for users to understand the underlying database structure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of natural language processing technology, and more specifically, to a database query guidance method, apparatus, medium, and device for multi-granular metadata. Background Technology

[0002] With the rapid development of large-scale language models and the continuous improvement of semantic understanding capabilities, using large models to directly convert natural language into structured query language has become a new paradigm for database interaction. This paradigm breaks down the underlying technical barriers of traditional relational database access, enabling non-professional business users to conveniently extract and analyze data through natural language, significantly improving the popularity of data applications and the efficiency of enterprise decision-making.

[0003] However, most natural language query conversion systems are based on the ideal assumption of "clear query intent." In actual deployments, they employ non-interactive end-to-end generation mechanisms, assuming that the user's natural language input can achieve precise semantic alignment with the underlying database schema. When faced with ambiguous user queries, these models lack intent analysis and force end-to-end reasoning, which can easily lead to logical illusions, resulting in generated SQL that is severely misaligned with the user's true intent. Summary of the Invention

[0004] This disclosure provides at least one database query guidance method, apparatus, medium, and device with multi-granularity metadata. By constructing a multi-granularity metadata semantic network, performing fuzzy quantitative evaluation, and providing iterative guidance for fuzzy queries and direct conversion to clear queries, it improves the accuracy and efficiency of converting natural language queries to structured query language in fuzzy query scenarios, and lowers the threshold for users to understand the underlying structure of the database.

[0005] This disclosure provides a database query guidance method for multi-granularity metadata, including: The metadata of a relational database is obtained, and the metadata is hierarchically abstracted according to multiple preset granularities to obtain a multi-granularity metadata structure; and a large language model is used to generate a corresponding natural language description for each granularity metadata node in the multi-granularity metadata structure, and a multi-granularity metadata semantic network database is constructed based on the generation results. The system receives a natural language query task sent by a user terminal, performs a fuzzy quantitative evaluation of the natural language query task based on the multi-granularity metadata semantic network database, and obtains fuzzy evaluation information. When the fuzzy evaluation information indicates that the natural language query task is a fuzzy query, based on the multi-granularity metadata semantic network database, the natural language query task, and the fuzzy evaluation information, guiding query data is determined; and the guiding query data is input into the large language model to generate natural language query suggestions and feed them back to the user terminal. Receive supplementary information from the user terminal regarding the natural language query suggestion, update the natural language query task based on the supplementary information, and re-execute the fuzzy quantitative evaluation step until the fuzzy evaluation information corresponding to the updated natural language query task indicates a clear query; When the fuzzy evaluation information indicates that the natural language query task is a clear query, a structured query language is generated based on the natural language query task and the multi-granularity metadata semantic network database, and the execution result of the structured query language is returned to the user terminal.

[0006] This disclosure provides a database query guidance device for multi-granularity metadata, including: The database construction module is used to acquire metadata from a relational database, abstract the metadata hierarchically according to multiple preset granularities to obtain a multi-granularity metadata structure, and use a large language model to generate a corresponding natural language description for each granularity metadata node in the multi-granularity metadata structure, and construct a multi-granularity metadata semantic network database based on the generation results. The fuzzy evaluation module is used to receive natural language query tasks sent by user terminals, perform fuzzy quantitative evaluation on the natural language query tasks based on the multi-granularity metadata semantic network database, and obtain fuzzy evaluation information. The query guidance module is used to determine guidance query data based on the multi-granularity metadata semantic network database, the natural language query task, and the fuzzy evaluation information when the fuzzy evaluation information indicates that the natural language query task is a fuzzy query; and input the guidance query data into the large language model to generate natural language query suggestions and feed them back to the user terminal. The query optimization module is used to receive supplementary information from the user terminal regarding the natural language query suggestion, update the natural language query task based on the supplementary information, and re-execute the fuzzy quantitative evaluation step until the fuzzy evaluation information corresponding to the updated natural language query task indicates a clear query. The query execution module is used to generate a structured query language based on the natural language query task and the multi-granularity metadata semantic network database when the fuzzy evaluation information indicates that the natural language query task is a clear query, and return the execution result of the structured query language to the user terminal.

[0007] This disclosure provides a computer device, including a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the computer device is running, the processor communicates with the memory via the bus. When the machine-readable instructions are executed by the processor, a database query guidance method for multi-granularity metadata as described in any of the above possible embodiments is executed.

[0008] This disclosure provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements a database query bootstrapping method for multi-granular metadata as described in any of the possible embodiments above.

[0009] The database query guidance method, apparatus, medium, and device for multi-granular metadata provided in this disclosure combine the ability to generate large language models with the semantic representation of multi-granular metadata to achieve gradual clarification and guidance of users' natural language queries, reduce the threshold for users to write or understand structured query languages, reduce invalid queries and interaction costs caused by query ambiguity, and improve the accuracy and interaction efficiency of database queries.

[0010] To make the above-mentioned objects, features and advantages of this disclosure more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0011] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings referenced in the embodiments will be briefly described below. These drawings are incorporated in and constitute a part of this specification. They illustrate embodiments conforming to this disclosure and, together with the specification, serve to explain the technical solutions of this disclosure. It should be understood that the following drawings only show some embodiments of this disclosure and should not be considered as limiting the scope. Those skilled in the art can obtain other related drawings based on these drawings without creative effort.

[0012] Figure 1 A flowchart of a database query guidance method for multi-granularity metadata provided in an embodiment of this disclosure is shown; Figure 2 A flowchart of a fuzzy quantification evaluation method provided by an embodiment of this disclosure is shown; Figure 3 A flowchart of a guided query data determination method provided by an embodiment of this disclosure is shown; Figure 4 A flowchart of an external knowledge fusion method provided by an embodiment of this disclosure is shown; Figure 5 This diagram illustrates the structure of a database query guidance device for multi-granularity metadata provided in an embodiment of the present disclosure. Figure 6 A schematic diagram of the structure of a computer device provided in an embodiment of this disclosure is shown. Detailed Implementation

[0013] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of the embodiments of this disclosure described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely represents selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.

[0014] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0015] In this document, the term "and / or" merely describes a relationship, indicating that three relationships can exist. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. Furthermore, the term "at least one" in this document means any combination of at least two of any one or more elements. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.

[0016] To facilitate understanding of this embodiment, the execution subject of the database query guidance method for multi-granularity metadata provided in this disclosure will first be described in detail. The execution subject of the database query guidance method for multi-granularity metadata provided in this disclosure is a computer device. This computer device can be a terminal device or a server. The terminal device can also be a mobile device, a user terminal, a terminal, a handheld device, a computing device, an in-vehicle device, a wearable device, etc. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud storage, big data, and artificial intelligence platforms. Optionally, this method can also be applied to an implementation environment composed of computer devices and servers.

[0017] The database query guidance method for multi-granularity metadata provided in this application embodiment will be described in detail below with reference to the accompanying drawings. See also Figure 1 The diagram shows a flowchart of a database query guidance method for multi-granularity metadata provided in this embodiment of the present disclosure. The method includes the following steps S101 to S105: S101, Obtain metadata from a relational database, abstract the metadata hierarchically according to multiple preset granularities to obtain a multi-granularity metadata structure; and use a large language model to generate a corresponding natural language description for each granularity metadata node in the multi-granularity metadata structure, and construct a multi-granularity metadata semantic network database based on the generation results.

[0018] As we can understand, a relational database refers to a data storage system that uses a tabular structure to organize and store data, and performs data manipulation and management through a structured query language. Common relational database products include MySQL, PostgreSQL, Oracle, and Microsoft SQL Server. Relational databases store a large amount of metadata, which describes the data itself. Specifically, in the context of relational databases, metadata can include the definition information of various objects within the database, such as the names and uses of all physical tables, the names and data types of each field in each physical table, the business meaning comments of each field, the primary and foreign key relationships between tables, and the definitions of various indexes and constraints.

[0019] Here, by hierarchically abstracting the acquired relational database metadata according to multiple preset granularities, the originally flat, physically storage-oriented metadata can be organized into a logical view with a business semantic hierarchy. This logical view is the multi-granularity metadata structure described in this disclosure. The multiple preset granularities refer to the hierarchical division standards used when abstracting and organizing the metadata. Different granularities correspond to different data abstraction levels and can be used as basic units for retrieval and recommendation in the subsequent query guidance process.

[0020] This disclosure establishes three granularity levels: topic granularity, table granularity, and field granularity. When performing hierarchical abstraction of relational database metadata according to these three granularities, the following steps (a) to (d) may be included: (a) Extract metadata from the acquired metadata corresponding to multiple physical tables belonging to the same business scope, and abstract the extracted metadata into a topic-level node; (b) Extract the metadata corresponding to each physical table from the obtained metadata, and abstract the extracted metadata into a table-level node; (c) Extract the metadata corresponding to each field from the obtained metadata, and abstract the extracted metadata into a field-level node; (d) Establish the hierarchical relationship between topic granularity nodes, table granularity nodes and field granularity nodes to obtain a multi-granularity metadata structure.

[0021] Here, extracting metadata from multiple physical tables belonging to the same business scope from the acquired metadata aims to overcome the limitations of a single physical table and logically merge multiple physical tables that are scattered but serve the same business objective into a unified business theme. Specifically, in real-world enterprise databases, a complete business analysis scenario often involves the combined use of multiple physical tables. For example, in a power grid load analysis scenario, the daily load details table, the substation basic information table, and the regional division table jointly support the business objective of load analysis. After extracting the metadata corresponding to these scattered physical tables and abstracting it into a theme-level node, this theme-level node represents a macro-level business analysis domain, enabling users to first locate their query needs from a business perspective. In practical implementation, determining which physical tables belong to the same business scope can be achieved by automatically identifying related table groups through parsing database foreign key relationships, semantic clustering based on table names and field comments using a large language model, or manual pre-configuration, among other methods.

[0022] Here, the purpose of extracting the metadata corresponding to each physical table from the acquired metadata is to logically encapsulate each physical table in the database as an independent business entity. A physical table is the structural unit for actually storing data in a relational database. Each physical table contains several fields, corresponding to a certain type of entity or business event in the real world. Taking a power grid database as an example, the daily load detail table stores the load sampling values ​​of each monitoring point at each time of day; the substation basic information table stores the name, location, and capacity information of each substation; and the user information table stores the file information of power users. These physical tables each carry different business information. After abstracting the metadata corresponding to each physical table into a table-level node, this table-level node represents a specific business data entity. Compared to topic-level nodes, table-level nodes have clearer business boundaries and carry richer field structure information. If the physical table itself already has annotation information, this annotation information can be directly used as the initial semantic description of the table-level node.

[0023] Here, extracting the metadata corresponding to each field from the acquired metadata aims to logically abstract each field in the physical table into a smallest, independently referable and recommendable data unit. A field is the finest-grained data definition unit in a relational database, possessing attributes such as name, data type, and business meaning. Taking a daily load detail table as an example, this table may contain multiple fields such as monitoring point number, data acquisition time, active power, reactive power, and voltage, each corresponding to a specific dimension of the load data. After abstracting the metadata corresponding to each field into a field-level node, this field-level node represents a finest-grained data indicator or data dimension. When the user's query intent is relatively clear and only needs to confirm specific filtering conditions or output indicators, the field-level node can play a direct recommendation and guidance role.

[0024] Understandably, after obtaining thematic granularity nodes, table granularity nodes, and field granularity nodes, a hierarchical relationship between these nodes can be established, thus forming a complete data structure with a hierarchical structure, i.e., multi-granularity metadata results. Specifically, a thematic granularity node can be subordinated to one or more table granularity nodes, indicating which business data entities the theme covers. For example, the thematic node "Power Grid Load Analysis" can be subordinated to three table granularity nodes: Daily Load Details Table, Substation Basic Information Table, and Regional Division Table. This indicates that the physical storage scope involved in the business theme of "Power Grid Load Analysis" covers three types of data entities: load sampling data, substation static information, and regional geographic information. A table granularity node can be subordinated to one or more field granularity nodes, indicating which data fields the table contains. For example, the table granularity node "Daily Load Details Table" can be subordinated to five field granularity nodes: Monitoring Point Number Field, Data Acquisition Time Field, Active Power Field, Reactive Power Field, and Voltage Field. This indicates each queryable data dimension specifically included in the load details data.

[0025] In this way, the above hierarchical relationship forms a tree structure that is gradually refined from top to bottom, namely a multi-granularity metadata structure. The topic granularity is at the top layer, which can provide a macro business perspective; the table granularity is at the middle layer, which can provide a meso business entity perspective; and the field granularity is at the bottom layer, which can provide a micro data indicator perspective.

[0026] In this way, by establishing hierarchical relationships between subject granularity, table granularity, and field granularity for the metadata of relational databases, this disclosure reorganizes various types of metadata, originally scattered across database system tables and guided by physical storage structure, into a tree structure with clear business semantic hierarchical relationships. This results in a multi-granularity metadata structure that refines from macro-level business themes to micro-level data fields. This multi-granularity metadata structure facilitates semantic retrieval and similarity calculation at different granularity levels during subsequent query guidance, helping to improve the efficiency and accuracy of intent clarification in fuzzy query scenarios.

[0027] In some other embodiments, the metadata of the relational database can be hierarchically abstracted based on a four-granularity partitioning approach. This involves adding an additional level of indicator granularity beyond the subject granularity, table granularity, and field granularity. The indicator granularity, located below the field granularity, is used to further abstract indicator type nodes with clear business quantitative meanings from the field granularity nodes. For example, based on the active power field node under the field granularity, multiple business indicator nodes such as daily maximum load indicator node, daily minimum load indicator node, daily average load indicator node, and load rate indicator node can be further abstracted. These indicator nodes describe common business statistical methods that can be performed on the same original field. In other embodiments, depending on the actual size of the target database and the application scenario requirements, only two levels—subject granularity and table granularity—can be set, omitting the separate abstraction of field granularity. This is suitable for lightweight application scenarios with a small number of data tables and simple field structures. The number and partitioning method of granularity levels can be flexibly configured according to the data size of the target relational database, the semantic richness of the business domain, and the complexity of the actual application scenario. This disclosure does not impose any restrictions in this regard.

[0028] Furthermore, after establishing the hierarchical relationships between topic-level nodes, table-level nodes, and field-level nodes as described above to obtain a multi-granularity metadata structure, all metadata nodes in this structure can be input into a large language model. The large language model then generates corresponding natural language descriptions for each granularity metadata node within the multi-granularity metadata structure. The large language model is a natural language processing model built using deep learning techniques and pre-trained on a large-scale text corpus. This model possesses the ability to understand natural language semantics and generate coherent natural language text.

[0029] In some possible embodiments, the large language model can be an open-source model, such as the LLaMA series models or the ChatGLM series models, or a commercial closed-source model, such as the GPT series models or the Wenxin Yiyan large language model. In specific applications, the model can be fine-tuned and trained on corpora of specific business domains based on the aforementioned basic models, enabling the model to have a stronger understanding of terminology and expressions specific to certain industries and to generate higher quality content. The specific selection and deployment method of the large language model can be flexibly configured according to the computational resource constraints and business needs of the actual application scenario, and this disclosure does not impose any limitations in this regard.

[0030] For example, taking the business scenario of power grid load analysis as an example, for the daily load details table as a granular node, the large language model can generate a natural language description with business semantics based on the field names, data types, and existing annotation information contained in the table. For example, the table records the load data of each monitoring point of the power grid at each collection time, including core indicators such as active power, reactive power, and voltage. For the monitoring point number as a granular node, the large language model can generate a natural language description that the field represents the unique identifier number of the collection point.

[0031] For example, taking a retail sales analysis business scenario, for the table-level node of the sales order details table, the large language model can generate a natural language description with business semantics based on the field names, data types, and existing annotation information contained in the table. For instance, this table records detailed transaction information for each sales order in a retail store, including core indicators such as order number, transaction time, product code, sales quantity, transaction amount, and discount amount. For the product code field-level node, the large language model can generate a natural language description that this field represents the unique identifier code of the sold product. For the retail sales analysis topic-level node, the large language model can generate a natural language description that summarizes and analyzes the sales data of retail stores under this topic, based on the description information of the table-level nodes to which this topic belongs.

[0032] In this way, by generating natural language descriptions for each granular node through a large language model, the raw metadata of the underlying database, which exists in the form of English abbreviations, technical names, or cryptographic encoding, can be transformed into business terms that business personnel can directly understand. This eliminates the semantic gap between the physical database model and user cognition, and improves the matching accuracy when performing semantic retrieval based on natural language queries.

[0033] Specifically, based on the natural language descriptions of all metadata nodes, a multi-granularity metadata semantic network database can be constructed. Each metadata node in this database is associated with a corresponding natural language description and vectorized representation. This database can support fuzzy quantitative evaluation and cross-granularity semantic retrieval when receiving user natural language query tasks.

[0034] In some possible embodiments, during the construction of a multi-granularity metadata semantic network database, the natural language descriptions generated for each granularity metadata node can be processed into high-dimensional vectors. This involves using a pre-trained language representation model to transform the natural language description text into a fixed-dimensional numerical vector. High-dimensional vectorization is the process of mapping natural language text to a numerical representation in a high-dimensional semantic space. This numerical vector can capture the semantic information of the text, allowing semantically similar texts to have similar distances or high cosine similarity in the vector space.

[0035] Among them, the pre-trained language representation models used when vectorizing natural language descriptions can be BERT, Sentence-BERT, SimCSE, etc. These models can encode variable-length natural language text into fixed-length dense vectors.

[0036] Furthermore, after high-dimensional vectorization, a node vector corresponding to each metadata node can be obtained. This node vector serves as the numerical coordinate of the corresponding metadata node in the semantic space, and is used in subsequent steps to calculate semantic similarity with the vector of the user query text. Then, the node vector is associated with and stored with its corresponding metadata node, establishing a mapping relationship between node vectors and metadata nodes. This allows for the retrieval of the corresponding node vector through a metadata node, and the location of the associated metadata node through the node vector, thus forming a multi-granularity metadata semantic network database. This database can store the metadata node's identification information, natural language description text, and node vectors together in the same data record, either in the form of key-value pairs or document records.

[0037] S102, receive the natural language query task sent by the user terminal, and perform fuzzy quantitative evaluation on the natural language query task based on the multi-granularity metadata semantic network database to obtain fuzzy evaluation information.

[0038] Here, the user terminal refers to the electronic device used by the user, which has data input and network communication functions, and can include personal computers, laptops, tablets, smartphones, and other device types. Users can input natural language query tasks through these terminal devices. Natural language query tasks refer to data query requests submitted by users in everyday natural language. These queries exist in text form; for example, a user can input a query about power grid load or a query about the top ten best-selling products from last month. Natural language query tasks differ from structured query languages ​​in that they are characterized by flexible expression, diverse sentence structures, and arbitrary vocabulary selection. Users can freely express their information needs without adhering to any grammatical rules or data dictionary constraints.

[0039] Specifically, the multi-granularity metadata semantic network database is a knowledge base pre-built in step S101. This database contains a three-layer structure of topic-granularity nodes, table-granularity nodes, and field-granularity nodes. Each node is associated with a corresponding natural language semantic description and vectorized representation. After receiving a natural language query task sent by the user terminal, the natural language query task can be evaluated using fuzzy quantitative methods based on this multi-granularity metadata semantic network database. Fuzzy quantitative evaluation refers to the process of quantitatively analyzing and classifying the clarity of the user's query through a series of calculable indicators. The purpose of this evaluation process is to determine whether the user's current query expression is sufficient to support the generation of accurate structured query language, and to identify which specific information is missing when the query expression is insufficient.

[0040] In some possible embodiments, considering that user natural language queries may simultaneously exhibit varying degrees of ambiguity across multiple dimensions such as pattern mapping, operational intent, and constraints, a single-dimensional evaluation is insufficient to comprehensively reflect the overall ambiguity of the query. Therefore, in fuzzy quantification evaluation, multiple independent dimensions can be set for separate scoring, referring to... Figure 2 As shown, the following steps S201~S204 may be included in the fuzzy quantification evaluation: S201, based on the multi-granularity metadata semantic network database, verify the degree of matching between words in the natural language query task and each metadata node, and determine the evaluation result of the pattern mapping dimension.

[0041] Specifically, the fuzzy quantification evaluation process for natural language query tasks can first evaluate the pattern mapping dimension of the query task, which is used to verify the degree of matching between words in the natural language query task and various metadata nodes in the multi-granularity metadata semantic network database.

[0042] For example, the natural language query task input by the user can be segmented and keywords extracted to obtain the core words and phrases in the query task. Then, the similarity between these words and the semantic vectors of each metadata node in the semantic network database can be calculated. If the core words in the query task can form semantic matches with a high proportion of metadata nodes, the pattern mapping dimension of the query task can be set to a high score, indicating that the user's query has a relatively clear direction at the database schema level. Conversely, if the words in the query task cannot find a sufficient number of high similarity matching nodes in the semantic network, the score of this dimension is low, indicating that the user's query is ambiguous in terms of pattern mapping. Taking the user input query "I want to see load data" as an example, the word "load" can form a semantic match with the power grid load analysis topic node and the daily load detail table node in the multi-granularity metadata semantic network, so the score of the pattern mapping dimension is high. If the user inputs "Help me check the situation," the word "situation" is too broad and cannot form an effective match with any specific metadata node, so the score of the pattern mapping dimension is correspondingly low.

[0043] S202, verify whether the natural language query task contains preset action keywords, and determine the evaluation result of the operation clarity dimension.

[0044] Specifically, the ambiguity of user queries is not only reflected in the inability to locate the correct data table or field, but also in the user's lack of knowledge about what operations to perform on the data. Therefore, the operational clarity dimension of the query task can also be evaluated. This dimension can be used to verify whether the natural language query task contains preset action keywords to determine whether the user has clearly indicated what analytical operations to perform on the data.

[0045] The preset action keywords are a set of predefined verbs and verb phrases that express the user's intention to analyze and process data. These can include operation types such as summation, calculating average, counting, sorting, grouping, comparison, finding maximum value, and finding minimum value.

[0046] Understandably, keyword scanning of user-input natural language queries can detect whether they contain the aforementioned preset action keywords, thereby determining whether the user has expressed a clear intention to perform data operations. If the query contains explicit action keywords, it indicates that the user has a clear direction regarding data analysis operations, and a higher score can be assigned to the action clarity dimension. If the query does not contain any action keywords, or if the contained action keywords are semantically ambiguous and cannot be clearly mapped to a specific data operation type, the score for this dimension will be lower, indicating ambiguity in the user's action intent.

[0047] For example, when a user enters a query to calculate last month's total sales, the keywords "calculate" and "sum" appear simultaneously, clearly indicating that a summation operation is required. Therefore, the operation clarity dimension score is high. If the user enters a query to view sales data, the keywords do not belong to any predefined operation keywords, making it unclear whether the user wants to view detailed data, calculate totals, or perform trend analysis. Consequently, the operation clarity dimension score is lower.

[0048] S203, verify the completeness of the data filtering conditions contained in the natural language query task, and determine the evaluation result of the constraint integrity dimension.

[0049] Furthermore, considering that even if the user has clearly defined the data table to query and the analysis operation to be performed, the query still cannot be executed within a reasonable scope or context if the necessary filtering conditions are lacking, the constraint integrity dimension of the query task can also be evaluated to verify the completeness of the data filtering conditions contained in the natural language query task.

[0050] Specifically, data filtering conditions refer to the filtering restrictions imposed by users on query results, such as time range restrictions, geographical region restrictions, category restrictions, and numerical range restrictions. By parsing the natural language query statement entered by the user, the various constraints involved are extracted, and then the type coverage and specificity of the extracted constraints are statistically analyzed to determine whether these constraints are sufficient to constitute an executable query.

[0051] For example, during the evaluation of the constraint integrity dimension, it can be checked whether the query statement contains the necessary time dimension constraints, such as specific dates, months, quarters, or years. It can also be checked whether there are other necessary constraints in the business dimension. Taking the power grid load query scenario as an example, if a user enters a query for load data, the query lacks the crucial constraint of time range, because load data must be accompanied by a specific time interval to have practical analytical significance, resulting in a low constraint integrity dimension score. If a user enters a query for load data in January 2024, the query contains a clear time range constraint, resulting in a higher constraint integrity dimension score.

[0052] S204. Based on the evaluation results of the pattern mapping dimension, the operation clarity dimension, and the constraint integrity dimension, determine the fuzziness level of the natural language query task, identify the specific missing information that causes the fuzziness level, and use the fuzziness level and the specific missing information as the fuzziness evaluation information.

[0053] Furthermore, after evaluating the pattern mapping dimension, operational clarity dimension, and constraint integrity dimension respectively, the fuzziness level of the natural language query task can be comprehensively determined based on the evaluation results of the above three dimensions, and the specific missing information leading to the fuzziness level can be identified. Here, the fuzziness level is a qualitative classification of the overall clarity of the user query, which can be divided into three levels: highly fuzzy, moderately fuzzy, and clear. Highly fuzzy indicates that the user query has significant deficiencies in all three dimensions, making it impossible to confirm the business topic, operation type, and filtering conditions involved in the user's intent; moderately fuzzy indicates that the user query has deficiencies in some dimensions, and the scope of the user's intent can be roughly determined, but there is still a lack of sufficient details to generate precise structured query language; clear indicates that the user query has reached the executable standard in all three dimensions and has the conditions to generate structured query language.

[0054] Here, while determining the fuzziness level, it's also possible to simultaneously identify the specific missing information that caused the fuzziness level when the fuzziness level indicator is highly or moderately fuzzy. This specific missing information refines the fuzziness level, indicating which specific content the user is missing in which specific dimension. For example, if the pattern mapping and operational clarity dimensions have high scores, but the constraint integrity dimension has a low score, the specific missing information can be recorded as a missing time range constraint. If the pattern mapping dimension has a high score, but both the operational clarity and constraint integrity dimensions have low scores, the specific missing information can be recorded as a missing analysis operation type and time range constraint.

[0055] In this way, by verifying and scoring natural language query tasks from three independent dimensions—pattern mapping, operational clarity, and constraint integrity—and combining the evaluation results of the three dimensions to determine the fuzziness level and specific missing information, abstract semantic fuzziness can be transformed into quantifiable evaluation indicators and clear descriptions of missing information. This improves the comprehensiveness and accuracy of fuzziness assessment and enables refined fuzzy diagnosis of user queries at three different logical levels: database pattern matching, data analysis operation, and data filtering conditions.

[0056] In some other embodiments, the natural language query task can be further evaluated based on evaluation metrics of different dimensions, such as the result quantity limitation dimension and the output range dimension, without specific limitations here. The manifestation of user query fuzziness varies in different business scenarios; therefore, the specific dimensions and number used in the fuzzy quantification evaluation can be adaptively adjusted according to the user query characteristics of the target application domain, and this disclosure does not impose any limitations in this regard.

[0057] S103, when the fuzzy evaluation information indicates that the natural language query task is a fuzzy query, guide query data is determined based on the multi-granularity metadata semantic network database, the natural language query task, and the fuzzy evaluation information; and the guide query data is input into the large language model to generate natural language query suggestions and feed them back to the user terminal.

[0058] Understandably, the fuzzy evaluation information includes the fuzziness level of the natural language query task and the specific missing information that leads to that level. If the fuzziness level is highly fuzzy or moderately fuzzy, it indicates that the current natural language query task is not yet sufficient to support the direct generation of structured query language. In this case, the query task can be classified as a fuzzy query.

[0059] Specifically, when a natural language query task is determined to be a fuzzy query, guidance logic can be activated. This involves determining guidance query data based on three input elements: a multi-granularity metadata semantic network database, the natural language query task, and fuzzy evaluation information. Here, guidance query data is a set of target metadata items selected from the multi-granularity metadata semantic network database in the current interaction round. These items are used to generate natural language query suggestions. The metadata items in this set are organized according to a specific granularity ratio and can serve as structured data input for the subsequent generation of guidance suggestions by the large language model. This data is used to provide users with optional directions for clarifying their intent in fuzzy query scenarios.

[0060] For example, in order to output differentiated guidance suggestions based on different levels of ambiguity in user queries, a dynamic matching mechanism can be set up, referring to... Figure 3 As shown, the process of determining the guiding query data may include the following steps S301~S303: S301, determine the proportion of recommendations corresponding to topic granularity, table granularity and field granularity under the constraints of the fuzziness level and the specific missing information.

[0061] It is understandable that the recommendation quantity ratio refers to the proportion of each granularity of the natural language query suggestions generated in this round of guidance to the total number of suggestions. This ratio is not a fixed value, but can be dynamically calculated based on the fuzziness of the current query.

[0062] Specifically, a set of ratio adjustment rules can be pre-set. For queries with a highly fuzzy level where the missing information does not indicate the user's business topic of interest, the proportion of recommendations at the topic level can be set to a higher value, while the proportions at the table and field levels can be set to a lower value. For example, the ratio of recommendations at the topic, table, and field levels could be 7:2:1. This will generate query suggestions primarily guided by the topic level, helping users to narrow down their business scope at a macro level and avoiding premature exposure to complex underlying table structures and field details, thus reducing the user's cognitive burden. For queries with a moderately fuzzy level where the missing information indicates a clear business topic but lacks specific analysis operations or filtering conditions, the proportion of recommendations at the topic level can be reduced, while the proportions at the table and field levels can be increased. This allows query suggestions to gradually delve into finer-grained data entities and data fields. For example, the ratio of recommendations at the topic, table, and field levels could be adjusted to 2:5:3. For queries where the fuzziness level is close to clear but some constraints are still unclear, the proportion of recommended field granularity is set to a higher value. By recommending specific field names as candidate filtering conditions, users can quickly refine their queries. For example, the proportion of recommended topics, tables, and fields can be adjusted to 1:3:6.

[0063] In some other embodiments, the above-mentioned ratio adjustment rules can also be personalized based on the user's historical query preferences, or adaptively optimized based on the metadata distribution density of the specific business domain involved in the current query, without specific limitations here. For example, in wide table scenarios with a large number of fields, the recommendation ratio at the field granularity level can be appropriately increased to help users quickly locate the target field among many fields; in complex database scenarios with a large number of tables, the recommendation ratio at the topic granularity and table granularity level can be appropriately increased to prevent users from getting lost in massive tables.

[0064] In this way, by determining the proportion of recommendations at the topic granularity, table granularity, and field granularity under the constraints of the fuzziness level and specific missing information corresponding to the current natural language query task, the granularity distribution of the subsequently generated query suggestions can be matched with the fuzziness of the user's current query. The higher the fuzziness, the greater the proportion of macro-level guidance, and the lower the fuzziness, the greater the proportion of micro-level details, thereby achieving a gradual guidance from macro to micro.

[0065] S302, according to the natural language query task, the topic granularity, the table granularity and the field granularity are used as filtering conditions to search the multi-granularity metadata semantic network database to obtain a set of semantically similar metadata items corresponding to each granularity.

[0066] Furthermore, after determining the proportion of recommendations at each granularity, the topic granularity, table granularity, and field granularity can be used as filtering conditions to retrieve data from the multi-granularity metadata semantic network database based on the semantic information in the natural language query task.

[0067] Specifically, the text content in a natural language query task can be converted into a query vector. This vector resides in the same semantic space as the node vectors stored in the multi-granularity metadata semantic network database. Then, the semantic similarity between this query vector and all topic-granularity node vectors, all table-granularity node vectors, and all field-granularity node vectors is calculated within the multi-granularity metadata semantic network database. Here, the semantic similarity can be calculated using cosine similarity algorithms or inner product similarity algorithms, both of which are standard techniques in the field of vector retrieval.

[0068] Understandably, after the search, three independent similarity ranking results can be obtained at different granular levels: metadata items arranged from highest to lowest semantic similarity at the topic level, table level, and field level. Each metadata item in each set carries a corresponding semantic similarity score, reflecting the semantic relevance of that metadata node to the user's current query.

[0069] S303, based on the recommended quantity ratio, select target metadata items from the set of semantically similar metadata items corresponding to each granularity, and determine the guided query data based on the selection results.

[0070] Furthermore, after obtaining the semantically similar metadata item sets for each of the three granularities, target metadata items can be selected from the semantically similar metadata item sets corresponding to each granularity based on the recommendation quantity ratio determined in step S301. The selection method can be as follows: calculate the number of metadata items to be selected for each granularity according to the recommendation quantity ratio of each granularity, and then select the top-ranked metadata items from the similarity ranking set of that granularity whose quantity is equal to the calculated quantity as target metadata items. For example, if the recommendation quantity ratio determines that the ratio of topic granularity, table granularity, and field granularity is 6:3:1, and the total number of recommended items in this round is 10, then the top 6 metadata items in terms of similarity in the topic granularity set are selected as target metadata items for the topic granularity, the top 3 metadata items in terms of similarity in the table granularity set are selected as target metadata items for the table granularity, and the top 1 metadata item in terms of similarity in the field granularity set is selected as target metadata items for the field granularity. After summarizing the target metadata items selected from the three granularities, we obtain the guided query data. The guided query data is essentially a multi-granularity metadata node list that has been dynamically matched and filtered. The metadata nodes in this list have been differentiated according to the fuzziness level of the current query.

[0071] Understandably, the guided query data provides structured, multi-level candidate information. In order to transform this candidate information into a natural language form that is easy for users to understand and manipulate, the guided query data can be input into a large language model, which will then generate natural language query suggestions. These suggestions are supplementary query information presented in the form of natural language text that users can choose from.

[0072] In some possible embodiments, during the generation of natural language query suggestions, the natural language descriptions corresponding to each target metadata item in the guided query data can be extracted and uniformly input into the large language model. This is because each target metadata item already has a corresponding natural language description associated with it in its node data structure, and these descriptions can be directly used as semantic material for the large language model to generate suggestion text. The large language model then generates natural language text based on the natural language description corresponding to each target metadata item. Specifically, the large language model expands the description of each target metadata item into a complete suggestion item in the form of a natural language question or statement, and organizes the generated natural language texts into hierarchical natural language query suggestions according to a preset prompt template, arranging items of different granularities within the same suggestion in a macro-to-micro order.

[0073] Here, the preset suggestion template can be used to instruct the large language model to organize the output content in a hierarchical order of topic granularity, table granularity and field granularity, and combine the natural language descriptions corresponding to the target metadata items belonging to the same granularity into a coherent natural language suggestion text. The suggestion texts of different granularities are arranged in order from macro to micro.

[0074] Thus, in the natural language query suggestions generated in the above manner, the suggestions are at the topic level first, then at the table level, and finally at the field level. The overall structure presents a hierarchical guidance structure from business topics to data entities and then to specific data fields. This can more effectively guide users to gradually clarify their query needs at different levels of abstraction, so that users can choose the most appropriate direction for clarification based on their current level of ambiguity.

[0075] Furthermore, the generated natural language query suggestions can be fed back to the user through the user terminal. That is, the suggestion text is transmitted to the user's terminal device via the network and presented on its display interface. The user can read these suggestions on the terminal screen and select one or more of them as the basis for further clarification of intent according to their own needs, or use the suggestions as a reference to input new supplementary information, thereby realizing interactive intent clarification with the user.

[0076] S104, receive supplementary information from the user terminal regarding the natural language query suggestion, update the natural language query task based on the supplementary information, and re-execute the fuzzy quantitative evaluation step until the fuzzy evaluation information corresponding to the updated natural language query task indicates a clear query.

[0077] Understandably, after receiving the natural language query suggestions, the user terminal displays these suggestions as natural language text. After reading the suggestions, the user can select one as supplementary information based on their actual query needs, or manually enter new supplementary text. The user's selection or input is transmitted back to the system via the user terminal's input device. The result of this operation is the supplementary information, which essentially clarifies and limits the user's initial query intent. This can manifest as the user specifically adding a topic-level node, table-level node, or field-level node from the suggestion list, or as the user manually entering new natural language text to supplement previously missing information such as time range, analysis operations, or filtering conditions.

[0078] Furthermore, after receiving supplementary information from the user terminal, this supplementary information can be integrated with the original natural language query task to update the natural language query task. Specifically, during the query task update process, this can be manifested as follows: if the supplementary information is a metadata node selected by the user, the semantic information of that metadata node is added to the original query task, giving the original query task a clear direction in the corresponding dimension. If the supplementary information is new text entered by the user, the new text is appended to the end of the original query task to form a more complete query statement. Here, the updated natural language query task contains more user intent information than the previous query task, and should show higher scores in the pattern mapping dimension, operational clarity dimension, or constraint integrity dimension.

[0079] Specifically, after obtaining the updated natural language query task, the process can return to step S102 above and re-execute the fuzzy quantitative evaluation process, i.e., recalculate the fuzziness level and specific missing information of the updated query task. If the fuzzy evaluation information corresponding to the updated query task still indicates a fuzzy query, the process re-enters the guidance logic in step S103, redetermines the recommendation quantity ratio based on the updated query task and the new fuzzy evaluation information, re-retrieves and filters target metadata items, regenerates natural language query suggestions and feeds them back to the user terminal, awaiting the user's next round of supplementary information. If the fuzzy evaluation information corresponding to the updated query task indicates a clear query, i.e., the evaluation results of all three dimensions reach the preset clear threshold, the iterative process of fuzzy quantitative evaluation ends, exits the guidance loop, and enters the query execution stage in step S105.

[0080] Here, the aforementioned multi-round interactive iteration process continues until the query task reaches a clear standard or the preset maximum number of interaction rounds. In each round of interaction, the recommendation ratio of each granular suggestion is dynamically adjusted according to the latest fuzzy state of the current query. The first stage mainly guides users with themes to help them lock in their business direction, while the second stage mainly guides users with tables and fields to help them refine their analysis indicators and filtering conditions, so as to achieve a gradual convergence of intent from macro to micro and from fuzzy to clear.

[0081] S105, when the fuzzy evaluation information indicates that the natural language query task is a clear query, a structured query language is generated based on the natural language query task and the multi-granularity metadata semantic network database, and the execution result of the structured query language is returned to the user terminal.

[0082] Understandably, when the fuzziness level in the fuzzy evaluation information is "clear," it indicates that the current natural language query task has reached the executable standard in the pattern mapping, operational clarity, and constraint integrity dimensions. Specifically, a pattern mapping score reaching a preset threshold means that the core terms in the user query can form a clear correspondence with metadata nodes in the multi-granularity metadata semantic network database, identifying the business theme involved in the user's intent and the targeted data tables and fields. An operational clarity score reaching a preset threshold means that the user query contains explicit action keywords, determining what analytical operation the user wants to perform on the data, such as summation, averaging, sorting, or grouping. A constraint integrity score reaching a preset threshold means that the user query contains sufficient filtering conditions, determining the time range, geographical region, and other necessary filtering restrictions that the query results should meet.

[0083] Furthermore, after confirming that the natural language query task is a definite query, the natural language query task that was initially determined to be a definite query, or the natural language query task that has undergone multiple rounds of interactive supplementation, can be used as input. This input is then combined with the metadata node mapping relationships in the multi-granularity metadata semantic network database to generate a structured query language. In this disclosure, the structured query language specifically refers to the standard structured query language, i.e., SQL, which is the universal standard language for data querying and manipulation in relational databases.

[0084] Specifically, the method for generating structured query language can be represented as follows: Extract the confirmed structured requirement details from the current natural language query task, including the physical table names corresponding to the user-defined business themes, the SQL operation types corresponding to the user-defined analytical operations, the field names corresponding to the user-defined data metrics, and the WHERE clause condition expressions corresponding to the user-defined filtering conditions. Then, assemble these structured requirement details according to SQL syntax rules to form a complete SQL statement, which can be directly executed in the target relational database and return query results.

[0085] Understandably, after the structured query language is generated, it can be submitted to a relational database for execution. The database executes the SQL statement and returns the execution result, which is the actual business data that matches the user's query conditions. The system receives the execution result and returns it to the user terminal in a format readable by the user's terminal, allowing the user to view the query result data on the terminal device's display interface.

[0086] For example, in a power grid load query scenario, the user's final query task after multiple rounds of interaction is to query the daily average active power of each monitoring point in January 2024. Based on this, the corresponding SQL statement is generated and submitted to the database for execution. The database returns multiple records containing three fields: monitoring point number, date, and daily average active power. These records are presented in a table format on the user terminal's display interface, allowing the user to directly view the average load value of each monitoring point for each day in January 2024.

[0087] In some other embodiments, the method provided in this disclosure may further include an external knowledge fusion step, which is located after the multi-granularity metadata semantic network database is constructed in S101 and before the fuzzy quantitative evaluation begins in S102, or is dynamically triggered at any stage of the query guidance process. External knowledge fusion refers to extracting unstructured text information from data sources outside of relational databases and transforming this information into structured knowledge compatible with the multi-granularity metadata semantic network database, thereby enhancing the coverage and expressive power of the semantic network. (Refer to...) Figure 4 The external knowledge fusion process shown may include the following steps S401~S404: S401, extract external natural language vocabulary from external data sources, and vectorize the external natural language vocabulary to obtain external vocabulary vectors.

[0088] Specifically, external data sources can include unstructured documents such as business operation manuals, data dictionary documents, historical query logs, business report templates, and industry standard specifications. External natural language vocabulary is extracted from these external data sources. This vocabulary typically consists of business terms or industry-standard expressions not directly recorded in the database, such as terms related to high-value customers, peak electricity consumption periods, and heavily overloaded equipment. Since external natural language vocabulary is unstructured information existing in the form of natural language text, it cannot be directly numerically calculated and compared with vectorized nodes in the multi-granularity metadata semantic network database. Therefore, the extracted external natural language vocabulary can be vectorized using the same vectorization model as in step S101 to obtain external vocabulary vectors, placing them in the same semantic vector space as the metadata node vectors.

[0089] S402, calculate the semantic similarity between each of the external vocabulary vectors and each metadata node vector in the multi-granularity metadata semantic network database.

[0090] Furthermore, after obtaining the external word vectors, semantic matching calculations can be performed, that is, calculating the semantic similarity between each external word vector and each metadata node vector in the multi-granularity metadata semantic network database, in order to determine the degree of semantic relevance between the external words and each metadata node.

[0091] S403, the metadata node with a semantic similarity greater than a preset enhancement threshold is determined as the associated node of the external vocabulary vector, and the external natural language vocabulary corresponding to the external vocabulary vector is added to the natural language description of the associated node.

[0092] Here, if the semantic similarity between an external vocabulary vector and a metadata node vector is greater than a preset enhancement threshold, it indicates that the external vocabulary and the corresponding metadata node are highly correlated at the semantic level. In this case, the external natural language vocabulary can be identified as the associated vocabulary of the node, and added to the original natural language description of the metadata node to expand the semantic expressive power of the node. For example, the external vocabulary "peak electricity consumption period" extracted from the business operation manual, after vectorization and semantic similarity calculation, has a semantic similarity with the collection time field node in the daily load details table that is higher than the preset enhancement threshold. Therefore, the external vocabulary "peak electricity consumption period" can be added to the natural language description of the collection time field node, expanding the description of the field node from "collection time" to "collection time, used to identify the time dimension in the analysis of peak electricity consumption periods," thereby enhancing the node's expressive power for business terms. For example, if the semantic similarity between the term "high-value customer" extracted from an external data source and the annual spending amount field node in the user information table is higher than a preset enhancement threshold, then the high-value customer can be added to the natural language description of the annual spending amount field node, so that when users enter a query for high-value customers, the annual spending amount field node can be matched through semantic retrieval.

[0093] The preset enhancement threshold can be set according to the distribution characteristics of node vectors in the multi-granularity metadata semantic network database and the overall distribution of external word vectors. For example, the preset enhancement threshold can be set to 0.7, without any specific limitation.

[0094] S404, based on the natural language description of the added associated nodes, update the metadata node vector of the associated nodes in the multi-granularity metadata semantic network database.

[0095] Furthermore, after adding external natural language words to the natural language description of the associated node, high-dimensional vectorization processing can be performed based on the updated natural language description of the associated node to generate the updated node vector of the node. The updated node vector is then used to replace the original node vector of the node in the multi-granularity metadata semantic network database, thereby completing the dynamic update of the multi-granularity metadata semantic network database.

[0096] Thus, through the aforementioned external knowledge fusion steps, the method provided in this disclosure can bridge the lexical gap between unstructured business documents and structured databases, enabling fuzzy quantitative assessment and query guidance processes to identify and understand more diverse user expressions, further enhancing its practicality and adaptability in complex business environments.

[0097] In some possible embodiments, the database query guidance method for multi-granularity metadata provided in this disclosure can be executed based on a multi-agent collaborative framework, which sets up multiple agents such as planning agent, advisor agent, research agent and execution agent to perform various functions such as fuzzy quantitative evaluation, dynamic guidance and query suggestion generation, external knowledge fusion and structured query language generation and execution. This decouples the evaluation, guidance and execution tasks, and ensures the stable response and scalability of the system under large-scale complex database mode.

[0098] The database query guidance method, apparatus, medium, and device for multi-granular metadata provided in this disclosure combine the ability to generate large language models with the semantic representation of multi-granular metadata to achieve gradual clarification and guidance of users' natural language queries, reduce the threshold for users to write or understand structured query languages, reduce invalid queries and interaction costs caused by query ambiguity, and improve the accuracy and interaction efficiency of database queries.

[0099] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.

[0100] Based on the same inventive concept, this disclosure also provides a database query guidance device for multi-granular metadata corresponding to the database query guidance method for multi-granular metadata. Since the principle of the device in this disclosure for solving the problem is similar to the database query guidance method for multi-granular metadata described above, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.

[0101] Reference Figure 5 The diagram shown is a schematic of a database query guidance device 500 for multi-granularity metadata provided in an embodiment of this disclosure. The device includes: The database construction module 501 is used to obtain metadata from a relational database, abstract the metadata hierarchically according to multiple preset granularities to obtain a multi-granularity metadata structure, and generate a corresponding natural language description for each granularity metadata node in the multi-granularity metadata structure using a large language model, and construct a multi-granularity metadata semantic network database based on the generation results. The fuzzy evaluation module 502 is used to receive a natural language query task sent by a user terminal, perform fuzzy quantitative evaluation on the natural language query task based on the multi-granularity metadata semantic network database, and obtain fuzzy evaluation information. The query guidance module 503 is used to determine guidance query data based on the multi-granularity metadata semantic network database, the natural language query task, and the fuzzy evaluation information when the fuzzy evaluation information indicates that the natural language query task is a fuzzy query; and input the guidance query data into the large language model to generate natural language query suggestions and feed them back to the user terminal. The query optimization module 504 is used to receive supplementary information from the user terminal regarding the natural language query suggestion, update the natural language query task based on the supplementary information, and re-execute the fuzzy quantitative evaluation step until the fuzzy evaluation information corresponding to the updated natural language query task indicates a clear query. The query execution module 505 is used to generate a structured query language based on the natural language query task and the multi-granularity metadata semantic network database when the fuzzy evaluation information indicates that the natural language query task is a clear query, and return the execution result of the structured query language to the user terminal.

[0102] In some possible embodiments, the database construction module 501 is specifically used for: Extract metadata corresponding to multiple physical tables belonging to the same business scope from the obtained metadata, and abstract the extracted metadata into a topic-level node; Extract the metadata corresponding to each physical table from the obtained metadata, and abstract the extracted metadata into a table-level node; Extract the metadata corresponding to each field from the obtained metadata, and abstract the extracted metadata into a field-level node; Establish the hierarchical relationship between the topic granularity node, the table granularity node, and the field granularity node to obtain the multi-granularity metadata structure.

[0103] In some possible embodiments, the fuzzy evaluation module 502 is specifically used for: Based on the multi-granularity metadata semantic network database, the degree of matching between words in the natural language query task and each metadata node is verified, and the evaluation result of the pattern mapping dimension is determined. Verify whether the natural language query task contains preset action keywords to determine the evaluation result of the operation clarity dimension; Verify the completeness of the data filtering conditions included in the natural language query task, and determine the evaluation result of the constraint completeness dimension; Based on the evaluation results of the pattern mapping dimension, the operational clarity dimension, and the constraint integrity dimension, the fuzziness level of the natural language query task is determined, and the specific missing information that leads to the fuzziness level is identified. The fuzziness level and the specific missing information are then used as the fuzziness evaluation information.

[0104] In some possible embodiments, the query guidance module 503 is specifically used for: Determine the percentage of recommendations corresponding to topic granularity, table granularity, and field granularity under the constraints of the fuzziness level and the specific missing information; According to the natural language query task, the topic granularity, the table granularity, and the field granularity are used as filtering conditions to search the multi-granularity metadata semantic network database to obtain a set of semantically similar metadata items corresponding to each granularity; Based on the recommended quantity ratio, target metadata items are selected from the set of semantically similar metadata items corresponding to each granularity, and the guided query data is determined based on the selection results.

[0105] In some possible embodiments, the query guidance module 503 is specifically used for: The natural language descriptions corresponding to each target metadata item in the guided query data are input into the large language model; The large language model generates natural language text based on the natural language description corresponding to each target metadata item, and organizes the generated natural language text into hierarchical natural language query suggestions according to a preset prompt template; wherein, the preset prompt template is used to instruct the large language model to organize the output content in a hierarchical order of topic granularity, table granularity and field granularity.

[0106] In some possible embodiments, the database construction module 501 is specifically used for: The natural language description generated for each granularity of metadata node is processed into a high-dimensional vector to obtain the node vector corresponding to each metadata node. The node vectors are associated with and stored with the corresponding metadata nodes to form the multi-granularity metadata semantic network database.

[0107] In some possible embodiments, the database construction module 501 is further configured to: External natural language vocabulary is extracted from external data sources, and the external natural language vocabulary is vectorized to obtain external vocabulary vectors; Calculate the semantic similarity between each of the external vocabulary vectors and each metadata node vector in the multi-granularity metadata semantic network database; The metadata nodes with semantic similarity greater than a preset enhancement threshold are identified as the associated nodes of the external vocabulary vectors, and the external natural language words corresponding to the external vocabulary vectors are added to the natural language description of the associated nodes. Based on the natural language description of the added associated nodes, the metadata node vector of the associated nodes in the multi-granularity metadata semantic network database is updated.

[0108] Based on the same technical concept, this disclosure also provides a computer device. (See also...) Figure 6 The diagram shows the structure of a computer device 600 provided in this embodiment of the present disclosure, including a processor 601, a memory 602, and a bus 603. The memory 602 stores execution instructions and includes a main memory 6021 and an external memory 6022. The main memory 6021, also called internal memory, is used to temporarily store computational data in the processor 601 and data exchanged with external memory 6022 such as a hard disk. The processor 601 exchanges data with the external memory 6022 through the main memory 6021.

[0109] In this embodiment, the memory 602 is specifically used to store application code that executes the solution of this application, and its execution is controlled by the processor 601. That is, when the computer device 600 is running, the processor 601 communicates with the memory 602 through the bus 603, so that the processor 601 executes the application code stored in the memory 602, and then executes the method described in any of the foregoing embodiments.

[0110] The memory 602 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.

[0111] Processor 601 may be an integrated circuit chip with signal processing capabilities. The aforementioned processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor can be a microprocessor or any conventional processor.

[0112] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the computer device 600. In other embodiments of this application, the computer device 600 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0113] This disclosure also provides a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the database query guidance method for multi-granular metadata described in the above method embodiments. The storage medium can be either volatile or non-volatile computer-readable storage.

[0114] This disclosure also provides a computer program product carrying program code. The program code includes instructions that can be used to execute the steps of the database query guidance method for multi-granularity metadata described in the above method embodiments. For details, please refer to the above method embodiments, which will not be repeated here.

[0115] The aforementioned computer program product can be implemented through hardware, software, or a combination thereof. In one optional embodiment, the computer program product is specifically embodied in a computer storage medium; in another optional embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.

[0116] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. In the several embodiments provided in this disclosure, it should be understood that the disclosed systems and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.

[0117] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0118] In addition, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0119] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0120] Finally, it should be noted that the above-described embodiments are merely specific implementations of this disclosure, used to illustrate the technical solutions of this disclosure, and not to limit it. The protection scope of this disclosure is not limited thereto. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this disclosure. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure, and should all be covered within the protection scope of this disclosure. Therefore, the protection scope of this disclosure should be determined by the protection scope of the claims.

Claims

1. A database query guidance method for multi-granularity metadata, characterized in that, include: Obtain metadata from a relational database, and abstract the metadata hierarchically according to multiple preset granularities to obtain a multi-granularity metadata structure; Furthermore, a large language model is used to generate corresponding natural language descriptions for each granularity metadata node in the multi-granularity metadata structure, and a multi-granularity metadata semantic network database is constructed based on the generation results. The system receives a natural language query task sent by a user terminal, performs a fuzzy quantitative evaluation of the natural language query task based on the multi-granularity metadata semantic network database, and obtains fuzzy evaluation information. When the fuzzy evaluation information indicates that the natural language query task is a fuzzy query, guide query data is determined based on the multi-granularity metadata semantic network database, the natural language query task, and the fuzzy evaluation information; The guided query data is then input into the large language model to generate natural language query suggestions, which are then fed back to the user terminal. Receive supplementary information from the user terminal regarding the natural language query suggestion, update the natural language query task based on the supplementary information, and re-execute the fuzzy quantitative evaluation step until the fuzzy evaluation information corresponding to the updated natural language query task indicates a clear query; When the fuzzy evaluation information indicates that the natural language query task is a clear query, a structured query language is generated based on the natural language query task and the multi-granularity metadata semantic network database, and the execution result of the structured query language is returned to the user terminal.

2. The method according to claim 1, characterized in that, The step of hierarchically abstracting the metadata according to multiple preset granularities includes: Extract metadata corresponding to multiple physical tables belonging to the same business scope from the obtained metadata, and abstract the extracted metadata into a topic-level node; Extract the metadata corresponding to each physical table from the obtained metadata, and abstract the extracted metadata into a table-level node; Extract the metadata corresponding to each field from the obtained metadata, and abstract the extracted metadata into a field-level node; Establish the hierarchical relationship between the topic granularity node, the table granularity node, and the field granularity node to obtain the multi-granularity metadata structure.

3. The method according to claim 2, characterized in that, The fuzzy quantitative evaluation of the natural language query task based on the multi-granularity metadata semantic network database includes: Based on the multi-granularity metadata semantic network database, the degree of matching between words in the natural language query task and each metadata node is verified, and the evaluation result of the pattern mapping dimension is determined. Verify whether the natural language query task contains preset action keywords to determine the evaluation result of the operation clarity dimension; Verify the completeness of the data filtering conditions included in the natural language query task, and determine the evaluation result of the constraint completeness dimension; Based on the evaluation results of the pattern mapping dimension, the operational clarity dimension, and the constraint integrity dimension, the fuzziness level of the natural language query task is determined, and the specific missing information that leads to the fuzziness level is identified. The fuzziness level and the specific missing information are then used as the fuzziness evaluation information.

4. The method according to claim 3, characterized in that, The process of determining guiding query data based on the multi-granularity metadata semantic network database, the natural language query task, and the fuzzy evaluation information includes: Determine the percentage of recommendations corresponding to topic granularity, table granularity, and field granularity under the constraints of the fuzziness level and the specific missing information; According to the natural language query task, the topic granularity, the table granularity, and the field granularity are used as filtering conditions to search the multi-granularity metadata semantic network database to obtain a set of semantically similar metadata items corresponding to each granularity; Based on the recommended quantity ratio, target metadata items are selected from the set of semantically similar metadata items corresponding to each granularity, and the guided query data is determined based on the selection results.

5. The method according to claim 4, characterized in that, The step of inputting the guided query data into the large language model to generate natural language query suggestions includes: The natural language descriptions corresponding to each target metadata item in the guided query data are input into the large language model; The large language model generates natural language text based on the natural language description corresponding to each target metadata item, and organizes the generated natural language text into hierarchical natural language query suggestions according to a preset prompt template; wherein, the preset prompt template is used to instruct the large language model to organize the output content in a hierarchical order of topic granularity, table granularity and field granularity.

6. The method according to claim 5, characterized in that, The multi-granularity metadata semantic network database constructed based on the generated results includes: The natural language description generated for each granularity of metadata node is processed into a high-dimensional vector to obtain the node vector corresponding to each metadata node. The node vectors are associated with and stored with the corresponding metadata nodes to form the multi-granularity metadata semantic network database.

7. The method according to claim 6, characterized in that, After forming the multi-granularity metadata semantic network database, the method further includes: External natural language vocabulary is extracted from external data sources, and the external natural language vocabulary is vectorized to obtain external vocabulary vectors; Calculate the semantic similarity between each of the external vocabulary vectors and each metadata node vector in the multi-granularity metadata semantic network database; The metadata nodes with semantic similarity greater than a preset enhancement threshold are identified as the associated nodes of the external vocabulary vectors, and the external natural language words corresponding to the external vocabulary vectors are added to the natural language description of the associated nodes. Based on the natural language description of the added associated nodes, the metadata node vector of the associated nodes in the multi-granularity metadata semantic network database is updated.

8. A database query guidance device for multi-granularity metadata, characterized in that, include: The database construction module is used to obtain metadata from relational databases and abstract the metadata hierarchically according to multiple preset granularities to obtain a multi-granularity metadata structure. Furthermore, a large language model is used to generate corresponding natural language descriptions for each granularity metadata node in the multi-granularity metadata structure, and a multi-granularity metadata semantic network database is constructed based on the generation results. The fuzzy evaluation module is used to receive natural language query tasks sent by user terminals, perform fuzzy quantitative evaluation on the natural language query tasks based on the multi-granularity metadata semantic network database, and obtain fuzzy evaluation information. The query guidance module is used to determine guidance query data based on the multi-granularity metadata semantic network database, the natural language query task, and the fuzzy evaluation information when the fuzzy evaluation information indicates that the natural language query task is a fuzzy query. The guided query data is then input into the large language model to generate natural language query suggestions, which are then fed back to the user terminal. The query optimization module is used to receive supplementary information from the user terminal regarding the natural language query suggestion, update the natural language query task based on the supplementary information, and re-execute the fuzzy quantitative evaluation step until the fuzzy evaluation information corresponding to the updated natural language query task indicates a clear query. The query execution module is used to generate a structured query language based on the natural language query task and the multi-granularity metadata semantic network database when the fuzzy evaluation information indicates that the natural language query task is a clear query, and return the execution result of the structured query language to the user terminal.

9. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 7.

10. A computer device, comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 7.