Method, device and equipment for constructing knowledge graph
By obtaining the directory tree of the target document, generating an initial summary and determining the priority access order, using a large language model to generate the target summary, clustering and defining entity types, and determining relationship triples, the problems of applicability of knowledge graph construction and cross-document recognition in existing technologies are solved, and high-quality knowledge graph construction is achieved.
Patent Information
- Application Number
- CN202510805265.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-16
- Publication Date
- 2025-10-17
AI Technical Summary
In the existing technology, the applicability of knowledge graph construction based on fine-tuned language models is poor. Pattern-guided KGC relies on manually defined patterns and cannot identify concept dependencies across documents. KGC based on reference knowledge integration cannot obtain proprietary terms and abbreviations of internal systems, resulting in poor quality of the constructed knowledge graph.
By obtaining the directory tree of the target document, generating an initial summary and determining the priority access order, using a large language model to generate the target summary, performing entity type clustering and definition, determining relationship triples, and constructing a knowledge graph.
It improves the accuracy of triples and builds a high-quality knowledge graph that can inherit knowledge across documents and adapt to the complexity of domain-specific corpora.
Smart Images

Figure CN120806080A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, more particularly, to a method, device and equipment for constructing knowledge graph. BACKGROUND
[0002] With the development of computer technology, the application of knowledge graph is more and more widely, the higher the quality of the constructed knowledge graph, the stronger the reasoning ability of the downstream application of specific scene generated based on the knowledge graph, for example, the question and answer system generated based on the knowledge graph can mine the structured knowledge in the private document in the above specific scene.
[0003] In the prior art, the knowledge graph is constructed by using the knowledge graph construction (KGC) based on fine-tuning language model, the KGC based on pattern guidance and the KGC based on reference knowledge integration, wherein the KGC based on fine-tuning language model needs to update the language model according to the corpus of specific field, the applicability of the language model is poor; the KGC based on pattern guidance depends on the manually defined pattern and only depends on the relationship identified in the single document, and cannot solve the concept dependence across documents; the KGC based on reference knowledge integration depends on external knowledge, and for the private corpus such as internal system specification or cloud system operation case, the special terms, concepts and abbreviations in specific scene or specific field are only known by internal personnel, and the external knowledge cannot be obtained through public network, resulting in poor quality of the constructed knowledge graph.
[0004] In summary, how to construct a high-quality knowledge graph is a problem to be solved at present. SUMMARY
[0005] Therefore, the embodiments of the present application provide a method, device and equipment for constructing knowledge graph, which can improve the accuracy of triple and further construct a high-quality knowledge graph.
[0006] In a first aspect, an embodiment of the present application provides a method for constructing a knowledge graph, the method comprising: obtaining a directory tree in a target document, wherein the directory tree comprises a root node, at least one directory node, and at least one child node; generating initial abstracts of the at least one child node, the at least one directory node, and the root node in sequence according to the directory tree; determining a priority access order of the root node, at least one directory node, and at least one child node according to the initial abstracts; generating target abstracts of the at least one child node in sequence according to the priority access order; determining a plurality of entity types according to the target abstracts; clustering the plurality of entity types to generate a plurality of entity type clusters, wherein each entity type cluster comprises at least one entity type; determining a definition of each entity type in the entity type cluster according to each entity type cluster; and determining at least one relationship triple corresponding to each child node according to the definitions of the plurality of entity types, wherein the relationship triple is a basic unit for constructing the knowledge graph.
[0007] Optionally, the method further comprises constructing a knowledge graph according to the plurality of relationship triples.
[0008] Optionally, the generating of the initial abstracts of the at least one child node, the at least one directory node, and the root node in sequence according to the directory tree specifically comprises: traversing the directory tree in a set order to generate the initial abstracts of the at least one child node, the at least one directory node, and the root node in sequence.
[0009] Optionally, the generating of the initial abstracts of the at least one child node, the at least one directory node, and the root node specifically comprises: inputting a raw document corresponding to each child node into a large language model to output an initial abstract of the child node; inputting initial abstracts of a plurality of child nodes included in each directory node into the large language model to output an initial abstract of the directory node; and inputting initial abstracts of a plurality of directory nodes included in the root node into the large language model to output an initial abstract of the root node.
[0010] Optionally, the generating of the target abstracts of the at least one child node in sequence according to the priority access order specifically comprises: determining a query vector according to a raw document of the child node; obtaining target abstracts of a plurality of precedent nodes related to the child node in a vector database according to the query vector; and determining a target abstract of the child node according to the raw document of the child node and the target abstracts of the plurality of precedent nodes.
[0011] Optionally, the method further comprises: determining a corresponding embedding vector according to the target abstract of the child node; and saving the embedding vector and the target abstract of the child node to the vector database.
[0012] Optionally, the determining the plurality of entity types according to the target summary specifically comprises: inputting preset first prompt word information, text content of each of the sub-nodes, and the corresponding target summary into a large language model, and outputting the plurality of entity types.
[0013] Optionally, the determining the definition of each entity type in the entity type cluster according to each of the entity type clusters specifically comprises: inputting preset second prompt word information, the entity type cluster, and the target summary corresponding to the entity type cluster into a large language model, and outputting the definition of the plurality of entity types in the entity type cluster.
[0014] Optionally, the determining the at least one relationship triple corresponding to each of the sub-nodes according to the definition of the plurality of entity types specifically comprises: determining an entity pair in an original document corresponding to each of the sub-nodes according to the definition of the plurality of entity types; and determining the relationship triple according to the entity pair.
[0015] In a second aspect, an embodiment of the present application provides a device for constructing a knowledge graph, the device comprising: an acquisition unit configured to acquire a directory tree in a target document, wherein the directory tree comprises a root node, at least one directory node, and at least one sub-node; a generation unit configured to generate initial summaries of the at least one sub-node, the at least one directory node, and the root node in sequence according to the directory tree; a determination unit configured to determine a priority access order of the root node, the at least one directory node, and the at least one sub-node according to the initial summaries; the generation unit is further configured to generate target summaries of the at least one sub-node in sequence according to the priority access order; the determination unit is further configured to determine a plurality of entity types according to the target summaries; the generation unit is further configured to cluster the plurality of entity types to generate a plurality of entity type clusters, wherein each of the entity type clusters comprises at least one entity type; the determination unit is further configured to determine a definition of each entity type in the entity type cluster according to each of the entity type clusters; and the determination unit is further configured to determine at least one relationship triple corresponding to each of the sub-nodes according to the definition of the plurality of entity types, wherein the relationship triple is a basic unit for constructing the knowledge graph.
[0016] Optionally, the device further comprises a construction unit configured to construct the knowledge graph according to the plurality of relationship triples.
[0017] Optionally, the generation unit is specifically configured to traverse the directory tree in a set order, and generate the initial summaries of the at least one sub-node, the at least one directory node, and the root node in sequence.
[0018] Optionally, the generating unit is specifically configured to: input the original document corresponding to each of the sub-nodes into a large language model to output an initial summary of the sub-node; input the initial summaries of the plurality of sub-nodes included in each of the directory nodes into the large language model to output an initial summary of the directory node; and input the initial summaries of the plurality of directory nodes included in the root node into the large language model to output an initial summary of the root node.
[0019] Optionally, the generating unit is specifically configured to: determine a query vector according to the original document of the sub-node; obtain target summaries of a plurality of precedent nodes related to the sub-node from a vector database according to the query vector; and determine a target summary of the sub-node according to the original document of the sub-node and the target summaries of the plurality of precedent nodes.
[0020] Optionally, the generating unit is further configured to: determine a corresponding embedding vector according to the target summary of the sub-node; and the apparatus further includes a saving unit configured to save the embedding vector and the target summary of the sub-node to the vector database.
[0021] Optionally, the determining unit is specifically configured to: input the pre-set first prompt word information, the text content of each of the sub-nodes, and the corresponding target summary into a large language model to output a plurality of entity types.
[0022] Optionally, the determining unit is specifically configured to: input the pre-set second prompt word information, the entity type cluster, and the target summary corresponding to the entity type cluster into a large language model to output definitions of the plurality of entity types in the entity type cluster.
[0023] Optionally, the determining unit is specifically configured to: determine an entity pair in the original document corresponding to each of the sub-nodes according to the definitions of the plurality of entity types; and determine a relationship triple according to the entity pair.
[0024] In a third aspect, an electronic device is provided, including a memory and a processor, the memory is configured to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method in the first aspect or any possible implementation of the first aspect.
[0025] In a fourth aspect, a computer readable storage medium is provided, which stores computer program instructions, and the computer program instructions are executed by a processor to implement the method in the first aspect or any possible implementation of the first aspect.
[0026] In the embodiment of the present application, a directory tree in a target document is acquired, wherein the directory tree comprises a root node, at least one directory node and at least one subnode; initial abstracts of the at least one subnode, the at least one directory node and the root node are generated in sequence according to the directory tree; a priority access order of the root node, the at least one directory node and the at least one subnode is determined according to the initial abstracts; target abstracts of the at least one subnode are generated in sequence according to the priority access order; a plurality of entity types are determined according to the target abstracts; the plurality of entity types are clustered to generate a plurality of entity type clusters, wherein each of the entity type clusters comprises at least one entity type; definitions of each of the entity types in the entity type clusters are determined according to each of the entity type clusters; at least one relationship triple corresponding to each of the subnodes is determined according to the definitions of the plurality of entity types, wherein the relationship triple is a basic unit for constructing a knowledge graph. Through the above method, the accuracy of the generated triples can be improved, and a high-quality knowledge graph can be constructed. BRIEF DESCRIPTION OF DRAWINGS
[0027] The above and other objects, features and advantages of the present application will become more apparent from the following description of the embodiments of the present application taken with reference to the accompanying drawings, in which:
[0028] Figure 1 is a flowchart of a method for constructing a knowledge graph in an embodiment of the present application;
[0029] Figure 2 is a schematic diagram of a Prometheus document directory in an embodiment of the present application;
[0030] Figure 3 is a flowchart of another method for constructing a knowledge graph in an embodiment of the present application;
[0031] Figure 4 is a flowchart of still another method for constructing a knowledge graph in an embodiment of the present application;
[0032] Figure 5 is a flowchart of yet another method for constructing a knowledge graph in an embodiment of the present application;
[0033] Figure 6 is a flowchart of a method for constructing a knowledge graph in an embodiment of the present application;
[0034] Figure 7 is a schematic diagram of a system structure for constructing a knowledge graph in an embodiment of the present application;
[0035] Figure 8 is a schematic diagram of an apparatus for constructing a knowledge graph in an embodiment of the present application;
[0036] Figure 9FIG. 1 is a schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0037] The present application is described below based on examples, but the present application is not limited to only the examples. In the following detailed description of the present application, some specific details are described in detail. The present application can also be fully understood without the description of these specific details by those skilled in the art. In order to avoid confusion of the essence of the present application, well-known methods, processes, procedures, elements and circuits are not described in detail.
[0038] In addition, it should be understood by those of ordinary skill in the art that the drawings provided herein are for illustrative purposes only and are not necessarily drawn to scale.
[0039] Unless the context clearly requires otherwise, throughout the description, the words "comprise", "comprising", and the like are to be construed in an inclusive sense as opposed to an exclusive or exhaustive sense; that is to say, in the sense of "including, but not limited to".
[0040] In the description of the present application, it should be understood that the terms "first", "second", and the like are used only for the purpose of description and should not be construed as indicating or implying relative importance. In addition, in the description of the present application, unless otherwise stated, the meaning of "a plurality of" is two or more.
[0041] In the prior art, a Konwledge Graph (KG) refers to a semantic network architecture that organizes information through graph structure data composed of nodes and edges, formally represents the attributes and relationships between real-world entities, and uses subject-predicate-object triplets to systematically organize knowledge, supporting downstream applications that require complex reasoning. For example, a Graph-Based Retrieval-Augmented Generation (Graph RAG) system can realize the mapping of natural language and related entities, providing structured knowledge support for question and answer systems. The above-mentioned retrieval-augmented generation refers to a technology that combines information retrieval and generation models. The core idea is to retrieve relevant information from external knowledge bases to provide real-time, domain-specific context support for generative models. Knowledge Graph Construction (KGC) refers to the process of automatically or semi-automatically extracting entities and relationships from unstructured or semi-structured data and forming a knowledge graph. Specifically, relationship triplets and their attributes are extracted from data sources and organized into coherent graph structures. Due to the large volume and high complexity of the data, manual construction of knowledge graphs is inefficient. When generating a knowledge graph based on a domain-specific corpus, there are issues such as knowledge dependency complexity, domain specialization, and limited reference knowledge. The domain-specific corpus in the above-mentioned domain-specific corpus is a collection of texts collected for a specific professional field (e.g., computer system operation and maintenance), used to train or analyze large language models (LLMs) in that field, with highly specialized terminology and expression characteristics. The large language model is based on a large-scale pre-trained natural language processing model. The above-mentioned knowledge dependency complexity refers to the hierarchical progression of domain knowledge from basic to advanced concepts, requiring cross-text reference analysis. The above-mentioned domain specialization refers to the inclusion of a large number of technical terms, domain-specific abbreviations, and complex implementation details. The above-mentioned limited reference knowledge refers to the fact that enterprise private documents and cloud system operation cases cannot be obtained through external knowledge sources.
[0042] To solve the above problems, the following methods are proposed to construct a knowledge graph: a knowledge graph construction based on a fine-tuned language model (KGC), a KGC based on schema guidance, and a KGC based on reference knowledge integration. In the KGC based on a fine-tuned language model, COMET predicts the tail entity given the head entity and the relation in a triple, and REBEL uses self-supervised learning to directly predict text to triples. Both COMET and REBEL are based on generative language models such as Bidirectional and Auto-Regressive Transformers (BART), which need to be updated according to the corpus of a specific domain (i.e., fine-tuning the language model), and the applicability of the language model is poor. The KGC based on schema guidance relies on the schema or ontology in the artificially defined schema to formally define the KG entities, relations, and attributes of entities and relations, ensuring the semantic consistency and quality of the constructed KG. It uses the context learning ability of LLMs to extract and align triples through schema-guided prompts. For example, CoT-Ontology combines domain schema and thought chain prompts to implement step-by-step triple extraction. The Recursive Acquisition Process (RAP) proposes a schema-aware retrieval enhancement method that dynamically integrates structured schema knowledge and semantically related instances as context prompts. AdaKGC introduces a schema-enhanced prefix instructor and a dynamic decoding method that can handle schema changes without model retraining. The Entity-Data-Context Framework (EDC) decouples KGC into three stages: open information extraction, schema definition, and schema normalization, which is suitable for scenarios where there is no predefined schema. However, these methods have limitations in handling domain-specific corpora, such as relying on artificially defined schema and ignoring knowledge dependency. Specifically, CoT-Ontology and RAP both rely on predefined schema to optimize prompts. AdaKGC supports dynamic schema adjustment during KG construction or maintenance, but cannot create a schema from scratch. EDC can dynamically construct a schema based on input text, but its schema definition stage only relies on relationships identified within a single document, making it impossible to solve cross-document concept dependencies. The KGC based on reference knowledge integration relies on external knowledge to enhance the KGC process by integrating multi-source knowledge, including search engines, open KGs, and domain corpora, to enable LLMs to have contextual domain awareness to improve triple extraction accuracy. Specifically, the SAC-KG framework uses domain corpora and DBpedia to retrieve relevant contexts and triples for specified entities. TKGCon generates a topic schema based on Wikipedia categories to construct a fine-grained topic KG, reducing the cost of manual work and adapting to knowledge updates.AutoKG works collaboratively through role-playing agent agents, integrating real-time Internet search systems; Papaluca et al. proposed KBTE pipeline dynamically aggregates input corpus derived knowledge base (context information, including context triples and <sentence, triple> pairs as few-shot examples); the above methods face limitations due to reliance on external knowledge, SAC-KG requires open source KG seed entities and reference triples, TKGCon uses the Wikipedia classification system, AutoKG relies on network search, and KBTE is based on manually annotated real triples to build a knowledge base for private corpus such as internal system specifications or cloud system operation cases, and specific scenarios or specific domain-specific terminology, concepts and abbreviations are only known by internal personnel, and external knowledge cannot be obtained through public networks, resulting in poor quality of the constructed knowledge graph. Therefore, how to construct a high-quality knowledge graph is a problem that needs to be solved at present.
[0043] In the embodiment of the application, in order to solve the above problems, a method for constructing a knowledge graph is provided, as shown in Figure 1 The method comprises the following steps:
[0044] Step S101, acquiring a directory tree in a target document.
[0045] The directory tree comprises a root node, at least one directory node and at least one sub-node.
[0046] Specifically, the above target document is a domain-specific corpus, for example, the target document is an open source monitoring system Prometheus document, as shown in Figure 2As shown, the Prometheus document is a directory tree structure, wherein the root node is the Prometheus document, the directory nodes are the Introduction node, the Concepts node, and the Best Practices node, etc. The Introduction node includes the Design Documents sub-node, the Roadmap sub-node, etc. The Concepts node includes the data model sub-node, the metric types sub-node, etc. The Best Practices node includes the Metric Naming sub-node, the Alerting sub-node, etc. The text content corresponding to the plurality of sub-nodes under the Introduction node helps to understand the overall architecture of the open source monitoring system. The text content corresponding to the plurality of sub-nodes under the Concepts node helps to understand the components and terms of the open source monitoring system. The text content corresponding to the plurality of sub-nodes under the Best Practices node is various downstream application cases.
[0047] In a possible implementation, the open source monitoring system Prometheus document is a multi-level hierarchical structure document. If the target document is a long unstructured text without a directory structure, the long unstructured text can be segmented into blocks, and each block is regarded as an independent document to establish a single-layer flat structure document.
[0048] In step S102, initial summaries of the at least one sub-node, the at least one directory node, and the root node are generated in sequence according to the directory tree.
[0049] In a possible implementation, the directory tree is traversed in a set order, and initial summaries of the at least one sub-node, the at least one directory node, and the root node are generated in sequence. Specifically, as shown in Figure 3 As shown, the method comprises the following steps:
[0050] In step S301, the original document corresponding to each sub-node is input into a large language model, and an initial summary of the sub-node is output.
[0051] For example, the original document corresponding to the Design Documents child node is input into the large language model to output an initial summary of the Design Documents child node; then the original document corresponding to the Roadmap child node is input into the large language model to output an initial summary of the Roadmap child node; the initial summary of the Design Documents child node and the initial summary of the Roadmap child node are independent summaries, and there is no cross-document reference between the summaries. This is only an example.
[0052] In a possible implementation, the large language model can be Llama-3.1-70B-Instruct. This is only an example.
[0053] In step S302, the initial summaries of the plurality of child nodes included in each of the directory nodes are input into the large language model to output an initial summary of the directory node.
[0054] For example, when the directory node is the Introduction node, after the initial summaries of all child nodes under the Introduction node are determined in step 301, the initial summaries of all child nodes under the Introduction node are input into the large language model to output an initial summary of the Introduction node. The initial summaries of all directory nodes under the root node are determined according to the above method.
[0055] In step S303, the initial summaries of the plurality of directory nodes included in the root node are input into the large language model to output an initial summary of the root node.
[0056] For example, when the root node is the Prometheus document, the initial summaries of all directory nodes under the Prometheus document, such as the Introduction node, the Concepts node, and the Best Practices node, are input into the large language model to output an initial summary of the root node.
[0057] In the embodiment of the application, the set order is the order of the directory tree from bottom to top, that is, the order from the child node to the directory node and then to the root node.
[0058] In step S103, the priority access order of the root node, at least one directory node, and at least one child node is determined according to the initial summaries.
[0059] Specifically, the dependency evaluation module traverses all nodes in the directory tree from top to bottom, at each level, the initial summary of each node at this level is used to build a prompt input into a large language model to evaluate the optimal access order, and if a subdirectory is encountered, recursive application is used to determine the access order, for example, the Introduction node, the Concepts node and the Best Practices node at the same level are sorted to determine that the Introduction node is accessed first, and since the Introduction node includes a subdirectory, i.e., the mechanical energy of the child node under the Introduction node is recursively sorted, and then the Concepts node and the Best Practices node are sorted, which is only an exemplary illustration.
[0060] Step S104, generating target summaries of the at least one child node in turn according to the priority access order.
[0061] Specifically, the target summaries of the at least one child node are generated in turn according to the priority access order, as shown in the following steps. Figure 4 As shown, the steps include:
[0062] Step S401, determining a query vector according to the original document of the child node.
[0063] The query vector is generated by compressing the original document of the child node, and is a semantic representation of the child node.
[0064] Step S402, obtaining target summaries of a plurality of previous nodes related to the child node in a vector database according to the query vector.
[0065] Specifically, the vector database includes embedding vectors of a plurality of sorted child nodes and target summaries of the plurality of sorted child nodes, and target summaries of the first K previous child nodes related to the child node are obtained in the vector database according to the condition that the cosine distance between the query vector and the embedding vector is minimum, where K is a positive integer greater than or equal to 1.
[0066] In the embodiment of the application, the reason for obtaining the first K previous nodes is that when generating the target summary of the child node, the historical knowledge of previously accessed documents needs to be referred to to generate a context-enhanced summary, and the autoregressive method ensures that each target summary refers to prior knowledge, and through ordered knowledge integration, a comprehensive knowledge base is gradually constructed, when processing a large amount of data, due to the context length limitation of the large language model, all previous document summaries cannot be included in the prompt, therefore, the target summaries of the first K previous child nodes which can be used as reference knowledge are determined by the above-mentioned method, and the length of the reference knowledge context can adapt to the context length of the large language model.
[0067] Step S403, determining the target summary of the child node according to the original document of the child node and the target summaries of the plurality of precedent nodes.
[0068] Specifically, inputting the original document of the child node and the target summaries of the plurality of precedent nodes into a large language model to output the target summary of the child node.
[0069] For example, the target summary of the child node is "Prometheus client library provides four core metric types: Counter, Gauge, Histogram, and Summary. These types are clearly distinguished in the client library and the transmission protocol, but the Prometheus server currently flattens all data into untyped time series", which is only an example for illustration, and the specific target summary is determined based on the actual situation.
[0070] In one possible implementation, after the step 403, other steps are further included, specifically as follows Figure 5 As shown, the following steps are included
[0071] Step S404, determining the corresponding embedding vector according to the target summary of the child node.
[0072] Step S405, saving the embedding vector and the target summary of the child node to the vector database.
[0073] In the embodiment of the application, after the target summary of the child node is saved to the vector database, it serves as reference knowledge for generating the target summary of the child node in sequence.
[0074] In the embodiment of the application, the steps S101 to S104 are executed by using a dependency evaluation module.
[0075] Step S105, determining a plurality of entity types according to the target summary.
[0076] Specifically, inputting the pre-set first prompt word information, the text content of each child node, and the corresponding target summary into a large language model to output a plurality of entity types.
[0077] For example, the first prompt word information is "Task: Provide a text and its summary below. Please refer to the summary and the text content to classify the meaningful entities in the text, and return a list containing all entity types", the text content of any sub-node is "Counter is a cumulative type of indicator …", and the target summary of the any sub-node is "Prometheus client library provides four core types of indicators: Counter, Gauge, Histogram and Summary"; the "Task: Provide a text and its summary below. Please refer to the summary and the text content to classify the meaningful entities in the text, and return a list containing all entity types", "Counter is a cumulative type of indicator …" and "Prometheus client library provides four core types of indicators: Counter, Gauge, Histogram and Summary" are input into the large language model, and the large language model outputs [Counter, Gauge, Histogram, Summary]; the Counter, Gauge, Histogram and Summary are entity types.
[0078] In the embodiment of the application, a plurality of entity types can be generated through a plurality of target summaries of a plurality of sub-nodes.
[0079] In step S106, the plurality of entity types are clustered to generate a plurality of entity type clusters.
[0080] Each of the entity type clusters includes at least one entity type.
[0081] Specifically, the plurality of entity types are redundant, in order to solve the problems of anaphora resolution and deduplication, first, the entity types that appear only once in the plurality of entity types are filtered out, then all the entity types are vectorized into embedding vectors, and the K-means clustering algorithm is used to aggregate the entity types with similar semantics, and the specific formula is as follows:
[0082]
[0083] Wherein, the x i represents the embedding vector of the i-th entity type, and the u j represents the center vector of each entity type cluster, and the S={C1, C2, …, C k is a set of all entity type clusters, and the C k represents an entity type cluster, and the k represents the number of clusters, which can also be referred to as the number of clusters.
[0084] In a possible implementation, the cluster number k is a hyperparameter, and an optimal k value is automatically determined by a silhouette coefficient s, which is a quantitative indicator for evaluating clustering quality, and a higher value indicates better clustering quality, stronger intra-cluster aggregation, and stronger inter-cluster separation:
[0085]
[0086] wherein a(i) is the intra-cluster average distance (i.e., compactness) of the entity type vector; b(i) is the nearest cluster average distance (i.e., separation) of the entity type vector i; and N represents the number of clusters in the current partition.
[0087] In the embodiment of the application, k is traversed from 1 to Kmax, for each k, all partitions S are traversed, for each S, formula 1 is calculated, the minimum S of formula 1 is obtained, that is, the best partition under the current k value, and the silhouette coefficient s is calculated using the current partition S.
[0088]
[0089] For each k, there is a (k, S, s) combination, that is, (cluster number, optimal partition corresponding to the current cluster number, silhouette coefficient corresponding to the current optimal partition), and the combination corresponding to the minimum S value is selected from all (k, S, s) combinations, that is, the clustering with the highest quality, and the partition result S corresponding thereto is taken as the final entity type cluster set.
[0090] In step S107, the definition of each entity type in the entity type cluster is determined according to each entity type cluster.
[0091] Specifically, the pre-set second prompt word information, the entity type cluster, and the target abstract corresponding to the entity type cluster are input into a large language model, and the definitions of the plurality of entity types in the entity type cluster are output.
[0092] In a possible implementation, vector retrieval is performed according to the entity type cluster to obtain a target abstract related thereto.
[0093] For example, the second prompt word information is "task: the following are several entity types. First, merge the types with the same semantics, and then define each merged type in one sentence. These types come from the same knowledge base, and you can refer to the relevant knowledge below", the entity type cluster is "Configuration, Configures,...", and the target summary corresponding to the entity type cluster is the reference knowledge, specifically "guides / multi-target-exporter": the document provides an example of YAML configuration for Prometheus to grab Blackbox Exporter metrics...", and the above content is input into the large language model, and the output is {Configuration: Prometheus is configured through a YAML file, which defines the target, time interval, storage settings, and alarm rules...}, which is only an example for illustration, and the specific determination is based on the actual situation.
[0094] In the embodiment, the steps S105 to S107 are executed by using the mode definition module.
[0095] Step S108, determining at least one relationship triple corresponding to each of the sub-nodes according to the definitions of the plurality of entity types.
[0096] The relationship triple is a basic unit for building a knowledge graph, and the definition of the entity type can also be referred to as an entity mode.
[0097] Specifically, the entity pairs in the original document corresponding to each of the sub-nodes are determined according to the definitions of the plurality of entity types, and the relationship triple is determined according to the entity pairs.
[0098] In one possible implementation, the third prompt word information, the original document of any sub-node, and the definitions of all entity types are input into the large language model, and the entity pairs in the original document corresponding to the sub-node are output.
[0099] For example, the third prompt word is "Task: Given the following document content, please extract meaningful entities and their types from the document according to the provided entity pattern." The original document of any child node is "This guide will introduce you to the multi-target exporter pattern...". The entity pattern is "{Configuration: Prometheus is configured by defining YAML files that specify scraping targets, time intervals, and alerting rules...}". The above content is input into the large language model, and the output entity pair is "{Configuration: [Blackbox.yml, Prometheus.yml],...}. This is only an example for illustration, and the specific determination is based on the actual situation.
[0100] In a possible implementation, the fourth prompt word information, the definition of all entity types of the original document of any child node, and the extracted entity pair are input into the large language model, and the entity pair in the original document corresponding to the child node is output.
[0101] For example, the fourth prompt word is "Task: Based on the document and the extracted entities, please identify the entity pairs with explicit relationships and list all relationship triples in the format [(subject entity, predicate, object entity)].". The original document of any child node is "This guide will introduce you to the multi-target exporter pattern...". The extracted entity pair is "{Configuration: [Blackbox.yml, Prometheus.yml],...}". The entity pattern is "{Configuration: Prometheus is configured by defining YAML files that specify scraping targets, time intervals, and alerting rules...}". The above content is input into the large language model, and the output triple is [(Prometheus.yml, defines, Scrape_configs),...]. This is only an example for illustration, and the specific determination is based on the actual situation.
[0102] In the embodiment, the step S108 is executed by using a triple extraction module.
[0103] In a possible implementation, after the step S108, other steps are further included, and the specific implementation is as follows. Figure 6 As shown in the figure, the following steps are included.
[0104] Step S109, constructing a knowledge graph according to a plurality of relationship triples.
[0105] Through the above embodiment, the documents of the plurality of child nodes generate a plurality of triples, and due to the language knowledge dependency (LKD) between the documents, cross-document knowledge inheritance is realized through context-aware target abstract generation, the generated relationship triples are relatively accurate, and the knowledge graph constructed through the relationship triples is of high quality, that is, the LKD-KGC knowledge graph construction method adopted by the application has good effects.
[0106] In the embodiment of the application, the overall structure diagram of the constructed knowledge graph is as shown in Figure 7 The method comprises a dependency evaluation module 701, a schema definition module 702 and a triple extraction module 703.
[0107] In the embodiment of the application, a device for constructing a knowledge graph is provided, as shown in Figure 8 The device comprises an acquisition unit 801, a generation unit 802 and a determination unit 803.
[0108] The acquisition unit 801 is configured to acquire a directory tree in a target document, wherein the directory tree comprises a root node, at least one directory node and at least one child node. The generation unit 802 is configured to generate initial abstracts of the at least one child node, the at least one directory node and the root node in sequence according to the directory tree. The determination unit 803 is configured to determine a priority access order of the root node, the at least one directory node and the at least one child node according to the initial abstracts. The generation unit 802 is further configured to generate target abstracts of the at least one child node in sequence according to the priority access order. The determination unit is further configured to determine a plurality of entity types according to the target abstracts. The generation unit 802 is further configured to cluster the plurality of entity types to generate a plurality of entity type clusters, wherein each entity type cluster comprises at least one entity type. The determination unit 803 is further configured to determine definitions of each entity type in each entity type cluster according to the entity type cluster. The determination unit 803 is further configured to determine at least one relationship triple corresponding to each child node according to the definitions of the plurality of entity types, wherein the relationship triple is a basic unit for constructing a knowledge graph.
[0109] Further, the device further comprises a construction unit configured to construct a knowledge graph according to the plurality of relationship triples.
[0110] Further, the generation unit is specifically configured to traverse the directory tree in a set order and generate initial abstracts of the at least one child node, the at least one directory node and the root node in sequence.
[0111] Furthermore, the generation unit is specifically used to: input the original document corresponding to each child node into the large language model and output the initial summary of the child node; input the initial summaries of the multiple child nodes included in each directory node into the large language model and output the initial summary of the directory node; input the initial summaries of the multiple directory nodes included in the root node into the large language model and output the initial summary of the root node.
[0112] Furthermore, the generation unit is specifically used to: determine a query vector based on the original document of the child node; obtain target summaries of multiple predecessor nodes related to the child node in a vector database based on the query vector; and determine the target summary of the child node based on the original document of the child node and the target summaries of multiple predecessor nodes.
[0113] Furthermore, the generating unit is further configured to: determine a corresponding embedding vector according to the target summary of the child node; and the apparatus further comprises a saving unit configured to save the embedding vector and the target summary of the child node to the vector database.
[0114] Furthermore, the determining unit is specifically configured to input the preset first prompt word information, the text content of each of the sub-nodes, and the corresponding target summary into the large language model, and output a plurality of entity types.
[0115] Furthermore, the determining unit is further configured to input the preset second prompt word information, the entity type cluster, and the target summary corresponding to the entity type cluster into the large language model, and output definitions of multiple entity types in the entity type cluster.
[0116] Furthermore, the determining unit is further configured to: determine an entity pair in the original document corresponding to each of the child nodes according to definitions of the plurality of entity types; and determine a relationship triple according to the entity pairs.
[0117] Figure 9 Schematic diagram of the structure of the electronic device in the embodiment of the present invention. Figure 9As shown, it includes a general computer hardware structure, which at least includes a processor 901 and a memory 902. The processor 901 and the memory 902 are connected through a bus 903. The memory 902 is suitable for storing instructions or programs executable by the processor 901. The processor 901 can be a stand-alone microprocessor, or a set of one or more microprocessors. Thus, the processor 901 performs the processing of data and the control of other devices by executing the instructions stored in the memory 902, thereby implementing the method flow of the embodiments of the present application as described above. The bus 903 connects the above-mentioned components together, while connecting the above-mentioned components to a display controller 904 and a display device, and an input / output (I / O) device 905. The input / output (I / O) device 905 can be a mouse, a keyboard, a modem, a network interface, a touch input device, a body sense input device, a printer, and other devices known in the art. Typically, the input / output device 905 is connected to the system through an input / output (I / O) controller 906.
[0118] The instructions stored in the memory 902 are executed by the at least one processor 901 to implement: obtaining a directory tree in a target document, wherein the directory tree includes a root node, at least one directory node, and at least one child node; generating initial summaries of the at least one child node, the at least one directory node, and the root node in turn according to the directory tree; determining a priority access order of the root node, at least one directory node, and at least one child node according to the initial summaries; generating target summaries of the at least one child node in turn according to the priority access order; determining a plurality of entity types according to the target summaries; clustering the plurality of entity types to generate a plurality of entity type clusters, wherein each of the entity type clusters includes at least one entity type; determining definitions of each entity type in the entity type cluster according to each of the entity type clusters; and determining at least one relationship triple corresponding to each of the child nodes according to the definitions of the plurality of entity types, wherein the relationship triple is a basic unit for constructing a knowledge graph.
[0119] In particular, the electronic device includes one or more processors 901 and a memory 902, Figure 9 Taking one processor 901 as an example. The processor 901 and the memory 902 can be connected through a bus or other means, Figure 9 Taking the connection through the bus as an example. The memory 902 is a non-volatile computer readable storage medium, which can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The processor 901 performs various functional applications and data processing of the device by running the non-volatile software programs, instructions and modules stored in the memory 902, that is, implements the method for determining and constructing a knowledge graph as described above.
[0120] The memory 902 can include a program storage area and a data storage area, where the program storage area can store an operating system, application programs required by at least one function, and the data storage area can store an option list and the like. In addition, the memory 902 can include a high-speed random access memory, and can also include a nonvolatile memory such as at least one disk storage device, a flash memory device, or other nonvolatile solid-state storage device. In some embodiments, the memory 902 can optionally include a memory disposed remotely with respect to the processor 901, which can be connected to an external device through a network. Examples of the above network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0121] One or more modules are stored in the memory 902, which, when executed by the one or more processors 901, perform the method of constructing a knowledge graph in any of the above method embodiments.
[0122] As those skilled in the art will appreciate, the various aspects of the embodiments of the present application can be implemented as a system, method or computer program product. Accordingly, the various aspects of the embodiments of the present application can take the form of an entirely hardware embodiment, an entirely software embodiment (including firmware, resident software, microcode, etc.) or an embodiment combining software and hardware aspects that can all generally be referred to herein as a "circuit", "module" or "system". Furthermore, the various aspects of the embodiments of the present application can take the form of a computer program product embodied in one or more computer readable medium(s) having computer readable program code embodied thereon.
[0123] Any combination of one or more computer readable medium(s) can be utilized. The computer readable medium can be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of the present embodiments, a computer readable storage medium can be any tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device.
[0124] A computer readable signal medium can include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated signal can take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium can be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
[0125] Program code embodied on a computer readable medium can be transmitted using any appropriate medium, including but not limited to wireless, wired, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0126] Computer program code for carrying out operations for aspects of the present embodiments can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++, or the like, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).
[0127] The flow diagrams depicted herein and / or described above and / or block diagrams described above and / or described below can also be stored upon computer readable media that can direct computers, other programmable data processing devices, or other devices to function in a particular manner, such that the instructions stored in the computer readable media produce an article of manufacture including instructions which implement the function / act specified in the flow diagrams and / or block diagrams and / or described above and / or described below.
[0128] The computer program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions / acts specified in the flow diagrams and / or block diagrams and / or described above and / or described below.
[0129] The computer program instructions may also be loaded onto a computer, other programmable data processing device or other apparatus to cause a series of operable steps to be performed on the computer, other programmable device or other apparatus to produce a computer-implemented process, such that the instructions executed on the computer or other programmable device provide a process for implementing the functions / actions specified in the flowchart and / or block diagram block or blocks.
[0130] The foregoing is merely a preferred embodiment of the present application and is not intended to limit the present application. Persons skilled in the art will readily appreciate that various modifications and variations are possible. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present application are intended to be within the scope of protection of the present application.
[0131] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation portals for users to choose to authorize or refuse. The user's refusal to process personal information other than the necessary information for basic functions will not affect the user's use of basic functions.
Claims
1. A method for constructing a knowledge graph, characterized in that: The method comprises: Obtaining a directory tree in a target document, wherein the directory tree includes a root node, at least one directory node, and at least one child node; According to the directory tree, generating an initial summary of the at least one child node, the at least one directory node and the root node in sequence; determining a priority access order of the root node, at least one directory node, and at least one child node according to the initial summary; sequentially generating a target summary of the at least one child node according to the priority access order; determining a plurality of entity types based on the target summary; Clustering the multiple entity types to generate multiple entity type clusters, wherein each entity type cluster includes at least one entity type; According to each entity type cluster, determining a definition of each entity type in the entity type cluster; At least one relationship triple corresponding to each of the child nodes is determined based on the definitions of the multiple entity types, wherein the relationship triple is a basic unit for constructing a knowledge graph.
2. The method according to claim 1, characterized in that The method further comprises: A knowledge graph is constructed based on the plurality of relationship triples.
3. The method according to claim 1, characterized in that The step of sequentially generating the at least one child node, the at least one directory node, and the initial summary of the root node according to the directory tree specifically includes: The directory tree is traversed in a set order, and initial summaries of the at least one child node, the at least one directory node, and the root node are generated in sequence.
4. The method according to claim 3, characterized in that The generating of the initial summary of the at least one child node, the at least one directory node, and the root node specifically includes: Inputting the original document corresponding to each of the sub-nodes into the large language model, and outputting the initial summary of the sub-node; Inputting the initial summaries of the plurality of subnodes included in each directory node into a large language model, and outputting the initial summaries of the directory nodes; The initial summaries of the plurality of directory nodes included in the root node are input into a large language model, and the initial summary of the root node is output.
5. The method according to claim 1, wherein The step of sequentially generating a target summary of the at least one child node according to the priority access order specifically includes: Determine a query vector according to the original document of the child node; Obtaining target summaries of multiple preceding nodes related to the child node in a vector database according to the query vector; The target digest of the child node is determined according to the original document of the child node and the target digests of a plurality of preceding nodes.
6. The method according to claim 5, characterized in that The method further comprises: Determine a corresponding embedding vector according to the target summary of the child node; The embedding vector and the target summary of the child node are saved in the vector database.
7. The method according to claim 1, characterized in that Determining multiple entity types according to the target summary specifically includes: The preset first prompt word information, the text content of each sub-node and the corresponding target summary are input into the large language model, and multiple entity types are output.
8. The method according to claim 1, characterized in that Determining, according to each entity type cluster, a definition of each entity type in the entity type cluster specifically includes: The preset second prompt word information, the entity type cluster and the target summary corresponding to the entity type cluster are input into the large language model, and the definitions of multiple entity types in the entity type cluster are output.
9. The method according to claim 1, characterized in that The determining, according to the definitions of the plurality of entity types, at least one relationship triple corresponding to each of the child nodes specifically includes: Determine an entity pair in the original document corresponding to each of the child nodes according to definitions of the plurality of entity types; A relation triple is determined according to the entity pairs.
10. A device for constructing a knowledge graph, characterized in that: The device comprises: An acquiring unit, configured to acquire a directory tree in a target document, wherein the directory tree includes a root node, at least one directory node, and at least one child node; a generating unit, configured to sequentially generate an initial summary of the at least one child node, the at least one directory node, and the root node according to the directory tree; a determining unit, configured to determine a priority access order of the root node, at least one directory node, and at least one child node according to the initial summary; The generating unit is further configured to sequentially generate a target summary of the at least one child node according to the priority access order; The determining unit is further configured to determine a plurality of entity types according to the target summary; The generating unit is further configured to cluster the plurality of entity types to generate a plurality of entity type clusters, wherein each entity type cluster includes at least one entity type; The determining unit is further configured to determine, based on each entity type cluster, a definition of each entity type in the entity type cluster; The determination unit is further used to determine at least one relationship triple corresponding to each of the child nodes based on definitions of the multiple entity types, wherein the relationship triple is a basic unit for constructing a knowledge graph.
11. An electronic device comprising a memory and a processor, characterized in that: The memory is configured to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Online reasoning method, device and equipment for constructing knowledge graph based on large model
CN119358685A