Retrieval enhancement generation method and system based on knowledge graph
By constructing an embedded vector and index library based on knowledge graphs and combining the incremental update mechanism, the problem of difficult to model the structured relationship between knowledge and real-time adaptation to knowledge updates in the existing technology is solved, and efficient retrieval and generation effect is achieved in the environment of frequent knowledge updates.
Patent Information
- Application Number
- CN202411716408.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-03-18
AI Technical Summary
The existing search-enhanced generative models are difficult to model the structured relationships between knowledge in a dynamic knowledge update environment, and it is difficult to adapt to knowledge base changes in real time, especially in scenarios where knowledge updates frequently.
By constructing an embedded vector based on knowledge graphs, an index library is generated, and a query vector is used to search similarity in the index library to generate weighted search results. At the same time, an incremental update mechanism is adopted to update the knowledge graph and index library in real time to adapt to the changes in knowledge.
It realizes that in an environment where knowledge is updated frequently, the structured relationship between knowledge can be effectively modeled, and search results that conform to the latest knowledge can be generated in real time, which improves the adaptability and response speed of the generative model.
Smart Images

Figure CN119646018A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electronic digital data processing, and in particular to a retrieval enhancement generation method and system based on a knowledge graph. Background Art
[0002] Retrieval-Augmented Generation (RAG) is a technology that combines retrieval and generation techniques to enhance the generation model by retrieving relevant information from an external knowledge base. Existing RAG models face two major challenges in a dynamic knowledge update environment: First, it is difficult to model the structured relationship between knowledge: Traditional RAG is usually based on the retrieval of text information and lacks modeling of structured relationships between knowledge. Although the relationship between text content is crucial in the generation process, RAG finds it difficult to fully capture this relational knowledge. Second, it is difficult to adapt to new information in real time when the knowledge base changes: RAG finds it difficult to adapt to new knowledge information in real time when the knowledge base data changes, especially in scenarios where knowledge is frequently updated, the generation ability of RAG will be affected.
[0003] Knowledge graphs represent the relationship between any two entities. Nodes represent entities such as people, places, or events, while edges represent the relationship between entities. Knowledge graphs can be used for graph retrieval enhancement generation (GRAG or GAG) and promote conversational interaction with documents. However, existing knowledge graph-based retrieval enhancement generation methods still lack modeling of structured relationships between knowledge and cannot adapt to scenarios where knowledge is frequently updated. Summary of the invention
[0004] In response to the above-mentioned technical problems existing in the prior art, the present invention provides a retrieval enhancement generation method and system based on a knowledge graph, which generates retrieval results based on the structured relationships of the nodes and relationships of the knowledge graph and can be adapted to scenarios where knowledge is frequently updated.
[0005] The present invention discloses a retrieval enhancement generation method based on a knowledge graph, comprising the following steps: constructing an embedding vector through the entities and relationship edges of the knowledge graph to obtain an index library, wherein the embedding vector includes an entity vector and a relationship vector; generating a query vector according to a query; obtaining a result set of the query vector in the index library through similarity; generating a retrieval result according to a weighted sum of the result set; and generating an output result according to the retrieval result and the query vector.
[0006] Preferably, the method for obtaining the result set includes:
[0007] Get the cosine similarity between the embedding vector and the query vector;
[0008] Determine whether the cosine similarity is greater than a threshold;
[0009] If so, add the embedding vector to the result set.
[0010] Preferably, the embedding vector includes an entity vector and a relationship vector;
[0011] The result set is a collection of entity vectors and relationship vectors.
[0012] Preferably, the method of generating the search results is expressed as:
[0013]
[0014] Among them, h context Represents the condition information of the retrieval result, α k and β kl are weight factors, is the entity vector, is the relationship vector, R q The result set.
[0015] Preferably, the weight factor is calculated as follows:
[0016]
[0017] Among them, h q is the query vector, cosine() represents the function of cosine similarity, For entity v j The entity vector of is a relationship vector, which is represented by the relationship vector of the relationship edge between entity i and entity j.
[0018] Preferably, the formula for generating the output result is expressed as:
[0019]
[0020] in, Expressed as the output result, h q For query vector, Generate() represents the generation function.
[0021] Preferably, the method for incrementally updating the index library includes:
[0022] Monitor changes to the knowledge base documents of the knowledge graph and obtain change documents;
[0023] According to the change document, an update collection is constructed, wherein the update collection includes a deletion collection and / or a new addition collection;
[0024] Update the index library according to the update collection:
[0025] According to the deleted set, the embedding vector of the index library is deleted, and the newly added set is merged into the index library to obtain a second index library;
[0026] According to the query vector, embedding vectors having a similarity higher than a threshold are retrieved from the second index library.
[0027] , the adjustment method of the weight factor of the new knowledge fragment:
[0028] Determining whether the result set includes a new knowledge fragment;
[0029] If so, adjust the weight factor of the new knowledge fragment and generate the search results:
[0030]
[0031] Among them, h context Represents the condition information of the retrieval result, α i is the weight factor, It is represented as the entity vector of the result set, and β is the new knowledge fragment h new The weight factor of .
[0032] The present invention also provides a system for implementing the above method, comprising an index library management module, a first query module, a second query module, an adaptive adjustment module and an output module.
[0033] The index library management module is used to construct an embedding vector through the entities and relationship edges of the knowledge graph to obtain an index library;
[0034] The first query module is used to generate a query vector according to the query;
[0035] The second query module is used to obtain a result set of the query vector in the index library through similarity;
[0036] The adaptive adjustment module is used to generate a search result according to the weighted sum of the result set;
[0037] The output module is used to generate output results according to the search results and the query vector.
[0038] Preferably, the index library management module is also used to incrementally update the index library; the adaptive adjustment module is also used to adjust the weight factor of the new knowledge fragment.
[0039] Compared with the prior art, the beneficial effects of the present invention are: generating output results based on the nodes and relationship edges of the knowledge graph, and the result set of the query vector; generating retrieval results through the above-mentioned structured relationships; and modifying the knowledge graph or index library by updating / modifying the nodes and relationships of the knowledge graph, which can be adapted to scenarios where knowledge is frequently updated. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 It is a flow chart of the knowledge graph-based retrieval enhancement generation method of the present invention;
[0041] Figure 2 It is a system logic block diagram of the present invention. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0043] The present invention is further described in detail below in conjunction with the accompanying drawings:
[0044] Retrieval enhancement generation methods based on knowledge graphs, such as Figure 1 As shown, the following steps are included:
[0045] Step 101: construct an embedding vector through the entities and relationship edges of the knowledge graph to obtain an index library, wherein the embedding vector includes an entity vector and a relationship vector.
[0046] Step 102: Generate a query vector according to the query.
[0047] Step 103: Obtain a result set of the query vector in the index library according to the similarity, wherein the result set includes at least one result.
[0048] Step 104: Generate a search result according to the weighted sum of the result set.
[0049] Step 105: Generate an output result according to the search result and the query vector.
[0050] Generate output results based on the nodes and relationship edges of the knowledge graph and the result set of the query vector; generate retrieval results through the above structured relationships; change the knowledge graph or knowledge base by updating / modifying the nodes and relationship edges of the knowledge graph, which can be suitable for scenarios with frequent knowledge updates.
[0051] More specifically, the search enhancement generation method includes the following steps:
[0052] Step 201: Build a knowledge graph.
[0053] Based on the text generation capability of the GPT model, the initial knowledge graph G is constructed. The graph contains entity nodes V and relationship edges E. The knowledge graph is constructed by automatically extracting entity and relationship edge triplets from domain text data. The knowledge graph G is defined as a directed graph, including nodes V and edges E. The graph structure is
[0054] G=(V,E)
[0055] V={v1,v2,...,v t ,...,v n}
[0056] E={e 11 ,e 12 ,...,e ij ,...}
[0057] Where V represents the set of entities / nodes, E represents the set of relationship edges, n represents the number of nodes, and relationship edges e ij Represents node V i and V j The knowledge graph structure can be stored through graph database tools to maintain the efficiency of graph query.
[0058] Step 202: Build embedding vectors and index libraries.
[0059] Index Library I T The embedding vectors of all entities and relationship edges are stored so that the RAG model can quickly retrieve relevant information when it is generated. For any time T, the index library is represented as:
[0060]
[0061] Represented as node v t The entity vector of Represented as node relationship edge e ij The relationship vector.
[0062] When an entity or relationship edge is updated, such as addition, deletion, and modification, the corresponding embedding vector is incrementally updated to the index library I T .
[0063] Step 203: Generate a query vector based on the input query. The query vector h q It is expressed as:
[0064] h q =Emb(q)
[0065] Among them, q represents the input query, h qIt is the representation of the query in the embedding space, and Emb(q) represents the mapping from the input query q to the embedding space.
[0066] Step 204: Obtain results in the index library through similarity to obtain a result set.
[0067] Cosine similarity can be used:
[0068]
[0069] Among them, cosine(h q ,h v ) is represented as a vector h q With vector h v Cosine similarity of; \\h q \\Represented as vector h q The norm of .
[0070] Through cosine similarity and corresponding thresholds, the most relevant set of entities and relationship edges can be screened out, that is, the result set R q :
[0071]
[0072] Among them, τ v and τ e is the threshold value, Indicated as conforming Collection of vectors.
[0073] Step 205: When a word or sentence is generated, a search result is generated based on the result by weighting:
[0074]
[0075] Among them, h context Represents the condition information of the retrieval result, α k and β kl are weight factors, based on h q The similarity is normalized:
[0076]
[0077] Through this weighted contextual representation, the retrieval results can be integrated into the generation process, making the generated content closer to the latest knowledge changes.
[0078] Step 206: Adjust the output result.
[0079] h context The query is embedded with the input q Combine to generate the final output
[0080]
[0081] Generate() represents a generative function, such as the autoregressive generative process based on GPT. By using the latest graph embedding, the generative model can generate high-quality answers that are consistent with the current state of knowledge.
[0082] The dynamic update mechanism of the present invention aims to solve the problem of response delay when the knowledge graph changes frequently. It can quickly adapt to changes in knowledge by incrementally updating the knowledge graph data and interacting with the RAG model in real time. This mechanism ensures that the system can accurately use the latest knowledge data when generating content.
[0083] The method for dynamically updating the knowledge graph of the present invention includes:
[0084] Step 301: Monitor changes to knowledge base documents.
[0085] The change of knowledge base can be detected by event triggering mechanism. Assume that the document set stored in the knowledge base is D = {D1, D2, ..., D k}, if a document D i If a change occurs (addition, modification or deletion), the change document ΔD is recorded i , defined as follows:
[0086]
[0087] When ΔD is monitored i =1, triggering the knowledge graph update.
[0088] Step 302: Construct an update collection according to the changes in the knowledge base documents. The update collection includes a deletion collection and a new addition collection.
[0089] By monitoring the changes in the document ΔD i , identify relevant entities and relationship edges, and construct the corresponding update set G to-update , and locally update the knowledge graph.
[0090] Step 303: Update the knowledge graph and index library according to the update collection.
[0091] Only the entity nodes and relationship edges of the changed parts are updated to avoid rebuilding the entire graph. For example, the update process in the knowledge graph G = (V, E) can be expressed as:
[0092] V new =V old ∪{v new}-{v del}
[0093] E new =E old ∪{e new}-{e del}
[0094] Among them, v new and e new Represent the newly added entities and relationship edges, v del and e del Represent the deleted entities and relationship edges, V new and E new Represents the updated entities and relationship edges.
[0095] Dynamically add the embedding vectors of new or updated entities and relationship edges to the index library I t , and the deleted part is removed from the index library to keep the index consistent with the latest status of the knowledge graph:
[0096] I new =I old +{h new}-{h del}
[0097] This incremental update strategy effectively reduces the overhead of index rebuilding and ensures the system's responsiveness when faced with frequent updates.
[0098] After the knowledge graph is updated, the generation process of the RAG model will automatically adapt to the latest knowledge changes to ensure that the generated content can reflect the latest information in real time. Specifically, when a query q is received, the latest index library I at the current time T is used to generate the query. T To search, the generation process is as follows:
[0099] h q =Emb(q)
[0100] R q =Retrieve(I T ,h q )
[0101] Among them, Retrieve(I T ,h q ) means retrieving the entity vector and relationship vector with the highest similarity to the query from the latest index library.
[0102] The present invention also includes a method for dynamically adjusting the generation strategy, combining the latest retrieved information to dynamically adjust the generation strategy / retrieval results. For example, if during the retrieval process, a new knowledge fragment h new The similarity is high, which can increase the weight of the new knowledge fragment in the generated content:
[0103]
[0104] Among them, h context Represents the condition information of the retrieval result, α i is the weight factor, It is represented as an entity vector, specifically the entity vector of the i-th entity vi, and β is an adaptive weight factor used to adjust the new knowledge fragment h new Impact in the retrieval / generation process. By dynamically adjusting β, the relationship between historical knowledge and new knowledge can be balanced to ensure the timeliness and accuracy of generated content. New knowledge fragments refer to knowledge fragments whose time difference between the time added to the index library and the current time is less than the time threshold.
[0105] In the adaptive generation process, not only the latest entities retrieved are considered, but also the relevant relationship information is combined to optimize the context, so that the generated text is more in line with the user's expectations. For example, when generating an answer to "Who is the new president?", the system will adaptively utilize the latest political figure information and ignore outdated content.
[0106] On the one hand, the present invention combines the dynamic update capability of the knowledge graph with the RAG model to achieve real-time optimization of generated content. During the generation process, the latest graph fragment (index library) is directly called to ensure that the generated content is synchronized with the knowledge update, thereby achieving a deep integration of the dynamic knowledge graph and RAG. On the other hand, after the knowledge graph is updated, the accuracy and timeliness of the generated content can be optimized through adaptive weight distribution. On the third hand, the intelligent trigger mechanism can be used to monitor changes in the knowledge base and automatically adjust the RAG model to ensure that the knowledge graph and the generated content are always consistent, providing stronger real-time performance and high precision of generated content.
[0107] The present invention also has the following characteristics: First, through the incremental update algorithm and dynamic indexing mechanism, the local update of the knowledge graph is realized, avoiding the process of full reconstruction of the graph. Compared with the traditional static update method, this method significantly reduces the time and update amount of the knowledge base update, and improves the response speed. Especially in the scenario where knowledge changes frequently, the generation model can receive the update signal in real time, so that the generated content is synchronized with the latest knowledge, thereby improving the generation efficiency. Reduce the computational cost of full reconstruction and indexing. In addition, the design of the dynamic index library makes the knowledge base and the generation model more closely integrated, effectively reduces the system's computing resource consumption in the frequent update scenario, and improves the overall performance of the system. Second, by combining the latest knowledge graph and adaptive generation strategy, the generation strategy can be dynamically adjusted according to the current query, so that the generated content is consistent with the latest state of the knowledge base. Not only improves the semantic consistency of the generated content, but also can more accurately answer questions based on new knowledge, thereby improving the relevance of the generated content and user satisfaction, and improving the accuracy and relevance of the generated content / output results. It can balance the relationship between historical knowledge and new knowledge, ensuring that the generated content has high timeliness and adaptability. Whether in industry applications where information is frequently updated or in scenarios where content needs to be generated in real time, the system can respond flexibly and provide efficient intelligent generation services.
[0108] The present invention also provides a system for implementing the above-mentioned search enhancement generation method, such as Figure 2 As shown, it includes an index library management module 1, a first query module 2, a second query module 3, an adaptive adjustment module 4 and an output module 5.
[0109] The index library management module 1 is used to construct an embedding vector through the entities and relationship edges of the knowledge graph to obtain an index library; it is also used to update the index library.
[0110] The first query module 2 is used to generate a query vector according to a query.
[0111] The second query module 3 is used to obtain a result set of the query vector in the index library through similarity.
[0112] The adaptive adjustment module 4 is used to generate a search result according to the weighted sum of the result set.
[0113] The output module 5 is used to generate an output result according to the search result and the query vector.
[0114] The index library management module 1 is used for incrementally updating the index library; the adaptive adjustment module 4 is also used for adjusting the weight factor of the new knowledge fragment.
[0115] Embodiment 1:
[0116] Step 401: Query: Are there any new drugs that can treat high blood pressure recently?
[0117] Input: User enters the query: "What new drugs are available to treat high blood pressure?"
[0118] Step 402: Dynamic knowledge graph update (new addition).
[0119] Knowledge base change detection: A new research report on the new drug "Locatep" for the treatment of hypertension was added to the knowledge base. The new document was detected and the update process was triggered.
[0120] Incremental update: add "Locatap" as a new entity and "treatment" as a new relationship edge to the knowledge graph.
[0121] Dynamic index update: The embedding model converts “locatap” and “therapy” into vector embeddings and updates the index library.
[0122] Step 403: Query results:
[0123] Retrieve entities and relationship edges related to "Hypertension Treatment", find "Locatapp", and adjust the weight of the entity.
[0124] Step 404: Output. Generate output: "The recently discovered new drug Locatep is effective in treating high blood pressure."
[0125] Example 2
[0126] Step 501: Query: Who is the latest CEO of Apple?
[0127] User enters the query: "Who is the newest CEO of Apple?"
[0128] Step 502: Dynamic knowledge graph update (modification).
[0129] Knowledge base change detection: The knowledge base has updated the information of Apple's CEO from "Tim Cook" to "John Smith".
[0130] Trigger the update process: The system detects the change of the "CEO" attribute of the "Apple" entity in the knowledge base and triggers the update process. Incremental update: Update the vector embedding of the "Apple" entity to reflect the new CEO information. Dynamic index update: Update the "Apple" entity vector in the index library.
[0131] Step 503: Query results: The RAG model retrieves entities related to "Apple CEO", finds the updated "John Smith", and adjusts the weight factor of the entity.
[0132] Step 504: Output. Generate output: "The newest CEO of Apple is John Smith."
[0133] Example 3
[0134] Step 601: Query: Where can I buy a MacBook Air 2015?
[0135] User enters the query: "Where can I buy a MacBook Air 2015?"
[0136] Step 602: Dynamic knowledge graph update (deletion).
[0137] Knowledge Base Change Detection: Apple has decided to end the production and sales of the 2015 MacBook Air, and this model has been officially discontinued.
[0138] Trigger the update process: The system detects the discontinuation of the 2015 MacBook Air and triggers the update process. Incremental update: Remove the original 2015 MacBook Air entity and related relationship edges from the knowledge graph and add the discontinuation information. Dynamic index update: Remove the vector embedding of the 2015 MacBook Air from the index library.
[0139] Step 603: Query results. Retrieve entities related to "MacBook Air 2015 model". Since the information has been deleted, return the result set related to discontinued products.
[0140] Step 604: Output. Generate output: "The 2015 MacBook Air has been discontinued and is no longer available for sale by Apple Inc. or its authorized resellers."
[0141] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A retrieval enhancement generation method based on knowledge graph, characterized in that: The following steps are involved: Through the entities and relationship edges of the knowledge graph, an embedding vector is constructed to obtain an index library, wherein the embedding vector includes an entity vector and a relationship vector; Generate a query vector based on the query; Obtaining a result set of the query vector in the index library according to the similarity, the result set including at least one result; generating a search result according to a weighted sum of the result set; An output result is generated according to the search result and the query vector.
2. The search enhancement generation method according to claim 1, characterized in that: The methods for obtaining result sets include: Get the cosine similarity between the embedding vector and the query vector; Determine whether the cosine similarity is greater than a threshold; If so, add the embedding vector to the result set.
3. The search enhancement generation method according to claim 2, characterized in that: The embedding vector includes an entity vector and a relation vector; The result set is a collection of entity vectors and relationship vectors.
4. The search enhancement generation method according to claim 1, characterized in that: The way to generate the search results is expressed as: Among them, h context Represents the condition information of the retrieval result, α k and β kl are weight factors, is the entity vector, For the relationship edge e kl The relationship vector, R q The result set.
5. The search enhancement generation method according to claim 4, characterized in that: The weight factor is calculated as: Among them, h q is the query vector, cosine() represents the function of cosine similarity, For entity v j The entity vector of For the relationship edge e ij The relationship vector.
6. The search enhancement generation method according to claim 4, characterized in that: The formula for generating the output is expressed as: in, Expressed as the output result, h q For query vector, Generate() represents the generation function.
7. The search enhancement generation method according to claim 1, characterized in that: It also includes methods for incremental update of the index library: Monitor changes to the knowledge base documents of the knowledge graph and obtain change documents; According to the change document, an update collection is constructed, wherein the update collection includes a deletion collection and / or a new addition collection; Update the index library according to the update collection: According to the deleted set, the embedding vector of the index library is deleted, and the newly added set is merged into the index library to obtain a second index library; According to the query vector, embedding vectors having a similarity higher than a threshold are retrieved from the second index library.
8. The search enhancement generation method according to claim 1, characterized in that: Method for adjusting the weight factor of new knowledge fragments: Determining whether the result set includes a new knowledge fragment; If so, adjust the weight factor of the new knowledge fragment and generate the search results: Among them, h context Represents the condition information of the retrieval result, α i is the weight factor, It is represented as the entity vector of the result set, and β is the new knowledge fragment h new The weight factor of .
9. A system, characterized in that: Used to implement the search enhancement generation method according to any one of claims 1 to 8, the system comprises an index library management module, a first query module, a second query module, an adaptive adjustment module and an output module, The index library management module is used to construct an embedding vector through the entities and relationship edges of the knowledge graph to obtain an index library; The first query module is used to generate a query vector according to the query; The second query module is used to obtain a result set of the query vector in the index library through similarity; The adaptive adjustment module is used to generate a search result according to the weighted sum of the result set; The output module is used to generate output results according to the search results and the query vector.
10. The system according to claim 9, characterized in that The index library management module is also used to incrementally update the index library; The adaptive adjustment module is also used to adjust the weight factor of the new knowledge segment.
Citation Information
Cited By
Intelligent popular science content retrieval interaction system and method combined with knowledge graph
CN120763341A