Knowledge graph-based efficient and accurate RAG question and answer method and device and storage medium

By constructing index key-value pairs and hybrid knowledge retrieval paradigms based on knowledge graphs, the shortcomings of the RAG system in capturing structural relationships and integrating information are solved, and efficient and accurate question-answering capabilities are achieved.

CN120763299APending Publication Date: 2025-10-10SHANDONG ZHIYANG SHANGSHUI INFORMATION TECH CO LTD

Patent Information

Application Number
CN202510918936.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-04
Publication Date
2025-10-10

AI Technical Summary

Technical Problem

The existing RAG system relies on text vector retrieval, which makes it difficult to capture structural relationships. Knowledge graph-based retrieval has ontological limitations and incomplete information. In addition, the integration of text and knowledge graph is loosely coupled, making it difficult to handle complex queries.

Method used

By reading text files and using large language models to extract open domain information, we construct optimized entity and relationship triples, combine them with knowledge graphs, store them as index key-value pairs, and use a hybrid knowledge retrieval paradigm for low-level and high-level retrieval to iteratively optimize answer generation.

Benefits of technology

It significantly improves the efficiency and accuracy of RAG question answering, reduces response time, effectively integrates unstructured text and structured knowledge, and enhances the ability to handle complex queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120763299A_ABST
    Figure CN120763299A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of RAG questioning and answering, and particularly relates to an efficient and accurate RAG questioning and answering method and device based on a knowledge graph and a storage medium. The method comprises the following steps: reading contents in a text file, dividing the contents to obtain text blocks, and obtaining an initial triple by using a large language model; performing post-processing on the initial triad to obtain an optimized triad, and constructing a knowledge graph; building an index key value pair based on the optimized triad and the text block to which the triad belongs, and storing the index key value pair in a vector database; performing mixed knowledge retrieval based on the index key value pair to obtain mixed knowledge beneficial to question answering: unstructured knowledge from the text and structured knowledge from the knowledge graph; and taking the mixed knowledge as the context of question answering, and reasoning by using a large-scale language model. According to the method, the response time is remarkably shortened, the unstructured knowledge and the structured knowledge are effectively integrated, and the accuracy of low-level retrieval and high-level retrieval is remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of RAG question answering, and more specifically, relates to an efficient and accurate RAG question answering method, device and storage medium based on knowledge graph. Background Art

[0002] Retrieval-augmented generation (RAG) systems enhance large language models by incorporating external knowledge sources, enabling them to generate responses that are more accurate, contextually relevant, and tailored to user needs, significantly improving their usefulness in real-world applications. By adapting domain-specific knowledge, RAG systems ensure that the information provided is not only relevant but also tailored to the user's needs. Furthermore, they provide up-to-date information, which is crucial in rapidly changing domains.

[0003] However, existing RAG systems suffer from several key limitations that hinder their performance. First, many methods rely primarily on vector retrieval of textual content within documents, such as in patent application number 202410664018.5. While vector embeddings are effective for measuring semantic similarity between two texts, text-based RAG struggles to capture the structural relationships between them. Second, some researchers have used query-relevant triples to inform large-scale language models, such as in patent application number 202410827337.3. While knowledge graphs are effective at constructing high-level concepts and relationships, they are inherently incomplete and lack information beyond their ontology. Furthermore, some recent work has focused on integrating text-based and knowledge graph-based RAG systems, such as in patent application number 202410899737.5, aggregating information retrieved from structured and unstructured knowledge sources to inform large-scale language models to answer questions. However, this approach does not improve retrieval results from one knowledge source by leveraging another. This loosely coupled combination approach is unsuitable for handling complex queries that require detailed information through in-depth retrieval. Summary of the Invention

[0004] The present invention aims to overcome at least one defect of the above-mentioned prior art and provide an efficient and accurate RAG question answering method based on knowledge graph to solve the technical problems that the above-mentioned RAG system has difficulty in capturing structural relationships by relying on text vector retrieval, ontology limitations and incomplete information based on knowledge graph retrieval, and loose coupling between text and knowledge graph integration to handle complex queries.

[0005] The present invention also discloses a device loaded with an efficient and accurate RAG question-answering method based on a knowledge graph.

[0006] The detailed technical solutions of the present invention are as follows: A high-efficiency and accurate RAG question answering method based on a knowledge graph, the method comprising: S1, reading the text content in the text file for text division, obtaining text blocks, and using a large language model to perform open domain information extraction on each text block to obtain initial entity and relationship triples; S2, post-processing the initial entity and relationship triples to obtain optimized entity and relationship triples, and constructing a knowledge graph based on the triples; S3, constructing an index key-value pair based on the optimized entity and relationship triples and the corresponding text blocks, and storing it in a vector database; S4, performing hybrid knowledge retrieval based on the index key-value pair to obtain hybrid knowledge beneficial to answering questions: unstructured knowledge from text-text blocks, and structured knowledge from the knowledge graph-optimized entity and relationship triples; S5, using the retrieved hybrid knowledge as the context for answering questions and using a large-scale language model for reasoning.

[0007] According to the application, reading the text content in the text file for text division, obtaining text blocks, and using a large language model to perform open domain information extraction on each text block to obtain initial entity and relationship triples comprises: Reading the text content in the text file, and dividing the text into text blocks using a text division algorithm; The large language model performs open domain information extraction on the text blocks that need to perform open domain information extraction in the open domain information extraction prompt words under the constraint of the open domain information extraction prompt words, to obtain initial triples composed of entities and relationships; The open domain information extraction prompt words include: open domain information extraction task instructions, extraction requirements, case descriptions, and text blocks that need to perform open domain information extraction.

[0008] According to the application, post-processing the initial entity and relationship triples to obtain optimized entity and relationship triples, and constructing a knowledge graph based on the triples comprises: Constructing rules for filtering triples with non-standard formats, and merging tail entities with the same head entity and relationship; Using the rules to filter the triples of each text block to obtain optimized entity and relationship triples; Importing the entity and relationship triples into a graph database Neo4j to obtain a knowledge graph.

[0009] According to the application, constructing an index key-value pair based on the optimized entity and relationship triples and the corresponding text blocks, and storing it in a vector database comprises: For each entity and relationship in the triple, a key-value pair is generated; Use entities and relationships as keys separately; Take the text blocks to which entities and relationships belong as values ​​respectively; Store index key-value pairs in a vector database to facilitate knowledge retrieval.

[0010] Preferably, according to the present invention, hybrid knowledge retrieval is performed based on index key-value pairs to obtain hybrid knowledge that is useful for answering questions: unstructured knowledge from text - text blocks, and structured knowledge from knowledge graphs - optimized entity and relationship triples including: The hybrid knowledge retrieval paradigm is defined as low-level retrieval and high-level retrieval. Low-level retrieval is detail-oriented, referencing specific entities in the knowledge graph and accurately retrieving information related to specific nodes and edges. High-level retrieval deals with a wider range of topics and themes, is not directly associated with specific entities, and is more conceptual. Configure the input interface to capture natural language query questions entered by users in real time; Use a large-scale language model to extract low-level keywords and high-level keywords from the query question. Low-level keywords are used for low-level retrieval, and high-level keywords are used for high-level retrieval. Initialize low-level search: Use entity linking tools to link low-level keywords with entities in the knowledge graph; use large-scale language models to evaluate the relevance of the query question and the entities, and based on the evaluation results, select a set of topic entities from the entities in the knowledge graph , where N is determined by a large-scale language model; a density retrieval model is used to extract entities related to the initial topic from all text blocks associated with the entities in the knowledge graph. Relevant top-K text blocks; use the large-scale language model to evaluate whether this information is sufficient to answer the question. If the large-scale language model believes that the existing information is sufficient, then no further steps are required; Initialize advanced search: Use a large-scale language model to link advanced keywords to relationships in the knowledge graph; select entities in the knowledge graph that are connected to the relationships; use a large-scale language model to evaluate the relevance of the query question and the entities, and based on the evaluation results, select a set of subject entities from the entities in the knowledge graph , where N is determined by a large-scale language model; a density retrieval model is used to extract entities related to the initial topic from all text blocks associated with the entities in the knowledge graph. Relevant top-K text blocks; use the large-scale language model to evaluate whether this information is sufficient to answer the question. If the large-scale language model believes that the existing information is sufficient, then no further steps are required; Low-level retrieval and high-level retrieval are performed iteratively, and finally hybrid knowledge is obtained as the context for answering questions.

[0011] According to the application, in the process of iteration of the low-level retrieval and the high-level retrieval, the low-level retrieval and the high-level retrieval each include two steps: context-based graph retrieval and knowledge-guided context retrieval; In the i-th iteration, the symbolic representation of the topic is The symbolic representation of the triple path is Wherein W is a hyperparameter of the retrieval width, is a triple Wherein r represents a relationship, e represents an entity, and when represents an initialization phase is empty; The context-based graph retrieval includes: Querying all the relationships of the topic entity from the knowledge graph, scoring the relationships using a large-scale language model, and selecting the relationships that are helpful to solve the problem; For each topic entity and its corresponding relationship, selecting the tail entity corresponding to the topic entity from the knowledge graph, and forming a triple with the topic entity and the relationship; The knowledge-guided context retrieval includes: Convert the triple corresponding to each tail entity into a simple sentence, and splice it with the corresponding text block to form a context text block. Use a density retrieval model to calculate the relevance score of the context text block to the query question, and select the top-K text blocks for each tail entity, K being the number of text blocks; For each tail entity, calculate the score of the tail entity by exponentially decaying weighted summation of its top-K text blocks, as follows: (1) Wherein, represents the candidate tail entity found in the i-th iteration from the j-th topic entity through the m-th relationship ; , is a hyperparameter for controlling the decay rate, which means that the higher the ranking of the context block, the greater the contribution of the candidate entity score; is the text block ranked k; is the score of the text block ranked k; is an indicator function, which is 1 if the text block ranked k belongs to the entity, and the tail entity with a score ranking top-W is selected as the topic entity for the next iteration .

[0012] According to the application, using the retrieved mixed knowledge as the context of the answer question and using a large-scale language model for reasoning includes: At the end of each iteration, a large-scale language model is used to evaluate whether the current knowledge is sufficient to answer the question. The current knowledge includes clues, triple paths, top-K entities and their corresponding text blocks. The clues are the retrieval feedback from the previous iteration, which aims to preserve useful knowledge from the historical context. If the large-scale language model determines that the provided knowledge is sufficient to answer the question, it will directly output the answer. Otherwise, it will continue to the next round of retrieval and summarize useful clues from the existing knowledge, reconstructing and optimizing the query based on accurate information until the maximum depth D is reached.

[0013] In another aspect of the present invention, a device for implementing an efficient and accurate RAG question-answering method based on a knowledge graph is provided, wherein the device comprises: at least one processor; and A memory storing instructions, which, when executed by the at least one processor, enables the at least one processor to execute the efficient and accurate RAG question answering method based on the knowledge graph as described above.

[0014] In another aspect of the present invention, a machine-readable storage medium is provided, which stores executable instructions. When the instructions are executed, the machine executes the efficient and accurate RAG question answering method based on the knowledge graph as described above.

[0015] Compared with the prior art, the present invention has the following beneficial effects: (1) The present invention uses index key-value pairs to store entity relationships and text blocks, and stores them in a vector database to improve retrieval efficiency, significantly reduce response time, and improve the efficiency of RAG.

[0016] (2) The present invention uses a hybrid knowledge retrieval paradigm to effectively integrate the unstructured knowledge in the text and the structured knowledge in the knowledge graph, significantly improving the accuracy of low-level and high-level retrieval. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 It is a flowchart of the efficient and accurate RAG question answering method based on knowledge graph described in the present invention.

[0018] Figure 2 A comparison chart of the question-answering effects of the question-answering method described in Example 1 of the present invention and a common question-answering method. DETAILED DESCRIPTION

[0019] The present disclosure will be further described below with reference to the accompanying drawings and embodiments.

[0020] Example 1 like Figure 1 As shown, this embodiment provides an efficient and accurate RAG question answering method based on a knowledge graph, the method comprising: In step S1, the text content in the text file is read and divided into text blocks. The large language model is then used to extract open domain information from each text block to obtain initial entity and relationship triples. The specific process is as follows: First, the text content in the text file is read, and the continuous text is divided into text blocks of appropriate length according to paragraphs or topic units using a text segmentation algorithm. It is assumed that a total of 800 text blocks are generated in this embodiment.

[0021] The large language model then performs open-domain information extraction on each text block, constrained by open-domain information extraction prompts. These prompts include the open-domain information extraction task instructions, extraction requirements, case description, and the text block to be processed. This process extracts initial triples consisting of entities and relations from each text block. For example, for the text block "Apple released the iPhone 4 in 2010," the triples (Apple, release, iPhone 4) and (iPhone 4, release date, 2010) are extracted. Ultimately, a total of 1,500 entities and 1,200 relations were extracted from 800 text blocks, forming the initial set of triples.

[0022] In step S2, the initial entity and relationship triples are post-processed to obtain optimized entity and relationship triples, and a knowledge graph is constructed based on the triples. The specific process is as follows: First, we build rules to filter out triplets with irregular formats and merge tail entities with the same head and relationship. For example, we filter out triplets containing null values ​​and illegal characters and merge (iPhone, color, black) with (iPhone, color, white) to get (iPhone, color, black, white).

[0023] Subsequently, the triples of each text block were filtered and merged using rules. After processing, about 15% of invalid triples were filtered out, and duplicate entities and relations were merged, ultimately obtaining 1,275 optimized entities and 1,020 relations.

[0024] Finally, the optimized entity and relationship triples are imported into the graph database Neo4j, where the knowledge graph is constructed using the graph database’s node-relationship model. Each entity is mapped as a node in the graph, and relationships are mapped as edges between nodes, forming a structured knowledge network.

[0025] In step S3, index key-value pairs are constructed based on the optimized entity and relationship triples and the corresponding text blocks and stored in the vector database. The specific process is as follows: For each entity and relationship in a triple, a key-value pair is generated. For example, the entity "Google" and the relationship "own", as well as the corresponding text block "Google has many patents in the field of artificial intelligence..." are identified, with "Google" as a key, "own" as another key, and the corresponding text block "Google has many patents in the field of artificial intelligence..." as the values ​​of these two keys respectively. Through this process, a large number of index key-value pairs are generated. Assume that in this embodiment, a total of 1275 entities and 1020 relationships are identified, that is, 2295 key-value pairs are generated. Subsequently, these index key-value pairs are stored in the vector database for subsequent knowledge retrieval. After the storage is completed, the integrity of the key-value pair storage can be verified through a database query statement. After query verification, all 2295 key-value pairs are accurately stored in the vector database.

[0026] In step S4, hybrid knowledge retrieval is performed based on the index key-value pairs to obtain hybrid knowledge that is useful for answering questions: unstructured knowledge from the text - text blocks, and structured knowledge from the knowledge graph - optimized entity and relationship triples. The specific steps are as follows: The retrieval paradigm is defined as low-level retrieval and high-level retrieval. Low-level retrieval is detail-oriented, usually referencing specific entities in the knowledge graph and requiring precise retrieval of information related to specific nodes or edges. High-level retrieval is more conceptual, dealing with a wider range of topics and themes, and is not directly associated with specific entities.

[0027] Configure the input interface to capture natural language query questions entered by users in real time; Using a large-scale language model, we extract low-level keywords such as "Google AI patents" and "Microsoft AI patents" from the query "Which technology companies have important patent achievements in the field of artificial intelligence?" and high-level keywords such as "Company categories with important patents in the field of artificial intelligence." Low-level keywords are used for low-level searches, while high-level keywords are used for high-level searches.

[0028] Initialize a low-level search: Use an entity linking tool to link the low-level keyword "Google AI patent" to the entity "Google" in the knowledge graph. Apply a large-scale language model to evaluate the relevance of the query and the entity. Based on the model's calculations and evaluation, select a set of subject entities from the entities in the knowledge graph. Assuming the model determines N to be 4, the four subject entities "Google," "Microsoft," "Baidu," and "Nvidia" are selected. A density retrieval model is used to extract the top K text blocks related to the initial subject entities from all text blocks associated with the entities in the knowledge graph. Assuming K is 12, 12 relevant text blocks are extracted for each subject entity, for a total of 48 text blocks. Use a large-scale language model to assess whether this information is sufficient to answer the question. The large-scale language model determines that the existing information is insufficient and requires further search.

[0029] Initialize the advanced search: Use a large-scale language model to link the high-level keyword "Company categories with important patents in the AI ​​field" to the relationship "Holding important patents in a certain field" in the knowledge graph. Select entities in the knowledge graph connected to the relationship "Holding important patents in a certain field," such as "Tech giants" and "Emerging tech companies." Use the large-scale language model to assess the relevance of the query to these entities. The remaining steps are the same as those described in Initialize the Low-Level Search. This step also extracts text blocks related to these entities, assuming 48 text blocks are also extracted.

[0030] The following are the steps for iterative low-level and high-level retrieval, which ultimately result in hybrid knowledge as the context for answering questions. The iterative process of the two retrieval methods includes two major steps: context-based graph retrieval and knowledge-guided context retrieval.

[0031] In the i-th iteration, the symbol of the topic is represented by , their triplet paths are represented as ,in ,W is the hyperparameter of the retrieval width, is a triple , where r represents relationship and e represents entity. Time represents the initialization phase Empty.

[0032] (1) Context-based graph retrieval Query the relationships of all subject entities from the knowledge graph. For example, query the relationship of "Google" and obtain relationships such as "R&D", "Cooperation", and "Acquisition (of companies with relevant patents)". Use a large-scale language model to score the relationships. Suppose "R&D" is scored 9 points, "Cooperation" is scored 7 points, and "Acquisition (of companies with relevant patents)" is scored 8 points. Based on the score, select relationships that may be helpful in solving the problem, such as the "R&D" relationship.

[0033] For each subject entity and its corresponding relationship, the tail entity corresponding to the subject entity is selected from the knowledge graph. For example, for the relationship between "Google" and "R&D", the tail entity is "artificial intelligence algorithm", and it forms a triplet "Google-R&D-artificial intelligence algorithm" with the subject entity and relationship.

[0034] (2) Knowledge-guided contextual retrieval The triples corresponding to each tail entity are converted into simple sentences, such as "Google develops artificial intelligence algorithms." These are then concatenated with the corresponding text blocks to form context blocks. A density retrieval model is used to calculate the relevance score between the context blocks and the query, "Which technology companies have important patent achievements in the field of artificial intelligence?" The top-K ranked text blocks are selected for each tail entity, with K set to 6. For example, for the tail entity "artificial intelligence algorithms," six highly relevant text blocks were obtained.

[0035] For each tail entity, the score of the tail entity is obtained by performing exponential decay weighted summation on its top-K text blocks. The formula is as follows: (1) in, Indicates that in the i-th iteration, from the j-th topic entity Through the mth relationship The candidate tail entities found; , is a hyperparameter used to control the decay rate, which means that the higher the ranking of the context block, the greater its contribution to the score of the candidate entity; is the text block with rank k; is the score of the text block ranked k; Is an indicator function, if the text block ranked k belongs to the entity, the value is 1, and the tail entity ranked top-W is selected as the topic entity for the next iteration ,set up is 0.6.

[0036] In step S5, the retrieved hybrid knowledge is used as the context for answering the question and reasoning is performed using a large-scale language model. The specific process is as follows: At the end of each iteration, a large-scale language model is used to assess whether the current knowledge is sufficient to answer the question. This knowledge includes clues, triple paths, top-K entities, and their corresponding text blocks. Clues are retrieval feedback from the previous iteration, aiming to preserve useful knowledge from historical context. For example, after the first iteration, if the large-scale language model determines that the current knowledge is insufficient to answer the question, it will proceed to the second iteration. After the second iteration, if the large-scale language model determines that the current knowledge is sufficient to answer the question "Which technology companies have important patent achievements in the field of artificial intelligence?", it will directly output the answer, such as "Technology companies such as Google, Microsoft, Baidu, and NVIDIA have important patent achievements in the field of artificial intelligence. Their patents cover a wide range of aspects, including AI algorithms, hardware architectures, and application scenarios." Otherwise, it will continue to the next round of search, summarizing useful clues from the existing knowledge and reconstructing and optimizing the query based on accurate information until the maximum depth D is reached. Assuming D is 6, this means a maximum of 6 iterations.

[0037] In a knowledge graph question-and-answer application scenario in the field of water conservancy projects, this invention focuses on the topic of the East Route of the water diversion project. Users pose complex questions such as, "In the water diversion project, which provinces does the East Route project pass through? What is the water resource situation in these provinces?" The proposed RAG question-and-answer method utilizes an efficient hybrid knowledge retrieval paradigm to generate hybrid knowledge—unstructured text blocks and structured knowledge graphs. This method accurately identifies that the East Route project covers four provinces and municipalities: Jiangsu, Shandong, Hebei, and Tianjin. Furthermore, it integrates deep data correlations on the water resource characteristics of each province and municipality to generate detailed answers, clearly elaborating on specific issues such as the uneven regional distribution and seasonal variations of water resources in Jiangsu, per capita water shortages in Shandong, the prominent supply-demand imbalance in Hebei, and Tianjin's reliance on external water diversion for resource-based water shortages. This enables precise and efficient knowledge exchange and information supply for complex water conservancy project issues.

[0038] like Figure 2As shown in the figure, by comparing typical cases of water conservancy industry problems, it can be seen that the RAG question-answering method proposed in the present invention shows significant advantages. When faced with complex problems, such as explaining the flood control scheduling method of the Three Gorges Reservoir, which requires logical reasoning, the RAG question-answering method of the present invention can fully explain the scheduling logic and mechanism based on the correlation between various factors in the knowledge graph, avoiding information omissions; for multi-dimensional information problems such as Xiaolangdi ecological scheduling measures, the RAG question-answering method of the present invention can comprehensively integrate various measures such as water and sediment regulation, ecological base flow, etc., demonstrating strong information association and reasoning capabilities. In terms of time consumption, the average time consumption is reduced by 15%-20% compared with ordinary RAG question-answering methods. While ensuring the accuracy and completeness of the answers, efficient responses are achieved, significantly improving the efficiency of knowledge acquisition. Compared with ordinary RAG question-answering methods, the RAG question-answering method of the present invention, relying on the hybrid knowledge retrieval paradigm, is superior in answer accuracy, information completeness, efficiency and professionalism, and is more suitable for precise question-answering in complex knowledge scenarios.

[0039] Example 2 This embodiment also provides a device for implementing an efficient and accurate RAG question-answering method based on a knowledge graph, including: at least one processor; and A memory storing instructions, which, when executed by the at least one processor, enables the at least one processor to execute the efficient and accurate RAG question answering method based on the knowledge graph as described above.

[0040] In this embodiment, the device may include but is not limited to: a personal computer, a server computer, a workstation, a desktop computer, a laptop computer, a notebook computer, a mobile computing device, a smart phone, a tablet computer, a cellular phone, a personal digital assistant (PDA), a handheld device, a messaging device, a wearable computing device, a consumer electronic device, and the like.

[0041] Example 3 This embodiment also provides a machine-readable storage medium storing executable instructions, which, when executed, enable the machine to execute the efficient and accurate RAG question-answering method based on the knowledge graph as described above.

[0042] Specifically, a system or device equipped with a readable storage medium can be provided, on which software program codes that implement the functions of any of the above-mentioned embodiments are stored, and a computer or processor of the system or device can read and execute instructions stored in the readable storage medium.

[0043] In this case, the program code itself read from the machine-readable medium can implement the functions of any one of the above embodiments, and thus the machine-readable code and the machine-readable storage medium storing the machine-readable code constitute part of this specification.

[0044] Examples of readable storage media include floppy disks, hard disks, magneto-optical disks, optical disks (e.g., CD-ROMs, CD-Rs, CD-RWs, DVD-ROMs, DVD-RAMs, DVD-RWs, DVD-RWs), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, the program code may be downloaded from a server computer or a cloud via a communication network.

[0045] Obviously, the above embodiments of the present invention are merely examples for the purpose of clearly illustrating the technical solutions of the present invention, and are not intended to limit the specific implementation methods of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the claims of the present invention shall be included within the scope of protection of the claims of the present invention.

Claims

1. An efficient and accurate RAG question answering method based on knowledge graph, characterized by: The method comprises: S1. Read the text content in the text file and divide it into text blocks. Then use the large language model to extract open domain information from each text block to obtain the initial entity and relationship triples. S2. Post-process the initial entity and relationship triples to obtain optimized entity and relationship triples, and build a knowledge graph based on these triples; S3: Build index key-value pairs based on the optimized entity and relationship triples and the corresponding text blocks, and store them in the vector database; S4. Perform hybrid knowledge retrieval based on index key-value pairs to obtain hybrid knowledge that is useful for answering questions: unstructured knowledge from text - text blocks, and structured knowledge from knowledge graphs - optimized entity and relationship triples; S5. Use the retrieved hybrid knowledge as the context for answering questions and use a large-scale language model for reasoning.

2. The efficient and accurate RAG question answering method based on knowledge graph according to claim 1 is characterized in that: In step S1, the text content in the text file is read and divided into text blocks, and the open domain information of each text block is extracted using a large language model to obtain the initial entity and relationship triples including: Read the text content in the text file and divide the text into text blocks using a text segmentation algorithm; Under the constraints of the open domain information extraction prompt words, the large language model performs open domain information extraction on the text blocks that need open domain information extraction in the open domain information extraction prompt words, and obtains the initial triples consisting of entities and relations; The open domain information extraction prompt words include: open domain information extraction task instructions, extraction requirements, case descriptions, and text blocks that require open domain information extraction.

3. The efficient and accurate RAG question answering method based on knowledge graph according to claim 1 is characterized in that: In step S2, the initial entity and relationship triples are post-processed to obtain optimized entity and relationship triples, and a knowledge graph is constructed based on the triples, including: Build rules for filtering triples with irregular formats and merging head entities with the same tail entities. For each text block triple, use rule filtering to obtain optimized entity and relationship triples; Import entity and relationship triples into the graph database Neo4j to obtain a knowledge graph.

4. The efficient and accurate RAG question answering method based on knowledge graph according to claim 1 is characterized in that: In step S3, index key-value pairs are constructed based on the optimized entity and relationship triples and the corresponding text blocks, and stored in the vector database, including: For each entity and relation in a triple, generate a key-value pair; Use entities and relationships as keys separately; Take the text blocks to which entities and relationships belong as values ​​respectively; Store index key-value pairs in a vector database to facilitate knowledge retrieval.

5. The efficient and accurate RAG question answering method based on knowledge graph according to claim 1 is characterized in that: In step S4, hybrid knowledge retrieval is performed based on the index key-value pairs to obtain hybrid knowledge that is useful for answering questions: unstructured knowledge from the text - text blocks, and structured knowledge from the knowledge graph - optimized entity and relationship triples including: The hybrid knowledge retrieval paradigm is defined as low-level retrieval and high-level retrieval. Low-level retrieval is detail-oriented, referencing specific entities in the knowledge graph and accurately retrieving information related to specific nodes and edges. High-level retrieval deals with a wider range of topics and themes, is not directly associated with specific entities, and is more conceptual. Configure the input interface to capture natural language query questions entered by users in real time; Use a large-scale language model to extract low-level keywords and high-level keywords from the query question. Low-level keywords are used for low-level retrieval, and high-level keywords are used for high-level retrieval. Initialize low-level search: Use entity linking tools to link low-level keywords with entities in the knowledge graph; use large-scale language models to evaluate the relevance of the query question and the entities, and based on the evaluation results, select a set of topic entities from the entities in the knowledge graph , where N is determined by a large-scale language model; a density retrieval model is used to extract entities related to the initial topic from all text blocks associated with the entities in the knowledge graph. Relevant top-K text blocks; use the large-scale language model to evaluate whether this information is sufficient to answer the question. If the large-scale language model believes that the existing information is sufficient, then no further steps are required; Initialize advanced search: Use a large-scale language model to link advanced keywords to relationships in the knowledge graph; select entities in the knowledge graph that are connected to the relationships; use a large-scale language model to evaluate the relevance of the query question and the entities, and based on the evaluation results, select a set of subject entities from the entities in the knowledge graph , where N is determined by a large-scale language model; a density retrieval model is used to extract entities related to the initial topic from all text blocks associated with the entities in the knowledge graph. Relevant top-K text blocks; use the large-scale language model to evaluate whether this information is sufficient to answer the question. If the large-scale language model believes that the existing information is sufficient, then no further steps are required; Low-level retrieval and high-level retrieval are performed iteratively, and finally hybrid knowledge is obtained as the context for answering questions.

6. The efficient and accurate RAG question answering method based on knowledge graph according to claim 5 is characterized in that: During the iterative process of low-level retrieval and high-level retrieval, low-level retrieval and high-level retrieval respectively include two major steps: context-based graph retrieval and knowledge-guided context retrieval; In the i-th iteration, the symbol of the topic is represented by , their triplet paths are represented as ,in , W is the hyperparameter of the retrieval width, is a triple , where r represents relationship and e represents entity. Time represents the initialization phase is empty; The context-based graph retrieval includes: Query the relationships of all subject entities from the knowledge graph and use a large-scale language model to score the relationships and select the relationships that are helpful for solving the problem; For each subject entity and its corresponding relationship, select the tail entity corresponding to the subject entity from the knowledge graph and form a triple with the subject entity and the relationship; The knowledge-guided contextual retrieval includes: The triples corresponding to each tail entity are converted into simple sentences and concatenated with the corresponding text blocks to form a context text block. The density retrieval model is used to calculate the relevance score between the context text block and the query question. The top-K ranked text blocks are selected for each tail entity, where K is the number of text blocks. For each tail entity, the score of the tail entity is obtained by performing exponential decay weighted summation on its top-K text blocks. The formula is as follows: (1) in, Indicates that in the i-th iteration, from the j-th topic entity Through the mth relationship The candidate tail entity found; , is a hyperparameter used to control the decay rate, which means that the higher the ranking of the context block, the greater its contribution to the score of the candidate entity; is the text block with rank k; is the score of the text block ranked k; Is an indicator function, if the text block ranked k belongs to the entity, the value is 1, and the tail entity ranked top-W is selected as the topic entity for the next iteration .

7. The efficient and accurate RAG question answering method based on knowledge graph according to claim 6 is characterized in that: In step S5, the retrieved hybrid knowledge is used as the context for answering the question, and reasoning is performed using a large-scale language model, including: At the end of each iteration, a large-scale language model is used to evaluate whether the current knowledge is sufficient to answer the question. The current knowledge includes clues, triple paths, top-K entities and their corresponding text blocks. The clues are the retrieval feedback from the previous iteration, which aims to preserve useful knowledge from the historical context. If the large-scale language model determines that the provided knowledge is sufficient to answer the question, it will directly output the answer. Otherwise, it will continue to the next round of retrieval and summarize useful clues from the existing knowledge, reconstructing and optimizing the query based on accurate information until the maximum depth D is reached.

8. A device for implementing an efficient and accurate RAG question answering method based on a knowledge graph, characterized in that: The device comprises: at least one processor; and A memory storing instructions, which, when executed by the at least one processor, causes the at least one processor to execute the efficient and accurate RAG question answering method based on the knowledge graph as described in any one of claims 1 to 7.

9. A machine-readable storage medium, characterized in that The machine-readable storage medium stores executable instructions, which, when executed, enable the machine to execute the efficient and accurate RAG question-answering method based on knowledge graph as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • A knowledge question answering processing method and device

    CN118227771B

  • Generative knowledge graph question and answer method

    CN118861195A

  • Response enhancement method and device based on RAG technology

    CN119005330A

Cited By

  • Rail transit maintenance knowledge graph construction method, terminal equipment and medium

    CN121257671A

  • Knowledge question-answering method and system based on topic knowledge graph retrieval enhancement

    CN121388124A

  • A knowledge question and answer method and system based on topic knowledge graph retrieval enhancement

    CN121388124B

  • Pure text RAG method based on triple logic chain

    CN121436195A