Knowledge graph-based two-hop incremental interface consistency verification method and system
Through the two-hop incremental interface consistency verification method based on knowledge graph, the problem of interface consistency checking in large multi-language code bases is solved, the automatic extraction and real-time verification of heterogeneous language interfaces are realized, the verification time is reduced and the real-time feedback efficiency of the CI pipeline is improved.
Patent Information
- Application Number
- CN202511232578.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-01
- Publication Date
- 2025-10-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In large multi-language code bases, traditional compilers or static analysis tools struggle to implement interface consistency checks across files or repositories, leading to link-time errors or runtime crashes. Existing tools also take a long time to perform full scans, making it difficult to implement real-time feedback and rapidly expand project-specific verification logic within IDEs or CI pipelines.
Through a two-hop incremental interface consistency verification method based on knowledge graph, the language parser is used to automatically identify interface entities and map them into language-independent metamodels. Combined with the two-hop breadth-first traversal algorithm and the hot-pluggable rule engine, structured storage and real-time verification of interface entities are achieved, and blocking instructions are generated to prevent interface conflicts in the CI pipeline.
It achieves the automated unified extraction of heterogeneous language interfaces, the structured storage of cross-language interface dependencies, and the precise location of the impact of changes. It reduces the verification time to milliseconds, maintains a 99% defect coverage rate, and implements real-time error blocking in the CI pipeline.
Smart Images

Figure CN120743922A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of electronic digital data processing technology, and in particular to a two-hop incremental interface consistency verification method and system based on a knowledge graph. Background Art
[0002] In large, multi-language code bases, interfaces (functions, types, RPCs, Schemas, etc.) are scattered across different files and even repositories. Traditional compilers or static analysis tools are often limited to consistency checks on a single file or compilation unit. When developers only modify header files, IDL files, or JSON Schemas without synchronizing the caller, link-time errors or runtime crashes often occur. While existing tools like CodeQL and SonarQube support cross-file analysis, they are typically based on full scans, taking tens of seconds or even minutes. This makes it difficult to integrate into IDE saves or real-time feedback scenarios within continuous integration (CI) pipelines. Furthermore, the rule systems are often fixed and built-in, making it difficult to quickly expand project-specific verification logic.
[0003] Patent application document CN119862195A discloses an incremental knowledge graph update and consistency verification system for the industrial field, including: monitoring original industrial data to obtain new data, old data and data change sets; converting new data and old data into structured data according to a preset knowledge extraction rule set, and mapping the structured data into triples according to preset mapping rules to obtain a triple change set; calculating the update priority of several attributes in the triple change set, and obtaining a first update graph based on the update priority; performing multiple consistency verifications on the first update graph, and modifying the first update graph based on the verification results to obtain a second update graph; constructing a knowledge change link graph based on the first update graph and the second update graph, and performing rollback verification on the knowledge change link graph. However, this patent cannot completely solve the current technical problems, nor can it meet the needs of the present invention. Summary of the Invention
[0004] In view of the defects in the prior art, the purpose of the present invention is to provide a two-hop incremental interface consistency verification method and system based on knowledge graph.
[0005] The two-hop incremental interface consistency verification method based on knowledge graph provided by the present invention includes: Step 1: Parse the modified source file and extract the interface entity; Step 2: Map the interface entity into a language-independent metamodel and write it into the knowledge graph; Step 3: Execute a two-hop breadth-first traversal algorithm starting from the changed node in the knowledge graph to obtain the affected subgraph; Step 4: Run a hot-pluggable rule set on the affected subgraph for verification. The rule set includes parameter quantity matching rules, type compatibility rules, version number increment rules, and field deletion prohibition rules. If the verification violates the rules, an error report is generated and a blocking instruction is output; if the verification does not violate the rules, the affected subgraph is merged back into the knowledge graph cache.
[0006] Preferably, the language parsing process includes: calling an abstract syntax tree parser of the corresponding language according to the source file type, and recursively traversing various declaration nodes in the abstract syntax tree to identify interface entities.
[0007] Preferably, the two-hop breadth-first traversal algorithm is: input the modified node set, initialize the queue and the visited set, when the queue is not empty and the traversal depth is ≤ 2, pop up the node and traverse its adjacent nodes, if the adjacent node has not been visited, add it to the queue and the visited set, and output the affected subgraph composed of the visited set.
[0008] Preferably, the hot-pluggable rule set is executed by the following process: loading rules written based on DSL from a rule repository, matching rule conditions on affected subgraphs using a graph query language, and executing bound action templates when the rules are triggered.
[0009] Preferably, the knowledge graph cache adopts a write-time merge strategy, and sets a validity period for cached data and a conflict handling mechanism based on optimistic locking of the graph database; The generation scenarios of the blocking instruction include: when it is detected that field deletion violates the field deletion prohibition rule, or when the function return type violates the type compatibility rule.
[0010] The knowledge graph-based two-hop incremental interface consistency verification system provided by the present invention includes: Module M1: Perform language parsing on the modified source files and extract interface entities; Module M2: Map the interface entity into a language-independent metamodel and write it into the knowledge graph; Module M3: Execute a two-hop breadth-first traversal algorithm starting from the changed node in the knowledge graph to obtain the affected subgraph; Module M4: Run a hot-pluggable rule set on the affected subgraph for verification. The rule set includes parameter quantity matching rules, type compatibility rules, version number increment rules, and field deletion prohibition rules. If the verification violates the rules, an error report is generated and a blocking instruction is output; if the verification does not violate the rules, the affected subgraph is merged back into the knowledge graph cache.
[0011] Preferably, the language parsing process includes: calling an abstract syntax tree parser of the corresponding language according to the source file type, and recursively traversing various declaration nodes in the abstract syntax tree to identify interface entities.
[0012] Preferably, the two-hop breadth-first traversal algorithm is: input the modified node set, initialize the queue and the visited set, when the queue is not empty and the traversal depth is ≤ 2, pop up the node and traverse its adjacent nodes, if the adjacent node has not been visited, add it to the queue and the visited set, and output the affected subgraph composed of the visited set.
[0013] Preferably, the hot-pluggable rule set is executed by the following process: loading rules written based on DSL from a rule repository, matching rule conditions on affected subgraphs using a graph query language, and executing bound action templates when the rules are triggered.
[0014] Preferably, the knowledge graph cache adopts a write-time merge strategy, and sets a validity period for cached data and a conflict handling mechanism based on optimistic locking of the graph database; The generation scenarios of the blocking instruction include: when it is detected that field deletion violates the field deletion prohibition rule, or when the function return type violates the type compatibility rule.
[0015] Compared with the prior art, the present invention has the following beneficial effects: (1) The language parser automatically selects the AST parser of the corresponding language and recursively traverses the abstract syntax tree to identify interface entities, solving the problem of scattered interface entities and high manual maintenance costs in multi-language code bases, and realizing the automatic unified extraction of heterogeneous language interfaces such as C / C++ / Go / Java / TypeScript / GraphQL; (2) By mapping interface entities into a language-independent metamodel IL-Y and writing it into the knowledge graph, the problem of interface relationship fragmentation caused by language differences in traditional tools is solved, and the structured storage and global semantic association of cross-language interface dependencies are achieved; (3) By using a two-hop breadth-first traversal algorithm starting from the modified node to generate the affected subgraph ΔG, the problem of long full-data scan time was solved, and the impact range of the change was accurately located in milliseconds while maintaining a 99% defect coverage rate. (4) Through the hot-swappable rule engine + action template, the problem of existing tool rule solidification and the need to modify the source code for expansion is solved, and a flexible verification mechanism for dynamic loading and real-time triggering of rules such as field deletion prohibition and type compatibility is realized; (5) By blocking instruction generation and merging with the KG cache, the defect of the CI pipeline being unable to intercept interface conflicts in real time is solved, and automated error blocking and incremental updates of the knowledge graph are achieved in the development and integration stages. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Other features, objects and advantages of the present invention will become more apparent upon reading the detailed description of non-limiting embodiments with reference to the following drawings: Figure 1 This is a schematic diagram of the overall system architecture; Figure 2 is a flow chart of the method; Figure 3 This is a timing diagram of impact range calculation and rule engine. DETAILED DESCRIPTION
[0017] The present invention will be described in detail below with reference to specific embodiments. The following examples will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those skilled in the art, several changes and improvements can be made without departing from the scope of the present invention. These all fall within the scope of protection of the present invention.
[0018] Example 1 The present invention provides a two-hop incremental interface consistency verification method based on knowledge graph, comprising: A) Interface entity extraction: Perform language parsing on the modified source files to extract interface entities (Type, Func, RPC, Schema).
[0019] The language parsing process is: 1. Parser call: Automatically select the abstract syntax tree (AST) parser of the corresponding language based on the source file type, for example: C / C++ files call Clang AST; Go files use go / parser and go / ast; Java files are based on JavassistX; TypeScript files use ts-compiler; GraphQL uses a parsing library (such as graphql / language / parser).
[0020] 2.AST traversal and interface identification: In the constructed abstract syntax tree, recursively traverse various declaration nodes (such as function definitions, type definitions, interface protocols, etc.) and filter out interface-related entities based on semantic tags: Function (Func): function signature, parameters, return type; Type: structure, class, interface, etc. RPC: service endpoints declared in IDL or RESTful interfaces; Schema: Field structure and type information defined in JSON Schema and GraphQL Schema.
[0021] 3. Entity abstraction and standardization: The identified entity information is structured and encapsulated into a unified intermediate format (Intermediate Language-Y, or IL-Y metamodel), including: Name, type, scope, file and location; List of function parameters and return value types; Interface documentation comments (for subsequent rule matching); Context information such as the module and namespace.
[0022] 4. Change Detection: Compare the abstract syntax trees before and after the change to determine the list of newly added, modified, and deleted interface entities, which will serve as input for subsequent knowledge graph updates and dependency propagation.
[0023] B) Knowledge graph writing: Map the interface entity to the language-independent metamodel IL-Y and write it into the knowledge graph KG. The node categories include Type, Func, RPC, and Schema; the edge categories include Implements, Calls, Serializes, and VersionOf.
[0024] Language-independent metamodel (IL-Y) expression: IL-Y is a unified JSON structure used to represent interface entities. Its main fields include: type (entity type, such as Func, Type, etc.), name (entity name), parameters (parameter list), return_type (return type), language (source language), file, line_range (location information); Model input: interface entities extracted from the language parser, including their semantic information, type structure, source code location, etc.
[0025] Model output: standardized graph nodes and edges (i.e., IL-Y nodes and relationships), which are used to be written into the knowledge graph (KG).
[0026] C) Graph traversal dependency propagation based on knowledge graph: Perform a two-hop breadth-first traversal starting from the modified node to obtain the affected subgraph ΔG.
[0027] By comparing the interface entity extraction results before and after the change (such as Git difference files or AST comparison), the newly added, modified or deleted interface entities are identified, and their corresponding nodes in the knowledge graph are used as the "changed nodes" set ΔNodes as the starting point for dependency propagation.
[0028] D) Rule engine validation: Run hot-swappable rule sets on ΔG (parameter number matching, type compatibility, version number incrementing, field deletion prohibition, etc.).
[0029] The specific process of running a hot-pluggable rule set is as follows: 1. Load the enabled rule set from the rule repository (written based on DSL); 2. Use a graph query language (such as Gremlin) to match rule conditions one by one on the subgraph ΔG; 3. If the rule is triggered, the bound action template is executed (such as returning an error code and prompt information); 4. Each rule runs as an independent module and can be added or deleted dynamically without affecting the main program.
[0030] E) Error reporting and blocking: If a violation is found, a verification error report is generated and a blocking instruction (such as Shellexit 3, HTTP 409, GitHub Actions exit_code=CI_BLOCK) is output to terminate the CI pipeline. If there is no violation, ΔG is merged back into the KG cache.
[0031] Specific application examples: At a large internet finance company, the front-end and back-end collaboratively developed interfaces using a Java + TypeScript technology stack. During a rollout, a back-end developer modified the field name of the TradeDTO in Java (changing orderId to tradeId) but failed to update the corresponding TypeScript interface call in the front-end. This resulted in a parsing error at runtime, and the CI process failed to detect the issue in a timely manner.
[0032] Application method: Use the method of this invention to connect to the GitHub Actions CI process: 1. Interface entity extraction: The system parses the Java and TS modification files and extracts the modified TradeDTO entity.
[0033] 2. Knowledge graph writing and propagation: The entity is written into the knowledge graph and two-hop dependency propagation is performed to find that the front-end call chain contains the affected node.
[0034] 3. Rule engine execution: Detected that the field deletion violated the "field deletion prohibited" rule (the field orderId was deleted).
[0035] 4.CI blocking and prompting: The system generates an error report during the PR check, blocks the merge, and prompts that the front-end has not synchronized the field changes.
[0036] This solution avoids online failures caused by missing fields at runtime and automatically detects and blocks the impact of backend changes on the frontend. It eliminates the need for a full scan and completes verification in just 180ms.
[0037] Two-hop propagation algorithm: Input: ΔNodes Queue ← ΔNodes, Visited ← {} while Queue not empty and depth ≤ 2: v ← Queue.pop() for edge (v,u) in KG: if u ∉ Visited: Queue.push(u) Visited.add(u) return KG.subgraph(Visited) Rule DSL Example rule R2_TypeCompatible { MATCH (a:Func)-[:Calls]->(b:Func) WHERE NOT SUBTYPEOF(a.return, b.return) ACTION ERROR CODE=2002 MSG="Return type is incompatible" } Caching strategy: merge on write, 24-hour TTL, and optimistic locking for graph databases (conflict ≤ 3 retries).
[0038] The multi-language parser supports C / C++ (Clang AST), Go (go / ast), Java (JavassistX), TypeScript (ts-compiler), and GraphQL.
[0039] The graph database used is JanusGraph (with Cassandra as the backend); the rule engine uses Gremlin syntax + template actions.
[0040] CI integration: Jenkins step sh 'checker || exit 3'; GitHub Actions run:checker and parse the return code.
[0041] like Figure 1The module composition and data flow of the entire system include the following five key units: 1. Code parsing unit 101: parses the modified file and extracts the interface entity.
[0042] 2. Knowledge graph construction unit 102: converts the interface entity into a language-independent metamodel and writes it into the graph database.
[0043] 3. Influence range calculation unit 103: performs two-hop dependency propagation starting from the modified node to obtain a subgraph ΔG.
[0044] 4. Rule engine unit 104: executes DSL rules to determine whether there is an interface consistency problem.
[0045] 5. Error blocking unit 105: outputs an error report and feeds back a blocking signal to the CI / IDE.
[0046] like Figure 2 , showing the main process of the method of the present invention, comprising the following steps: First, extract the interface entity in the modified file; Then write the interface information into the knowledge graph; Perform two-hop dependency propagation in the knowledge graph to obtain the affected subgraph; Calculate the minimum core influence area using the dominating set algorithm based on the subgraph; Construct semantic patch subgraph (Δ-Context); Serialize the patch information to generate a ΔDSL file; Trigger incremental compilation based on patches and perform some regression tests; Finally, decide whether to block or update the knowledge graph based on the verification results.
[0047] like Figure 3 , is a timing diagram, which is used to show the call timing between modules after the change node is triggered, including: change detection trigger → parsing → graph update → ΔG calculation → DSL rule execution → output feedback. The diagram clearly reflects the interaction sequence between system modules and is an important support for implementation details.
[0048] Example 2 The present invention also provides a two-hop incremental interface consistency verification system based on a knowledge graph. The two-hop incremental interface consistency verification system based on a knowledge graph can be implemented by executing the process steps of the two-hop incremental interface consistency verification method based on a knowledge graph, that is, those skilled in the art can understand the two-hop incremental interface consistency verification method based on a knowledge graph as an optimal implementation of the two-hop incremental interface consistency verification system based on a knowledge graph.
[0049] The system includes: module M1: performing language parsing on the modified source file and extracting the interface entity; module M2: mapping the interface entity into a language-independent metamodel and then writing it into the knowledge graph; module M3: executing a two-hop breadth-first traversal algorithm with the modified node in the knowledge graph as the starting point to obtain the affected subgraph; module M4: running a hot-pluggable rule set on the affected subgraph for verification, the rule set including parameter quantity matching rules, type compatibility rules, version number increment rules and field deletion prohibition rules. If the verification violates the rules, an error report is generated and a blocking instruction is output; if the verification does not violate the rules, the affected subgraph is merged back into the knowledge graph cache.
[0050] The language parsing process includes: calling an abstract syntax tree parser of the corresponding language according to the source file type, and recursively traversing various declaration nodes in the abstract syntax tree to identify interface entities.
[0051] The two-hop breadth-first traversal algorithm is as follows: input the modified node set, initialize the queue and the visited set, when the queue is not empty and the traversal depth is ≤ 2, pop the node and traverse its adjacent nodes, if the adjacent node has not been visited, add it to the queue and the visited set, and output the affected subgraph consisting of the visited set.
[0052] The hot-pluggable rule set is executed through the following process: loading rules written based on DSL from the rule repository, matching rule conditions on the affected subgraphs using graph query language, and executing bound action templates when the rules are triggered.
[0053] The knowledge graph cache adopts a write-time merge strategy, and sets the validity period of cached data and a conflict handling mechanism based on optimistic locking of the graph database; The generation scenarios of the blocking instruction include: when it is detected that field deletion violates the field deletion prohibition rule, or when the function return type violates the type compatibility rule.
[0054] Those skilled in the art will appreciate that, in addition to implementing the system, device, and various modules provided by the present invention in purely computer-readable program code, it is entirely possible to implement the same program in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, embedded microcontrollers, and the like by logically programming the method steps. Therefore, the system, device, and various modules provided by the present invention can be considered a hardware component, and the modules included therein for implementing various programs can also be considered structures within the hardware component; the modules for implementing various functions can also be considered both software programs for implementing the method and structures within the hardware component.
[0055] The above describes specific embodiments of the present invention. It should be understood that the present invention is not limited to the specific embodiments described above, and those skilled in the art may make various changes or modifications within the scope of the claims, which do not affect the essence of the present invention. The embodiments of this application and the features in the embodiments may be combined with each other in any manner unless there is a conflict.
Claims
1. A two-hop incremental interface consistency verification method based on knowledge graph, characterized in that: include: Step 1: Parse the modified source file and extract the interface entity; Step 2: Map the interface entity into a language-independent metamodel and write it into the knowledge graph; Step 3: Execute a two-hop breadth-first traversal algorithm starting from the changed node in the knowledge graph to obtain the affected subgraph; Step 4: Run the hot-pluggable rule set on the affected subgraph for verification. The rule set includes parameter quantity matching rules, type compatibility rules, version number increment rules, and field deletion prohibition rules. If the verification violates the rules, an error report is generated and a blocking instruction is output. If there is no violation in the verification, the affected subgraph will be merged back into the knowledge graph cache.
2. The two-hop incremental interface consistency verification method based on knowledge graph according to claim 1 is characterized in that: The language parsing process includes: calling an abstract syntax tree parser of the corresponding language according to the source file type, and recursively traversing various declaration nodes in the abstract syntax tree to identify interface entities.
3. The two-hop incremental interface consistency verification method based on knowledge graph according to claim 1 is characterized in that: The two-hop breadth-first traversal algorithm is as follows: input the modified node set, initialize the queue and the visited set, when the queue is not empty and the traversal depth is ≤ 2, pop the node and traverse its adjacent nodes, if the adjacent node has not been visited, add it to the queue and the visited set, and output the affected subgraph consisting of the visited set.
4. The two-hop incremental interface consistency verification method based on knowledge graph according to claim 1 is characterized in that: The hot-pluggable rule set is executed through the following process: loading rules written based on DSL from the rule repository, matching rule conditions on the affected subgraphs using graph query language, and executing bound action templates when the rules are triggered.
5. The two-hop incremental interface consistency verification method based on knowledge graph according to claim 1 is characterized in that: The knowledge graph cache adopts a write-time merge strategy, and sets the validity period of cached data and a conflict handling mechanism based on optimistic locking of the graph database; The generation scenarios of the blocking instruction include: when it is detected that field deletion violates the field deletion prohibition rule, or when the function return type violates the type compatibility rule.
6. A two-hop incremental interface consistency verification system based on knowledge graph, characterized in that: include: Module M1: Perform language parsing on the modified source files and extract interface entities; Module M2: Map the interface entity into a language-independent metamodel and write it into the knowledge graph; Module M3: Execute a two-hop breadth-first traversal algorithm starting from the changed node in the knowledge graph to obtain the affected subgraph; Module M4: Runs a hot-pluggable rule set on the affected subgraph for verification. The rule set includes parameter quantity matching rules, type compatibility rules, version number increment rules, and field deletion prohibition rules. If the verification violates the rules, an error report is generated and a blocking instruction is output. If there is no violation in the verification, the affected subgraph will be merged back into the knowledge graph cache.
7. The two-hop incremental interface consistency verification system based on knowledge graph according to claim 6 is characterized in that: The language parsing process includes: calling an abstract syntax tree parser of the corresponding language according to the source file type, and recursively traversing various declaration nodes in the abstract syntax tree to identify interface entities.
8. The two-hop incremental interface consistency verification system based on knowledge graph according to claim 6 is characterized in that: The two-hop breadth-first traversal algorithm is as follows: input the modified node set, initialize the queue and the visited set, when the queue is not empty and the traversal depth is ≤ 2, pop the node and traverse its adjacent nodes, if the adjacent node has not been visited, add it to the queue and the visited set, and output the affected subgraph consisting of the visited set.
9. The two-hop incremental interface consistency verification system based on knowledge graph according to claim 6 is characterized in that: The hot-pluggable rule set is executed through the following process: loading rules written based on DSL from the rule repository, matching rule conditions on the affected subgraphs using graph query language, and executing bound action templates when the rules are triggered.
10. The two-hop incremental interface consistency verification system based on knowledge graph according to claim 6 is characterized in that: The knowledge graph cache adopts a write-time merge strategy, and sets the validity period of cached data and a conflict handling mechanism based on optimistic locking of the graph database; The generation scenarios of the blocking instruction include: when it is detected that field deletion violates the field deletion prohibition rule, or when the function return type violates the type compatibility rule.
Citation Information
Patent Citations
Incremental knowledge graph updating and consistency verification system for industrial field
CN119862195A
Large language model enhanced question and answer generation method
CN118013051A
Knowledge graph automatic updating method based on natural language processing technology
CN118607623A
Automatic interface document generation method and related equipment thereof
CN119396375A
Report verification batch parallel execution optimization method based on pluggable rule engine framework
CN120492451A
Cited By
Timing task-driven submitted data acquisition quality monitoring method and system
CN121051104A
Cold rolling processing line production schedule optimization method based on knowledge graph
CN122311821A