Database query method and system based on natural language and electronic equipment

By constructing a semantic analysis model and a confidence evaluation model using a large language model, semantic tags and structured query statements are generated, solving the problem of low efficiency in cross-table queries of natural language query interfaces and realizing automated table join logic judgment and efficient querying.

CN121542282APending Publication Date: 2026-02-17广域铭岛数字科技有限公司 +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511710201.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-20
Publication Date
2026-02-17

AI Technical Summary

Technical Problem

Existing natural language query interfaces cannot effectively discover implicit relationships when performing cross-table queries, resulting in low query efficiency. Users need to have a deep understanding of the database structure and the business logic behind it, and manually write structured query languages.

Method used

A semantic analysis model is constructed using a large language model to perform semantic analysis on metadata, generate semantic tags, and use a confidence evaluation model to filter target relationships, establish a database knowledge graph, and generate structured query statements.

Benefits of technology

It implements automatic determination of correct table join logic, improves database query efficiency, ensures the accuracy and comprehensiveness of target relationship lookup, and solves the problem of natural language commands failing due to the lack of implicit relationships.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121542282A_ABST
    Figure CN121542282A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of database query, and provides a database query method and system based on a natural language and electronic equipment. According to the method, the big language model is introduced to perform semantic analysis on the metadata, the semantic analysis result is expanded along different dimensions, the structured semantic tag is generated, the target relationship between the metadata is screened according to the semantic tag and the confidence evaluation model, and the database knowledge graph is established; on one hand, a complete relation search logic is constructed by introducing semantic analysis capability and relation evaluation capability of a large language model, on the other hand, semantic tags of metadata are greatly enriched through multi-dimensional semantic expansion, the accuracy and comprehensiveness of target relation search are ensured, and a database knowledge graph established based on a target relation has a good application prospect. A natural language instruction needing cross-table operation can be automatically converted into a structured query statement containing correct connection logic, and the query efficiency of a database is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of database query technology, specifically to a database query method, system, and electronic device based on natural language. Background Technology

[0002] In existing database management systems, database queries rely on explicitly declared relational models. These models define the relationships between data through constraints such as foreign keys to ensure the integrity of data associations. Users then construct Structured Query Language (SQL) based on their understanding of the database structure. This allows the Database Management System (DBMS) to parse the SQL using the relational model and perform cross-table data join operations, enabling multi-table queries and analysis.

[0003] Currently, users can perform database queries through the Natural Language Query (NLQ) interface. However, the relationships between data cannot be fully covered by manually configured constraints. Undefined relationships are implicitly embedded in the business logic layer. As a result, when the NLQ interface executes complex cross-table query commands, it cannot effectively discover implicit relationships and cannot automatically determine the correct table join logic. Users still need to have a deep understanding of complex table structures and their underlying business logic, and manually write the correct structured query language, which greatly increases the cost of data querying and results in low query efficiency. Summary of the Invention

[0004] To provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. This summary is not intended as a general commentary, nor is it intended to identify key / important components or describe the scope of protection of these embodiments, but rather as a prelude to the detailed description that follows.

[0005] In view of the shortcomings of the prior art described above, this application provides a database query method, system and electronic device based on natural language to improve the efficiency of database query based on natural language.

[0006] This application provides a natural language-based database query method, comprising: acquiring one or more target databases, wherein the target databases include multiple metadata; performing semantic analysis on the metadata using a semantic analysis model constructed by a large language model, and semantically expanding the semantic analysis results according to different semantic aspect dimensions to obtain semantic tags corresponding to the metadata; evaluating the relationships between the metadata based on the semantic tags, constructing candidate relationships based on the relationship evaluation results, and evaluating the confidence of the candidate relationships using a confidence evaluation model constructed by a large language model, and determining a target relationship from the candidate relationships based on the confidence evaluation results; constructing a database knowledge graph based on the target relationship, and using the database knowledge graph to generate a structured query statement containing the target relationship according to natural language instructions, so as to query the target database through the structured query statement.

[0007] In one embodiment of this application, the semantic analysis result includes the metadata semantic concept corresponding to the metadata. The semantic analysis result is semantically expanded according to different semantic aspect dimensions to obtain the semantic tags corresponding to the metadata, including: if the semantic aspect dimension includes a concept dimension, then according to a preset standardized concept library, a standardized concept corresponding to the metadata semantic concept is matched, and the standardized concept is added to the semantic tag; if the semantic aspect dimension includes a domain dimension, then the business domain corresponding to the standardized concept is added to the semantic tag; if the semantic aspect dimension includes a similarity dimension, then according to a preset semantic concept library, similar semantic concepts similar to the metadata semantic concept are matched, and the similar semantic concepts are added to the semantic tag, wherein the semantic concept library is used to store the metadata semantic concepts output by the semantic analysis model; if the semantic aspect dimension includes a confidence dimension, then according to the semantic analysis model, the semantic confidence corresponding to the metadata semantic concept is obtained, and the semantic confidence is added to the semantic tag; if the semantic aspect dimension includes a relation dimension, then according to the metadata semantic concept, a matching is performed to establish the semantic relation corresponding to the metadata semantic concept, and the semantic relation is added to the semantic tag.

[0008] In one embodiment of this application, the relationship evaluation between the metadata is performed based on the semantic tags to construct candidate relationships based on the relationship evaluation results. This includes: obtaining relationship evaluation factors, wherein the relationship evaluation factors include one or more of the following: name similarity between data names, semantic similarity between standardized concepts, type compatibility between data types, domain relevance between business domains, business logic between metadata, and constraint matching relationships between metadata; evaluating the relationship between the metadata according to the relationship evaluation factors to obtain a relationship evaluation result, wherein the relationship evaluation result includes an initial confidence level, wherein the two metadata corresponding to the relationship evaluation result originate from the same or different target databases; and constructing a candidate relationship between the two metadata if the initial confidence level between the two metadata is greater than or equal to a preset initial confidence level threshold.

[0009] In one embodiment of this application, a confidence assessment model constructed using a large language model is used to assess the confidence of the candidate relationship, including: filling in a preset prompt word template according to the semantic tags corresponding to the candidate relationship to obtain confidence assessment prompt words; inputting the confidence assessment prompt words into the confidence assessment model to assess the confidence of the candidate relationship using the confidence assessment model to obtain a confidence assessment result.

[0010] In one embodiment of this application, the method further includes: the confidence assessment result includes a confidence score and the reasoning process text corresponding to the confidence score; counting the number of times a preset reasoning keyword appears in the reasoning process text; if the number of times the reasoning keyword appears is less than a preset threshold, then the confidence assessment of the candidate relationship is performed again.

[0011] In one embodiment of this application, determining a target relationship from candidate relationships based on confidence assessment results includes: pre-constructing confidence assessment strategies corresponding to different application scenarios based on confidence assessment factors, wherein the confidence assessment strategies include the confidence assessment results, the tag similarity between the semantic tags, and the relationship assessment factors; obtaining the current scenario, and matching it with each of the confidence assessment strategies based on the comparison results between the current scenario and each of the application scenarios to obtain the target strategy corresponding to the current scenario; calculating the confidence assessment factors corresponding to the candidate relationships according to the target strategy to obtain the comprehensive confidence level corresponding to the candidate relationships; if the comprehensive confidence level corresponding to the candidate relationships is greater than or equal to a preset comprehensive confidence level threshold, then the candidate relationships are determined as target relationships.

[0012] In one embodiment of this application, the database knowledge graph is used to generate a structured query statement containing the target relationship based on a natural language instruction, comprising: obtaining a natural language instruction; performing intent parsing on the natural language instruction using a large language model to obtain an intent parsing result, wherein the intent parsing result includes user intent and / or query conditions; querying the database knowledge graph according to the intent parsing result to obtain the element to be queried and the graph relationship between the element to be queried, so as to perform path planning based on the element to be queried and the graph relationship to obtain a cross-database metadata connection strategy; generating a structured query statement according to the metadata connection strategy, wherein the structured query statement includes multiple query statements corresponding to a single target database, federated query statements for multiple target databases, or query statements corresponding to multiple target databases respectively.

[0013] In one embodiment of this application, after generating a structured query statement containing the target relationship using the database knowledge graph based on natural language instructions, the method further includes: obtaining user feedback results corresponding to the structured query statement, and determining the target relevance relationship on which the structured query statement depends based on the target relationship; if the user feedback result is a positive feedback result, increasing the overall confidence level corresponding to the relevance relationship; if the user feedback result is a negative feedback result, decreasing the overall confidence level corresponding to the relevance relationship.

[0014] This application also provides a natural language-based database query system, comprising: an acquisition module for acquiring one or more target databases, wherein the target databases include multiple metadata; a semantic analysis module for performing semantic analysis on the metadata using a semantic analysis model constructed by a large language model, and semantically expanding the semantic analysis results according to different semantic aspect dimensions to obtain semantic tags corresponding to the metadata; an evaluation module for evaluating the relationships between the metadata based on the semantic tags, constructing candidate relationships based on the relationship evaluation results, and evaluating the confidence of the candidate relationships using a confidence evaluation model constructed by a large language model, and determining the target relationship from the candidate relationships based on the confidence evaluation results; and a query module for constructing a database knowledge graph based on the target relationship, and generating a structured query statement containing the target relationship based on the database knowledge graph and natural language instructions, so as to query the target database through the structured query statement.

[0015] This application also provides an electronic device, including: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory to cause the electronic device to perform the method described above.

[0016] The beneficial effects of this application are: By introducing a large language model to perform semantic analysis on metadata and expanding the results along different dimensions, structured semantic tags are generated. Then, based on these semantic tags and a confidence assessment model, target relationships between metadata are filtered, and a database knowledge graph is established. This knowledge graph is then used to generate structured query statements containing target relationships based on natural language instructions, enabling cross-table queries. In this way, on the one hand, the semantic analysis and relationship assessment capabilities of the large language model are introduced to construct a complete relationship lookup logic; on the other hand, multi-dimensional semantic expansion greatly enriches the semantic tags of metadata, ensuring the accuracy and comprehensiveness of target relationship lookup. Finally, the database knowledge graph built based on target relationships can automatically convert natural language instructions requiring cross-table operations into structured query statements containing correct join logic, solving the problem of natural language instruction failure caused by the lack of implicit relationships and improving database query efficiency. Attached Figure Description

[0017] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.

[0018] In the attached diagram: Figure 1 This is a flowchart illustrating a database query method based on natural language in an embodiment of this application. Figure 2 This is a schematic diagram of the structure of a semantic analysis module for metadata in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of a knowledge graph construction module based on semantic tags in an embodiment of this application; Figure 4 This is a flowchart illustrating another database query method based on natural language in an embodiment of this application; Figure 5 This is a schematic diagram of the structure of a natural language-based database query system in an embodiment of this application; Figure 6 This is a schematic diagram of the structure of an electronic device in an embodiment of this application. Detailed Implementation

[0019] The following specific examples illustrate the implementation of this application. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. This application can also be implemented or applied through other different specific embodiments. Various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.

[0020] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this application. The drawings only show the components related to this application and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.

[0021] In the following description, numerous details are explored to provide a more thorough explanation of embodiments of the present application. However, it will be apparent to those skilled in the art that embodiments of the present application may be practiced without these specific details. In other embodiments, well-known structures and devices are shown in block diagram form rather than in detail to avoid obscuring embodiments of the present application.

[0022] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion.

[0023] Unless otherwise stated, the term "multiple" means two or more.

[0024] In this application, the character " / " indicates that the objects before and after it are in an "or" relationship. For example, A / B means: A or B.

[0025] The term "and / or" describes an association between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or A and B.

[0026] Combination Figure 1 As shown, this application provides a database query method based on natural language, including: Step S101: Obtain one or more target databases; The target database includes multiple metadata entries; Step S102: Using the semantic analysis model constructed by the large language model, perform semantic analysis on the metadata, and extend the semantic analysis results according to different semantic aspect dimensions to obtain the semantic tags corresponding to the metadata; Step S103: Evaluate the relationship between each metadata according to the semantic tags, construct candidate relationships based on the relationship evaluation results, and use the confidence evaluation model constructed by the large language model to evaluate the confidence of the candidate relationships, so as to determine the target relationship from the candidate relationships based on the confidence evaluation results. Step S104: Construct a database knowledge graph based on the target relationship, and use the database knowledge graph to generate a structured query statement containing the target relationship based on natural language instructions, so as to query the target database through the structured query statement.

[0027] This application employs a natural language-based database query method. By introducing a large language model to perform semantic analysis on metadata and expanding the results along different dimensions, structured semantic tags are generated. Then, based on these semantic tags and a confidence assessment model, target relationships between metadata are filtered, and a database knowledge graph is established. This knowledge graph is then used to generate structured query statements containing target relationships based on natural language instructions, enabling cross-table queries. In this way, on the one hand, the semantic analysis and relationship assessment capabilities of the large language model are introduced to construct a complete relationship lookup logic; on the other hand, multi-dimensional semantic expansion greatly enriches the semantic tags of the metadata, ensuring the accuracy and comprehensiveness of target relationship lookup. Finally, the database knowledge graph built based on target relationships can automatically convert natural language instructions requiring cross-table operations into structured query statements containing correct join logic, solving the problem of natural language instruction failure caused by the lack of implicit relationships and improving database query efficiency.

[0028] Combination Figure 2 As shown, this application provides a semantic analysis module for metadata, including a metadata extraction unit 201, a semantic analysis unit 202, a large language model client 203, and a semantic tag generator 204.

[0029] Metadata extraction unit 201 is used to connect to the target database through the database interface and extract metadata from the target database.

[0030] In some embodiments, the metadata extraction unit 201 serves as an entry component for data acquisition, responsible for connecting to various types of database systems. It extracts raw metadata such as table structure, column definitions, and constraints through standardized database interfaces, supports multiple database types, and outputs standardized Table Metadata and Column Metadata objects to provide a unified data format.

[0031] In some embodiments, the target database includes MySQL, PostgreSQL, Oracle, etc.

[0032] In some embodiments, metadata includes database name, table name, column name, data type, data length, whether null values ​​are allowed, primary key constraint, foreign key constraint, unique constraint, table comment, column comment, etc.

[0033] Optionally, the semantic analysis results include metadata semantic concepts corresponding to the metadata. The semantic analysis results are semantically extended according to different semantic aspect dimensions to obtain semantic tags corresponding to the metadata, including: if the semantic aspect dimension includes a concept dimension, then according to a preset standardized concept library, the standardized concepts corresponding to the metadata semantic concepts are matched, and the standardized concepts are added to the semantic tags; if the semantic aspect dimension includes a domain dimension, then the business domains corresponding to the standardized concepts are added to the semantic tags; if the semantic aspect dimension includes a similarity dimension, then according to a preset semantic concept library, similar semantic concepts similar to the metadata semantic concepts are matched, and the similar semantic concepts are added to the semantic tags, wherein the semantic concept library is used to store the metadata semantic concepts output by the semantic analysis model; if the semantic aspect dimension includes a confidence dimension, then according to the semantic analysis model, the semantic confidence corresponding to the metadata semantic concepts is obtained, and the semantic confidence is added to the semantic tags; if the semantic aspect dimension includes a relation dimension, then according to the metadata semantic concepts, matching is performed to establish semantic relations corresponding to the metadata semantic concepts, and the semantic relations are added to the semantic tags.

[0034] Semantic analysis unit 202 is used to perform semantic analysis on metadata using a semantic analysis model constructed from a large language model.

[0035] In some embodiments, by invoking the large language model client 203, the semantic analysis unit 202 performs deep semantic analysis on the metadata to obtain metadata semantic concepts with business meaning, and converts the text-formatted metadata semantic concepts into computable semantic vectors.

[0036] In some embodiments, the semantic analysis unit 202 includes a semantic caching mechanism for storing analyzed metadata semantic concepts and their results. When encountering the same or similar concepts, it can be directly invoked to improve the processing efficiency of similar semantic concepts. For example, the three naming methods "user_id", "uid", and "customer_no" all point to the similar semantic concept "user unique identifier".

[0037] The Large Language Model Client 203 encapsulates the interactive interface of the semantic analysis model, providing capabilities such as semantic analysis, tag generation, and confidence evaluation.

[0038] Semantic tag generator 204 is used to convert semantic analysis results into semantic tags.

[0039] In some embodiments, the semantic tag generator 204 stores standardized concepts through a standardized concept library and ensures that metadata semantic concepts with the same semantics can obtain consistent standardized concepts through a lookup mechanism.

[0040] In some embodiments, the relationship between metadata and standardized concepts includes “uid / user unique identifier”, “customer_id / user unique identifier”, “user_no / user unique identifier”, “create_date / time identifier”, “register_time / time identifier”, etc.

[0041] In some embodiments, the semantic tag generator 204 pre-sets a mapping relationship between standardized concepts and business domains; using the mapping relationship, the metadata semantic concepts are mapped to the business domains corresponding to the standardized concepts.

[0042] In some embodiments, the semantic tag generator 204 establishes semantic relationships based on the similarity between metadata semantic concepts, providing a reference for subsequent target relationship reasoning.

[0043] In this way, by using the semantic analysis module for metadata provided in this application, a one-way processing flow of metadata, semantic analysis, and tag generation is established to ensure the traceability of semantic tags and to upgrade metadata from the syntactic level to the semantic level through semantic tags.

[0044] Combination Figure 3 As shown, this application provides a knowledge graph construction module based on semantic tags, including a relation discovery control unit 301, a semantic matching unit 302, a candidate relation generation unit 303, a relation evaluation unit 304, a large language model client 203, a confidence calculation unit 305, and a knowledge graph construction unit 306.

[0045] The relationship discovery control unit 301 is used to control the knowledge graph construction module to form a complete relationship discovery pipeline, manage data consistency, and have data traceability capabilities.

[0046] Optionally, the relationship between each metadata is evaluated based on semantic tags to construct candidate relationships based on the relationship evaluation results. This includes: obtaining relationship evaluation factors, wherein the relationship evaluation factors include one or more of the following: name similarity between data names, semantic similarity between standardized concepts, type compatibility between data types, domain relevance between business domains, business logic between metadata, and constraint matching relationship between metadata; evaluating the relationship between each metadata according to the relationship evaluation factors to obtain relationship evaluation results, wherein the relationship evaluation results include an initial confidence level, wherein the two metadata corresponding to the relationship evaluation results originate from the same or different target databases; and constructing candidate relationships between the two metadata if the initial confidence level between the two metadata is greater than or equal to a preset initial confidence level threshold.

[0047] Semantic matching unit 302 is used to evaluate the relationship between metadata based on semantic tags.

[0048] In some embodiments, the semantic matching unit 302 adopts a probabilistic evaluation method instead of the traditional binary judgment method based on whether it is a complete match. That is, it combines name similarity, semantic similarity, type compatibility and domain relevance to calculate the initial confidence between two semantic tags, thereby realizing similarity comparison at the semantic level and avoiding the omission of real relationships.

[0049] The candidate relationship generation unit 303 is used to construct a candidate relationship between two metadata if the initial confidence between the two metadata is greater than or equal to a preset initial confidence threshold.

[0050] In some embodiments, the candidate relationship generation unit 303 constructs candidate relationships, filters implicit relationships in the first stage, and includes a field filtering mechanism to exclude metadata pairs with low similarity.

[0051] The relation evaluation unit 304 is used to evaluate the confidence of candidate relations using a confidence evaluation model constructed by a large language model, and to determine the target relation from the candidate relations based on the confidence evaluation results.

[0052] Optionally, the confidence assessment model constructed using a large language model is used to assess the confidence of candidate relations, including: filling in a preset prompt word template based on the semantic tags corresponding to the candidate relations to obtain confidence assessment prompt words; inputting the confidence assessment prompt words into the confidence assessment model to assess the confidence of candidate relations using the confidence assessment model to obtain the confidence assessment result.

[0053] In some embodiments, the relationship evaluation unit 304 calls the confidence evaluation model through the large language model client 203, and uses prompt words to instruct the confidence evaluation model to play the role of "database architect", and controls the confidence evaluation model to output confidence scores and the inference process text corresponding to the confidence scores, forming quantifiable relationship evaluation indicators.

[0054] In some embodiments, the prompt word template includes: "As a database architect with 20 years of experience, please evaluate the likelihood of association between the following two fields using semantic tags: {Metadata A} {Metadata B}. Please analyze from the following perspectives: 1. Naming semantic similarity; 2. Data type compatibility; 3. Business logic rationality; 4. Constraint matching degree. Provide a confidence score of 0-1 and a detailed reasoning process." In some embodiments, the output of the confidence assessment model includes: "Confidence: 0.9; Reasoning process: 1. Naming similarity (0.8): uid and user_no both clearly represent user identifiers and are highly semantically related; 2. Type compatibility (1.0): INT and INTEGER are fully compatible; 3. Business logic (0.9): The order table references the primary key of the user table, which conforms to typical e-commerce business logic; 4. Constraint matching (0.9): The source is a primary key, and the target is a regular field, which conforms to the foreign key relationship pattern. Overall assessment: This is a highly reliable foreign key relationship."

[0055] Optionally, the method further includes: the confidence assessment result includes a confidence score and the reasoning process text corresponding to the confidence score; the number of times the preset reasoning keywords appear in the reasoning process text is counted; if the number of times the reasoning keywords appear is less than a preset threshold, the confidence assessment of the candidate relationship is re-evaluated.

[0056] In some embodiments, inference keywords include business logic, semantics, primary and foreign keys, etc. When the large language model first evaluates the candidate relationship between orders.user_no and users.uid, the confidence score returned by the large language model is 0.95, but its inference process text is only "the texts of these two fields have a certain degree of similarity". The occurrence frequency of the inference keyword is 0, which is less than the preset frequency threshold of 2. The large language model needs to re-evaluate the candidate relationship between orders.user_no and users.uid. When the large language model evaluates the candidate relationship between orders.user_no and users.uid for the second time, the inference process text returned by the large language model includes "from a business logic perspective, order referencing user is a standard design; from a semantic perspective, both point to user identifiers, and users.uid is the primary key in the primary and foreign keys". The occurrence frequency of the inference keyword is 3, which meets the preset frequency threshold of 2. The confidence score of this evaluation is adopted, thereby effectively filtering evaluations with high scores but insufficient inference, ensuring the rigor and reliability of the relationship discovery process.

[0057] The confidence calculation unit 305 is used to obtain the current scenario and, based on the comparison results between the current scenario and each application scenario, match it from each confidence evaluation strategy to obtain the target strategy corresponding to the current scenario; calculate the confidence evaluation factors corresponding to the candidate relationship according to the target strategy to obtain the comprehensive confidence of the candidate relationship; and feed the comprehensive confidence back to the relationship evaluation unit 304.

[0058] Optionally, determining the target relationship from candidate relationships based on the confidence assessment results includes: pre-constructing confidence assessment strategies corresponding to different application scenarios based on confidence assessment factors, wherein the confidence assessment strategy includes confidence assessment results, label similarity between semantic tags, and relationship assessment factors; obtaining the current scenario and matching it with each confidence assessment strategy based on the comparison results between the current scenario and each application scenario to obtain the target strategy corresponding to the current scenario; calculating the confidence assessment factors corresponding to the candidate relationships according to the target strategy to obtain the comprehensive confidence of the candidate relationships; if the comprehensive confidence of the candidate relationships is greater than or equal to a preset comprehensive confidence threshold, then the candidate relationship is determined as the target relationship.

[0059] In some embodiments, the confidence calculation unit 305 not only needs to refer to the confidence score output by the large language model, but also needs to combine semantic labels and relationship evaluation factors. However, unlike the reference indicators used when establishing candidate relationships, when calculating the comprehensive confidence, the semantic labels and relationship evaluation factors need to be quantified into specific scores with reference significance to realize deep similarity calculation.

[0060] In some embodiments, the confidence calculation unit 305 adjusts the weight configuration based on different application scenarios. For example, in cross-system data integration application scenarios, explicit features such as name similarity and type compatibility are given higher weights, while in business insight analysis application scenarios, semantic tags and business logic judgments of large language models are used as the core basis, so that the calculation of comprehensive confidence can fit the needs of specific scenarios and thus more accurately determine the final target relationship.

[0061] The knowledge graph construction unit 306 is used to convert metadata and target relationships into nodes and edges in the knowledge graph, forming a database knowledge graph.

[0062] In some embodiments, metadata is stored as node attributes in a graph database, and target relationships are stored as references type edges, with edge attributes including confidence scores, reasoning basis, discovery time, and other information.

[0063] In some embodiments, nodes in a knowledge graph include databases, tables, columns, etc.; edges in a knowledge graph include containsTable, hasColumn, primary key, foreign key references, semanticallySimilarTo, etc.

[0064] In some embodiments, the knowledge graph construction unit 306 also supports interactive exploration, relationship verification, data lineage analysis, and impact analysis. Interactive exploration includes providing a graphical user interface to intuitively display the semantic topology of the database. Relationship verification allows domain experts or data administrators to manually review, confirm, or reject probabilistic relationships with confidence levels automatically discovered by the system. Data lineage analysis traces upstream from any data asset, clearly showing its complete processing, transformation, and aggregation path from its original source to its current state, to reveal the data's lifecycle and origin. Impact analysis traces downstream from any data entity to identify all downstream assets that depend on that entity, such as reports, applications, and data pipelines, aiming to help developers and operations personnel predict the chain reactions that changes may trigger, thereby avoiding potential system failures.

[0065] Optionally, a structured query statement containing target relationships is generated based on a database knowledge graph according to natural language instructions, including: obtaining natural language instructions; performing intent parsing on the natural language instructions using a large language model to obtain intent parsing results, wherein the intent parsing results include user intent and / or query conditions; querying the database knowledge graph according to the intent parsing results to obtain the query element and the graph relationships between the query elements, so as to perform path planning based on the query element and graph relationships to obtain a cross-database metadata connection strategy; generating a structured query statement according to the metadata connection strategy, wherein the structured query statement includes multiple query statements corresponding to a single target database, federated query statements for multiple target databases, or query statements corresponding to multiple target databases respectively.

[0066] In some embodiments, for multiple query objects, it is not possible to complete the query in the same database with a single SQL statement. Multiple query statements corresponding to a single target database are automatically generated according to the metadata connection strategy, and each query statement is executed sequentially according to the connection order in the metadata connection strategy to realize multiple metadata queries with enhanced semantic relationships. For example, if the natural language instruction includes "query the average salary of the department with the most employees", then the query is first executed to find the ID of the department with the most employees, and then a second query is executed based on this department ID to calculate the average salary of the department.

[0067] In some embodiments, if the query objects are scattered across different target databases and the underlying databases support a federated query engine, a federated query statement is automatically generated. When executing the federated query statement, tables from different databases are automatically accessed and joined. For example, a natural language instruction may include "query the total sales of all sales personnel in the Shanghai branch". The federated query statement connects the employee table in the HR database and the order table in the sales database, and executes the query through a unified query engine to calculate the final result in one go, without the need for data integration at the application level.

[0068] In some embodiments, if the query objects are scattered across different target databases and the underlying database does not support a federated query engine, the prior art requires executing a query statement in one target database to obtain intermediate results, and then combining the intermediate results to generate a query statement in another target database. Unlike the prior art, this application can directly generate query statements corresponding to each target database based on the metadata connection strategy, without needing to obtain intermediate results, thereby improving the query efficiency of the database. For example, if the natural language instruction includes "query the name of the product with the highest sales last month", then it is necessary to query the product ID in the order database and the product name in the product database respectively. Based on the metadata connection strategy, the association between the product ID and the product name is determined, and query statements corresponding to the two are generated respectively.

[0069] In some embodiments, if the natural language instruction includes "display the total number of orders and total amount for each user", then by performing intent recognition on the natural language instruction, it is determined that the natural language instruction is a statistical query and involves user data (user_info) and order data (order_master); the database knowledge graph is used to find the graph relationship between user data and order data; a structured query statement is established based on the graph relationship, as shown below: SELECT u.user_name, COUNT(o.order_id) as order_count, SUM(o.order_amount) as total_amount FROM user_info u LEFT JOIN order_master o ON u.uid = o.user_no GROUP BY u.uid, u.user_name".

[0070] Optionally, after generating a structured query statement containing target relations based on natural language instructions using a database knowledge graph, the method further includes: obtaining user feedback results corresponding to the structured query statement, and determining the target related relations on which the structured query statement depends based on the target relations; if the user feedback results are positive, increasing the overall confidence level corresponding to the related relations; if the user feedback results are negative, decreasing the overall confidence level corresponding to the related relations.

[0071] In some embodiments, if the natural language instruction includes "display the total number of orders for all users", a structured query statement corresponding to the natural language instruction is generated; if the user reports that the query result corresponding to the structured query statement is correct, the overall confidence of the correlation is increased; if the user reports that the query result corresponding to the structured query statement is incorrect, the overall confidence of the correlation is decreased.

[0072] Combination Figure 4 As shown, this application provides a database query method based on natural language, including: Step S401: Extract metadata from the target database; Step S402: Use the semantic analysis model constructed by the large language model to perform semantic analysis on the metadata; Step S403: Semantically expand the semantic analysis results according to different semantic aspect dimensions to obtain the semantic tags corresponding to the metadata; Step S404: Evaluate the relationships between the metadata according to the relationship evaluation factors to obtain the initial confidence level; Step S405: Determine whether the initial confidence level is greater than or equal to the initial confidence level threshold. If yes, proceed to step S406; otherwise, proceed to step S401. Step S406: Construct candidate relationships among the metadata corresponding to the initial confidence level; Step S407: Use the confidence evaluation model constructed by the large language model to evaluate the confidence of the candidate relations; Step S408: Calculate the confidence evaluation factors corresponding to the candidate relationships according to the target strategy to obtain the comprehensive confidence level corresponding to the candidate relationships; Step S409: Determine whether the overall confidence level is greater than or equal to the overall confidence level threshold. If yes, proceed to step S410; otherwise, proceed to step S401. Step S410: Determine the candidate relation as the target relation; Step S411: Construct a database knowledge graph based on the target relationship; Step S412: Using the database knowledge graph, generate a structured query statement containing the target relationship based on natural language instructions.

[0073] This application employs a natural language-based database query method. By introducing a large language model to perform semantic analysis on metadata and expanding the results along different dimensions, structured semantic tags are generated. Then, based on these semantic tags and a confidence assessment model, target relationships between metadata are filtered, and a database knowledge graph is established. This knowledge graph is then used to generate structured query statements containing target relationships based on natural language instructions, enabling cross-table queries. In this way, on the one hand, the semantic analysis and relationship assessment capabilities of the large language model are introduced to construct a complete relationship lookup logic; on the other hand, multi-dimensional semantic expansion greatly enriches the semantic tags of the metadata, ensuring the accuracy and comprehensiveness of target relationship lookup. Finally, the database knowledge graph built based on target relationships can automatically convert natural language instructions requiring cross-table operations into structured query statements containing correct join logic, solving the problem of natural language instruction failure caused by the lack of implicit relationships and improving database query efficiency.

[0074] Combination Figure 5 As shown, this application provides a database query system based on natural language, including an acquisition module 501, a semantic analysis module 502, an evaluation module 503, and a query module 504.

[0075] The acquisition module 501 is used to acquire one or more target databases, wherein the target database includes multiple metadata.

[0076] The semantic analysis module 502 is used to perform semantic analysis on metadata using the semantic analysis model constructed by the large language model, and to extend the semantic analysis results according to different semantic aspect dimensions to obtain the semantic tags corresponding to the metadata.

[0077] The evaluation module 503 is used to evaluate the relationship between the metadata based on the semantic tags, construct candidate relationships based on the relationship evaluation results, and use the confidence evaluation model constructed by the large language model to evaluate the confidence of the candidate relationships, so as to determine the target relationship from the candidate relationships based on the confidence evaluation results.

[0078] The query module 504 is used to construct a database knowledge graph based on the target relationship, and use the database knowledge graph to generate a structured query statement containing the target relationship based on natural language instructions, so as to query the target database through the structured query statement.

[0079] This application employs a natural language-based database query system. By introducing a large language model to perform semantic analysis on metadata and expanding the results along different dimensions, structured semantic tags are generated. Then, based on these semantic tags and a confidence assessment model, target relationships between metadata are filtered, and a database knowledge graph is established. This knowledge graph is then used to generate structured query statements containing target relationships based on natural language instructions, enabling cross-table queries. In this way, on the one hand, the semantic analysis and relationship assessment capabilities of the large language model are introduced to construct a complete relationship lookup logic; on the other hand, multi-dimensional semantic expansion greatly enriches the semantic tags of the metadata, ensuring the accuracy and comprehensiveness of target relationship lookup. Finally, the database knowledge graph built based on target relationships can automatically convert natural language instructions requiring cross-table operations into structured query statements containing correct join logic, solving the problem of natural language instruction failure caused by the lack of implicit relationships and improving database query efficiency.

[0080] This application also provides an electronic device, including: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device performs the above-described method.

[0081] Figure 6 A schematic diagram of a computer system suitable for implementing the embodiments of this application is shown. It should be noted that... Figure 6 The computer system 600 of the electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0082] like Figure 6As shown, the computer system 600 includes a Central Processing Unit (CPU) 601, which can perform various appropriate actions and processes, such as executing the methods described in the above embodiments, based on programs stored in Read-Only Memory (ROM) 602 or programs loaded from storage portion 608 into Random Access Memory (RAM) 603. The RAM 603 also stores various programs and data required for system operation. The CPU 601, ROM 602, and RAM 603 are interconnected via a bus 604. An Input / Output (I / O) interface 605 is also connected to the bus 604.

[0083] The following components are connected to I / O interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to I / O interface 605 as needed. A removable medium 611, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 610 as needed so that computer programs read from it can be installed into storage section 608 as needed.

[0084] The electronic device disclosed in this embodiment includes a processor, a memory, a transceiver, and a communication interface. The memory and the communication interface are connected to the processor and the transceiver and enable communication between them. The memory is used to store computer programs, the communication interface is used for communication, and the processor and transceiver are used to run the computer programs, causing the electronic device to perform the various steps of the above method. The above description and drawings fully illustrate the embodiments of this disclosure to enable those skilled in the art to practice them. Other embodiments may include structural, logical, electrical, procedural, and other changes. The embodiments represent only possible variations. Unless explicitly required, individual components and functions are optional, and the order of operation may vary. Parts and subsamples of some embodiments may be included in or replace parts and subsamples of other embodiments. Moreover, the terminology used in this application is only for describing embodiments and is not intended to limit the claims. As used in the description of embodiments and claims, the singular forms “a,” “an,” and “the” are intended to equally include the plural forms unless the context clearly indicates otherwise. Similarly, the term “and / or” as used in this application means including one or more of the associated listed items and all possible combinations thereof. Additionally, when used in this application, the term "comprise" and its variations "comprises" and / or "comprising" refer to the presence of stated subsamples, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other subsamples, wholes, steps, operations, elements, components, and / or groups thereof. Without further limitations, an element defined by the phrase "comprising a..." does not exclude the presence of other identical elements in the process, method, or apparatus that includes the element. In this document, each embodiment may focus on the differences from other embodiments, and similar or identical parts between embodiments can be referred to mutually. For methods, products, etc., disclosed in the embodiments, if they correspond to the method section disclosed in the embodiments, the relevant parts can be referred to the description of the method section.

[0085] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0086] The methods and products (including but not limited to devices and equipment) disclosed in the embodiments herein can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For instance, the division of units may be merely a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some sub-samples may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms. Units described as separate components may or may not be physically separate, and 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 implement this embodiment according to actual needs. Furthermore, the functional units in this application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0087] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of the systems, methods, and computer program products according to this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing the specified logical function. In some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. In the descriptions corresponding to the flowcharts and block diagrams in the accompanying drawings, the operations or steps corresponding to different blocks may also occur in a different order than those disclosed in the description; sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

Claims

1. A database query method based on natural language, characterized in that, include: Obtain one or more target databases, wherein the target databases include multiple metadata; Using a semantic analysis model constructed with a large language model, semantic analysis is performed on the metadata, and the semantic analysis results are semantically expanded according to different semantic aspect dimensions to obtain the semantic tags corresponding to the metadata; The relationships between the metadata are evaluated based on the semantic tags to construct candidate relationships based on the relationship evaluation results. The confidence evaluation model constructed by the large language model is used to evaluate the confidence of the candidate relationships to determine the target relationship from the candidate relationships based on the confidence evaluation results. A database knowledge graph is constructed based on the target relationship, and a structured query statement containing the target relationship is generated based on the database knowledge graph according to natural language instructions, so as to query the target database through the structured query statement.

2. The method according to claim 1, characterized in that, The semantic analysis results include the metadata semantic concepts corresponding to the metadata. The semantic analysis results are then semantically expanded according to different semantic dimensions to obtain the semantic tags corresponding to the metadata, including: If the semantic aspect dimension includes a concept dimension, then according to the preset standardized concept library, the standardized concept corresponding to the metadata semantic concept is matched, and the standardized concept is added to the semantic tag; If the semantic aspect dimension includes a domain dimension, then the business domain corresponding to the standardized concept is added to the semantic tag; If the semantic aspect dimension includes a similarity dimension, then similar semantic concepts that are similar to the metadata semantic concepts are matched according to a preset semantic concept library, and the similar semantic concepts are added to semantic tags. The semantic concept library is used to store the metadata semantic concepts output by the semantic analysis model. If the semantic aspect dimension includes a confidence dimension, then according to the semantic analysis model, the semantic confidence corresponding to the semantic concept of the metadata is obtained, and the semantic confidence is added to the semantic label; If the semantic aspect dimension includes a relation dimension, then matching is performed based on the metadata semantic concept to establish the semantic relationship corresponding to the metadata semantic concept, and the semantic relationship is added to the semantic tag.

3. The method according to claim 1, characterized in that, The relationship between the metadata is evaluated based on the semantic tags, and candidate relationships are constructed based on the relationship evaluation results, including: Obtain relationship evaluation factors, wherein the relationship evaluation factors include one or more of the following: name similarity between data names, semantic similarity between standardized concepts, type compatibility between data types, domain relevance between business domains, business logic between metadata, and constraint matching relationship between metadata; The relationship between each metadata is evaluated according to the relationship evaluation factor to obtain the relationship evaluation result, which includes an initial confidence level. The two metadata corresponding to the relationship evaluation result come from the same or different target databases. If the initial confidence level between two metadata items is greater than or equal to a preset initial confidence level threshold, then a candidate relationship is constructed between the two metadata items.

4. The method according to claim 1, characterized in that, The confidence evaluation model constructed using a large language model is used to evaluate the confidence of the candidate relations, including: Fill in the preset prompt word template according to the semantic tags corresponding to the candidate relationship to obtain the confidence evaluation prompt words; The confidence assessment prompts are input into the confidence assessment model to evaluate the confidence of the candidate relationship and obtain the confidence assessment result.

5. The method according to claim 4, characterized in that, The method further includes: The confidence assessment result includes a confidence score and the reasoning process text corresponding to the confidence score; The number of times the pre-defined inference keywords appear in the text of the inference process is counted; If the number of occurrences of the inference keyword is less than a preset threshold, the confidence level of the candidate relationship is reassessed.

6. The method according to claim 1, characterized in that, Determining the target relation from the candidate relations based on the confidence assessment results includes: Based on the confidence assessment factors, confidence assessment strategies corresponding to different application scenarios are constructed in advance. The confidence assessment strategies include the confidence assessment results, the label similarity between the semantic labels, and the relationship assessment factors. The current scenario is obtained, and based on the comparison results between the current scenario and each of the application scenarios, a match is made from each of the confidence evaluation strategies to obtain the target strategy corresponding to the current scenario. The confidence evaluation factors corresponding to the candidate relationships are calculated according to the target strategy to obtain the comprehensive confidence level corresponding to the candidate relationships; If the overall confidence level corresponding to the candidate relationship is greater than or equal to the preset overall confidence level threshold, then the candidate relationship is determined as the target relationship.

7. The method according to any one of claims 1 to 6, characterized in that, Using the database knowledge graph, a structured query statement containing the target relation is generated based on natural language instructions, including: Obtain natural language commands; The natural language instruction is parsed using a large language model to obtain the intent parsing result, wherein the intent parsing result includes the user intent and / or query conditions; Based on the intent parsing results, the database knowledge graph is queried to obtain the element to be queried and the graph relationship between the elements to be queried. Path planning is then performed based on the element to be queried and the graph relationship to obtain a cross-database metadata connection strategy. Structured query statements are generated based on the metadata connection strategy. The structured query statements include multiple query statements corresponding to a single target database, federated query statements for multiple target databases, or query statements corresponding to multiple target databases respectively.

8. The method according to any one of claims 1 to 6, characterized in that, After generating a structured query statement containing the target relation based on natural language instructions using the database knowledge graph, the method further includes: Obtain the user feedback results corresponding to the structured query statement, and determine the target relevance relationship on which the structured query statement depends based on the target relationship; If the user feedback is positive, then increase the overall confidence level corresponding to the correlation. If the user feedback is negative, then the overall confidence level corresponding to the correlation is reduced.

9. A database query system based on natural language, characterized in that, include: An acquisition module is used to acquire one or more target databases, wherein the target databases include multiple metadata. The semantic analysis module is used to perform semantic analysis on the metadata using a semantic analysis model constructed by a large language model, and to extend the semantic analysis results according to different semantic aspect dimensions to obtain the semantic tags corresponding to the metadata. An evaluation module is used to evaluate the relationship between the metadata based on the semantic tags, construct candidate relationships based on the relationship evaluation results, and use a confidence evaluation model constructed by a large language model to evaluate the confidence of the candidate relationships, so as to determine the target relationship from the candidate relationships based on the confidence evaluation results. The query module is used to construct a database knowledge graph based on the target relationship, and use the database knowledge graph to generate a structured query statement containing the target relationship according to natural language instructions, so as to query the target database through the structured query statement.

10. An electronic device, characterized in that, include: Processor and memory; The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory to cause the electronic device to perform the method as described in any one of claims 1-8.