Context- and Relationship-Aware RAG Method and System Based on Hierarchical Hybrid Graphs
By constructing a hierarchical hybrid graph structure, the problem of difficulty in integrating text semantics and entity relationship information in existing technologies is solved, achieving efficient knowledge retrieval and generation, and improving the accuracy and interpretability of complex knowledge question answering tasks.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ZHEJIANG UNIV
- Filing Date
- 2026-04-10
- Publication Date
- 2026-07-10
AI Technical Summary
Existing retrieval enhancement generation technologies struggle to effectively integrate textual semantic information with entity relationship information in complex knowledge scenarios, resulting in retrieval results lacking complete knowledge structure support and affecting the accuracy and interpretability of the generated results.
A hybrid graph structure integrating entity nodes and text block nodes is constructed, and a hierarchical graph index is established on this basis to form a hierarchical hybrid graph structure, realizing unified modeling of text semantic information and entity relationship information, and enabling efficient retrieval and generation through the hybrid graph.
It improves the retrieval efficiency and reasoning ability of the retrieval enhancement generation system in complex knowledge question answering tasks, and enhances the accuracy and interpretability of the generated results.
Smart Images

Figure CN122364385A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of natural language processing and graph structure information retrieval technology, and particularly relates to a context- and relation-aware RAG method and system based on hierarchical hybrid graphs. Background Technology
[0002] With the rapid development of large-scale pre-trained language models (LLMs), language model-based question-answering systems, knowledge retrieval systems, and intelligent dialogue systems have been widely used in information services, knowledge management, and intelligent decision support. However, since the knowledge of large language models mainly comes from the corpus data used in the training phase, its knowledge is static and limited, and it often struggles to provide accurate and reliable answers when faced with real-time updated knowledge or complex knowledge relationships.
[0003] To address the aforementioned issues, Retrieval-Augmented Generation (RAG) technology has been proposed. By incorporating an external knowledge base for information retrieval during the generation process, it provides additional contextual information to the language model, thereby improving the accuracy and reliability of the generated results. Traditional RAG methods typically rely on vector similarity for text retrieval, using text fragments semantically similar to the user's query as contextual input into the language model for generation.
[0004] However, such methods typically rely solely on textual semantic similarity for retrieval, neglecting the underlying structured relationships between texts. For example, in complex knowledge scenarios such as encyclopedic knowledge, scientific literature, or corporate knowledge bases, entities often possess rich semantic relationships, such as hierarchical relationships, causal relationships, and collaborative relationships. Relying solely on textual similarity for retrieval often fails to fully capture this structured knowledge, thus limiting the system's performance in complex problems, multi-hop reasoning, and relational reasoning tasks.
[0005] To address these issues, researchers have begun to incorporate knowledge graphs or graph-structured data into retrieval-enhanced generative frameworks, constructing entity relationship networks to improve the model's understanding of structured knowledge. However, existing methods typically use entity relationship graphs directly for retrieval, neglecting the close connection between textual information and entity relationships, and also lacking the ability to model the hierarchical structure of graphs. In large-scale knowledge bases, the sheer number of entities and the complexity of their relationships mean that a lack of effective hierarchical organization will lead to reduced retrieval efficiency and increase the inference complexity of the generative model.
[0006] Furthermore, in complex question-answering tasks, user questions often require reasoning that integrates multiple entities and their relationships, such as cross-document information integration or multi-hop reasoning problems. Existing retrieval methods typically struggle to simultaneously consider both textual context information and entity relationship information, resulting in retrieval results lacking a complete knowledge structure, thus affecting the accuracy and interpretability of the final generated results.
[0007] Therefore, how to construct a knowledge representation structure that can simultaneously integrate textual semantic information and entity relationship information, and on this basis realize an efficient retrieval and generation mechanism, has become an important problem that current retrieval enhancement generation technology urgently needs to solve. Summary of the Invention
[0008] To address the aforementioned issues, this invention proposes a context-aware and relation-aware RAG method and system based on hierarchical hybrid graphs. By constructing a hybrid graph structure that integrates entity nodes and text block nodes, and establishing a hierarchical graph index on this basis, a hierarchical hybrid graph structure is formed, achieving unified modeling of text semantic information and entity relation information. This improves the retrieval efficiency and reasoning ability of the retrieval enhancement generation system in complex knowledge question answering tasks.
[0009] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0010] In a first aspect, this invention proposes a context- and relation-aware RAG method based on hierarchical hybrid graphs, comprising the following steps:
[0011] S1. Based on the original text data, construct a hybrid graph containing text block nodes and entity nodes, and generate multi-level summary nodes on the basis of the hybrid graph to form a hierarchical hybrid graph structure;
[0012] S2. Receive user query and perform retrieval in the hierarchical hybrid graph structure. The retrieval includes: retrieving relevant text block nodes and summary nodes based on query semantics, and expanding the retrieval of relevant entity nodes based on the connection relationship between text block nodes and entity nodes in the hybrid graph, as well as directly retrieving relevant entity nodes based on query semantics, thereby obtaining the relationship between relevant entity nodes.
[0013] S3. Integrate the retrieved text block nodes, summary nodes, entity nodes, and entity relationships into an enhanced context, and input it into the large language model along with the user query to generate the final answer.
[0014] Furthermore, in S1, constructing a hybrid graph containing text block nodes and entity nodes specifically includes:
[0015] S11. The original text is divided into blocks to obtain multiple text blocks. Each text block is regarded as a text block node. The content of the text block node includes text content and text vector representation.
[0016] S12. Perform entity recognition and relation extraction on the text block to obtain an entity set and a set of relationships between entities. Each entity is regarded as an entity node. The content of the entity node includes the entity name and entity vector representation.
[0017] S13. Based on the set of relationships between entities, construct entity relationship edges between the corresponding entity nodes;
[0018] S14. If a text block contains an entity, then construct an association edge between the text block node and the corresponding entity node.
[0019] S15. If there is an intersection between the entity sets contained in two text block nodes, then construct a text relationship edge between the two text block nodes.
[0020] Furthermore, in step S1, multi-level summary nodes are generated based on the hybrid graph to form a hierarchical hybrid graph structure, specifically including:
[0021] S16. Divide the nodes in the hybrid graph into communities, and assign nodes with similar semantics and close connections on the graph to the same community;
[0022] S17. For each community obtained from the division, the content of all nodes in the community is summarized using a large language model to generate a text summary of the community, and the text summary is regarded as a summary node. The content of the summary node includes the text summary and the text summary vector representation.
[0023] S18. The newly generated set of summary nodes is used as a new set of nodes. Steps S16 and S18 are executed recursively until the preset level depth is reached, thereby forming a hierarchical index from the bottom-level original text blocks and entity nodes to the high-level abstract summary nodes, forming a hierarchical hybrid graph structure.
[0024] Furthermore, in S16, community division is performed on the nodes in the hybrid graph, including:
[0025] Generate a structure-aware embedding vector that incorporates graph structure information for each node in the hybrid graph;
[0026] Based on the structure-aware embedding vector, nodes are clustered using locality-sensitive hashing and community detection algorithms to form initial communities;
[0027] Adjust the size of the initial community so that the number of nodes in each community is between the preset minimum and maximum size.
[0028] Furthermore, the structure-aware embedding vector is generated using the Cleora algorithm; the Cleora algorithm takes a hierarchical hybrid graph structure as input and outputs the structure-aware embedding vector of each node.
[0029] Further, S2 includes:
[0030] S21. Semantically encode the user query to obtain a query vector. Calculate the similarity between the query vector and the vector representations of text block nodes and summary nodes in the hierarchical hybrid graph structure. Retrieve the K most relevant text block nodes and summary nodes as initial relevant nodes.
[0031] S22. Based on the text block nodes in the initial related nodes, according to the association edges between the text block nodes and entity nodes in the hybrid graph, obtain the entity nodes directly connected to the text block nodes to form the first entity set;
[0032] S23. Based on the query vector, perform similarity calculation with the vector representation of all entity nodes in the hybrid graph, and directly retrieve the K most relevant entity nodes to form a second entity set;
[0033] S24. Merge the first entity set and the second entity set to obtain the total set of related entity nodes, and obtain the relationship between entity nodes in the total set based on the relationship edges between entity nodes in the hybrid graph.
[0034] Furthermore, the similarity calculation in S21 and S23 is implemented using cosine similarity or vector inner product.
[0035] Furthermore, the enhanced context includes:
[0036] The text content related to the query includes the text content of the retrieved text block nodes and the summary text content of the summary nodes;
[0037] A list of entities related to the query, including the entity names of the retrieved entity nodes;
[0038] Description of relationships between related entities, including retrieved entity relationship edges.
[0039] Furthermore, step S0 is included before step S1:
[0040] Collect raw text data and preprocess the raw text data, the preprocessing including text cleaning, sentence segmentation and block segmentation; the raw text data includes one or more of the following: encyclopedic knowledge text, academic literature text, news text, technical document text or Internet web page text.
[0041] Secondly, this invention proposes a context- and relation-aware RAG system based on hierarchical hybrid graphs to implement the aforementioned context- and relation-aware RAG method based on hierarchical hybrid graphs.
[0042] The beneficial effects of this invention are:
[0043] This invention achieves unified modeling of textual semantic information and entity relationship information by constructing a hybrid graph structure that integrates entity nodes and text block nodes, and further constructing a hierarchical graph index to form a hierarchical hybrid graph structure. By combining context-aware retrieval with relationship-aware retrieval, it can simultaneously obtain textual information and entity relationship information related to the query, thus providing a more complete knowledge context for large language models. This method can effectively improve the accuracy and interpretability of retrieval-enhanced generation systems in complex knowledge question answering and multi-hop reasoning tasks, while also improving the retrieval efficiency and generation quality in large-scale knowledge base scenarios. Attached Figure Description
[0044] Figure 1 This is a general block diagram of a context- and relation-aware RAG method based on hierarchical hybrid graphs, as shown in an embodiment of the present invention.
[0045] Figure 2 This is a schematic diagram of the data acquisition module shown in an embodiment of the present invention.
[0046] Figure 3 This is a schematic diagram of a hybrid graph construction module shown in an embodiment of the present invention.
[0047] Figure 4 This is a schematic diagram of the retrieval module shown in an embodiment of the present invention.
[0048] Figure 5 This is a schematic diagram of the fusion module shown in an embodiment of the present invention. Detailed Implementation
[0049] The present invention will be further described and illustrated below with reference to specific embodiments. The embodiments described are merely examples of the content of this disclosure and do not limit the scope of the invention. The technical features of each embodiment in the present invention can be combined accordingly, provided that there is no mutual conflict.
[0050] The accompanying drawings are merely illustrative of the invention and are not necessarily drawn to scale. Some of the block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0051] The flowchart shown in the attached diagram is merely an illustrative example and does not necessarily include all steps. For example, some steps may be broken down, while others may be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.
[0052] Figure 1 The diagram illustrates the overall framework of a context- and relation-aware RAG method based on hierarchical hybrid graphs proposed in this invention. This method mainly includes a data acquisition module, a hybrid graph construction module, a retrieval module, and a fusion generation module. Finally, the fused structured information is input into a large language model for inference generation. Each part is described in detail below.
[0053] I. Data Acquisition Module
[0054] like Figure 2 As shown, the data acquisition module is mainly used to build knowledge data sources, which mainly includes three parts: raw text data collection, text preprocessing, and knowledge extraction, as detailed below.
[0055] S11, Raw Text Data Collection
[0056] In this embodiment, the raw data can come from various types of knowledge sources, such as encyclopedic knowledge text, academic literature text, news text, technical document text, or Internet webpage text. This text data constitutes the system's original knowledge base. In one embodiment of the present invention, the raw text data mainly consists of a large-scale document collection, with each document containing information such as a title, body text, and related metadata.
[0057] To ensure comprehensive knowledge coverage, this embodiment collects text data from different fields, thus forming a multi-source knowledge dataset. Examples include: encyclopedic knowledge data (such as people, organizations, and geographical information); news text (such as press releases from different dates); technical document data (such as software development documents and API descriptions); and internet webpage text data.
[0058] By testing data from different sources, the robustness of a system can be effectively verified.
[0059] In one specific embodiment of the present invention, a total of five text question-answering datasets were compiled for the above-mentioned fields, including multihop-rag, quality, popqa, musique, and hotpotqa.
[0060] S12 performs preprocessing operations on the raw text data, mainly including: text cleaning, text segmentation, and text chunking.
[0061] In this embodiment, to adapt to the retrieval enhancement generation system, long texts are divided into multiple fixed-length text chunks. Each text chunk serves as a node in the graph structure. For example, the original text: "Artificial intelligence is a technology that simulates human intelligent behavior through computers..." After being divided into chunks, we get: text chunk 1, text chunk 2, and text chunk 3, each of which serves as a node in the graph structure.
[0062] S13. After text preprocessing, named entity recognition and relation extraction are performed on the text blocks to extract entities and their relations. For example: Text block: "Graph neural networks were proposed by Scarselli et al. in 2009." The following can be extracted: Entity 1: Graph Neural Network, Entity 2: Scarselli, Entity 3: 2009; Relationships: Proposal relation, Time relation.
[0063] Entity recognition and relation extraction can be achieved using existing natural language processing models, such as large-scale pre-trained language models.
[0064] This step yields: a set of entities, a set of entity relationships, and a set of text blocks. This data will be used for subsequent graph structure construction.
[0065] II. Hybrid Graph Construction Module
[0066] like Figure 3 As shown, this invention proposes a hybrid graph structure that integrates entity nodes and text block nodes. This module mainly includes three parts: text block node construction, entity node construction, and relation edge construction.
[0067] S21, Text Node Construction. Each text block generated in the text preprocessing stage is added as a node to the graph structure. Each text block node contains: text content and a text vector representation. The text vector can be obtained by encoding the text content using a language model, for example: bge-m3.
[0068]
[0069] in, It is the text content within the text block. It is the text vector representation of a text block. It is a language model encoder.
[0070] S22, create an entity node for each entity in the entity set. The entity node contains: an entity name and an entity vector representation. Similarly, the entity vector representation can be obtained by encoding the entity name using a language model, for example: bge-m3.
[0071] S23, Based on the entity relation set, establish relation edges between entity nodes. For example: Entity A: Graph Neural Network, Entity B: Scarselli; Relation: Proposal. Then, establishing a relation edge between the two entity nodes is represented as:
[0072]
[0073] in, It is a set of entity nodes. It is a set of entity relationship edges. It is a graph structure composed of entities.
[0074] S24, if two text blocks Corresponding entity set If the intersection of the two text blocks is greater than a threshold, then a relation edge is constructed between them. This yields the set of text block relation edges. :
[0075]
[0076] in, It is the distance threshold.
[0077] S25. To establish the association between text information and entity information, connecting edges are created between entity nodes and text block nodes. When a text block contains an entity, an edge is created between that entity node and the text block node. For example, if text block 1 contains the entity "graph neural network", then the following connection is established: text block node 1 → entity node "graph neural network". Through the above steps, a hybrid graph structure containing two types of nodes can be constructed: text block nodes and entity nodes, as well as two types of relationships: entity relationship edges, entity-text connection edges, and text relationship edges.
[0078] S26, Construct a hybrid graph structure, as follows:
[0079]
[0080] in, It is a hybrid graph structure. These are the sets of text block nodes and the set of entity nodes, respectively, which serve as the leaf node layer; It is a set of edges relating text block nodes. It is a set of edges relating entity nodes. It is the set of associated edges between entity nodes and text block nodes.
[0081] S27. To further improve retrieval efficiency and organize high-level communities, this invention constructs a hierarchical graph index based on a hybrid graph, generating a hierarchical hybrid graph structure. This step is performed entirely offline and does not affect online retrieval efficiency. The specific steps are as follows:
[0082] (1) Generate structure-aware node embeddings.
[0083] The Cleora algorithm is used to generate embedding vectors for the fused graph structure information of all nodes (text block nodes and entity nodes) in the hybrid graph, specifically represented as follows:
[0084]
[0085] Where v is any node in the hybrid graph. This is its corresponding structure-aware embedding vector. This invention directly incorporates the hybrid graph structure... Inputting the Cleora algorithm generates a structure-aware embedding vector for each node. Unlike pure text semantic embedding, the structure-aware embedding vector simultaneously encodes the textual semantics of the node and the graph topology information, making nodes with similar semantics and connected on the graph closer in the embedding space.
[0086] (2) Clustering of nodes based on Local Sensitive Hash (LSH).
[0087] Embedding vector for each node Randomly sample k hyperplanes {h1,…,h} k}, calculate its hash code:
[0088]
[0089] Using a community detection algorithm, nodes with similar hash codes (smaller Hamming distance) are grouped into the same community, thus forming the initial community.
[0090] (3) Adjust the size of the community.
[0091] For each community B, based on the preset minimum size S min and the largest S max Perform a split or merge operation. Specifically, if the size of community B exceeds the maximum size, then split the community; if the size of community B is below the minimum size, then merge the community; otherwise, retain the original community B.
[0092] After adjustment, the size of each community C meets the requirement of S. min ≤|C|≤S max This ensures that the community is neither too fragmented nor too crude.
[0093] (4) Generate a community summary representation.
[0094] For each adjusted community C, a Large Language Model (LLM) is invoked to generate a text summary of the content of all nodes within the community, and an embedding model is used to encode the text summary into a vector representation:
[0095]
[0096]
[0097] Among them, t C The text summary for community C is generated by inputting the entity names and / or text block content corresponding to all nodes in community C into an LLM, which realizes the true integration of contextual information and relational information. The LLM used in this embodiment is Llama3.1-8B-Instruct. Let C be the dense vector representation of the text summary for community C. An embedding model used to generate encoded vectors, such as bge-m3.
[0098] The text summary and its corresponding dense vector representation are used as the first-level summary node. It serves as a leaf node layer. The next level node.
[0099] (5) Recursively construct multi-level indexes.
[0100] First-level summary node As input, steps (2) to (4) are executed recursively to generate higher-level summary nodes in sequence. This process continues until the preset maximum number of levels L is reached, ultimately constructing an L-level hierarchical index tree as a hierarchical hybrid graph structure. , represented as:
[0101]
[0102] The higher the level, the higher the degree of semantic abstraction. This hierarchical index tree is used as an efficient retrieval database during the online retrieval phase, supporting context-aware and relationship-aware retrieval across granularities.
[0103] III. Search Module
[0104] The retrieval module is used in the constructed hierarchical hybrid graph structure The search function retrieves knowledge information related to user queries, and its structure is as follows: Figure 4 As shown.
[0105] S31, User query parsing.
[0106] First, the system receives the user's query and uses a language model to semantically encode the query, thus obtaining a query vector representation. Simultaneously, entity recognition technology is used to identify potential entity information from the query to assist in the subsequent graph retrieval process.
[0107] S31, Text block node and summary node retrieval.
[0108] By calculating the similarity between the query vector and the text block node vector, several text block nodes and summary nodes most relevant to the query semantics are retrieved from the hierarchical hybrid graph structure. In this embodiment, the similarity calculation can be implemented using vector cosine similarity or vector inner product, and the retrieved data is obtained from the hierarchical hybrid graph structure. The node contains text block nodes and summary nodes.
[0109] S32, perform entity node expansion retrieval based on text blocks.
[0110] After obtaining the initial relevant text block nodes in S31, relation expansion retrieval is performed through the entity nodes and their relation edges in the leaf node layer of the hierarchical hybrid graph structure, specifically as follows:
[0111] Based on the initial related text block nodes, according to Obtain entity nodes ;
[0112] S33, using the similarity calculation between the query vector and the entity node vector, retrieves... Entity Node ;
[0113] S34, merge the entity nodes retrieved in S32 and S33 to obtain the total set of entity nodes:
[0114]
[0115] S35, according to Get The entity relationship edge between them.
[0116] IV. Fusion Module
[0117] The fusion module is used to integrate the retrieved contextual and relational information and input it into the large language model to generate the final answer. Its structure is as follows: Figure 5 As shown.
[0118] S41, Constructing an Enhanced Context
[0119] The retrieved text block nodes, summary nodes, entity nodes, and their entity relationship information are structured and organized to construct an enhanced context. This enhanced context mainly includes the following:
[0120] (1) Text fragments related to the query, consisting of text block nodes and summary nodes, containing text block content and summary text.
[0121] (2) Related entity information, consisting of entity nodes, including entity name.
[0122] (3) The relationship information between entities is composed of entity relationship edges.
[0123] In this way, scattered knowledge and information are integrated into a unified enhanced context.
[0124] S42, Generate the final answer
[0125] The query question and the constructed augmented context are input into a large language model, such as a GPT-like model or other generative language model, and the language model generates the final answer based on the augmented context.
[0126] Through the above methods, the present invention can make full use of textual context information and entity relationship information when generating answers, thereby improving the accuracy and completeness of knowledge.
[0127] This embodiment uses a specific experiment to verify the implementation effect of the present invention.
[0128] I. Data Description
[0129] This invention uses five question-answering datasets covering different task types, including PopQA, QuALITY, MultiHop-RAG, MuSiQue, and HotpotQA, covering three task scenarios: factual accuracy, reading comprehension, and multi-hop reasoning.
[0130] PopQA is a dataset for evaluating factual accuracy. It contains 1,399 questions and a total corpus of approximately 3.89 million words, with an average of about 121 words per text block. It primarily tests the ability of models to retrieve accurate facts from large-scale documents.
[0131] QuALITY is a long text reading comprehension dataset containing 4,609 questions, with a corpus of approximately 1.52 million words and an average text block length of approximately 1,084 words. It requires models to perform deep semantic understanding and reasoning in long contexts.
[0132] MultiHop-RAG is a benchmark dataset for enhanced generation of multi-hop retrieval, containing 2,556 questions, a corpus of approximately 1.42 million words, and an average text block of approximately 921 words. It is specifically designed to evaluate multi-step reasoning capabilities across documents.
[0133] MuSiQue is a dataset that constructs multi-hop questions by combining single-hop questions. It contains 3,000 questions, with a corpus of approximately 3.13 million words and an average text block of approximately 105 words. It focuses on examining the model's multi-step logical reasoning and evidence integration capabilities.
[0134] HotpotQA is a multi-hop question-answering dataset containing 3,702 questions and a corpus of approximately 8.14 million words. The average text block is about 122 words. It requires models to perform multi-step reasoning across multiple documents to answer complex questions that require integrating information from multiple sources.
[0135] II. Baseline Model
[0136] The method of this invention is denoted as HyGRAG. To fully verify the effectiveness of the HyGRAG framework of this invention, it was systematically compared with 14 baseline methods from three categories.
[0137] The first category is the pure LLM method: Zero-shot directly uses the parameter memory of the large language model for inference without using any retrieval; CoT introduces chain-like thinking prompts on the basis of Zero-shot, and improves the model's logical inference ability through step-by-step reasoning.
[0138] The second category is context-aware methods: VanillaRAG retrieves the most relevant text blocks based on embedding similarity and concatenates them as context; RAPTOR performs hierarchical summarization of text blocks through recursive clustering and uses GMM clustering to build a tree index; RAPTOR-K uses the K-means clustering algorithm to replace GMM, achieving a balance between efficiency and performance; EraRAG uses Locality Sensitive Hashing (LSH) for multi-level summarization organization and reduces redundant information by forcing the selection of non-leaf nodes in the retrieval strategy.
[0139] The third category is relation-aware methods: L-GraphRAG (the local mode of Microsoft GraphRAG) supports retrieval centered on local keywords by constructing a knowledge graph and performing community summarization; L / G / H-LightRAG represents the local, global, and hybrid retrieval variants of LightRAG, respectively, integrating graph structures into text indexes; HippoRAG and HippoRAG2 draw on neurobiological memory mechanisms and utilize personalized PageRank for multi-hop reasoning on knowledge graphs; HiRAG bridges local entity details with global semantic summarization through hierarchical graph structures; ArchRAG enhances generation through hierarchical retrieval based on attribute communities.
[0140] III. Evaluation Indicators
[0141] This invention uses two evaluation metrics to assess the proposed method:
[0142] Accuracy measures the proportion of times a model's predictions perfectly match the standard answer. It is a core metric for evaluating the performance of question-answering tasks, ranging from 0% to 100%, with higher values indicating better model performance. For the QuALITY dataset, only accuracy is used as the evaluation metric.
[0143] Recall measures the proportion of the model's generated answers that contain key information from the standard answer. It is suitable for evaluating the completeness of information coverage in open-ended question-answering tasks. The value ranges from 0% to 100%, and the higher the value, the stronger the model's ability to retrieve and utilize relevant information.
[0144] IV. Comparative Experiment
[0145] The experimental results are shown in Table 1. Using Llama-3.1-8B-Instruct as the backbone model, the accuracy and recall of each method were comprehensively compared on five static QA datasets.
[0146] Table 1. Overall performance comparison of the static RAG question-answering dataset (Llama-3.1-8B-Instruct)
[0147]
[0148] As can be clearly observed from Table 1, the HyGRAG framework proposed in this invention significantly outperforms existing baseline methods on various question-answering tasks. Pure LLM inference methods (Zero-shot and CoT) perform the worst on all datasets, indicating that relying solely on model parameter memorization is insufficient for knowledge-intensive inference tasks.
[0149] Among context-aware methods, VanillaRAG, RAPTOR, and EraRAG achieve similar results in fact accuracy and multi-hop inference datasets, while EraRAG performs best on the QuALITY dataset. This result indicates that the advantages of high-order community structures are not apparent in all scenarios, and their effectiveness largely depends on whether multi-hop content is aggregated into the same community during the offline indexing phase.
[0150] In relation-aware methods, different LightRAG variants exhibit distinct advantages: L-LightRAG achieves the highest recall rate (39.97%) on PopQA, while G-LightRAG and H-LightRAG perform relatively weaker, because high-level global concepts are not suitable for highly specific query tasks. HippoRAG and its improved version HippoRAG2 demonstrate competitiveness on tasks such as MultiHop-RAG, but their overall accuracy still falls short of this method.
[0151] Overall, HyGRAG achieved best-in-class or near-best-in-class performance across all tasks. On PopQA, it achieved 72.34% accuracy and 43.51% recall, outperforming other methods by 6.2% and 8.9%, respectively. On MultiHop-RAG, it achieved 65.41% accuracy, a 6.0% improvement over the strongest baseline. On MuSiQue and HotpotQA, the average gain was approximately 11.1%. After introducing the inference enhancement strategy (+Inference), MuSiQue and HotpotQA further improved by 2.0% and 0.4%, respectively. These results demonstrate that HyGRAG, through the synergistic fusion of relational and contextual information, achieves stable robustness and superior performance in fact-finding, reading comprehension, and multi-hop inference tasks.
[0152] Based on the same inventive concept, this embodiment also provides a context- and relation-aware RAG system based on hierarchical hybrid graphs, the system comprising:
[0153] The hybrid graph construction module is used to construct a hybrid graph containing text block nodes and entity nodes based on the original text data, and generate multi-level summary nodes on the basis of the hybrid graph to form a hierarchical hybrid graph structure;
[0154] The retrieval module is used to receive user queries and perform retrieval in the hierarchical hybrid graph structure. The retrieval includes: retrieving relevant text block nodes and summary nodes based on query semantics, and expanding the retrieval of relevant entity nodes based on the connection relationship between text block nodes and entity nodes in the hybrid graph, as well as directly retrieving relevant entity nodes based on query semantics, thereby obtaining the relationship between relevant entity nodes.
[0155] The fusion generation module is used to integrate the retrieved text block nodes, summary nodes, entity nodes, and entity relationships into an enhanced context, which is then input into the large language model along with the user query to generate the final answer.
[0156] Furthermore, it also includes a data acquisition module for collecting raw text data and preprocessing the raw text data, the preprocessing including text cleaning, sentence segmentation and block segmentation; the raw text data includes one or more of the following: encyclopedic knowledge text, academic literature text, news text, technical document text or Internet web page text.
[0157] For the system embodiments, since they basically correspond to the method embodiments, relevant details can be found in the descriptions of the method embodiments; the implementation methods of the remaining modules will not be repeated here. The system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of the present invention according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0158] The system embodiments of the present invention can be applied to any device with data processing capabilities, such as a computer or other similar device. The system embodiments can be implemented in software, hardware, or a combination of both. Taking software implementation as an example, as a logical device, it is formed by the processor of any data processing device loading the corresponding computer program instructions from non-volatile memory into memory for execution.
[0159] The above-described embodiments are merely illustrative of several implementations of the present invention, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the invention. Those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these modifications and improvements all fall within the scope of protection of the present invention.
Claims
1. A context- and relation-aware RAG method based on hierarchical hybrid graphs, characterized in that, Includes the following steps: S1. Based on the original text data, construct a hybrid graph containing text block nodes and entity nodes, and generate multi-level summary nodes on the basis of the hybrid graph to form a hierarchical hybrid graph structure; S2. Receive user query and perform retrieval in the hierarchical hybrid graph structure. The retrieval includes: retrieving relevant text block nodes and summary nodes based on query semantics, and expanding the retrieval of relevant entity nodes based on the connection relationship between text block nodes and entity nodes in the hybrid graph, as well as directly retrieving relevant entity nodes based on query semantics, thereby obtaining the relationship between relevant entity nodes. S3. Integrate the retrieved text block nodes, summary nodes, entity nodes, and entity relationships into an enhanced context, and input it into the large language model along with the user query to generate the final answer.
2. The context- and relation-aware RAG method based on hierarchical hybrid graphs according to claim 1, characterized in that, In step S1, a hybrid graph containing text block nodes and entity nodes is constructed, specifically including: S11. The original text is divided into blocks to obtain multiple text blocks. Each text block is regarded as a text block node. The content of the text block node includes text content and text vector representation. S12. Perform entity recognition and relation extraction on the text block to obtain an entity set and a set of relationships between entities. Each entity is regarded as an entity node. The content of the entity node includes the entity name and entity vector representation. S13. Based on the set of relationships between entities, construct entity relationship edges between the corresponding entity nodes; S14. If a text block contains an entity, then construct an association edge between the text block node and the corresponding entity node. S15. If there is an intersection between the entity sets contained in two text block nodes, then construct a text relationship edge between the two text block nodes.
3. The context- and relation-aware RAG method based on hierarchical hybrid graphs according to claim 2, characterized in that, In step S1, multi-level summary nodes are generated based on the hybrid graph to form a hierarchical hybrid graph structure, specifically including: S16. Divide the nodes in the hybrid graph into communities, and assign nodes with similar semantics and close connections on the graph to the same community; S17. For each community obtained from the division, the content of all nodes in the community is summarized using a large language model to generate a text summary of the community, and the text summary is regarded as a summary node. The content of the summary node includes the text summary and the text summary vector representation. S18. The newly generated set of summary nodes is used as a new set of nodes. Steps S16 and S18 are executed recursively until the preset level depth is reached, thereby forming a hierarchical index from the bottom-level original text blocks and entity nodes to the high-level abstract summary nodes, forming a hierarchical hybrid graph structure.
4. The context- and relation-aware RAG method based on hierarchical hybrid graphs according to claim 3, characterized in that, In step S16, the nodes in the hybrid graph are divided into communities, including: Generate a structure-aware embedding vector that incorporates graph structure information for each node in the hybrid graph; Based on the structure-aware embedding vector, nodes are clustered using locality-sensitive hashing and community detection algorithms to form initial communities; Adjust the initial community size so that the number of nodes in each community is between the preset minimum and maximum size.
5. The context- and relation-aware RAG method based on hierarchical hybrid graphs according to claim 4, characterized in that, The structure-aware embedding vectors are generated using the Cleora algorithm; the Cleora algorithm takes a hierarchical hybrid graph structure as input and outputs the structure-aware embedding vectors of each node.
6. The context- and relation-aware RAG method based on hierarchical hybrid graphs according to claim 1, characterized in that, S2 includes: S21. Semantically encode the user query to obtain a query vector. Calculate the similarity between the query vector and the vector representations of text block nodes and summary nodes in the hierarchical hybrid graph structure. Retrieve the K most relevant text block nodes and summary nodes as initial relevant nodes. S22. Based on the text block nodes in the initial related nodes, according to the association edges between the text block nodes and entity nodes in the hybrid graph, obtain the entity nodes directly connected to the text block nodes to form the first entity set; S23. Based on the query vector, perform similarity calculation with the vector representation of all entity nodes in the hybrid graph, and directly retrieve the K most relevant entity nodes to form a second entity set; S24. Merge the first entity set and the second entity set to obtain the total set of related entity nodes, and obtain the relationship between entity nodes in the total set based on the relationship edges between entity nodes in the hybrid graph.
7. The context- and relation-aware RAG method based on hierarchical hybrid graphs according to claim 6, characterized in that, The similarity calculations in S21 and S23 are implemented using cosine similarity or vector inner product.
8. The context- and relation-aware RAG method based on hierarchical hybrid graphs according to claim 1, characterized in that, The enhanced context includes: The text content related to the query includes the text content of the retrieved text block nodes and the summary text content of the summary nodes; A list of entities related to the query, including the entity names of the retrieved entity nodes; Description of relationships between related entities, including retrieved entity relationship edges.
9. The context- and relation-aware RAG method based on hierarchical hybrid graphs according to claim 1, characterized in that, Step S0 is included before step S1: Collect raw text data and preprocess the raw text data, the preprocessing including text cleaning, sentence segmentation and block segmentation; the raw text data includes one or more of the following: encyclopedic knowledge text, academic literature text, news text, technical document text or Internet web page text.
10. A context- and relation-aware RAG system based on hierarchical hybrid graphs, used to implement the context- and relation-aware RAG method based on hierarchical hybrid graphs as described in claim 1, characterized in that the system... include: The hybrid graph construction module is used to construct a hybrid graph containing text block nodes and entity nodes based on the original text data, and generate multi-level summary nodes on the basis of the hybrid graph to form a hierarchical hybrid graph structure; The retrieval module is used to receive user queries and perform retrieval in the hierarchical hybrid graph structure. The retrieval includes: retrieving relevant text block nodes and summary nodes based on query semantics, and expanding the retrieval of relevant entity nodes based on the connection relationship between text block nodes and entity nodes in the hybrid graph, as well as directly retrieving relevant entity nodes based on query semantics, thereby obtaining the relationship between relevant entity nodes. The fusion generation module is used to integrate the retrieved text block nodes, summary nodes, entity nodes, and entity relationships into an enhanced context, which is then input into the large language model along with the user query to generate the final answer.