Graph RAG-based retrieval methods, apparatus, computer equipment, and storage media
By extracting triples and filtering similarity in Graph RAG, the limitations of semantic matching in traditional Graph RAG are solved, resulting in more accurate and richer retrieval results and improving the retrieval performance of knowledge graphs.
Patent Information
- Application Number
- CN202610154574.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-02-03
- Publication Date
- 2026-11-10
- Estimated Expiration
- 2046-02-03
AI Technical Summary
Traditional Graph RAGs have low search accuracy, mainly due to limitations in semantic matching between search statements and triple entity nodes. Entity descriptions are too concise, resulting in insufficient information. Furthermore, they lack in-depth analysis of the document's hierarchical structure, making it impossible to accurately identify the relationships between different levels.
By extracting triples from the query statement, a first semantic vector is generated. The target edge is then queried in the pre-built knowledge graph to determine the target entity node set. Combining community nodes and document fragment nodes, similarity filtering is used to determine the target community summary and document fragment set, returning rich search results.
It expands the search scope, improves the accuracy and richness of search results, and can more comprehensively reflect the overall hierarchical structure and entity relationships of documents, thereby improving the quality and efficiency of search results.
Smart Images

Figure CN122087125B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data retrieval technology, and in particular to a Graph RAG-based retrieval method, apparatus, computer device, computer-readable storage medium, and computer program product. Background Technology
[0002] With the rapid development of information technology, Graph RAG (Graph-based Retrieval-Augmented Generation, an advanced evolution of RAG) represents a significant advancement over traditional RAG (Retrieval-Augmented Generation). By introducing knowledge graphs to understand and connect information, it significantly enhances the ability of large models to handle complex problems.
[0003] The traditional search principle of a Graph RAG is as follows: when a user asks a question, a semantic search is first performed on the triple entity nodes based on the search query to obtain relevant entities. Then, these entities are used to perform retrieval and reasoning from a global perspective of the entire dataset to obtain the search results.
[0004] However, due to the limitations of semantic matching between search statements and triple entity nodes—just as a sentence consists of a subject, verb, and object, while an entity node is only the subject or object and cannot represent the meaning of the entire sentence—traditional Graph RAG search methods have low accuracy. Summary of the Invention
[0005] Therefore, it is necessary to provide a Graph RAG-based retrieval method, apparatus, computer device, computer-readable storage medium, and computer program product to address the aforementioned technical problems.
[0006] Firstly, this application provides a GraphRAG-based retrieval method, the method comprising: In response to a retrieval instruction for a query statement, a first triplet information of the query statement and a first semantic vector of the first triplet information are generated according to the retrieval instruction. In a pre-constructed knowledge graph, a target edge corresponding to a second semantic vector that matches the first semantic vector is queried. The knowledge graph includes nodes and edges. The nodes are used to represent triple entities in the source document, the communities or document fragments associated with the entities, and the edges are used to represent the relationships between entities. The edges have triple attributes, and the triple attributes record the second triple information of the corresponding edge and the second semantic vector of the second triple information. Based on the relationship between the entities represented by the target edge, determine the set of target entity nodes corresponding to the target edge; For each target entity node in the target entity node set, an associated community node set and document shard node set are determined from the knowledge graph; each community node in the community node set records the third semantic vector of the corresponding community summary, and each document shard node in the document shard node set records the fourth semantic vector of the corresponding document shard. Based on the similarity between the first semantic vector and the third or fourth semantic vector, determine the target community summary set and the target document fragment set; The second triplet information of the target edge, the target community summary set, and the target document fragment set are returned as search results.
[0007] In one embodiment, prior to responding to a retrieval instruction for a query, the method further includes converting source documents in the database into a structured knowledge graph.
[0008] In one embodiment, the step of converting source documents in the database into a structured knowledge graph includes: generating source document nodes for each source document in the database; segmenting the source document based on a preset length to obtain multiple document segments and generating document segment nodes; traversing each document segment and extracting triples to obtain multiple triples for each document segment; each triple includes two entities and the relationship between the two entities; generating entity nodes based on the entities, and generating edges in the knowledge graph based on the relationships between the entities, document segments, and source documents; analyzing the entity nodes based on a community detection algorithm to determine communities and generate community nodes, and establishing relationships between community nodes and entity nodes in the triples; and generating triple attributes for corresponding edges based on the relationships between entity nodes in the triples.
[0009] In one embodiment, the method further includes: generating a community summary based on the triples corresponding to the community; encoding the community summary to obtain a third semantic vector of the community summary, and recording the community summary and the corresponding third semantic vector in the corresponding community node; encoding each document fragment to obtain a fourth semantic vector of the document fragment, and recording the document fragment and the corresponding fourth semantic vector in the corresponding document fragment node.
[0010] In one embodiment, the step of traversing each document segment and extracting triples to obtain multiple triples for the document segment includes: traversing each document segment, performing hierarchical analysis on the document segment based on a deep learning model to obtain a tree-like hierarchical structure of the document segment; the tree-like hierarchical structure includes multiple levels and topics and content corresponding to each level; identifying the relationships between multiple levels in the tree-like hierarchical structure, and generating multiple triples for the document segment based on the relationships and the tree-like hierarchical structure.
[0011] In one embodiment, the step of performing hierarchical analysis on the document fragments based on a deep learning model to obtain a tree-like hierarchical structure of the document fragments includes: in response to a hierarchical analysis instruction for the document fragments, sending the hierarchical analysis instruction to the deep learning model; the hierarchical analysis instruction being used to instruct the deep learning model to perform hierarchical analysis on the document fragments; and receiving the tree-like hierarchical structure of the document fragments output by the deep learning model after performing hierarchical analysis on the document fragments based on the hierarchical analysis instruction.
[0012] In one embodiment, the hierarchical analysis instruction includes a corresponding task instruction and a target output format; the task instruction is used to instruct the deep learning model to perform hierarchical analysis on the document fragments, and the target output format is used to instruct the deep learning model on the output format after performing hierarchical analysis on the document fragments.
[0013] In one embodiment, identifying the relationships between multiple levels in the hierarchical tree structure and generating multiple triples for the document fragments based on the relationships and the hierarchical tree structure includes: parsing the hierarchical tree structure of the document fragments to generate a structured data list; each row of the structured data list includes a level identifier and a topic and content corresponding to the level identifier; traversing each row of the structured data list in a preset order to determine the first level identifier of the currently traversed row; querying the structured data list for a second level identifier that is related to the first level identifier of the currently traversed row; if a second level identifier that is related to the first level identifier of the currently traversed row is found, determining the target row corresponding to the second level identifier; and generating corresponding triples based on the relationships, the currently traversed row, and the target row.
[0014] In one embodiment, generating corresponding triples based on the association relationship, the current traversed row, and the target row includes: when the association relationship determines that the first level identifier of the current traversed row is the parent level of the second level identifier of the target row, taking the first content corresponding to the first level identifier as the head entity of the triple, taking the second topic corresponding to the second level identifier as the relation of the triple, and taking the second content corresponding to the second level identifier as the tail entity of the triple; generating corresponding triples based on the head entity, relation, and tail entity; or, when the association relationship determines that the first level identifier of the current traversed row is the child level of the second level identifier of the target row, taking the second content corresponding to the second level identifier as the head entity of the triple, taking the first topic corresponding to the first level identifier as the relation of the triple, and taking the first content corresponding to the first level identifier as the tail entity of the triple; generating corresponding triples based on the head entity, relation, and tail entity.
[0015] In one embodiment, querying the target edge corresponding to the second semantic vector that matches the first semantic vector in the pre-constructed knowledge graph includes: querying the first similarity between the first semantic vector and each second semantic vector in the pre-constructed knowledge graph; and determining the edge of the second semantic vector corresponding to the first similarity as the target edge if the first similarity is greater than or equal to the first similarity threshold.
[0016] In one embodiment, determining the target community summary set and the target document fragment set based on the similarity between the first semantic vector and the third semantic vector or the fourth semantic vector includes: traversing the third semantic vector corresponding to the community summary of each community node in the community node set, and obtaining a second similarity between the first semantic vector and the third semantic vector; if the second similarity is greater than or equal to a second similarity threshold, determining the community summary of the third semantic vector corresponding to the second similarity as the target community summary, and generating the target community summary set based on the target community summary; traversing the fourth semantic vector corresponding to the document fragment of each document fragment node in the document fragment node set, and obtaining a third similarity between the first semantic vector and the fourth semantic vector; if the third similarity is greater than or equal to a third similarity threshold, determining the document fragment of the fourth semantic vector corresponding to the third similarity as the target document fragment, and generating the target document fragment set based on the target document fragment.
[0017] Secondly, this application also provides a GraphRAG-based retrieval device, the device comprising: A retrieval response module is used to respond to a retrieval instruction for a query statement and generate, according to the retrieval instruction, the first triplet information of the query statement and the first semantic vector of the first triplet information; The query module is used to query the target edge corresponding to the second semantic vector that matches the first semantic vector in a pre-built knowledge graph. The knowledge graph includes nodes and edges. The nodes are used to represent triple entities in the source document, the communities or document fragments associated with the entities, and the edges are used to represent the relationships between entities. The edges have triple attributes, and the triple attributes record the second triple information of the corresponding edge and the second semantic vector of the second triple information. The entity node determination module is used to determine the set of target entity nodes corresponding to the target edge based on the relationship between the entities represented by the target edge; The associated node determination module is used to determine the associated community node set and document fragment node set from the knowledge graph for each target entity node in the target entity node set; each community node in the community node set records the third semantic vector of the corresponding community summary, and each document fragment node in the document fragment node set records the fourth semantic vector of the corresponding document fragment. The similarity matching module is used to determine the target community summary set and the target document fragment set based on the similarity between the first semantic vector and the third semantic vector or the fourth semantic vector. The retrieval result return module is used to return the second triplet information of the target edge, the target community summary set, and the target document fragment set as retrieval results.
[0018] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the method described in the first aspect.
[0019] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in the first aspect above.
[0020] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the method described in the first aspect above.
[0021] The aforementioned Graph RAG-based retrieval method, apparatus, computer device, computer-readable storage medium, and computer program product, in response to a retrieval instruction for a query statement, generate first triplet information and a first semantic vector of the query statement based on the retrieval instruction. It then queries a pre-constructed knowledge graph for the target edge corresponding to a second semantic vector that matches the first semantic vector. Based on the relationships between entities represented by the target edge, it determines the set of target entity nodes corresponding to the target edge. For each target entity node in the target entity node set, it determines the associated community node set and document fragment node set from the knowledge graph. Based on the similarity between the first semantic vector and the third or fourth semantic vector, it determines the target community summary set and the target document fragment set. Finally, it returns the second triplet information of the target edge, the target community summary set, and the target document fragment set as the retrieval results. This improves the accuracy of the retrieval results by first extracting triples from the query statement to expand the retrieval scope, and then using similarity filtering to determine the target community summary set and the target document fragment set. Attached Figure Description
[0022] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 This is a flowchart illustrating a Graph RAG-based retrieval method in one embodiment; Figure 2 This is a flowchart illustrating the knowledge graph construction steps in one embodiment; Figure 3 This is a schematic diagram of node relationships in one embodiment; Figure 4 This is a schematic diagram of a knowledge graph in one embodiment; Figure 5 This is a flowchart illustrating the triplet extraction steps in one embodiment; Figure 6 This is a flowchart illustrating the steps for generating triples in one embodiment; Figure 7 This is a structural block diagram of a Graph RAG-based retrieval device in one embodiment; Figure 8 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0025] It should be noted that the terms "first," "second," etc., used in this application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "comprising" and "having," and any variations thereof, used in this application, are intended to cover non-exclusive inclusion. The term "multiple" used in this application refers to two or more. The term "and / or" used in this application refers to one of the embodiments, or any combination of multiple embodiments.
[0026] Traditional Graph RAG search methods suffer from low accuracy. This is due to two main reasons: firstly, the semantic matching between search terms and triple entity nodes is limited; secondly, traditional techniques extract overly concise entity descriptions from documents, filtering out much useful information and hindering the generation of informative community summaries, thus impacting subsequent search results. Furthermore, traditional triple extraction methods typically process sentence or paragraph-level text, failing to effectively capture the overall hierarchical structure of documents. When dealing with complex documents, these methods often fail to accurately identify the relationships between different levels, resulting in incomplete or erroneous extracted triples. Finally, traditional triple extraction techniques lack in-depth analysis and understanding of document hierarchical structures, failing to fully utilize document structural features to improve the accuracy and completeness of triple extraction.
[0027] Based on this, this application provides a Graph RAG-based retrieval method. This embodiment illustrates the application of this method to a terminal. It is understood that this method can also be applied to a server, and further to a system including both a terminal and a server, and implemented through interaction between the terminal and the server. In this embodiment, as... Figure 1 As shown, the method may include the following steps: Step 102: In response to the retrieval instruction for the query statement, generate the first triplet information of the query statement and the first semantic vector of the first triplet information according to the retrieval instruction.
[0028] Here, the retrieval instruction is the directive or command used to retrieve data. The query statement is the statement used to retrieve data from the database, representing the retrieval scope. The first triplet information is obtained by extracting triples from the query statement, represented in the form of <start node>-<relation>-<end node>. The first semantic vector is obtained by vector encoding the first triplet information.
[0029] In this embodiment, when a user needs to perform a search, a query statement is first defined, and a search instruction for the query statement is initiated through the terminal. The terminal then responds to the search instruction and extracts triples from the query statement to obtain the extracted first triple information.
[0030] For example, when extracting triples from a query statement, hierarchical analysis can be performed on the query statement to identify the relationships between different levels, and information-rich triple information can be generated based on this, thereby improving the quality and efficiency of knowledge extraction, while also expanding the retrieval scope and enhancing the comprehensiveness of the retrieval. Furthermore, the extracted first triple information can be vector-encoded to obtain the corresponding first semantic vector, facilitating subsequent retrieval analysis.
[0031] Step 104: Query the target edge corresponding to the second semantic vector that matches the first semantic vector in the pre-constructed knowledge graph.
[0032] The knowledge graph is a structured graph pre-built from source documents in a database. The source documents are the knowledge materials in the database, such as scientific and technological documents, news reports, encyclopedias, etc. The source documents can be in various formats, including but not limited to TXT, PDF, DOC, HTML, etc.
[0033] For example, a knowledge graph includes nodes and edges. Nodes represent triple entities in a source document, communities associated with entities, or document fragments, etc.; edges represent relationships between entities and also have triple attributes, which record the second triple information of the corresponding edge and the second semantic vector of the second triple information. The construction process of the knowledge graph can be referred to the following embodiments.
[0034] The target edge is the edge in the knowledge graph that corresponds to the second semantic vector that matches the first semantic vector. For example, the first similarity between the first semantic vector and the second semantic vector of each edge can be queried in the pre-constructed knowledge graph. If the first similarity is greater than or equal to the first similarity threshold, the edge of the second semantic vector corresponding to the first similarity is determined as the target edge.
[0035] The first similarity threshold is used to determine the minimum similarity of a target edge. This threshold can be any value between 0.4 and 0.8, and its specific value can be flexibly configured based on the precision of the retrieval scenario; this embodiment does not impose any limitation on it. For example, taking a first similarity threshold of 0.4, for the first semantic vector of the first triplet information in the query statement, the first similarity between the first semantic vector and the second semantic vector of each edge can be queried in a pre-constructed knowledge graph. If the first similarity is greater than or equal to 0.4, then the edge of the second semantic vector corresponding to that first similarity is determined to be a target edge. It is understood that there can be one or more target edges.
[0036] Step 106: Based on the relationships between the entities represented by the target edge, determine the set of target entity nodes corresponding to the target edge.
[0037] Since edges in a knowledge graph represent relationships between entities, such as <start node>-<relationship>-<end node>, each edge corresponds to two entity nodes in the knowledge graph (i.e., the start node and the end node). Therefore, based on the relationship between entities represented by each target edge, we can obtain the two target entity nodes corresponding to each target edge, and the two target entity nodes corresponding to each target edge form the corresponding set of target entity nodes.
[0038] Step 108: For each target entity node in the target entity node set, determine the associated community node set and document shard node set from the knowledge graph.
[0039] Since nodes in a knowledge graph represent triple entities, associated communities, or document fragments within a source document, for each target entity node in the target entity node set, associated community nodes and document fragment nodes can be determined from the knowledge graph. This leads to the sets of community nodes and document fragment nodes associated with the target entity node set. Each community node in the community node set records the third semantic vector summarizing the corresponding community, and each document fragment node in the document fragment node set records the fourth semantic vector of the corresponding document fragment.
[0040] Step 110: Determine the target community summary set and the target document fragment set based on the similarity between the first semantic vector and the third or fourth semantic vector.
[0041] Specifically, the third semantic vector corresponding to the community summary of each community node in the community node set determined in the above steps can be traversed. The second similarity between the first semantic vector and the third semantic vector of the first triplet information of the query statement is obtained. If the second similarity is greater than or equal to the second similarity threshold, the community summary of the third semantic vector corresponding to the second similarity is determined as the target community summary. A target community summary set is then generated based on the target community summary. The second similarity threshold is the minimum similarity used to perform similarity judgment to filter out community summaries with low relevance. For example, the second similarity threshold can be any value between 0.7 and 0.9, and its specific configuration can be flexibly configured based on the precision of the retrieval scenario. This embodiment does not limit this.
[0042] Alternatively, the fourth semantic vector corresponding to the document fragment of each document fragment node in the document fragment node set determined in the above steps can be traversed to obtain the third similarity between the first semantic vector and the fourth semantic vector of the first triplet information of the query statement. If the third similarity is greater than or equal to the third similarity threshold, the document fragment corresponding to the fourth semantic vector of the third similarity is determined as the target document fragment, and a target document fragment set is generated based on the target document fragment. The third similarity threshold is the minimum similarity used to perform similarity judgment to filter document fragments with low relevance. For example, the third similarity threshold can be any value between 0.7 and 0.9, and its specific configuration can be flexibly configured based on the precision of the retrieval scenario. This embodiment does not limit this.
[0043] Step 112: Return the second triplet information of the target edge, the target community summary set, and the target document fragment set as the search results.
[0044] Specifically, the second triplet information of the target edge, the target community summary set, and the target document fragment set determined above can be returned as search results to complete the retrieval of the query statement.
[0045] In the aforementioned Graph RAG-based retrieval method, in response to a retrieval command for a query, the method generates first triplet information and a first semantic vector for the query. It then queries a pre-constructed knowledge graph for the target edge corresponding to a second semantic vector that matches the first semantic vector. Based on the relationships between entities represented by the target edge, it determines the set of target entity nodes corresponding to the target edge. For each target entity node in the target entity node set, it determines the associated community node set and document fragment node set from the knowledge graph. Based on the similarity between the first semantic vector and the third or fourth semantic vector, it determines the target community summary set and the target document fragment set. Finally, it returns the second triplet information of the target edge, the target community summary set, and the target document fragment set as the retrieval results. This method improves the accuracy of the retrieval results by first extracting triples from the query to expand the retrieval scope, and then using similarity filtering to determine the target community summary set and the target document fragment set.
[0046] In an exemplary embodiment, in step 102, prior to a retrieval instruction for a query statement, the method may further include converting source documents in the database into a structured knowledge graph.
[0047] For example, such as Figure 2 As shown, converting source documents in a database into a structured knowledge graph can specifically include the following steps: Step 202: For each source document in the database, generate a source document node.
[0048] In this embodiment, source documents are knowledge materials from the database. For each source document in the database, a source document node in the knowledge graph is generated, and triples are extracted from each source document based on subsequent steps to construct a structured knowledge graph.
[0049] Step 204: The source document is segmented based on a preset length to obtain multiple document segments of the source document and generate document segment nodes.
[0050] The preset length can be a pre-defined character length for segmenting the document. Specifically, the source document can be segmented based on the preset length to obtain multiple document segments, and each document segment can be stored in the graph as a node in the knowledge graph, i.e., a document segment node is generated.
[0051] In one scenario, each document fragment can also be vector-encoded to obtain a fourth semantic vector for each document fragment, and the document fragment and its corresponding fourth semantic vector can be recorded in the attributes of the corresponding document fragment node. The vector encoding can be implemented using the BGE-M3 model (a semantic vector model).
[0052] Step 206: Traverse each document fragment and extract triples to obtain multiple triples for each document fragment.
[0053] A triple consists of two entities and a relationship between them, such as the form <start node>-<relation>-<end node>. Specifically, by traversing each document fragment and extracting triples, multiple triples for each document fragment can be obtained.
[0054] In one scenario, document fragments can be preprocessed before triple extraction, including text cleaning, word segmentation, part-of-speech tagging, and named entity recognition. Specifically, text cleaning can be performed on the document fragments to remove noise, special characters, and formatting tags. Then, word segmentation is performed on the cleaned text, dividing continuous text into meaningful word units. Next, part-of-speech tagging is performed on the segmented results to identify the part-of-speech category of each word, such as noun, verb, or adjective. Finally, named entity recognition is performed to identify named entities such as person names, place names, and organization names from the text, providing a foundation for subsequent triple extraction. This embodiment significantly improves the accuracy and efficiency of document analysis by introducing preprocessing, laying a solid foundation for subsequent triple generation.
[0055] Step 208: Generate entity nodes based on entities, and generate edges in the knowledge graph based on the relationships between entities, document fragments, and source documents.
[0056] Document fragments are obtained by splitting a source document into fragments. Therefore, there are corresponding edges between document fragments obtained from the same source document and that source document. Entities are entities extracted from triples based on document fragments. Therefore, there are corresponding edges between the entities in a triple extracted from a document fragment and that document fragment, and there are also corresponding edges between the two entity nodes (start node and end node) in the corresponding triple. For example... Figure 3 As shown, green nodes are source documents, red nodes are document fragments, and orange nodes are entity nodes in triples.
[0057] Step 210: Analyze entity nodes based on the community detection algorithm, identify communities and generate community nodes, and establish the relationship between community nodes and entity nodes in triples.
[0058] Community detection algorithms aim to identify subgroups of nodes (i.e., communities) in a network that are tightly connected internally and sparsely connected externally. For example, community detection algorithms can be implemented using algorithms such as Leiden, Louvain, or Infomap.
[0059] Specifically, entity nodes can be analyzed using community detection algorithms to identify subgroups of nodes with tightly connected internal connections and sparse external connections as communities, generating corresponding community nodes and establishing relationships between community nodes and entity nodes in their corresponding triples. It's understandable that different communities correspond to different themes or concepts within a document.
[0060] In one scenario, a community summary (i.e., a summary of the core content of the community) can be generated based on the triples corresponding to the community. This summary is then vector-encoded to obtain a third semantic vector, and both the summary and the corresponding third semantic vector are recorded in the corresponding community node. Specifically, the triple information corresponding to each community can be sent to a large language model (such as GPT-4, DeepSeek, or Qwen). The large language model generates a community summary for the corresponding community and uses the BGE-M3 model to encode the summary to obtain the corresponding third semantic vector. The community summary and the corresponding third semantic vector are then recorded in the attributes of the corresponding community node.
[0061] Step 212: Generate the triplet attributes of the corresponding edges based on the relationships between the entity nodes in the triplet.
[0062] The edge triplet attributes record the second triplet information of the corresponding edge and the second semantic vector of the second triplet information. The second triplet information is used to represent the plaintext of the corresponding edge triplet; for example, its format could be: <start node>-<relation>-<end node>. The corresponding second semantic vector is obtained by vector encoding the second triplet information, i.e., the plaintext triplet. Specifically, by analyzing the relationships between entity nodes in the triplet, the triplet attributes of edges between entities in the same triplet are generated. This results in the constructed structured knowledge graph, whose graph structure is as follows: Figure 4 As shown.
[0063] In this embodiment, source documents in the database are converted into a structured knowledge graph, thereby providing data support for subsequent rapid retrieval.
[0064] In one exemplary embodiment, such as Figure 5 As shown, in step 206, each document fragment is traversed and triples are extracted to obtain multiple triples for each document fragment. Specifically, this may include the following steps: Step 502: Traverse each document fragment and perform hierarchical analysis on the document fragments based on a deep learning model to obtain a tree-like hierarchical structure of the document fragments.
[0065] The deep learning model can be a pre-trained artificial intelligence model based on the transformer architecture, or a large language model (such as GPT-4, DeepSeek, or Qwen). This embodiment does not limit this.
[0066] In this embodiment, a deep learning model is used to perform hierarchical analysis on document fragments, such as semantic understanding of the text content of the document fragments, organizing the text content into a hierarchical tree structure. For example, the document fragments can first be semantically segmented to identify basic units such as paragraphs, sentences, and phrases. Then, a deep learning algorithm is used to perform semantic understanding and relationship analysis on these basic units to construct a hierarchical tree structure of the document. This hierarchical tree structure includes multiple levels, as well as the topics and content corresponding to each level.
[0067] Because its extracted content is not limited to noun phrases but can also include short sentences, it can retain the original information of document fragments relatively completely. Furthermore, the various levels form a tree structure; for example, a tree structure can include multiple levels, each containing at least one root level and one or more child levels. Multiple child levels can belong to the same level or to different levels. When multiple child levels belong to different levels, one child level can be the parent level of another, and vice versa. Therefore, there is a parent-child relationship between the levels. It is understandable that the root level is generally the parent level and is not considered a child level.
[0068] In an exemplary embodiment, during hierarchical analysis, the terminal can send a hierarchical analysis instruction to the deep learning model in response to the instruction for hierarchical analysis of document fragments. This hierarchical analysis instruction instructs the deep learning model to perform hierarchical analysis on the document fragments. Subsequently, the terminal can also receive a tree-like hierarchical structure of the document fragments output by the deep learning model after performing hierarchical analysis on the document fragments based on the hierarchical analysis instruction.
[0069] In this process, hierarchical analysis instructions can include corresponding task instructions and target output formats. Task instructions direct the deep learning model to perform hierarchical analysis on document fragments, while the target output format specifies the output format of the content after the deep learning model's hierarchical analysis of the document fragments. For example, a hierarchical analysis instruction could be: "Please analyze the article's structure, extract important information, and construct a tree-like data structure. Each row should contain three items: hierarchy, topic, and content." In this hierarchical analysis instruction, the first sentence represents the task instruction, and the second sentence represents the target output format.
[0070] For example, if the input document segment is: "In the ancient castle, the king held a grand banquet. During the banquet, knights demonstrated their swordsmanship, while poets sang hymns of praise. As night fell, fireworks lit up the entire castle." Based on the hierarchical analysis instructions described above, the tree-like hierarchical structure of the document fragments output by the deep learning model is shown below: 0*Article Topic*: A Banquet in the Castle 1. Location: An ancient castle 1. Event: The King's Banquet 2*Program*: A Knight's Swordsmanship Demonstration 3 Characters: Knight 4*Demonstration*: Swordsmanship 2*Program*: Poets' Recitation of Poems 3. Character: Poet 3. Recitation: Poetry 1. Time: Night falls 2*Event*: Fireworks Display 3*Light Up*: Castle In this hierarchy, the first number indicates the level identifier; different numbers represent different levels of hierarchy to distinguish them. For example, the number 0 represents the root level, the number 1 is a child level of root level 0, the number 2 is a child level of level 1, and so on, with adjacent levels having a parent-child relationship. The part enclosed by an asterisk represents the subject (or relationship) of the corresponding level, and the part after the colon represents the content (or entity) of the corresponding level.
[0071] Step 504: Identify the relationships between multiple levels in the hierarchical tree structure, and generate multiple triples for document fragments based on the relationships and the hierarchical tree structure.
[0072] The relationship can be a parent-child relationship, a sibling relationship, or other logical relationships. Taking the parent-child relationship as an example, if one level is the parent level of the other, or one level is the child level of the other, then there is a parent-child relationship between the two levels.
[0073] In one scenario, the relationships between levels can be determined based on the level identifiers corresponding to each level. The level identifier represents the hierarchy level, distinguishing different levels. Different levels of the same level can use the same level identifier; however, different levels of different levels should use different level identifiers. For example, if the level identifier is a number, different numbers represent different levels. The level can be defined according to the order of the numbers, such as defining levels in ascending order, where smaller numbers correspond to higher levels. Only adjacent levels have a relationship. For example, there is a relationship between a level with identifier 0 and a level with identifier 1, and a relationship between a level with identifier 1 and a level with identifier 2. It is understandable that letters or other symbols can also be used as level identifiers, as long as the relationship between different levels of level identifiers is predefined; for example, level 0 is the parent level of level 1, or level 0 is the child level of level 1.
[0074] In this embodiment, the relationships between multiple levels in a tree-like hierarchical structure can be accurately identified based on the predefined relationships between hierarchical identifiers at different levels, and information-rich triples can be generated based on the hierarchical levels with relationships in the tree-like hierarchical structure.
[0075] Specifically, the hierarchical relationships between nodes (such as hierarchy identifiers) in the tree-like hierarchical structure can be analyzed first to identify entity pairs and relationship types that may form triples. Then, a semantic analysis algorithm is applied to extract the subject entity (i.e., the entity corresponding to the start node), the object entity (i.e., the entity corresponding to the end node), and the relationships between them from each node of the tree-like hierarchical structure to construct a standardized triple structure. The semantic analysis algorithm in this embodiment can handle complex semantic relationships, including but not limited to subordinate relationships, causal relationships, temporal relationships, and conditional relationships, ensuring that the generated triples accurately reflect the true relationships between entities in the document fragments.
[0076] This embodiment traverses each document fragment and performs hierarchical analysis based on a deep learning model to obtain a tree-like hierarchical structure of the document fragments. By identifying the relationships between multiple levels in the tree-like hierarchical structure, corresponding triples are generated based on these relationships and the tree-like hierarchical structure. Because the tree-like hierarchical structure extracted by the deep learning model can maintain the integrity of the original information and accurately identify the relationships between different levels, it can generate information-rich triples while effectively preserving the details of the original document fragments. This not only improves the quality and efficiency of knowledge extraction but also provides richer information for retrieval.
[0077] In one exemplary embodiment, such as Figure 6 As shown, in step 504, the relationships between multiple levels in the tree-like hierarchical structure are identified, and multiple triples for document fragments are generated based on the relationships and the tree-like hierarchical structure. Specifically, this may include: Step 602: Perform text parsing on the tree-like hierarchical structure of the document fragments to generate a structured data list.
[0078] Specifically, the hierarchical tree structure of document fragments can be parsed to obtain a structured data list. Each row of the structured data list includes a hierarchy identifier and the corresponding topic and content.
[0079] For example, if the input document is segmented as follows: The significance of DeVron's CNAS certification The successful completion of the CNAS review signifies that the Defraud Laboratory has made significant progress in laboratory construction and testing operations.
[0080] Meanwhile, based on this review, the laboratory drew inferences from one instance to others, deepened its awareness of the standards, and promoted the continuous improvement of the company's documented quality management system. This enhanced the laboratory's comprehensive service capabilities and market competitiveness, providing a strong guarantee for providing the public with fair, accurate, and objective testing data. Based on the hierarchical analysis instructions described above, the tree-like hierarchical structure of the document fragments output by the deep learning model is shown below: 0*Article Topic*: The Significance of DeVron's CNAS Certification 1. Certification Result: Successfully passed the CNAS review panel assessment. 2. Significance: Significant progress has been made in laboratory construction. 2. Significance: Significant progress has been made in the testing work. 1. Follow-up Measures: Based on the review, draw inferences from one instance to others. 2. Deepening the Content: Awareness of Standards 2. **Driven by Content:** Continuous improvement of the documented quality management system. 1. Positive Impact: Enhances the laboratory's comprehensive service capabilities. 1. Positive Impact: Enhances market competitiveness 1. Core Guarantee: Providing impartial, accurate, and objective testing and inspection data. 2. Service Targets: Society The above tree-like hierarchical structure is then parsed into a structured data list, which can be in the form shown in Table (1) below: This information can then be processed through subsequent steps to generate the corresponding triplet information.
[0081] Step 604: Traverse each row of the structured data list according to a preset order and determine the first-level identifier of the current traversed row.
[0082] Here, the current traversed row can be the row currently being traversed in the structured data list, and the first-level identifier refers to the level identifier corresponding to the current traversed row. For example, if the current traversed row is the row with row number 1, then the first-level identifier of the current traversed row is 0.
[0083] The preset order includes either a top-down order based on the structured data list or a bottom-up order based on the structured data list; this embodiment does not limit this. For ease of explanation, this embodiment will use a top-down order for traversing the structured data list as an example.
[0084] Step 606: Query the structured data list for second-level identifiers that are associated with the first-level identifiers of the current traversed row.
[0085] If the relationship between different levels of hierarchical identifiers is defined in the following way: only two adjacent levels have a parent-child relationship, and the level with the smaller number corresponds to a higher level, that is, level n is the parent level of level (n+1).
[0086] Based on this, the structured data list is traversed from top to bottom, searching for other rows that are related to each row. For example, taking the current traversed row as the first row in the structured data list (i.e., the row with row number 1), the first-level identifier of the current traversed row is 0, and the nearest level is then found as its sub-level. From the predefined relationship between the level identifiers of different levels, we know that the level identifier of its sub-level is 1, which means that the second-level identifier related to the first-level identifier 0 is 1. Therefore, we can query the structured data list for the second-level identifier 1 that is related to the first-level identifier 0 of the current traversed row.
[0087] Step 608: If it is determined that a second-level identifier is found that is related to the first-level identifier of the currently traversed row, the target row corresponding to the second-level identifier is determined.
[0088] Specifically, if it is determined that a second-level identifier is found that is related to the first-level identifier of the currently traversed row, then the target row corresponding to the second-level identifier can be determined.
[0089] For example, taking the second level identifier as 1, as shown in the table above, the rows corresponding to the level identifier 1 include rows 2, 5, 8, 9 and 10, so these rows can be identified as the target rows.
[0090] Step 610: Generate the corresponding triples based on the association relationship, the current traversed row, and the target row.
[0091] Since the predefined hierarchical relationship is that level n is the parent level of level (n+1), it can be determined that the level with level identifier 0 is the parent level of the level with level identifier 1. Based on this relationship, corresponding triples can be generated according to the topic and content of the corresponding levels (i.e., the parent level and each child level). For example, the first row with level identifier 0 and the second row with level identifier 1 can generate a triple, and the first row with level identifier 0 and the fifth row with level identifier 1 can also generate a triple. Based on this, multiple triples of document fragments can be obtained.
[0092] In one scenario, the relationship between the hierarchy of the current traversed row and the hierarchy of the target row can be determined first. If, based on the relationship, the first level identifier of the current traversed row is determined to be the parent level of the second level identifier of the target row, then the first content corresponding to the first level identifier can be used as the head entity (i.e., the start node entity) of the triple, the second topic corresponding to the second level identifier can be used as the relationship of the triple, and the second content corresponding to the second level identifier can be used as the tail entity (i.e., the end node entity) of the triple. An edge can then be generated based on the relationship between the head entity and the tail entity to obtain the corresponding triple.
[0093] In one scenario, if the first-level identifier of the current traversed row is determined to be a sub-level of the second-level identifier of the target row based on the association relationship, then the second content corresponding to the second-level identifier can be used as the head entity of the triple, the first topic corresponding to the first-level identifier can be used as the relationship of the triple, and the first content corresponding to the first-level identifier can be used as the tail entity of the triple. An edge is generated based on the relationship between the head entity and the tail entity to obtain the corresponding triple.
[0094] That is, the first entity of the triple is determined from the higher level, and the relationship and the last entity of the triple are determined from the lower level, thereby generating the corresponding triple.
[0095] Based on the above logic, multiple triples can be generated. For example, the table (1) above can be traversed from top to bottom to find the direct parent level of each level (i.e., the level whose nearest level is the current level - 1) and generate triples.
[0096] For example, first process the level with a level identifier of 1: find the level with the nearest parent level identifier of 0 as the parent level.
[0097] For the first level in table (1) marked with 1, which has 2 rows, the corresponding query result is: (1) Authentication result -> Parent level: (0) Article topic; Based on the above logic, the resulting triple is: The significance of DeFrançois's CNAS certification → Certification result → Successfully passed the CNAS review panel review.
[0098] For the second level in Table (1) with an identifier of 1, which has 5 rows, the corresponding query result is: (1) Follow-up measures -> Parent level: (0) Article topic; Based on the above logic, the resulting triple is: The significance of DeFrançois's CNAS certification → Follow-up measures → Applying the lessons learned to other situations based on the review.
[0099] For the third level in Table (1) with a flag of 1, which has 8 rows, the corresponding query result is: (1) Positive impact -> Parent level: (0) Article topic; Based on the above logic, the resulting triple is: The significance of DeFlang's CNAS accreditation → Positive impact → Enhanced comprehensive laboratory service capabilities.
[0100] For the fourth level in Table (1) with a flag of 1, which has 9 rows, the corresponding query result is: (1) Positive impact -> Parent level: (0) Article topic; Based on the above logic, the resulting triple is: The significance of Defraud's CNAS certification → Positive impact → Enhanced market competitiveness.
[0101] For the fifth level in Table (1) with a flag of 1, which has 10 rows, the corresponding query result is: (1) Core Security -> Parent Level: (0) Article Topic; Based on the above logic, the resulting triple is: The significance of Defraud's CNAS certification → Core guarantee → Providing fair, accurate, and objective testing and inspection data.
[0102] Then, process the level with the level identifier 2: find the nearest parent level with the level identifier 1 as the parent level.
[0103] For the first level in Table (1) marked with 2, which has 3 rows, the corresponding query result is: (2) Significance -> Parent level: The most recent (1) authentication result; Based on the above logic, the resulting triple is: Successfully passing the CNAS review panel review → Significant implications → Significant progress in laboratory construction.
[0104] For the second level in Table (1) with the identifier 2, its row count is 4, and the corresponding query result is: (2) Significance -> Parent level: The most recent (1) authentication result; Based on the above logic, the resulting triple is: Successfully passed the CNAS review panel review → Significant implications → Significant progress has been made in the testing work.
[0105] For the third level in Table (1) with the identifier 2, which has 6 rows, the corresponding query result is: (2) Deepen content -> parent level: the most recent (1) follow-up measures; Based on the above logic, the resulting triple is: apply the lessons learned from the review process to other situations → deepen the content → awareness of the principles.
[0106] For the fourth level in Table (1) with the identifier 2, which has 7 rows, the corresponding query result is: (2) Promote content -> parent level: the most recent (1) follow-up measures; Based on the above logic, the resulting triple is: learn from one example and apply it to others based on the review → promote content → continuously improve the documented quality management system.
[0107] For the fifth level in Table (1) with the identifier 2, which has 11 rows, the corresponding query result is: (2) Service object -> Parent level: the nearest (1) core guarantee; Based on the above logic, the resulting triple is: providing fair, accurate, and objective testing and inspection data → service recipients → society.
[0108] After traversing table (1), the final triplet information is as follows: The significance of DeFlang's CNAS accreditation - Accreditation result -> Successfully passed the CNAS review panel's assessment. The significance of DeFlang's CNAS accreditation - follow-up measures -> drawing inferences from one instance to another based on the review The significance of DeFlang's CNAS accreditation - positive impact -> enhances the laboratory's comprehensive service capabilities The significance of Defran's CNAS certification - positive impact -> enhanced market competitiveness The significance of Defraud's CNAS accreditation - core guarantee -> providing impartial, accurate, and objective testing and inspection data. Successfully passing the CNAS review panel review - a significant milestone -> substantial progress in laboratory construction. Successfully passing the CNAS review panel review - Significance -> Significant progress has been made in the testing work. Based on the review, draw inferences from one instance to another - deepen the content -> awareness of the standards Based on the review, we can draw inferences from one instance to another and continuously improve the content-documented quality management system. Providing impartial, accurate, and objective testing and inspection data - Service recipients -> Society The above embodiment analyzes the hierarchical levels in the tree structure. Only two adjacent levels can establish a parent-child relationship. The entity content of the higher level is taken as the head node (i.e., the start node entity) of the triple, and the topic and entity content of the next lower level are taken as the relation and the tail node (i.e., the end node entity) to form the triple. All triples are generated sequentially from level 0 to level N-1 according to the rules. This method can automatically extract semantically clear triple information from document fragments. This triple information can be used for various application scenarios such as subsequent knowledge graph construction and data retrieval.
[0109] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps. It is understood that the steps in different embodiments can be freely combined as needed, and all non-contradictory solutions formed by such combinations are within the scope of protection of this application.
[0110] Based on the same inventive concept, this application also provides a graph RAG-based retrieval device for implementing the graph RAG-based retrieval method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more graph RAG-based retrieval device embodiments provided below can be found in the limitations of the graph RAG-based retrieval method described above, and will not be repeated here.
[0111] In one exemplary embodiment, such as Figure 7 As shown, a Graph RAG-based retrieval device is provided, including: a retrieval response module 702, a query module 704, an entity node determination module 706, an association node determination module 708, a similarity matching module 710, and a retrieval result return module 712, wherein: The retrieval response module 702 is used to respond to a retrieval instruction for a query statement and generate first triplet information of the query statement and a first semantic vector of the first triplet information according to the retrieval instruction. The query module 704 is used to query the target edge corresponding to the second semantic vector that matches the first semantic vector in a pre-built knowledge graph; the knowledge graph includes nodes and edges, the nodes are used to represent entities in the source document, the communities or document fragments associated with the entities, the edges are used to represent the relationships between entities, the edges have triplet attributes, and the triplet attributes record the second triplet information of the corresponding edge and the second semantic vector of the second triplet information; The entity node determination module 706 is used to determine the set of target entity nodes corresponding to the target edge based on the relationship between the entities represented by the target edge; The associated node determination module 708 is used to determine the associated community node set and document fragment node set from the knowledge graph for each target entity node in the target entity node set; each community node in the community node set records the third semantic vector of the corresponding community summary, and each document fragment node in the document fragment node set records the fourth semantic vector of the corresponding document fragment. The similarity matching module 710 is used to determine the target community summary set and the target document fragment set based on the similarity between the first semantic vector and the third semantic vector or the fourth semantic vector. The retrieval result return module 712 is used to return the second triplet information of the target edge, the target community summary set, and the target document fragment set as retrieval results.
[0112] In one exemplary embodiment, the apparatus further includes a knowledge graph construction module for converting source documents in the database into a structured knowledge graph.
[0113] In an exemplary embodiment, the knowledge graph construction module is further configured to: generate source document nodes for each source document in the database; perform fragmentation processing on the source document based on a preset length to obtain multiple document fragments of the source document and generate document fragment nodes; traverse each document fragment and extract triples to obtain multiple triples of the document fragment; the triples include two entities and the relationship between the two entities; generate entity nodes based on the entities, and generate edges in the knowledge graph based on the relationship between the entities, document fragments, and source documents; analyze the entity nodes based on a community detection algorithm, determine communities and generate community nodes, and establish the relationship between community nodes and entity nodes in the triples; and generate triple attributes of the corresponding edges according to the relationship between entity nodes in the triples.
[0114] In an exemplary embodiment, the knowledge graph construction module is further configured to: generate a community summary based on the triples corresponding to the community; encode the community summary to obtain a third semantic vector of the community summary, and record the community summary and the corresponding third semantic vector in the corresponding community node; encode each document fragment to obtain a fourth semantic vector of the document fragment, and record the document fragment and the corresponding fourth semantic vector in the corresponding document fragment node.
[0115] In an exemplary embodiment, the knowledge graph construction module is further configured to: traverse each document segment, perform hierarchical analysis on the document segment based on a deep learning model, and obtain a tree-like hierarchical structure of the document segment; the tree-like hierarchical structure includes multiple levels and topics and content corresponding to each level; identify the association relationships between multiple levels in the tree-like hierarchical structure, and generate multiple triples of the document segment based on the association relationships and the tree-like hierarchical structure.
[0116] In an exemplary embodiment, the knowledge graph construction module is further configured to: send the hierarchical analysis instruction to the deep learning model in response to the hierarchical analysis instruction for the document fragment; the hierarchical analysis instruction is used to instruct the deep learning model to perform hierarchical analysis on the document fragment; and receive the tree-like hierarchical structure of the document fragment output by the deep learning model after performing hierarchical analysis on the document fragment based on the hierarchical analysis instruction.
[0117] In an exemplary embodiment, the hierarchical analysis instruction includes a corresponding task instruction and a target output format; the task instruction is used to instruct the deep learning model to perform hierarchical analysis on the document fragments, and the target output format is used to instruct the deep learning model on the output format after performing hierarchical analysis on the document fragments.
[0118] In an exemplary embodiment, the knowledge graph construction module is further configured to: perform text parsing on the tree-like hierarchical structure of the document fragments to generate a structured data list; each row of the structured data list includes a level identifier and a topic and content corresponding to the level identifier; traverse each row of the structured data list according to a preset order to determine the first level identifier of the currently traversed row; query the structured data list for a second level identifier that is associated with the first level identifier of the currently traversed row; if it is determined that a second level identifier that is associated with the first level identifier of the currently traversed row is found, determine the target row corresponding to the second level identifier; and generate corresponding triples based on the association, the currently traversed row, and the target row.
[0119] In an exemplary embodiment, the knowledge graph construction module is further configured to: when the first level identifier of the current traversed row is determined to be the parent level of the second level identifier of the target row according to the association relationship, take the first content corresponding to the first level identifier as the head entity of the triple, take the second topic corresponding to the second level identifier as the relation of the triple, and take the second content corresponding to the second level identifier as the tail entity of the triple; generate a corresponding triple based on the head entity, relation, and tail entity; or, when the first level identifier of the current traversed row is determined to be the child level of the second level identifier of the target row according to the association relationship, take the second content corresponding to the second level identifier as the head entity of the triple, take the first topic corresponding to the first level identifier as the relation of the triple, and take the first content corresponding to the first level identifier as the tail entity of the triple; generate a corresponding triple based on the head entity, relation, and tail entity.
[0120] In an exemplary embodiment, the query module is further configured to: query a first similarity between a first semantic vector and each second semantic vector in a pre-constructed knowledge graph; and, if the first similarity is determined to be greater than or equal to a first similarity threshold, determine the edge of the second semantic vector corresponding to the first similarity as the target edge.
[0121] In an exemplary embodiment, the similarity matching module is further configured to: traverse the third semantic vector corresponding to the community summary of each community node in the community node set, and obtain a second similarity between the first semantic vector and the third semantic vector; if the second similarity is greater than or equal to a second similarity threshold, determine the community summary of the third semantic vector corresponding to the second similarity as a target community summary, and generate the target community summary set based on the target community summary; traverse the fourth semantic vector corresponding to the document fragment of each document fragment node in the document fragment node set, and obtain a third similarity between the first semantic vector and the fourth semantic vector; if the third similarity is greater than or equal to a third similarity threshold, determine the document fragment of the fourth semantic vector corresponding to the third similarity as a target document fragment, and generate the target document fragment set based on the target document fragment.
[0122] The modules in the aforementioned Graph RAG-based retrieval device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can invoke and execute the operations corresponding to each module.
[0123] In one exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 8 As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When executed by the processor, the computer program implements a Graph RAG-based retrieval method. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0124] Those skilled in the art will understand that Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0125] In one exemplary embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described method embodiments.
[0126] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the above method embodiments.
[0127] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0128] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0129] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0130] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0131] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A retrieval method based on Graph RAG, characterized in that, The method includes: In response to a retrieval instruction for a query statement, a first triplet information of the query statement and a first semantic vector of the first triplet information are generated according to the retrieval instruction. In a pre-constructed knowledge graph, a target edge corresponding to a second semantic vector that matches the first semantic vector is queried. The knowledge graph includes nodes and edges. The nodes are used to represent triple entities in the source document, the communities or document fragments associated with the entities, and the edges are used to represent the relationships between entities. The edges have triple attributes, and the triple attributes record the second triple information of the corresponding edge and the second semantic vector of the second triple information. Based on the relationship between the entities represented by the target edge, determine the set of target entity nodes corresponding to the target edge; For each target entity node in the target entity node set, an associated community node set and document shard node set are determined from the knowledge graph; each community node in the community node set records the third semantic vector of the corresponding community summary, and each document shard node in the document shard node set records the fourth semantic vector of the corresponding document shard. Based on the similarity between the first semantic vector and the third or fourth semantic vector, determine the target community summary set and the target document fragment set; The second triplet information of the target edge, the target community summary set, and the target document fragment set are returned as search results.
2. The method according to claim 1, characterized in that, Prior to responding to a retrieval instruction for a query statement, the method further includes: Convert source documents in the database into structured knowledge graphs.
3. The method according to claim 2, characterized in that, The process of converting source documents in the database into a structured knowledge graph includes: For each source document in the database, generate a source document node; The source document is segmented based on a preset length to obtain multiple document segments of the source document and generate document segment nodes. Each document fragment is traversed and triples are extracted to obtain multiple triples for each document fragment; each triple includes two entities and the relationship between the two entities. Entity nodes are generated based on the entities, and edges in the knowledge graph are generated based on the relationships between the entities, document fragments, and source documents. The entity nodes are analyzed based on the community detection algorithm to identify communities and generate community nodes, and to establish the relationship between community nodes and entity nodes in the triples. Based on the relationships between the entity nodes in the triplet, generate the triplet attributes of the corresponding edges.
4. The method according to claim 3, characterized in that, The method further includes: A community summary is generated based on the triples corresponding to the community; the community summary is encoded to obtain the third semantic vector of the community summary; and the community summary and the corresponding third semantic vector are recorded in the corresponding community node. Each document segment is encoded to obtain a fourth semantic vector for the document segment, and the document segment and the corresponding fourth semantic vector are recorded in the corresponding document segment node.
5. The method according to claim 3, characterized in that, The process of traversing each document fragment and extracting triples yields multiple triples for each document fragment, including: Each document segment is traversed, and a hierarchical analysis of the document segment is performed based on a deep learning model to obtain a tree-like hierarchical structure of the document segment; the tree-like hierarchical structure includes multiple levels and the topics and content corresponding to each level; Identify the relationships between multiple levels in the tree-like hierarchical structure, and generate multiple triples for the document fragments based on the relationships and the tree-like hierarchical structure.
6. The method according to claim 5, characterized in that, The hierarchical analysis of the document fragments based on the deep learning model to obtain the tree-like hierarchical structure of the document fragments includes: In response to a hierarchical analysis instruction for the document fragments, the hierarchical analysis instruction is sent to the deep learning model; the hierarchical analysis instruction is used to instruct the deep learning model to perform hierarchical analysis on the document fragments. The system receives the tree-like hierarchical structure of the document fragments output by the deep learning model after performing hierarchical analysis on the document fragments based on the hierarchical analysis instructions.
7. The method according to claim 6, characterized in that, The hierarchical analysis instruction includes a corresponding task instruction and a target output format; the task instruction is used to instruct the deep learning model to perform hierarchical analysis on the document fragments, and the target output format is used to instruct the deep learning model on the output format after performing hierarchical analysis on the document fragments.
8. The method according to claim 5, characterized in that, The step of identifying the relationships between multiple levels in the tree-like hierarchical structure, and generating multiple triples for the document fragments based on the relationships and the tree-like hierarchical structure, includes: The hierarchical tree structure of the document fragments is parsed to generate a structured data list; each row of the structured data list includes a hierarchy identifier and the topic and content corresponding to the hierarchy identifier; Based on a preset order, each row of the structured data list is traversed to determine the first-level identifier of the currently traversed row; Query the structured data list for a second-level identifier that is associated with the first-level identifier of the currently traversed row; If it is determined that a second-level identifier is found that is related to the first-level identifier of the currently traversed row, the target row corresponding to the second-level identifier is determined; Generate corresponding triples based on the association, the current traversed row, and the target row.
9. The method according to claim 8, characterized in that, The step of generating corresponding triples based on the association relationship, the current traversed row, and the target row includes: If, based on the association relationship, the first-level identifier of the currently traversed row is determined to be the parent level of the second-level identifier of the target row, then the first content corresponding to the first-level identifier is used as the head entity of the triple, the second topic corresponding to the second-level identifier is used as the relation of the triple, and the second content corresponding to the second-level identifier is used as the tail entity of the triple; a corresponding triple is generated based on the head entity, relation, and tail entity; or... If, based on the association relationship, the first level identifier of the current traversed row is determined to be a sub-level of the second level identifier of the target row, the second content corresponding to the second level identifier is taken as the head entity of the triple, the first topic corresponding to the first level identifier is taken as the relation of the triple, and the first content corresponding to the first level identifier is taken as the tail entity of the triple; and the corresponding triple is generated based on the head entity, relation, and tail entity.
10. The method according to any one of claims 1 to 9, characterized in that, The step of querying the target edge corresponding to the second semantic vector that matches the first semantic vector in the pre-constructed knowledge graph includes: Query the first similarity between the first semantic vector and each second semantic vector in the pre-constructed knowledge graph; If the first similarity is determined to be greater than or equal to the first similarity threshold, the edge of the second semantic vector corresponding to the first similarity is determined to be the target edge.
11. The method according to any one of claims 1 to 9, characterized in that, The step of determining the target community summary set and the target document fragment set based on the similarity between the first semantic vector and the third or fourth semantic vector includes: Traverse the third semantic vector corresponding to the community summary of each community node in the community node set, and obtain the second similarity between the first semantic vector and the third semantic vector; If the second similarity is determined to be greater than or equal to the second similarity threshold, the community summary of the third semantic vector corresponding to the second similarity is determined as the target community summary, and the target community summary set is generated based on the target community summary; Traverse the fourth semantic vector corresponding to the document segment of each document segment node in the document segment node set, and obtain the third similarity between the first semantic vector and the fourth semantic vector; If the third similarity is greater than or equal to the third similarity threshold, the document segment corresponding to the fourth semantic vector of the third similarity is determined as the target document segment, and the target document segment set is generated based on the target document segment.
12. A retrieval device based on Graph RAG, characterized in that, The device includes: A retrieval response module is used to respond to a retrieval instruction for a query statement and generate, according to the retrieval instruction, the first triplet information of the query statement and the first semantic vector of the first triplet information; The query module is used to query the target edge corresponding to the second semantic vector that matches the first semantic vector in a pre-built knowledge graph. The knowledge graph includes nodes and edges. The nodes are used to represent triple entities in the source document, the communities or document fragments associated with the entities, and the edges are used to represent the relationships between entities. The edges have triple attributes, and the triple attributes record the second triple information of the corresponding edge and the second semantic vector of the second triple information. The entity node determination module is used to determine the set of target entity nodes corresponding to the target edge based on the relationship between the entities represented by the target edge; The associated node determination module is used to determine the associated community node set and document fragment node set from the knowledge graph for each target entity node in the target entity node set; each community node in the community node set records the third semantic vector of the corresponding community summary, and each document fragment node in the document fragment node set records the fourth semantic vector of the corresponding document fragment. The similarity matching module is used to determine the target community summary set and the target document fragment set based on the similarity between the first semantic vector and the third semantic vector or the fourth semantic vector. The retrieval result return module is used to return the second triplet information of the target edge, the target community summary set, and the target document fragment set as retrieval results.
13. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 11.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 11.
15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Crop disease and insect pest knowledge question and answer method based on GraphRAG
CN121277965A
Retrieval generation method and system based on large model and knowledge graph fusion
CN121388189A
