A method and device for finding an entity association path in a knowledge graph
By maintaining a global family table and dynamic family structure in the knowledge graph, and using family identifiers for pre-judgment and merging, the problems of wasted computing resources and low search efficiency in existing technologies are solved, and efficient and real-time entity association path query is realized.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- COLASOFT
- Filing Date
- 2026-03-04
- Publication Date
- 2026-06-12
Smart Images

Figure CN122196193A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of knowledge graph technology, and in particular relates to a method and apparatus for finding entity association paths in a knowledge graph. Background Technology
[0002] Currently, bidirectional traversal strategies and their variants are widely used in entity association path finding in knowledge graphs, but these algorithms still have some shortcomings, such as:
[0003] (1) The existing method requires expansion from two starting points for each query, resulting in a large number of invalid traversal nodes and a time complexity of O(n²). When the knowledge graph reaches the scale of millions of entities, it will seriously waste computing resources. In particular, when the two entities are actually completely independent subgraphs (i.e., the two entities do not have any related paths), all calculations will be invalid, resulting in a waste of computing power.
[0004] (2) In real-world scenarios, users typically only need the shortest path or the Top-K most important paths. However, existing methods usually return all the paths found directly, which may result in a large number of lengthy, irrelevant, or low-quality paths, causing information overload. Users or downstream systems still need to perform secondary processing. In addition, some of the entity association paths found by existing methods are long paths with too many hops and weak semantic associations (such as more than 10 hops), but these paths often lack practical value in actual business scenarios.
[0005] (3) Existing methods typically treat each query as an independent and complete computation process. When the knowledge graph changes dynamically (e.g., adding new users, transactions, or other real-time data), previous query results or intermediate states cannot be effectively utilized, leading to repeated computations for high-frequency queries targeting the same or similar entities (e.g., association analysis of popular products on e-commerce platforms). Furthermore, the algorithm itself lacks incremental processing capabilities. For dynamically updated knowledge graphs, any data update (e.g., adding entities / relationships in real time) may trigger a full or large-scale recalculation, resulting in high response latency and making it difficult to adapt to application scenarios with high real-time requirements.
[0006] (4) The time complexity of existing methods is highly dependent on the actual distance between the two entities. The time taken to find the intersection is exponentially related to the distance between the two entities. In the worst case (such as when the two entities are not connected or are extremely far apart), it is necessary to traverse the entire graph to confirm the intersection. At the same time, the search process of existing methods needs to be explored in the entire graph or a very large subgraph. When the graph contains multiple heterogeneous entities (such as people, institutions, events, locations, etc.), it is impossible to quickly locate potential related areas, resulting in low search efficiency. Summary of the Invention
[0007] The purpose of this invention is to overcome the shortcomings of the prior art and provide a method and apparatus for finding entity association paths in a knowledge graph, which greatly improves the query efficiency of entity association paths.
[0008] This invention is achieved through the following technical solution:
[0009] The first aspect of this invention discloses a method for finding entity association paths in a knowledge graph, including a family structure dynamic maintenance stage and a path query stage:
[0010] The dynamic maintenance phase of the family structure includes the following steps:
[0011] When inserting a relation triple into the knowledge graph incrementally, a global family table is queried to determine the connection relationship between the triple and existing families: if the triple has no connection with any family, the entities contained in the triple are set as a new family, and the family identifier is created and recorded in the global family table; if the triple has a connection relationship with one or more existing families, the entities contained in the triple are assigned to the family determined by the connection relationship, and the global family table is updated.
[0012] When two entities in the triple are assigned to different families, the two families are merged into one family, and the global family table is updated with the unified family identifier of the merged family.
[0013] The path query phase includes the following steps:
[0014] In response to a path query request for the starting entity and the target entity, the global family table is queried to determine whether the two have the same family identifier: if the family identifiers are different, the result of determining that there is no associated path is returned directly; if the family identifiers are the same, the corresponding entity set is determined based on the family identifier, and a graph search is performed in the entity set to obtain the associated path between the two.
[0015] Furthermore, the entities it contains are classified into the families determined by this connection, including:
[0016] If the triple is connected to only one family, then it is assigned to that family;
[0017] If the triple is connected to two different families, then the two entities in the triple are assigned to the two different families respectively.
[0018] Furthermore, the two races will be merged into one race, including:
[0019] Compare the number of entities contained in each of the two groups to be merged;
[0020] Modify the family identifier of entities in families with fewer entities to the family identifier of families with more entities.
[0021] Furthermore, the family identifiers of entities in families with fewer entities are modified to match the family identifiers of families with more entities, including:
[0022] By using a depth-first search algorithm, the family identifiers of entities in families with fewer entities are modified to the family identifiers of families with more entities.
[0023] Further, query the global family table to determine whether the two have the same family identifier, including:
[0024] The family identifier of the entity is obtained from the global family table using a binary search operation;
[0025] Determine whether the family identifiers of the starting entity and the target entity are the same.
[0026] Furthermore, a graph search is performed within this entity set to obtain the association path between the two, including:
[0027] A graph search is performed within the entity set using a breadth-first search to obtain the association path between the two entities, and the first path found is the shortest path between the starting entity and the target entity.
[0028] A second aspect of the present invention discloses an apparatus for finding entity association paths in a knowledge graph, comprising:
[0029] The family structure maintenance module is configured to perform dynamic maintenance operations when incrementally inserting relation triples into the knowledge graph;
[0030] The path query module is configured to perform query operations in response to path query requests for the starting entity and the target entity;
[0031] The family structure maintenance module includes:
[0032] The connection relationship determination unit is configured to query a global family table and determine the connection relationship between the entity in the triplet and an existing family in the table.
[0033] The family affiliation determination unit is configured to determine the family affiliation of the entities contained in the triple based on the judgment result of the connection relationship judgment unit: if the triple has no connection with any family, the entities contained in the triple are set as a new family, and this family identifier is created and recorded in the global family table; if the triple has a connection relationship with one or more existing families, the entities contained in it are assigned to the family determined by the connection relationship, and the global family table is updated.
[0034] The family merging processing unit is configured to merge the two families into one family when the two entities in the triple are assigned to different families, and update the global family table with the unified family identifier of the merged family.
[0035] Among them, the path query module includes:
[0036] A connectivity pre-judgment unit, configured to query the global family table and determine whether the starting entity and the target entity have the same family identifier;
[0037] A result generation unit, configured to directly return a determination result of no associated path when the family identifiers of the starting entity and the target entity are different;
[0038] A path search unit, configured to, when the family identifiers of the starting entity and the target entity are the same, determine a corresponding entity set according to the family identifier, and perform a graph search within the entity set to obtain an associated path between the two.
[0039] The third aspect of the present invention discloses an electronic device, including:
[0040] A processor;
[0041] A memory, connected to the processor, for storing a computer program;
[0042] Wherein, when the processor executes the computer program, it implements a method for finding an entity association path in a knowledge graph as described in the first aspect of the present invention.
[0043] The fourth aspect of the present invention discloses a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements a method for finding an entity association path in a knowledge graph as described in the first aspect of the present invention.
[0044] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0045] (1) The present invention fundamentally changes the path search paradigm through a pre-judgment mechanism of "family". For a query request, first perform a millisecond-level comparison of family identifiers (time complexity is O(log n)). When the two entities do not belong to the same family, immediately (sub-second level) return a conclusion of no associated path, completely eliminating the huge waste of computing resources caused by the invalid traversal of the entire graph or a large-scale sub-graph in such scenarios by traditional methods. Even if the two entities are in the same family, the actual graph search is strictly limited within the connected sub-graph corresponding to the family (time complexity O(k), k << n). Actual measurements show that in a knowledge graph with tens of millions of entities, the cross-family query response time of the present invention is less than 1 millisecond, and the average time-consuming for in-family path queries is about 15 milliseconds, and the comprehensive performance is improved by more than 100 times compared with traditional methods. At the same time, due to the significant reduction in the search range, only the relevant data of the target family needs to be loaded into the cache, reducing more than 90% of the invalid memory accesses, and significantly improving the overall memory access efficiency and system throughput;
[0046] (2) The strategy of “merging families with fewer entities into families with more entities” adopted in this invention can effectively control the length of the family merging chain, optimize the efficiency of a single merging operation (minimize the number of entities that need to be updated), and make the data structure remain stable when faced with a continuous influx of massive data, thereby ensuring the long-term stability and scalability of the system in processing ultra-large-scale knowledge graphs.
[0047] (3) The maintenance of the "family" structure in this invention is incremental. Each time a new relation triple is inserted into the knowledge graph, it only triggers the update or limited merging operation of the local "family" state, without the need for a full recalculation, so that the real-time changes of the graph can be immediately reflected in the global connectivity index. This mechanism enables this invention to adapt to the dynamic knowledge graph scenario where data is frequently updated and evolved, without the need for periodic and costly full graph recalculation, and realizes real-time response to data changes and synchronous update of the index;
[0048] (4) The core of this invention relies on family table lookup and memory address operation, which are very basic and efficient computational operations. They do not depend on complex third-party graph computation libraries, which reduces the implementation complexity and maintenance cost of the system, while improving the overall stability and reliability of the system. Attached Figure Description
[0049] The accompanying drawings, which are included to provide a further understanding of embodiments of the invention and form part of this application, do not constitute a limitation thereof. In the drawings:
[0050] Figure 1 This is a flowchart of a method for finding entity association paths in a knowledge graph according to the present invention;
[0051] Figure 2 This is a block diagram of one component of the device for finding entity association paths in a knowledge graph according to the present invention. Detailed Implementation
[0052] The technical solution of the present invention will be further described below with reference to the accompanying drawings and specific embodiments.
[0053] The accompanying drawings are for illustrative purposes only and are schematic diagrams, not actual pictures, and should not be construed as limiting the invention. To better illustrate the embodiments of the invention, some parts in the drawings may be omitted, enlarged, or reduced, and do not represent the actual product dimensions. It is understandable to those skilled in the art that some well-known structures and their descriptions may be omitted in the drawings.
[0054] In the accompanying drawings of the embodiments of the present invention, the same or similar reference numerals correspond to the same or similar components. In the description of the present invention, it should be understood that if terms such as "upper," "lower," "left," "right," "inner," and "outer" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, they are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, the terms used to describe positional relationships in the accompanying drawings are only for illustrative purposes and should not be construed as limiting the present invention. For those skilled in the art, the specific meaning of the above terms can be understood according to the specific circumstances.
[0055] In the description of this invention, unless otherwise explicitly specified and limited, the term "connection" or similar designation indicating a connection between components should be interpreted broadly. For example, it can refer to a fixed connection, a detachable connection, or an integral part; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium; it can refer to the internal communication between two components or the interaction between two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.
[0056] like Figures 1 to 2 As shown in the figure, this embodiment discloses a method and apparatus for finding entity association paths in a knowledge graph.
[0057] The first aspect of this embodiment discloses a method for finding entity association paths in a knowledge graph, such as... Figure 1 As shown, the method includes a family structure dynamic maintenance phase and a path query phase.
[0058] The dynamic maintenance phase of the family structure aims to maintain a global family table, which records the family to which each entity belongs. A family represents a connected component in the knowledge graph, meaning that there is a direct or indirect relationship path between any two entities within the same family, while entities in different families are not connected by a path.
[0059] In some implementations of this embodiment, the global family table can be implemented using a hash table. For example, the key of the hash table is the unique identifier of the entity (such as the entity name), and the value of the hash table is the unique identifier of the family to which the entity belongs (family identifier).
[0060] In actual programming implementation, the "family identifier" can be represented as a memory address, reference, or handle pointing to the data structure storing family information, so as to achieve efficient association access.
[0061] Initially, both the knowledge graph and the global family table are empty.
[0062] The dynamic maintenance phase of the family structure includes step S100.
[0063] Step S100. When incrementally inserting a relation triple into the knowledge graph, query a global family table to determine the connection relationship between the triple and existing families: if the triple has no connection with any family, then the entity contained in the triple is set as a new family, and the family identifier is created and recorded in the global family table; if the triple has a connection relationship with one or more existing families, then the entity contained in the triple is assigned to the family determined by the connection relationship, and the global family table is updated.
[0064] In some implementations of this embodiment, the rule for determining the connection relationship between a triple and an existing family is as follows: if an entity in the triple already exists in the global family table, it is determined that it has a connection with the family corresponding to the recorded family identifier; otherwise, it is determined that it has no connection with any family.
[0065] In some embodiments of this example, when the knowledge graph is empty, the entities contained in the first inserted triple are set as a new independent family.
[0066] In this embodiment, when two entities in the triple are assigned to different families, the two families are merged into one family, and the global family table is updated with the unified family identifier of the merged family.
[0067] The path query phase is executed when a user or system initiates a path query request, and the path query phase includes step S200.
[0068] Step S200. In response to the path query request for the starting entity and the target entity, query the global family table to determine whether the two have the same family identifier: if the family identifiers are different, return the result of no associated path directly; if the family identifiers are the same, determine the corresponding entity set based on the family identifier, and perform graph search in the entity set to obtain the associated path between the two.
[0069] In this embodiment, all entities belonging to the same family can be quickly retrieved from the global family table based on the same family identifier, forming a definite search subgraph, which greatly narrows the search scope.
[0070] In some implementations of this embodiment, the entities contained therein are assigned to a family determined by the connection relationship, including: if the triple is connected to only one family, then it is assigned to that family; if the triple is connected to two different families, then the two entities in the triple are assigned to the two different families respectively.
[0071] In some implementations of this embodiment, merging two families into one family includes: comparing the number of entities contained in each of the two families to be merged; and modifying the family identifier of the entity in the family with fewer entities to the family identifier of the family with more entities.
[0072] In these implementations, for two families with a connection relationship, merging the family with fewer entities into the family with more entities can minimize the number of entities that need to update the family identifier, thereby improving the efficiency of family merging.
[0073] In some implementations of this embodiment, the family identifier of entities in a family with fewer entities is modified to the family identifier of a family with more entities using a depth-first search (DFS) algorithm.
[0074] For example, to merge a family A with fewer entities and a family B with more entities, we start from any entity in family A and execute a depth-first search algorithm. During the traversal of the depth-first search algorithm, for each entity belonging to family A that is visited, its family identifier in the global family table is updated from A to B. After the traversal is complete, family A no longer exists, all its entities now belong to family B, and the global family table is updated.
[0075] In some implementations of this embodiment, querying the global family table to determine whether the two entities have the same family identifier includes: obtaining the entity's family identifier from the global family table through a binary search operation; and determining whether the family identifiers of the starting entity and the target entity are the same.
[0076] In these implementations, the binary search method is used to find the family to which the entity belongs, with a time complexity of O(logn), where n is the number of families, thereby improving the search efficiency.
[0077] In some implementations of this embodiment, a graph search is performed within a defined set of entities using a breadth-first search (BFS) algorithm to obtain the associated path between them, and the first path found is the shortest path between the starting entity and the target entity.
[0078] In these implementations, if the user needs the Top-K paths or all paths, the search can continue based on the breadth-first search algorithm.
[0079] The method of this embodiment will be illustrated below with an example.
[0080] Initially, both the knowledge graph and the global family table are empty.
[0081] Insert a triple (entity 1, relation 1, entity 2) into the knowledge graph. At this time, neither entity 1 nor entity 2 is in the global family table. Create a new family A, and both entity 1 and entity 2 belong to family A.
[0082] Next, insert a triple (entity 3, relation 2, entity 4) into the knowledge graph. At this point, neither entity 3 nor entity 4 is in the global family table. Create a new family B, and both entity 3 and entity 4 belong to family B.
[0083] Next, insert a triple (entity 5, relation 3, entity 6) into the knowledge graph. At this point, neither entity 5 nor entity 6 is in the global family table. Create a new family C, and both entity 5 and entity 6 belong to family C.
[0084] Then insert a triple (entity 1, relation 4, entity 7) into the knowledge graph. At this time, entity 1 is in family A, entity 7 is not in the global family table, and the triple has a connection relationship with family A. Therefore, entity 7 is assigned to family A.
[0085] Next, insert a triple (entity 1, relation 5, entity 3) into the knowledge graph. At this time, entity 1 is in family A and entity 3 is in family B. This triple has connections with both family A and family B, triggering a merge operation between family A and family B. Since the number of entities in family B is less than the number of entities in family A, the family identifier of the entities in family B is updated to family A.
[0086] After the above operations, Group A includes Entity 1, Entity 2, Entity 3, Entity 4 and Entity 7, and Group C includes Entity 5 and Entity 6.
[0087] Suppose we want to find the path between entity 1 and entity 4. If we query the global family table and find that both entity 1 and entity 4 belong to family A, then entity 1 and entity 4 are connected. Then we perform a breadth-first search algorithm within the entity set {entity 1, entity 2, entity 3, entity 4, entity 7} corresponding to family A. It is possible to find the path entity 1-entity 3-entity 4. This path is the shortest path.
[0088] The second aspect of this embodiment discloses an apparatus for finding entity association paths in a knowledge graph, such as... Figure 2 As shown, the device includes a family structure maintenance module and a path query module.
[0089] The family structure maintenance module is configured to perform dynamic maintenance operations when incrementally inserting relation triples into the knowledge graph.
[0090] Specifically, the family structure maintenance module includes a connection relationship judgment unit, a family affiliation determination unit, and a family merging processing unit.
[0091] The connection relationship determination unit is configured to query a global family table and determine the connection relationship between the entity in the triple and an existing family in the table.
[0092] The family affiliation determination unit is configured to determine the family affiliation of the entities contained in the triple based on the judgment result of the connection relationship judgment unit: if the triple has no connection with any family, the entities contained in the triple are set as a new family, and this family identifier is created and recorded in the global family table; if the triple has a connection relationship with one or more existing families, the entities contained in it are assigned to the family determined by the connection relationship, and the global family table is updated.
[0093] The family merging processing unit is configured to merge the two families into one family when the two entities in the triple are assigned to different families, and update the global family table with the unified family identifier of the merged family.
[0094] The path query module is configured to perform a query operation in response to a path query request for the starting entity and the target entity.
[0095] Specifically, the path query module includes a connectivity prediction unit, a result generation unit, and a path search unit.
[0096] The connectivity prediction unit is configured to query the global family table to determine whether the starting entity and the target entity have the same family identifier.
[0097] The result generation unit is configured to directly return a determination result of no associated path when the family identifiers of the starting entity and the target entity are different.
[0098] The path search unit is configured to determine the corresponding entity set based on the family identifier when the family identifiers of the starting entity and the target entity are the same, and to perform a graph search within the entity set to obtain the associated path between the two.
[0099] It should be noted that those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system or device described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0100] The third aspect of this embodiment discloses an electronic device, which includes a processor and a memory.
[0101] The memory is connected to the processor and is used to store computer programs.
[0102] When the processor executes the computer program, it implements a method for finding entity association paths in a knowledge graph as described in the first aspect of this embodiment.
[0103] The fourth aspect of this embodiment discloses a computer-readable storage medium storing a computer program that, when executed by a processor, implements a method for finding entity association paths in a knowledge graph as described in the first aspect of this embodiment.
[0104] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for finding entity association paths in a knowledge graph, characterized in that, This includes the dynamic maintenance phase of the family structure and the path query phase: The dynamic maintenance phase of the family structure includes the following steps: When inserting a relation triple into the knowledge graph incrementally, a global family table is queried to determine the connection relationship between the triple and existing families: if the triple has no connection with any family, the entities contained in the triple are set as a new family, and the family identifier is created and recorded in the global family table; if the triple has a connection relationship with one or more existing families, the entities contained in the triple are assigned to the family determined by the connection relationship, and the global family table is updated. When two entities in the triple are assigned to different families, the two families are merged into one family, and the global family table is updated with the unified family identifier of the merged family. The path query phase includes the following steps: In response to a path query request for the starting entity and the target entity, the global family table is queried to determine whether the two have the same family identifier: if the family identifiers are different, the result of determining that there is no associated path is returned directly; if the family identifiers are the same, the corresponding entity set is determined based on the family identifier, and a graph search is performed in the entity set to obtain the associated path between the two.
2. The method for finding entity association paths in a knowledge graph according to claim 1, characterized in that, The entities it contains are classified into families determined by this connection, including: If the triple is connected to only one family, then it is assigned to that family; If the triple is connected to two different families, then the two entities in the triple are assigned to the two different families respectively.
3. The method for finding entity association paths in a knowledge graph according to claim 1, characterized in that, Merging two families into one family includes: Compare the number of entities contained in each of the two groups to be merged; Modify the family identifier of entities in families with fewer entities to the family identifier of families with more entities.
4. The method for finding entity association paths in a knowledge graph according to claim 3, characterized in that, Modify the family identifier of entities in families with fewer entities to the family identifier of families with more entities, including: By using a depth-first search algorithm, the family identifiers of entities in families with fewer entities are modified to the family identifiers of families with more entities.
5. The method for finding entity association paths in a knowledge graph according to claim 1, characterized in that, Query the global family table to determine whether the two have the same family identifier, including: The family identifier of the entity is obtained from the global family table using a binary search operation; Determine whether the family identifiers of the starting entity and the target entity are the same.
6. The method for finding entity association paths in a knowledge graph according to claim 1, characterized in that, Perform a graph search within this entity set to obtain the association path between the two entities, including: A graph search is performed within the entity set using a breadth-first search to obtain the association path between the two entities, and the first path found is the shortest path between the starting entity and the target entity.
7. An apparatus for finding entity association paths in a knowledge graph, characterized in that, include: The family structure maintenance module is configured to perform dynamic maintenance operations when incrementally inserting relation triples into the knowledge graph; The path query module is configured to perform query operations in response to path query requests for the starting entity and the target entity; The family structure maintenance module includes: The connection relationship determination unit is configured to query a global family table and determine the connection relationship between the entity in the triplet and an existing family in the table. The family affiliation determination unit is configured to determine the family affiliation of the entities contained in the triple based on the judgment result of the connection relationship judgment unit: if the triple has no connection with any family, the entities contained in the triple are set as a new family, and this family identifier is created and recorded in the global family table; if the triple has a connection relationship with one or more existing families, the entities contained in it are assigned to the family determined by the connection relationship, and the global family table is updated. The family merging processing unit is configured to merge the two families into one family when the two entities in the triple are assigned to different families, and update the global family table with the unified family identifier of the merged family. The path query module includes: The connectivity prediction unit is configured to query the global family table to determine whether the starting entity and the target entity have the same family identifier. The result generation unit is configured to directly return a determination result of no associated path when the family identifiers of the starting entity and the target entity are different. The path search unit is configured to determine the corresponding entity set based on the family identifier when the family identifiers of the starting entity and the target entity are the same, and to perform a graph search within the entity set to obtain the associated path between the two.
8. An electronic device, characterized in that, include: processor; A memory, connected to the processor, is used to store computer programs; When the processor executes the computer program, it implements a method for finding entity association paths in a knowledge graph as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The storage medium stores a computer program that, when executed by a processor, implements a method for finding entity association paths in a knowledge graph as described in any one of claims 1 to 6.