An Automated Database Business Data Extraction Method Based on AI Agent and Knowledge Graph

CN122334437BActive Publication Date: 2026-08-11CHINA LIFE INSURANCE CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-06-08
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0007]本发明提出一种基于AI Agent与知识图谱的自动化数据库业务数据抽取方法,以解决现有技术中效率低、易出错及安全性差的问题

Benefits of technology

[0009]与现有技术相比,本发明的有益效果为:通过构建知识图谱,将数据库表结构与业务语义显式化、结构化地表达为可查询的语义网络,解决了人工查找表结构效率低和口径理解不一致的问题,实现了快速、精准的数据来源定位。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122334437B_ABST
    Figure CN122334437B_ABST
Patent Text Reader

Abstract

This invention provides an automated database business data extraction method based on AI Agent and knowledge graph, relating to the fields of artificial intelligence and data processing technology. The method includes: first, extracting metadata from a relational database and constructing a table structure knowledge graph by combining it with business concepts; second, using an AI Agent to parse user natural language requirements, extracting key business concepts, and matching candidate tables, fields, and related paths by querying the knowledge graph; third, the AI ​​Agent automatically generating SQL query statements based on the matching results and data security rules; and finally, executing the SQL by calling the database interface through the Model Context Protocol (MCP), obtaining the result set, and exporting it to a file. This invention integrates knowledge graph semantics with AI Agent intent understanding to achieve fully automated extraction, solving problems of low efficiency, error susceptibility, and poor security compliance, thus improving intelligence and security.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of artificial intelligence and data processing technology, and in particular to an automated database business data extraction method based on AI Agent and knowledge graph. Background Technology

[0002] In daily business operations, business departments often need to extract specific business data from databases to support needs such as business analysis, regulatory reporting, and performance statistics. Existing data retrieval processes heavily rely on manual processes, typically involving: business personnel submitting requests, data engineers parsing the requests and confirming the business scope, manually querying the database table structure and writing SQL scripts, executing the SQL, and exporting the results.

[0003] The existing technical solutions have the following obvious shortcomings: Inefficient and costly in terms of communication: Business personnel and data engineers need to communicate in multiple rounds to accurately describe requirements, especially when it comes to complex data extraction involving cross-tables and cross-systems. Manually looking up table structures and foreign key relationships is time-consuming and involves a lot of repetitive work.

[0004] High error rate and inconsistent data definitions: With complex table structures, manually written SQL is prone to problems such as concatenation errors, omission of join conditions, or inconsistent data definitions, resulting in inaccurate data results.

[0005] Significant security risks exist: the desensitization of personally identifiable information relies on engineers' individual experience, resulting in inconsistent standards and a high risk of sensitive data leakage. Furthermore, manual query execution lacks unified access control and audit traceability, posing security vulnerabilities.

[0006] Therefore, there is an urgent need for a technical solution that can automate, intelligently, and securely complete the entire chain from natural language requirements to data file export. Summary of the Invention

[0007] This invention proposes an automated database business data extraction method based on AI Agent and knowledge graph to solve the problems of low efficiency, error susceptibility and poor security in the existing technology.

[0008] To achieve the above objectives, the present invention adopts the following technical solution: an automated database business data extraction method based on AI Agent and knowledge graph, comprising the following steps: S1: Extract metadata from the target relational database and combine it with predetermined business concepts to construct a table structure knowledge graph G=(V,E) in the graph database, where V is the vertex set and E is the edge set; S11: Define business concept nodes and establish semantic mapping relationships between them and corresponding field nodes; S12: Import the extracted metadata and defined business concepts into the graph database to construct a table structure knowledge graph G=(V,E); S2: Receive the user's input natural language data extraction requirement D, use the AI ​​Agent to parse the requirement D to extract key business concepts, and obtain candidate tables, fields and related paths related to the key business concepts by querying the table structure knowledge graph G. S21: The AI ​​Agent calls the Large Language Model (LLM) to perform semantic parsing on the natural language data extraction requirements and extract one or more key business concepts; S22: Call the knowledge graph query interface to search for business concept nodes that match the key business concept in the graph database; S23: Starting from the matching business concept node through graph query, backtracking along the semantic mapping relationship to the relevant field node and table node, and traversing along the foreign key relationship to discover the association path between tables, and finally outputting the candidate table list, field list and table join path; S3: The AI ​​Agent automatically generates SQL query statements that meet business requirements based on the matched candidate tables, fields and associated paths, and in combination with preset data security rules; S31: Generate an initial SQL statement containing table join logic based on the candidate tables and the association paths; S32: Based on the business constraints parsed from the natural language requirements, generate conditional clauses for dimension filtering, time partitioning, and state filtering, and add them to the initial SQL statement; S33: Identify the fields marked with a sensitivity level in the field list, and automatically replace the sensitive fields with corresponding desensitized expressions according to the preset desensitization strategy, and finally generate a secure and compliant SQL query statement; S4: Call the MCP service interface corresponding to the relational database through the Model Context Protocol (MCP), execute the SQL query statement to obtain the result set, and export the result set as a file in the specified format; S41: Perform performance analysis on the generated SQL query statement to determine whether the execution plan and the estimated result set size meet the preset safety threshold; S42: If the threshold is met, the SQL query statement is executed by calling the read-only database MCP service interface through the MCP protocol, and the result set is obtained through pagination or streaming. S43: Generate a log record containing audit information, which includes at least the original requirement description, generated SQL, execution statistics, and operation timestamp; S44: Export the obtained result set as an Excel or CSV file and save it to the specified location.

[0009] Compared with the prior art, the beneficial effects of the present invention are as follows: by constructing a knowledge graph, the database table structure and business semantics are explicitly and structurally expressed as a queryable semantic network, which solves the problems of low efficiency and inconsistent interpretation of manual table structure lookup, and realizes fast and accurate data source location.

[0010] By using an AI Agent to parse natural language requirements into business concepts and query a knowledge graph to determine the data source, SQL is generated based on these concepts, rather than directly from natural language. This solves the problem of high error rates in traditional methods and significantly improves the accuracy and reliability of SQL generation.

[0011] By embedding security rules and execution controls throughout the entire process, such as automatic data masking, read-only execution, row limit, and end-to-end auditing, the security risks in the data extraction process are resolved, achieving end-to-end data security and compliance assurance. Attached Figure Description

[0012] Figure 1 This is a schematic diagram of the AI ​​Agent data extraction process in Embodiment 1 of the present invention. Detailed Implementation

[0013] To provide a further understanding of the purpose, structure, features, and functions of the present invention, detailed descriptions are provided below with reference to specific embodiments.

[0014] Example 1: As Figure 1 As shown, an automated database business data extraction method based on AI Agent and knowledge graph includes the following steps: S1: Extract metadata from the target relational database and combine it with predetermined business concepts to build a table structure knowledge graph in the graph database; Furthermore, the system extracts the raw metadata required for constructing the knowledge graph by querying the data dictionary view of the target relational database. The extraction of this metadata is strictly limited to a pattern whitelist pre-configured by the system administrator. Each element This refers to the database schema name extracted for authorization. The system queries the data dictionary view to find the schema that satisfies the schema constraint schema∈ The metadata of all tables is extracted and formed into the following three sets: Table dataset ={(schema,table,comment)|schema∈ }; Field Metadataset ={(schema,table,column,dataType ,null able ,comment)|schema∈ }; Foreign Key Metadataset ={(constraint, , , , , , )| ∈ }

[0015] Among them, whitelist The boundary conditions constituting the system's operational domain are defined as follows: for any subsequent operation, the set of patterns in the discoverable table is... Data in unrelated schemas is not visible to the system, thus preventing unauthorized access at the architectural level.

[0016] The technical significance of the whitelist mechanism lies in its ability to define the data domain boundaries that AI agents can operate on from the very beginning of knowledge graph construction. Once a pattern is not included in the whitelist, its table structure information will not appear in the knowledge graph, and the AI ​​agent will be unable to discover or access any data under that pattern in subsequent steps. This fundamentally prevents unauthorized access and represents a security boundary definition built into the system architecture. The content of the whitelist can be dynamically configured and updated by the system administrator based on changes in the scope of business authorization.

[0017] S11: Define business concept nodes and establish semantic mapping relationships between them and corresponding field nodes; After extracting metadata, the system further defines business concept nodes and establishes semantic mapping relationships between them and corresponding field nodes. These business concept nodes are predefined by data analysts or system administrators through a configuration interface. Each business concept node v bc It includes the following attributes: main name of the concept, a standard term used to uniquely identify the business concept, such as "health insurance policy"; aliases, a set of synonyms that may be used for the business concept in business communication, such as ['healthpolicy', 'medpolicy']; and description, a natural language description of the business meaning of the business concept.

[0018] Based on the above definitions, the system establishes a semantic mapping relationship between field nodes and business concept nodes. This mapping relationship is defined as an edge set. × , satisfying: if ( , )∈ , then indicates the field Value range and business concept The semantic domains of the domains have a non-empty intersection, i.e., Domain( )∩Semantics( )≠ This mapping relationship satisfies the many-to-many property—one field can be mapped to multiple business concepts, and multiple fields can also be mapped to the same business concept. It also supports incremental updates over time to adapt to the evolution of business definitions.

[0019] S12: Import the extracted metadata and defined business concepts into the graph database to construct a table structure knowledge graph G=(V,E); The metadata set extracted in the preceding steps , , With the defined set of business concept nodes and semantic mapping relationship Import them into the graph database and construct a table-structured knowledge graph G=(V,E).

[0020] The knowledge graph is defined as follows: The vertex set V is the union of three mutually disjoint subsets: V = ∪ ∪ Among them, the table node subset ={ | correspond The set of attributes of the tuple is}, and its attribute set is Attrs( ) {name,schema,comment}; a subset of field nodes ={ | correspond The set of attributes of the tuple is}, and its attribute set is Attrs( ) {name,data Type The property `comment, piiLevel}`, where `piiLevel` ∈ {0, 1, 2, 3, 4, null}, is used to trigger automatic data masking in subsequent SQL generation steps; a subset of business concept nodes. ={ | For predefined business concept nodes}, its attribute set Attrs( = {name, aliases, desc}.

[0021] Edge set E V×V×Type, where Type is a relation type enumeration: Type={ , , The definitions of the three edge types satisfy the following constraints: × This connects the table node and the field node, indicating that the table contains this field. × For any foreign key edge e=( , , )∈E, which carries the attribute From(e) Attrs( ) and To(e) Attrs( Record the foreign key fields in the source table and the referenced fields in the target table respectively, so as to provide an accurate basis for generating inter-table join conditions in the future; × This corresponds to the semantic mapping relationship established in S11.

[0022] By establishing a table structure knowledge graph G=(V,E), the static metadata and dynamic business semantics of the database are integrated into a reasonable relational network. This network enables subsequent steps to discover the path from business concepts to physical data locations in polynomial time complexity using standard graph traversal algorithms, thereby solving the problems of inconsistent definitions and low efficiency of manual searches mentioned in the background technology.

[0023] S2: Receive the user's input natural language data extraction request, use the AI ​​Agent to parse the request to extract key business concepts, and obtain candidate tables, fields and related paths related to the key business concepts by querying the table structure knowledge graph; S21: The AI ​​Agent calls the Large Language Model (LLM) to perform semantic parsing on the natural language data extraction requirements and extract one or more key business concepts; Let D be the user's input request for natural language data extraction. The AI ​​Agent inputs D into a large language model, which, after semantic parsing, outputs a structured intent triple: ; Among them, the set of business concepts Examples include "health insurance," "insurance policy," and "customer." Business constraint set C includes time interval constraints (e.g., "first half of 2024" is parsed as [2024-01-01, 2024-06-30]), geographical dimension constraints (e.g., "Suzhou"), and business status constraints (e.g., "effective"). Output field requirement set F: A list of fields that the user explicitly requests to be output, such as "policy number", "customer name", "last four digits of ID number", "product name", and "premium". S22: Call the knowledge graph query interface to search for business concept nodes in the graph database G that match the set of key business concepts Q, and obtain the set of matching nodes. .

[0024] This matching process is implemented based on a semantic similarity calculation mechanism. Let the semantic similarity function Sim: String × String → [0,1], satisfying that Sim(a,b) quantifies the semantic similarity between strings a and b. Its implementation can be based on cosine similarity using word embedding vectors, normalized values ​​based on edit distance, or keyword retrieval scores based on inverted indexes. For each concept in Q... The system traverses the graph G. Each business concept node in the subset ,calculate and The semantic similarity of each alias in the alias set Sim(alias, Nodes that meet the similarity threshold will be included in the matching node set. ={ ∈ |∃alias∈Attrs( ).aliases,Sim(alias, )≥θ} Where θ∈(0,1] is the preset similarity threshold, and in this embodiment, θ=0.5 is taken.

[0025] This step also includes an important branching logic. If = That is, for all concepts in Q , its in If the highest semantic similarity in all queries is below the threshold θ, the AI ​​Agent terminates subsequent steps and returns a prompt to the user, requesting the user to semantically supplement or quantitatively define the business concepts in the request. This branch processing constitutes the system's fallback strategy for mismatched requirements—it is better to explicitly request clarification from the user than to rashly generate and execute an incorrect query when the semantics are uncertain. This reflects an important characteristic of the system's robust design.

[0026] S23: Query the set of matching business concept nodes using graph queries. Starting from, along the semantic mapping relationship Tracing back to the relevant field nodes and table nodes, and along the foreign key relationships. The graph traversal process is broken down into the following sub-steps: Traversing the graph to discover the relationships between tables, ultimately outputting a list of candidate tables, a list of fields, and table join paths. S231: Reverse mapping traversal. For Each business concept node in Edge type Traverse in the reverse direction to reach all field nodes that have a semantic mapping relationship with the business concept, forming a set of field nodes: ={ ∈ |∃e=( , , )∈E, ∈ } S232: Table-attribute traversal. For Each field node in Edge type In the reverse direction, reach the set of nodes in the corresponding table: ={ ∈ |∃e=( , , )∈E, ∈ } S233: Multi-hop foreign key path expansion. Each table node in the table is a source node. Edge type Perform a restricted graph search outwards. Let H be the maximum number of hops for the foreign key traversal, and define the path as a sequence of nodes. ,in , )∈E. From the source point The set of starting paths is recursively defined as: Paths( ,0)={[ ]}; Paths( ,h)=Paths( ,h-1)∪{P⊕[ ]|P∈Paths( ,h-1), and (P.last, , )∈E}; The final set of paths (Paths) )=Paths( H).

[0027] The default value for H is 3. This value is based on experience in the normalized design of enterprise-level relational databases, where the table join depth involved in the vast majority of business queries does not exceed 3 hops. Tables exceeding this range typically belong to different business domains in terms of business semantics. The value of H can be configured by the administrator according to the specific database architecture complexity.

[0028] S234: Candidate Set Summarization. The traversal results from S231 to S233 are summarized into the following three candidate sets, which serve as the final output of step S2: Candidate table list, merging the direct hit table with the association table found in multi-hop paths: = ∪{ |∃P∈Paths( ), ∈ , For non-first nodes of P; List of available fields, merging the matching fields with the remaining queryable fields in the candidate table: = ∪{ ∈ |∃ ∈ ,( , , )∈E}; The candidate join path set records each path and its corresponding inter-table join condition: ={(P, (P))|P is from The path discovered starting from the middle node; in, (P) From each of the paths P The From and To properties of an edge generate an equi-join condition.

[0029] S3: The AI ​​Agent automatically generates SQL query statements that meet business requirements based on the matched candidate tables, fields and associated paths, and in combination with preset data security rules; S31: Generate an initial SQL statement containing table join logic based on the candidate tables and the association paths; First, determine the driving table for the query. Let the selection function for the driving table be: from the set of tables directly hit... In this process, the table with the highest correlation to the matching field is selected as the driving table: =argmax_{ ∈ }|{ ∈ |( , , )∈E}| That is, choose The table with the most matching fields is used as the driving table.

[0030] Based on the selected driving table and candidate connection path set This generates the FROM and JOIN clauses of the initial SQL skeleton. The FROM clause uses... For the driving table. The JOIN clause iterates through the table. The selected path P, for each pair of adjacent nodes on the path ( ,vtgt), based on the corresponding The From and To properties of an edge generate equi-join conditions: cond( ,v tgt )≡( .From=v tgt To) Generate a set of connection relationships ={( v tgt ,cond)|( v tgt Let ) be the pair of adjacent nodes on path P.

[0031] The SELECT clause initially contains All fields in the output are then pruned according to F, retaining only the fields that the user explicitly requests to be output.

[0032] S32: Based on the business constraints parsed from the natural language requirements, generate conditional clauses for dimension filtering, time partitioning, and state filtering, and add them to the initial SQL statement; Define constraint mapping function The constraint elements in the business constraint set C output by S21 are mapped to condition predicates in the SQL statement. The mapping rules are as follows: —Time interval constraint (type=time): Let the parsed time interval be [ , ), mapped to conditional predicates >= AND < ; Geographic dimension constraint (type=geo): Let the parsed geographic value be value, which is mapped to a conditional predicate. =value; Business status constraint (type=status): Let the list of parsed status values ​​be... Mapped to conditional predicates IN( ).

[0033] The set of business condition predicates obtained through mapping is denoted as .

[0034] In addition, two types of globally fixed safety constraints are injected: Soft deletion constraint: arbitrary ∈ If its attribute set contains Fields, then inject =0; Tenant isolation constraints: injection = ,in This is the tenant identifier to which the current operator belongs.

[0035] Will The conditional predicates of the two types of fixed constraints mentioned above are added to the WHERE clause of the SQL statement.

[0036] S33: Identify the fields marked with a sensitivity level in the field list, and automatically replace the sensitive fields with corresponding desensitized expressions according to the preset desensitization strategy, and finally generate a secure and compliant SQL query statement; For each field f in the SELECT clause, query its representation in graph G. Corresponding nodes in the subset The value of the piiLevel property.

[0037] Define a desensitization function mapping table Φ, which maps sensitivity levels to their corresponding desensitization function expressions. The domain of Φ is {1,2,3,4}, and the mapping relationship is as follows: The final output expression of field f (f) is determined by the following rules: (f) = f, if piiLevel ∈ {0, null}; Φ(piiLevel)(f), if piiLevel∈{1,2,3,4}.

[0038] The system replaces the original references of all fields in the SELECT clause that satisfy piiLevel≥1 with the corresponding de-identification function expressions.

[0039] After the de-identified injection is completed, the system imposes a limit on the number of rows in the result set on the SQL statement, appending LIMIT. Clause, in which Set the preset maximum number of rows to return. Add an audit comment prefix to the SQL statement header, including the operator identifier, work order number, and masking strategy version information.

[0040] The final query statement generated after the above three sub-steps is denoted as... .

[0041] Step S3 input is ( , , (,C,F,G), the output is .

[0042] The beneficial effects of the S3 step include: shifting security and compliance checks from "post-audit" to the "code generation" stage; minimizing the exposure of sensitive data at the database execution level by introducing the field masking function mapping table Φ, thus eliminating the risk of leakage at the source; and ensuring the controllability and traceability of generated SQL by enforcing a maximum row limit and injecting audit comments beforehand.

[0043] S4: Call the MCP service interface corresponding to the relational database through the Model Context Protocol (MCP), execute the SQL query statement to obtain the result set, and export the result set as a file in the specified format; S41: Perform performance analysis on the generated SQL query statement to determine whether the execution plan and the estimated result set size meet the preset safety threshold; The system sends an EXPLAIN command (or the equivalent EXPLAINANALYZE command) to the target database via the MCP protocol, requesting the database to return a response. The execution plan information is displayed, but the query is not actually executed.

[0044] Extract the following three key metrics from the returned execution plan: ( ): Estimated number of rows to be scanned, obtained from the rows field of the execution plan; ( ): Estimated query cost, obtained from the cost field of the execution plan; Type( ): Access type, with values ​​such as ALL (full table scan), index (index scan), range (range scan), etc.

[0045] Define the safety determination predicate Safe( The logical AND operation is performed on the following three conditions: Safe )≡( ( )≤ )∧( ( )≤ )∧(Type( )∉ ) in, The maximum allowed number of scan rows threshold is set to 10 in this embodiment. 6 ; This is the maximum allowed query cost threshold; This embodiment represents the set of prohibited access types. ={ALL} means that full table scans without index support are prohibited.

[0046] If Safe( If )=false, the system immediately interrupts the process, returns to the REJECTED status, and outputs a warning message to the user.

[0047] S42: If the threshold is met, the SQL query statement is executed by calling the read-only database MCP service interface through the MCP protocol, and the result set is obtained through pagination or streaming. After the pre-check passes, the system calls the target database's MCP service interface via the MCP protocol to establish a constrained database session. The following set of security parameters is forcibly set during session establishment: ={mode= , =1, = , ∈{PAGE,STREAM}}; Where, mode= Set the session to read-only mode; =1 Enables secure update mode; = Set the execution timeout threshold; Specify the result set retrieval strategy, with values ​​for either pagination mode (PAGE) or streaming mode (STREAM).

[0048] The execution method of pagination mode is defined as follows. Let the number of rows per page be... Page number i ∈ {1, 2, ...}. The query for page i is in Add a pagination clause to the basic structure: (i)= ∪{ (i-1)× } The execution process is a loop: i starts from 1 and increments, and each time it is executed... (i) Retrieve the result set record of the i-th page and the number of rows returned on the current page. The loop terminates under the following condition: ( < )∨( ≥ ) in This represents the total number of rows returned so far. This is the maximum number of rows to return preset in S33. ≥ Force termination and set a truncation flag. =true.

[0049] S43: Generate a log record containing audit information, which includes at least the original requirement description, generated SQL, execution statistics, and operation timestamp; Each execution generates a structured audit log record L, whose fields are defined as follows: L is persistently written to the log storage system for post-event traceability and compliance review.

[0050] S44: Export the obtained result set as an Excel or CSV file and save it to the specified location.

[0051] Exported files should be named according to the following format function: Filename=Concat(BizConcept(C),"",DateRange(C),"", ,".",ext) Where Concat is an underscore concatenation function; BizConcept(C) starts from... Extract the matched business concept names and connect them with underscores; DateRange(C) extracts from the time constraint and formats it as YYYYMMDD_YYYYMMDD; This is the identifier for end-to-end tracing; ext∈{xlsx,csv} is the file extension for the exported file format.

[0052] The generated file is stored in a preset shared storage directory, and the system returns the file path (FilePath) to the user.

[0053] Example 2: This example uses a regulatory data reporting scenario of an insurance company. Sales staff need to submit a list of all effective health insurance policies in Beijing for the first quarter of 2024 to the regulatory authorities.

[0054] In the dialogue interface with the AI ​​Agent, the user enters natural language request D: "Export all effective health insurance policies in Beijing in the first quarter of 2024, including customer name, product name and premium." After receiving the request, AIAgent first calls the large language model to execute step S21, outputting a structured intent triple: (D) = (Q, C, F), where Q = {"Health Insurance", "Policy", "Customer", "Product"}, C contains the time range [2024-01-01, 2024-03-31], the geographical condition "Beijing" and the status condition "Effective", and F contains three output fields: customer name, product name and premium.

[0055] Then, step S22 is executed, searching in graph G for business concept nodes that match the concepts in Q. Three business concept nodes, "health insurance policy," "customer," and "product," are successfully matched with a similarity score higher than the threshold θ, thus forming... .

[0056] Next, the graph traversal in step S23 is performed: The relevant field nodes are located through reverse mapping traversal (S231); the three physical tables, biz.policy (policy table), biz.customer (customer table), and biz.product (product table), are located through table attribution traversal (S232); and the multi-hop foreign key path expansion (S233) reveals that the policy table is accessed through... Foreign key joins to the customer table, via Foreign key joins the two join paths of the product table; summarize and generate a candidate set (S234).

[0057] In step S3, the system generates an initial SQL skeleton using biz.policy as the driving table (S31), injecting time, region, and status constraints, as well as two types of fixed constraints: soft deletion and tenant isolation (S32). During the de-identified injection phase (S33), the system identifies the ID number field in the biz.customer table. The piiLevel attribute value is 2, which belongs to the sensitive field of the ID number category. The desensitization function Φ(2) is automatically called to replace it with the desensitization expression RIGHT( which only retains the last four digits). ,4), and also add LIMIT Clause and audit comment prefixes, generate .

[0058] In step S4, the system... Perform a pre-check (S41) to confirm that the estimated number of rows scanned and the query cost do not exceed the thresholds and that the access type is an index scan, then determine Safe( =true. Then, a read-only session is established via the MCP protocol to execute the query (S42), which takes 5 seconds and returns 1,200 records. The system generates a complete audit log (S43) and exports the result set as a file named, for example, health_policy_20240101_20240331_trace001.xlsx (S44).

[0059] The effect of this embodiment is that business personnel obtain the required data file approximately 10 seconds after submitting their request, without the need for data engineer intervention. The ID card number field in the returned result has been automatically anonymized, displaying only the last four digits to ensure the security of customer privacy information. The entire process is fully recorded in the audit log, allowing for retrospective review at any time.

[0060] Example 3: This example demonstrates the system's robust handling capabilities when faced with ambiguous requests. Based on the same system configuration as in Example 1, a user inputs a non-standardized business request D: "Check the status of recent large claims." After receiving the request, the AI ​​Agent performs semantic parsing in step S21, outputting Q = {“large amount”, “compensation case”}. However, during semantic matching in step S22, the system traverses graph G... After calculating the semantic similarity of the alias sets of each business concept node in the subset, it was found that for "large amount", all There are no matching terms in the alias set that have a semantic similarity exceeding the threshold θ for the concept; the same applies to "compensation case". Sim(aliases( ), “large amount”) < θ, and Sim(aliases( Therefore, “compensation case”) < θ. = .

[0061] After triggering the fallback branch, the AI ​​Agent terminates the subsequent S23 graph traversal, S3SQL generation, and S4 execution export steps, and directly returns structured prompts to the user, requesting the user to clearly define the specific numerical threshold of "large amount" (such as a single compensation amount exceeding 100,000 yuan) and the business status or table name corresponding to the "compensation case".

[0062] The technical effect demonstrated in this embodiment is that, when semantics are ambiguous, the system does not forcefully guess and generate potentially erroneous SQL queries. Instead, it guides users to clarify their needs through structured questions. This design principle of "preferring explicit requests to blind execution" effectively avoids the generation of erroneous data and the waste of system resources, demonstrating the system's robustness under boundary conditions.

[0063] The present invention has been described in the above-described embodiments; however, these embodiments are merely examples for implementing the present invention. It must be noted that the disclosed embodiments do not limit the scope of the present invention. Conversely, any modifications and refinements made without departing from the spirit and scope of the present invention are within the scope of patent protection of the present invention.

Claims

1. An AI Agent and knowledge graph based automated database business data extraction method, characterized in that, include: S1: Extract metadata from the target relational database and combine it with predetermined business concepts to construct a table structure knowledge graph G=(V,E) in the graph database, where V is the vertex set and E is the edge set; Wherein, the vertex set V is composed of mutually disjoint table node subsets , field node subsets and business concept node subsets ; the edge set E at least includes HA SCOLUMN edges connecting table nodes and field nodes, FOREIGN KEY edges connecting table nodes and table nodes, and MAPS TO edges connecting field nodes and business concept nodes; the MAPS TO edges are used to define non-empty intersection mapping relationships between value ranges of field nodes and semantic domains of business concept nodes. S2: Receive the user's input natural language data extraction requirement D, use the AI ​​Agent to parse the requirement D to extract key business concepts, and obtain candidate tables, fields and related paths related to the key business concepts by querying the table structure knowledge graph G. S3: The AI ​​Agent automatically generates SQL query statements that meet business requirements based on the matched candidate tables, fields and associated paths, and in combination with preset data security rules; S4: Call the MCP service interface corresponding to the relational database through the Model Context Protocol (MCP), execute the SQL query statement to obtain the result set, and export the result set as a file in the specified format.

2. The automated database business data extraction method based on AI Agent and knowledge graph as described in claim 1, characterized in that, Step S1 includes: S11: By querying the data dictionary view of the target relational database, retrieve the data from the pre-configured schema whitelist. Metadata is extracted within the defined schema range to form a metadata set. Field Metadataset and foreign key meta dataset The pattern whitelist mentioned above The boundary conditions that constitute the system's operational domain enable subsequent operations to discover the set of schemas in the table. ; S12: Define the set of business concept nodes Each business concept node It includes the concept master name, a list of aliases, and a semantic description, and establishes a semantic mapping relationship between field nodes and business concept nodes. This semantic mapping relationship is defined as an edge set. Satisfy: If ( , )∈ , then indicates the field Value range and business concept The semantic domains have a non-empty intersection; S13: Will , , , and Import the graph database and construct the table structure knowledge graph G = (V, E), where the vertex set V = ∪ ∪ The union of three disjoint subsets, edge set Type = , × , × And each While carrying the source foreign key field attribute From and the target reference field attribute To, × .

3. The automated database business data extraction method based on AI Agent and knowledge graph as described in claim 2, characterized in that... Step S2 includes: S21: The AI ​​Agent invokes the Large Language Model (LLM) to perform semantic parsing on the natural language data extraction requirement D, and outputs structured intent triples. (D) = (Q, C, F), where Q is the set of extracted business concepts, C is the set of business constraints, and F is the set of output field requirements; S22: Define a semantic similarity function Sim: String × String → [0, 1], for each concept in Q. In Figure G The subset calculates its relationship with each business concept node. The semantic similarity of the alias set will satisfy Sim(alias, Nodes whose values ​​are greater than or equal to θ are included in the set of matching nodes. , where θ∈(0,1] is the preset similarity threshold.

4. The automated database business data extraction method based on AI Agent and knowledge graph as described in claim 3, characterized in that: Step S2 further includes: S23: From the set of matching nodes Starting with the graph traversal, candidate tables, fields, and association paths are obtained. This graph traversal includes: S231: Reverse mapping traversal, along the edge type In the reverse direction, we obtain the set of field nodes. ; S232: Table traversal, edge-type In the reverse direction, we obtain the set of table nodes. ; S233: Multi-hop foreign key path expansion, with Each table node in the table is a source node. Edge type Perform a restricted graph search, let H be the maximum number of hops for the foreign key traversal, and define the path as a sequence of nodes. ,in , From the source The set of starting paths is recursively defined as follows: Paths( ,h)=Paths( ,h-1)∪{P⊕[ ]|P∈Paths( ,h-1), and (P.last, , )∈E}, the final path set Paths( ) = Paths( ,H); S234: Summarize the candidate set and output the candidate list. List of available fields and candidate connection path set .

5. The automated database business data extraction method based on AI Agent and knowledge graph as described in claim 4, characterized in that: In step S22, if = That is, for all concepts in Q , its in If the highest semantic similarity in all cases is below the threshold θ, the AI ​​Agent terminates subsequent steps S23, S3 and S4, and returns a prompt to the user, requesting the user to semantically supplement or quantitatively define the business concepts in the requirements.

6. The automated database business data extraction method based on AI Agent and knowledge graph as described in claim 4, characterized in that: In step S233, the default value of the maximum foreign key traversal jump number H is 3. This value is based on the experience of enterprise-level relational database normalization design, so that the table association depth can avoid introducing irrelevant data tables that do not belong to the same business domain semantically, provided that the coverage function is greater than 95%. The value of H can be configured according to the complexity of the specific database architecture.

7. The automated database business data extraction method based on AI Agent and knowledge graph as described in claim 4, characterized in that: Step S3 includes: S31: with The table with the most matching fields is used as the driving table. Based on the set of candidate connection paths Generate an initial SQL statement containing table join logic, where adjacent node pairs on the path ( , The connection condition for ) is cond( , )≡( .From= .To); S32: Define constraint mapping functions Map the set of business constraints C to a set of condition predicates. And inject soft delete constraints and tenant isolation constraints, and add them to the WHERE clause of the initial SQL statement; S33: Identify fields used in the SELECT clause The sensitivity level attribute piiLevel of the corresponding node is used to replace the original references of fields with sensitivity levels 1 to 4 with the corresponding desensitization function expressions according to the preset desensitization function mapping table Φ, and the upper limit of the number of rows in the result set is appended. Add audit comment prefixes to generate secure and compliant SQL query statements. .

8. The automated database business data extraction method based on AI Agent and knowledge graph as described in claim 7, characterized in that: In step S33, the field node The sensitivity level attribute piiLevel ∈ {0, 1, 2, 3, 4, null}, the domain of the desensitization function mapping table Φ is {1, 2, 3, 4}, and the final output expression of field f is determined by the following rule: if piiLevel ∈ {0, null}, then (f) = f; if piiLevel ∈ {1, 2, 3, 4}, then (f)=Φ(piiLevel)(f).

9. The automated database business data extraction method based on AI Agent and knowledge graph as described in claim 8, characterized in that: The desensitization function expressions corresponding to each sensitivity level in the desensitization function mapping table Φ are as follows: When piiLevel = 1, the name field uses the expression CONCAT(LEFT(f,1),REPEAT('*',LENGTH(f)-1)); when piiLevel = 2, the ID number field uses the expression CONCAT(REPEAT('*',LENGTH(f)-4),RIGHT(f,4)); when piiLevel = 3, the mobile phone number field uses the expression CONCAT(LEFT(f,3),'**',RIGHT(f,4)); when piiLevel = 4, the email address field uses the expression CONCAT(LEFT(f,3),'**',RIGHT(f,4)); (f,'@',1),2),'*@', (f,'@',2)).

10. The automated database business data extraction method based on AI Agent and knowledge graph as described in claim 7, characterized in that: Step S4 includes: S41: Send the EXPLAIN command to the target database via the MCP protocol to obtain... Extract the estimated number of scan rows from the execution plan information. ( ), estimated query cost ( ) and access type (Type) Define the safety determination predicate Safe( )≡( ( )≤ )∧( ( )≤ )∧(Type( )∉ If Safe() is false, the process is interrupted and a rejection status is returned. This is the maximum allowed number of scan rows threshold. This is the maximum allowed query cost threshold. This is a set of prohibited access types. S42: If Safe( If the condition is true, then a constrained database session is established and executed via the MCP protocol. Session parameters include read-only mode, secure update mode, execution timeout limit, and pagination or streaming retrieval strategy. The result set is retrieved via loop pagination or streaming. When the cumulative number of returned rows reaches the preset maximum row count limit... Force termination and set a truncation flag; S43: Generate a structured audit log record L, wherein the audit log record L includes a full-link tracing identifier, original requirement description, matching business concept, final executed SQL statement, execution plan summary, execution start and end time, execution time, number of returned rows, truncation marker, operator identifier, export file path and execution status; S44: Export the obtained result set to a file in a specified format. The file name follows the format: Filename = Concat(BizConcept(C), "_ ",DateRange(C)," _", The expression `,".",ext)` is used, where `BizConcept(C)` represents the extracted and matched business concept names connected by underscores, and `DateRange(C)` represents the time constraint formatting result. This is the identifier for end-to-end tracing; ext is the file extension.

Citation Information

Patent Citations

  • Driving type data analysis method and system based on AI

    CN121705309A

  • Systems and Methods for Textual Classification Using Natural Language Understanding Machine Learning Models for Automating Business Processes

    US20240062016A1