Knowledge graph retrieval enhancement method and system based on path exploration
By building a knowledge graph and performing path exploration and path mining, using large language models to generate answers, the problems of weak semantic correlation and high noise in the existing technology are solved, and more efficient and accurate answer generation is achieved.
Patent Information
- Application Number
- CN202510491673.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-18
- Publication Date
- 2025-08-08
AI Technical Summary
The existing search enhancement method based on knowledge graphs has problems such as weak semantic correlation, high noise and high cost when generating answers, which leads to inaccurate content and is difficult to implement in actual applications.
By constructing a knowledge graph, using a large language model to extract keywords, conduct path exploration and path mining, and filtering paths with cosine similarity, generate final answers and reduce the introduction of invalid information.
Improves the accuracy of generated answers and reduces usage costs, and enhances the interpretability and decision-making reliability of generative AI.
Smart Images

Figure CN120448554A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of retrieval enhancement technology, and in particular to a knowledge graph retrieval enhancement method and system based on path exploration. Background Art
[0002] Retrieval-Augmented Generation (RAG) effectively improves the accuracy and factual consistency of generated content by combining large-scale pre-trained language models with external knowledge retrieval. Its core mechanism is to dynamically retrieve relevant document fragments as contextual basis during the generation process, thereby alleviating the "hallucination" problem caused by the limitations of parameterized knowledge in traditional models. Typical RAG systems use a two-stage process: first, candidate text blocks are screened from the knowledge base through dense vector retrieval, and then the generative model fuses the retrieval results with user instructions to generate the final response. However, existing methods still face challenges such as weak semantic relevance and context fragmentation. In particular, when dealing with complex reasoning or multi-hop question and answering, traditional vector retrieval has difficulty capturing the deep logical relationships between concepts, which can easily lead to structural defects in the generated content.
[0003] To overcome this bottleneck, the Knowledge Graph-Based Retrieval Enhancement (GraphRAG) method innovatively introduces a knowledge graph enhancement architecture. This method constructs a domain knowledge graph, transforming discrete text snippets into a structured semantic graph. This graph enhancement mechanism demonstrates significant advantages in areas requiring complex reasoning, such as financial risk assessment and legal clause parsing, achieving higher accuracy than traditional RAG methods. By explicitly modeling relationships within knowledge graphs, GraphRAG provides a new technical paradigm for improving the interpretability and decision reliability of generative AI.
[0004] Existing GraphRAG methods often rely solely on semantic similarity for large-scale matching. This results in retrieved data not necessarily being strongly relevant to the user's question, introducing considerable noise and affecting the accuracy of the final output. Furthermore, an excessive number of search results leads to higher costs, making it difficult to implement in practical applications. Therefore, a knowledge graph retrieval enhancement method is urgently needed that can effectively address these issues and produce more reliable answers at a lower cost. Summary of the Invention
[0005] The purpose of the present invention is to address the shortcomings of the existing technology and provide a knowledge graph retrieval enhancement method and system based on path exploration, which can reduce the cost of use while increasing the accuracy of generated answers.
[0006] In order to solve the above technical problems, the present invention adopts the following technical solutions:
[0007] A knowledge graph retrieval enhancement method based on path exploration includes the following steps:
[0008] Step 1: Read text information from an external material library, divide the text information into text blocks, extract entities and relationships, build a knowledge graph, and store the entities and relationships in a vector database;
[0009] Step 2: Extract keywords from user questions using a large language model. The keywords are entity content in the user questions.
[0010] Step 3: Based on the keywords extracted in step 2, query the entities in the vector database to obtain the entities whose similarity ranking exceeds the similarity ranking threshold for each keyword. Use the large language model to identify whether these entities are strongly related to the keywords, and then form a set of nodes to be considered;
[0011] Step 4: Combine the nodes in the node set to be considered into node pairs, perform path mining on the knowledge graph, set an upper bound on the number of path hops, stop mining when the number of hops is exceeded, and store the path;
[0012] Step 5: Calculate the average similarity between the nodes and relationships of each path and the user question, and retain the paths whose average similarity exceeds the average similarity ranking threshold as the context for answer generation;
[0013] Step 6: Input the filtered path information as prompt words into the large language model to generate the final answer.
[0014] Furthermore, step 1 of dividing the text blocks based on the large language model includes the following sub-steps:
[0015] Step 1.1: Use dynamic window segmentation algorithm to process the text into blocks;
[0016] Step 2.2: Use the large language model to analyze each text block and extract the entities and relations.
[0017] Step 2.3: Generate a summary based on the extracted entities and relationships and the original text context.
[0018] Step 2.4: De-duplicate the extracted entities and relationships, and integrate and rewrite their corresponding summaries;
[0019] Step 2.5: Build a knowledge graph using the extracted, summarized, and deduplicated entities and relationships.
[0020] Furthermore, in step 2, before extracting keywords from the user question, several examples of keyword extraction are given in the prompt words of the large language model to guide the large model to extract entity information appearing in the user question according to the examples.
[0021] Furthermore, in step 3, entities in the query vector database are queried using cosine similarity.
[0022] Furthermore, in step 4, the path mining adopts a depth-first search algorithm to perform multi-hop expansion.
[0023] Furthermore, the average similarity between the nodes and relationships in each path and the user question in step 5 is calculated by calculating the cosine similarity between the description of each node and relationship in the path and the user question, and then dividing the sum by the total number of nodes and relationships in the path.
[0024] Furthermore, in step 5, if the number of paths is less than the average similarity ranking threshold, all of them are retained as the context for answer generation.
[0025] Furthermore, in step 6, the filtered path information is input into the large language model in the form of structured prompt words.
[0026] Furthermore, the depth-first search algorithm prioritizes exploring deep logical relationships during path mining until reaching an upper bound on the number of hops or a target node.
[0027] In another aspect, the present invention provides a knowledge graph retrieval enhancement system based on path exploration, comprising:
[0028] Knowledge graph generation module: It is used to read text information from an external material library, divide the text information into text blocks and extract entities and relationships, build a knowledge graph, and store the entities and relationships in a vector database;
[0029] User question processing module: It is used to extract keywords from user questions through a large language model. The keywords are entity contents in user questions;
[0030] Keyword matching module: This module is used to query entities in the vector database based on the extracted keywords, obtain entities whose similarity ranking for each keyword exceeds the similarity ranking threshold, and use the large language model to identify whether these entities are strongly related to the keywords, thereby forming a set of nodes to be considered;
[0031] Path exploration module: It is used to group the nodes in the node set to be considered into node pairs, perform path mining on the knowledge graph, set an upper limit on the number of path hops, and stop mining and store the path when the hop count is exceeded;
[0032] Path screening module: This module calculates the average similarity between the nodes and relationships of each path and the user's question, and retains paths whose average similarity exceeds the average similarity ranking threshold as the context for answer generation;
[0033] Answer generation module: It is used to input the filtered path information as prompt words into the large language model to generate the final answer.
[0034] Compared with the prior art, the present invention has the following beneficial effects:
[0035] The present invention adopts a knowledge graph retrieval enhancement method based on path exploration. In the actual application of the knowledge graph-based retrieval enhancement method, the noise and additional overhead introduced by retrieving too much invalid information are reduced, and the quality of the generated answers is increased. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction is given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0037] Figure 1 This is a flow chart of a knowledge graph retrieval enhancement method based on path exploration proposed in the present invention.
[0038] Figure 2 This is the specific process of constructing the knowledge graph in step 1. DETAILED DESCRIPTION
[0039] To make the above-mentioned objects, features, and advantages of the present application more clearly understood, the specific embodiments of the present application are described in detail below with reference to the accompanying drawings. The following description sets forth many specific details to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar improvements without violating the scope of the present application. Therefore, the present application is not limited to the specific embodiments disclosed below.
[0040] Example 1
[0041] See also Figure 1 The knowledge graph retrieval enhancement method based on path exploration proposed in the present invention includes the following steps.
[0042] Step 1: Knowledge graph construction
[0043] First, the relevant text information is read from an external material library. This text is then processed using a large language model, dividing it into several text blocks. Next, key entities and relationships between entities are extracted from these text blocks. Based on these extracted entities and relationships, a knowledge graph is constructed. Finally, the entities and relationships in the knowledge graph are stored in a vector database, allowing for easy access to this data in subsequent steps, supporting subsequent analysis, queries, and other operations.
[0044] Step 2: User question processing. First, the present invention will receive the question text input by the user. Then, by calling the powerful semantic understanding ability of the large language model, the user's question is deeply analyzed. The model will parse the semantic structure of the question word by word and identify the core vocabulary and key information. In this process, the model will focus on those words with clear reference meanings. These words are usually specific things, concepts or objects involved in the question, which are so-called "entity content". The present invention will extract these entity contents as keywords for subsequent processing and analysis. These keywords can help the present invention better understand the focus and intention of the user's question, thereby providing an accurate basis for subsequent queries, matching or other operations. In this embodiment, the user question is: What is the relationship between Harry Potter and Voldemort? The extracted keywords are: Harry Potter, Voldemort
[0045] Step 3: Keyword matching. The present invention will calculate the similarity between each keyword and the entity vector in the database one by one. Through a complex vector comparison algorithm, the present invention will screen out the top five entities with similarity to each keyword, and then further use the large language model to identify whether these entities are strongly correlated with the keywords, and then include these entities in the set of nodes to be considered. Subsequently, the present invention will store this set of nodes to be considered so that these nodes can be easily called in subsequent steps. The set of nodes to be considered in this embodiment is shown in Table 1:
[0046] Table 1
[0047]
[0048] The set of nodes to be considered that are actually associated with the keywords after LLM screening is shown in Table 2:
[0049] Table 2
[0050] Harry Potter Harry Potter Voldemort Voldemort
[0051] Step 4: Path Exploration. Within the set of nodes to be considered obtained in Step 3, pairwise nodes are grouped into node pairs. Path mining is then performed on the knowledge graph for each node pair. Given that the number of hops in real-world problems is often limited, the path mining hop limit is set to 10. If the number of hops exceeds this upper bound during the mining process, path mining for that node pair is terminated. Successfully mined paths are stored.
[0052] Step 5: Path Filtering. The paths mined in Step 4 need to be filtered. The filtering method is: first, calculate the similarity between the nodes and relationships on each path and the user's question, and then solve for the average similarity value of the path. If there are more than eight paths, sort them from high to low by average similarity, and select the top eight paths by average similarity as the context for answer generation. If there are fewer than eight paths, all of them are included in the context for answer generation.
[0053] The paths mined in this embodiment are shown in Table 3:
[0054] Table 3
[0055]
[0056]
[0057]
[0058]
[0059]
[0060] Step 6: Answer generation: Use the path information provided in step 5 as prompt words and provide them to the large language model to assist it in answering the user's question.
[0061] The answer generated in this example is: The relationship between Harry Potter and Voldemort is a fateful confrontation, and it also represents the core of the entire magical world's struggle between light and darkness. Voldemort once attempted to kill the infant Harry, but the spell backfired, nearly destroying him and making Harry the "Boy Who Lived." Since then, their fates have been intertwined. Voldemort repeatedly attempts to kill Harry to eliminate the threat, while Harry, through his adventures at Hogwarts, continues to uncover Voldemort's past and secrets. A mysterious telepathic connection also exists between them, caused by a fragment of Voldemort's Horcrux accidentally lodging in Harry's body.
[0062] Dumbledore, Harry's mentor, offered him protection and guidance from the moment he entered school. Not only did he protect Harry from Voldemort's threats, he also revealed his weaknesses and the secrets of his Horcruxes, guiding him on his quest to save the wizarding world. Dumbledore's struggle with Voldemort permeates the entire story, and he served as Harry's crucial pillar of support in his fight against Voldemort.
[0063] Ron Weasley, Harry's best friend, always stood by his side as they faced the threat of Voldemort. Whether battling trolls, exploring the Chamber of Secrets, or destroying Horcruxes, Ron stepped forward without hesitation. His loyalty and support provided Harry with crucial emotional and practical support.
[0064] The Malfoy family are staunch supporters of Voldemort, and Draco has been indoctrinated into blindly worshipping him since childhood. However, as the story progresses, Draco gradually realizes Voldemort's cruelty and unreasonableness, and is filled with fear and inner struggle. His existence not only reflects Voldemort's profound influence on the wizarding world but also adds complexity to Harry's struggle against him.
[0065] In summary, the relationship between Harry Potter and Voldemort is more than just a personal vendetta; it represents a symbolic confrontation between light and darkness in the wizarding world. Harry's upbringing, Dumbledore's guidance, Ron's support, and the struggles of the Malfoy family all form the complex backdrop for this fateful confrontation. Voldemort's threat permeates the entire story, and Harry, as the "Boy Who Lived," ultimately becomes the key to ending the forces of darkness.
[0066] See also Figure 2 , the step 1 further includes the following steps.
[0067] Step 2.1: Text Segmentation. A dynamic window segmentation algorithm is used to segment the text into blocks. The window size is set to 1024 tokens and the sliding step size is 15%. This ensures that semantic integrity is maintained as much as possible during the segmentation process, thereby providing high-quality text blocks for subsequent processing.
[0068] Step 2.2: Entity and Relationship Extraction. Use the large language model to analyze each text block and extract the entities and relationships within it. During the extraction process, the large language model is repeatedly prompted to ensure that it extracts as comprehensive entities as possible and avoids missing important information.
[0069] Step 2.3: Summarization Generation. Based on the extracted entities and relationships, combined with the original context, a corresponding summary is generated. This process aims to provide a clear and accurate description of each entity and relationship to better understand its meaning and role.
[0070] Step 2.4: Deduplication. Deduplication is performed on the extracted entities and relationships. For duplicate entities, their corresponding summaries are consolidated and rewritten to ensure the simplicity and consistency of the information in the knowledge graph.
[0071] Step 2.5: Knowledge Graph Construction. Utilize the extracted, summarized, and deduplicated entities and relationships to construct a knowledge graph. By rationally organizing these elements, a structured knowledge network is formed to support subsequent knowledge management and application.
[0072] Example 2
[0073] A specific embodiment of the present invention provides a knowledge graph retrieval enhancement system based on path exploration, including:
[0074] Knowledge graph generation module: It is used to read text information from an external material library, divide the text information into text blocks and extract entities and relationships, build a knowledge graph, and store the entities and relationships in a vector database;
[0075] User question processing module: It is used to extract keywords from user questions through a large language model. The keywords are entity contents in user questions;
[0076] Keyword matching module: This module is used to query entities in the vector database based on the extracted keywords, obtain entities whose similarity ranking for each keyword exceeds the similarity ranking threshold, and use the large language model to identify whether these entities are strongly related to the keywords, thereby forming a set of nodes to be considered;
[0077] Path exploration module: It is used to group the nodes in the node set to be considered into node pairs, perform path mining on the knowledge graph, set an upper limit on the number of path hops, and stop mining and store the path when the hop count is exceeded;
[0078] Path screening module: This module calculates the average similarity between the nodes and relationships of each path and the user's question, and retains paths whose average similarity exceeds the average similarity ranking threshold as the context for answer generation;
[0079] Answer generation module: It is used to input the filtered path information as prompt words into the large language model to generate the final answer.
[0080] The above is only a preferred specific implementation method of the present application, but the scope of protection of the present application is not limited thereto. Any changes or replacements that can be easily thought of by any technician familiar with this technical field within the technical scope disclosed in this application should be covered by the scope of protection of the present application.
[0081] It should be understood that parts not elaborated in detail in this specification belong to the prior art.
[0082] It should be understood that the above description of the preferred embodiment is relatively detailed and cannot be regarded as limiting the scope of protection of the patent of the present invention. Under the guidance of the present invention, ordinary technicians in this field can also make substitutions or modifications without departing from the scope of protection of the claims of the present invention, which all fall within the scope of protection of the present invention. The scope of protection requested by the present invention shall be based on the attached claims.
Claims
1. A knowledge graph retrieval enhancement method based on path exploration, characterized in that: The following steps are involved: Step 1: Read text information from an external material library, divide the text information into text blocks, extract entities and relationships, build a knowledge graph, and store the entities and relationships in a vector database; Step 2: Extract keywords from user questions using a large language model. The keywords are entity content in the user questions. Step 3: Based on the keywords extracted in step 2, query the entities in the vector database to obtain entities whose similarity ranking exceeds the similarity ranking threshold for each keyword. Use the large language model to identify whether these entities are strongly related to the keywords, and then form a set of nodes to be considered; Step 4: Combine the nodes in the node set to be considered into node pairs, perform path mining on the knowledge graph, set an upper bound on the number of path hops, stop mining when the number of hops is exceeded, and store the path; Step 5: Calculate the average similarity between the nodes and relationships of each path and the user question, and retain the paths whose average similarity exceeds the average similarity ranking threshold as the context for answer generation; Step 6: Input the filtered path information as prompt words into the large language model to generate the final answer.
2. The knowledge graph retrieval enhancement method based on path exploration according to claim 1 is characterized in that: Step 1, which divides text blocks based on a large language model, includes the following sub-steps: Step 1.1: Use dynamic window segmentation algorithm to process the text into blocks; Step 2.2: Use the large language model to analyze each text block and extract the entities and relations. Step 2.3: Generate a summary based on the extracted entities and relationships and the original text context. Step 2.4: De-duplicate the extracted entities and relationships, and integrate and rewrite their corresponding summaries; Step 2.5: Build a knowledge graph using the extracted, summarized, and deduplicated entities and relationships.
3. The knowledge graph retrieval enhancement method based on path exploration according to claim 1 is characterized in that: In step 2, before extracting keywords from the user's question, several examples of keyword extraction are given in the prompt words of the large language model to guide the large model to extract entity information appearing in the user's question according to the examples.
4. The knowledge graph retrieval enhancement method based on path exploration according to claim 1 is characterized in that: In step 3, entities in the query vector database are queried using cosine similarity.
5. The knowledge graph retrieval enhancement method based on path exploration according to claim 1 is characterized in that: In step 4, the path mining adopts a depth-first search algorithm to perform multi-hop expansion.
6. The knowledge graph retrieval enhancement method based on path exploration according to claim 1 is characterized in that: The average similarity between the nodes and relationships in each path and the user question in step 5 is calculated by calculating the cosine similarity between the description of each node and relationship in the path and the user question, and then dividing the sum by the total number of nodes and relationships in the path.
7. The knowledge graph retrieval enhancement method based on path exploration according to claim 1 is characterized in that: In step 5, if the number of paths is less than the average similarity ranking threshold, all of them are retained as the context for answer generation.
8. The knowledge graph retrieval enhancement method based on path exploration according to claim 1 is characterized in that: In step 6, the filtered path information is input into the large language model in the form of structured prompt words.
9. The knowledge graph retrieval enhancement method based on path exploration according to claim 5 is characterized in that: The depth-first search algorithm prioritizes exploring deep logical relationships during path mining until the upper bound of the number of hops or the target node is reached.
10. A knowledge graph retrieval enhancement system based on path exploration, characterized in that: include: Knowledge graph generation module: It is used to read text information from an external material library, divide the text information into text blocks and extract entities and relationships, build a knowledge graph, and store the entities and relationships in a vector database; User question processing module: It is used to extract keywords from user questions through a large language model. The keywords are the entity content in the user questions; Keyword matching module: This module is used to query entities in the vector database based on the extracted keywords, obtain entities whose similarity ranking for each keyword exceeds the similarity ranking threshold, and use the large language model to identify whether these entities are strongly related to the keywords, thereby forming a set of nodes to be considered; Path exploration module: It is used to group nodes in the node set to be considered into node pairs, perform path mining on the knowledge graph, set an upper limit on the number of path hops, and stop mining and store the path when the hop count is exceeded; Path screening module: This module calculates the average similarity between the nodes and relationships of each path and the user question, and retains paths whose average similarity exceeds the average similarity ranking threshold as the context for answer generation; Answer generation module: This module is used to input the filtered path information as prompt words into the large language model to generate the final answer; The path exploration-based knowledge graph retrieval enhancement system is used to execute the steps in the path exploration-based knowledge graph retrieval enhancement method described in any one of claims 1-9.
Citation Information
Cited By
Academic paper innovation point identification method and system
CN121859895A
A method and system for identifying innovative points in academic papers
CN121859895B