Search enhancement generation method and apparatus
By constructing a lexical dictionary constraint relationship type generation and a k-BET reasoning subgraph retrieval algorithm, the semantic alignment and structural integrity problems in knowledge graph augmented reasoning are solved, and efficient and low-overhead reasoning subgraph generation is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 启元实验室
- Filing Date
- 2026-03-24
- Publication Date
- 2026-07-24
AI Technical Summary
Existing knowledge graph augmented reasoning methods face challenges in terms of semantic alignment and structural integrity, resulting in incomplete and semantically unfaithful reasoning subgraph retrieval, as well as high retrieval efficiency and resource overhead.
By constructing a lexical dictionary to constrain relation types, the k-BET inference subgraph retrieval algorithm is used to search for the target inference subgraph in the knowledge graph. The large model is called only once in the relation generation stage, and the final result is generated by combining the inference results with the generation model.
It achieves semantically faithful and structurally complete reasoning subgraph retrieval, reduces latency and computational overhead, and improves retrieval efficiency and resource utilization efficiency.
Smart Images

Figure CN121901401B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, specifically to a method and apparatus for generating enhanced search results. Background Technology
[0002] Currently, with the rapid development of large-scale pre-trained language models (LLM), they are widely used in scenarios such as search, customer service, and office collaboration. However, LLM's reliance solely on the internal memory of model parameters has two prominent problems: internal knowledge is prone to becoming outdated and it is susceptible to "illusions," which limits its application in scenarios with high reliability requirements.
[0003] To address these issues, the Retrieval Augmentation (RAG) paradigm has become the mainstream solution. Traditional RAGs typically build vector indexes based on unstructured text (documents, web pages, reports, etc.), but unstructured text lacks explicit entity and relational structures, making it difficult to support complex queries that require multi-hop reasoning, combinatorial reasoning, and complex constraints.
[0004] Therefore, GraphRAG (Graph-based Retrieval Augmentation) combining knowledge graphs (KG) has emerged as a new solution. However, existing KG / GraphRAG-based augmented reasoning methods still face two major challenges: incomplete inference subgraph retrieval and inaccurate semantic alignment. Incomplete inference subgraph retrieval can easily lead to structural incompleteness, while inaccurate semantic alignment can result in semantic infidelity.
[0005] Therefore, under the existing GraphRAG / knowledge graph augmented reasoning technology, there is an urgent need for a technical solution that can simultaneously guarantee (1) semantic faithfulness: the reasoning subgraph covers as much as possible all relation types related to the semantics of the question; (2) structural completeness: the reasoning subgraph contains a complete logical path from the subject entity to the potential answer entity; and take into account retrieval efficiency and resource overhead. Summary of the Invention
[0006] Based on this, this application provides a method and apparatus for generating retrieval enhancements, which achieves structural integrity, semantic fidelity, and balances retrieval efficiency and resource consumption.
[0007] According to one aspect of this application, a retrieval-enhanced generation method is proposed, comprising: constructing a lexical dictionary based on a pre-built knowledge graph; inputting the question to be reasoned and the lexical dictionary into a pre-built relation type generation model to obtain a relation type set; performing entity recognition on the question to be reasoned and mapping the recognized entities to entity nodes in the knowledge graph to obtain a topic entity set; using the topic entity set as a starting point, using the k-BET reasoning subgraph retrieval algorithm, searching in the knowledge graph under the constraints of the relation type set to obtain a target reasoning subgraph; converting the triples in the target reasoning subgraph into a preset format, and inputting the format-converted triples and the question to be reasoned into a pre-built reasoning result generation model to obtain a generation result.
[0008] According to some embodiments, a lexical dictionary is constructed based on a pre-built knowledge graph, including: dividing the names of relation types included in the knowledge graph into multiple lexical units according to preset rules to obtain a lexical unit sequence; constructing a multi-branch prefix tree as a lexical dictionary based on the lexical unit sequence, wherein each path from the root to the leaf in the multi-branch prefix tree corresponds to a relation type, and the node subset of the multi-branch prefix tree represents the set of candidate lexical units that can be expanded under the current lexical unit prefix.
[0009] According to some embodiments, a knowledge graph is pre-constructed through the following steps: extracting multiple entities and relationships between multiple entities from multi-source data; constructing an initial graph based on the multiple entities and relationships between multiple entities; assigning unique identifiers and names based on word sequences to the relationship types of the initial graph to obtain the knowledge graph.
[0010] According to some embodiments, the problem to be reasoned and the lexical dictionary are input into a pre-built relation type generation model to obtain a relation type set, including: generating a model input sequence based on the problem to be reasoned and a predefined prompt word template; adding the root node of the lexical dictionary and its corresponding lexical prefix path to a search queue; retrieving the current node from the head of the search queue; if the current node is a terminal node, adding the lexical prefix path corresponding to the current node to the relation type set; if the current node is not a terminal node, obtaining multiple sub-paths according to a pre-set dictionary constraint decoding step, and adding the multiple sub-paths and their corresponding nodes to the tail of the search queue.
[0011] According to some embodiments, the trie constraint decoding step includes: inputting the model input sequence and the lexical prefix corresponding to the current node into the relation type generation model to obtain the model logical output value; masking the model logical output value according to the candidate lexical set of the current node, and normalizing the masked model logical output value to obtain the conditional probability distribution of the candidate lexicals in the candidate lexical set; selecting a preset number of candidate lexicals with a probability greater than a preset threshold as target sub-lexicals based on the conditional probability distribution; and obtaining the sub-path according to the lexical prefix path of the current node and the target sub-lexical.
[0012] According to some embodiments, starting with a set of topic entities, the k-BET inference subgraph retrieval algorithm is used to search the knowledge graph under the constraint of a set of relation types to obtain the target inference subgraph. This includes: S1: Initializing the relation budget vectors of the topic entities in the topic entity set to preset values, and adding the topic entities and their relation budget vectors to the search stack; S2: Retrieving the current entity and its current relation budget vector from the top of the search stack; S3: Obtaining the adjacent edges of the current entity in the knowledge graph; S4: [The text abruptly ends here, so the translation stops here as well.] If the preset conditions are met, add the triples corresponding to the adjacent edges to the current inference subgraph and update the search stack according to the triples. The triples include the current entity, the edge, and the associated entity corresponding to the edge. S5: If the relation type of the adjacent edge does not belong to the relation type set and / or the relation budget vector of the current entity is 0, skip the adjacent edge. S6: Repeat steps S3-S5 until the adjacent edges of the current entity in the knowledge graph are traversed. S7: If the search stack is not empty, jump to step S2. S8: If the search stack is empty, output the current inference subgraph as the target inference subgraph.
[0013] According to some embodiments, step S4 includes: if there is at least one element in the historical relation budget vector set of the associated entity such that the element is not less than the current relation budget vector in all relation type dimensions, then skip the associated entity; if for any element in the historical relation budget vector set of the associated entity, there is at least one relation type dimension less than the current relation budget vector, then update the current relation budget vector, the relation budget vector set of the associated entity, and the search stack.
[0014] According to some embodiments, if for any element in the historical relation budget vector set of the associated entity, there exists at least one relation type dimension smaller than the current relation budget vector, then the current relation budget vector, the relation budget vector set of the associated entity, and the search stack are updated, including: if for any element in the historical relation budget vector set of the associated entity, there exists at least one relation type dimension smaller than the current relation budget vector, then one unit budget is deducted from the current relation budget vector as the new current relation budget vector; the associated entity and the updated current relation budget vector are added to the top of the search stack; and the relation budget vector set of the associated entity is updated using the updated current relation budget vector.
[0015] According to one aspect of this application, a retrieval-enhanced generation apparatus includes: a lexical dictionary unit for constructing a lexical dictionary based on a pre-built knowledge graph; a first set unit for inputting the question to be reasoned and the lexical dictionary into a pre-built relation type generation model to obtain a relation type set; a second set unit for performing entity recognition on the question to be reasoned and mapping the recognized entities to entity nodes in the knowledge graph to obtain a topic entity set; a reasoning subgraph unit for using the topic entity set as a starting point and employing the k-BET reasoning subgraph retrieval algorithm to search the knowledge graph under the constraints of the relation type set to obtain a target reasoning subgraph; and a result generation unit for converting the triples in the target reasoning subgraph into a preset format and inputting the format-converted triples and the question to be reasoned into a pre-built reasoning result generation model to obtain a generation result.
[0016] According to one aspect of this application, an electronic device is provided, comprising: one or more processors; a storage device for storing one or more programs; and, when the one or more programs are executed by the one or more processors, causing the one or more processors to implement the method as described above.
[0017] According to one aspect of this application, a computer-readable medium is provided that stores a computer program or instructions thereon, which, when executed by a processor, implement the method as described above.
[0018] Through the embodiments provided in this application, a lexical dictionary is constructed based on the knowledge graph. A set of relation types is generated using the large model constrained by the lexical dictionary, thereby significantly reducing the probability of relation type illusion and achieving a faithful mapping of the question's semantics. Entity identification is performed on the question to be reasoned, and the results are mapped to the knowledge graph to obtain a set of topic entities. Starting from the entities in the topic entity set, the k-BET reasoning subgraph retrieval algorithm is used to search the knowledge graph to obtain the target reasoning subgraph. This ensures that the multi-hop path from the entity to the candidate answer entity is as complete as possible, avoiding the loss of key edges due to fixed Top-k truncation, thus achieving structural integrity. The large model is called only once during the relation generation stage, reducing the number of online large model calls and shrinking the retrieval scale, significantly reducing latency and computational overhead while maintaining performance. The target reasoning subgraph and the question to be reasoned are input into the reasoning result generation model to obtain the generated result, achieving structural integrity, semantic fidelity, and retrieval enhancement generation that balances retrieval efficiency and resource consumption. Attached Figure Description
[0019] It should be understood that the above general description and the following detailed description are merely exemplary and do not limit this application.
[0020] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings, without exceeding the scope of protection claimed by this application.
[0021] Figure 1 A flowchart of the retrieval enhancement generation method provided in the embodiments of this application;
[0022] Figure 2 The flowchart of the retrieval enhancement generation method provided in this application embodiment for constructing a lexical dictionary tree; Figure 3 A schematic diagram of the lexical dictionary structure of the retrieval enhancement generation method provided in this application embodiment; Figure 4 A flowchart illustrating the generation method for enhancing retrieval provided in this application, including the generation of a set of relation type data; Figure 5 A flowchart of the search target reasoning subgraph of the retrieval enhancement generation method provided in this application embodiment; Figure 6 A flowchart of step S4 of the retrieval enhancement generation method provided in this application embodiment; Figure 7 A block diagram of a retrieval enhancement generation apparatus provided in an embodiment of this application; Figure 8This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0023] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0024] Furthermore, the described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Numerous specific details are provided in the following description to give a thorough understanding of embodiments of this application. However, those skilled in the art will recognize that the technical solutions of this application can be practiced without one or more of the specific details, or other methods, components, apparatuses, steps, etc., can be employed. In other instances, well-known methods, apparatuses, implementations, or operations are not shown or described in detail to avoid obscuring various aspects of this application.
[0025] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0026] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.
[0027] It should be understood that although the terms first, second, third, etc., may be used herein to describe various components, these components should not be limited by these terms. These terms are used to distinguish one component from another. Therefore, the first component discussed below may be referred to as the second component without departing from the teachings of this application. As used herein, the term "and / or" includes all combinations of any one and more of the associated listed items.
[0028] Currently, traditional RAGs (Research Graphs) primarily construct vector indexes from unstructured text (documents, web pages, reports, etc.) and rely on semantic vector similarity for retrieval. However, unstructured text lacks explicit entity and relational structures, making it difficult to cover the complete reasoning chain under multi-hop reasoning, combinatorial reasoning, and complex constraints. Knowledge Graphs (KGs), on the other hand, explicitly organize entities and their relationships in the form of triples, possessing clear structure and semantic interpretability, making them ideal for carrying verifiable factual knowledge and complex reasoning processes involving multiple entities and relationships. A typical workflow involves extracting a "reasoning subgraph" from the KG based on the user's question, and then inputting the triples of this subgraph or formatted text into an LLM (Local Level Management Graph) to obtain the final answer.
[0029] However, existing KG / GraphRAG augmented reasoning methods generally suffer from two key bottlenecks: (1) Incomplete retrieval of reasoning subgraphs: When constructing reasoning subgraphs from KG, many schemes either use a limited-depth search starting from the topic entity or first coarsely recall larger subgraphs and then truncate them by scoring. The former relies on manually set maximum depth and heuristic pruning, which is prone to losing critical paths; the latter usually prunes candidate triples by fixing the Top-k method, which may mistakenly delete the edges or intermediate entities necessary to form a complete reasoning chain, resulting in an incomplete structure. (2) Inaccurate semantic alignment: There is no one-to-one correspondence between predicates and phrases in natural language problems and relation types in knowledge graphs. Graph relation patterns often contain hierarchical, long-tail, and a large number of domain-specific relations. If only simple vector similarity or rule matching is used, semantic infidelity is likely to occur: either irrelevant relation types are selected incorrectly, or relations that are strongly related to the semantics of the problem but are expressed in a more subtle way are missed, resulting in the retrieved subgraphs failing to fully cover the problem intent at the semantic level.
[0030] Existing methods can be roughly divided into two paradigms: (1) Model pre-selection mode: LLM is frequently called during the graph traversal stage to select the edge type or path to be expanded in the next round, thereby gradually constructing the reasoning subgraph. Although this type of method utilizes the semantic understanding ability of LLM to a certain extent, it has two problems: First, it requires multiple rounds of model calls, which are costly and time-consuming; second, if the wrong key relation type is selected in a certain round, the subsequent traversal path will accumulate deviation, causing the relations and entities retrieved in the subsequent retrieval to be offset, and the semantics of the reasoning subgraph deviates from the problem intent. (2) Model post-filtering mode: First, a larger candidate subgraph is constructed from the KG through embedding / similarity and other methods, and then LLM or lightweight model is used to score and filter the candidate triples. Although this type of method can guarantee the richness of recall to a certain extent, when the fixed scale is truncated, it is easy to cut off the key edges on some multi-hop reasoning chains, resulting in incomplete structure. Although the context obtained by LLM contains relevant entities, it lacks a complete logical path and is difficult to provide a reliable reasoning process.
[0031] The aforementioned semantic infidelity and structural incompleteness are often intertwined: if the set of relation types chosen semantically is incomplete, even traversing the graph structure will not find the necessary path to the answer; conversely, if edges that "appear to be related" are retained only from a semantic perspective, the LLM still cannot obtain a complete causal or inference chain because the overall structure is truncated, resulting in an incorrect answer or a lack of evidence.
[0032] Furthermore, in the context of large-scale knowledge graphs (often containing hundreds of millions of nodes and billions of edges), how to perform efficient reasoning subgraph retrieval within limited time and computing resources is also an important problem in engineering practice. Simply using breadth-first or depth-first traversal will lead to an exponential explosion in depth under multi-hop conditions, making it difficult to meet the latency requirements of online services and easily exceeding the context length limit of LLM.
[0033] Based on this, this application provides a method and apparatus for generating enhanced search results.
[0034] For specific implementation details, please refer to the following examples.
[0035] Figure 1 A flowchart illustrating the retrieval enhancement generation method provided in this application embodiment. For example... Figure 1 As shown, the method includes steps S110-S150.
[0036] In step S110, a lexical dictionary is constructed based on the pre-built knowledge graph.
[0037] Representing the relational schema of a knowledge graph as a token-trie allows for structural constraints on the relational type generation space.
[0038] In step S120, the problem to be reasoned and the lexical dictionary are input into the pre-built relation type generation model to obtain a set of relation types.
[0039] The relation type generation model is a pre-built large language model, and this application does not limit its specific architecture or model. The problem to be reasoned is the input natural language problem.
[0040] The input reasoning question is encoded based on the relation type generation model, and relation type words are decoded step by step under the constraint of the word trie to obtain the relation type set R.
[0041] Specifically, by using a relation type generation model based on a lexical dictionary structure, the relation type set of the reasoning problem is predicted to obtain a set of semantically relevant and pattern-valid relation types.
[0042] Furthermore, the final set of relation types R is a group of relation types related to the semantics of the question, such as travel / has_airport, location / contained_by, country / borders_with, etc. These relations all come from the relation type pattern of the knowledge graph, thus avoiding the problem of relation types not being semantically faithful.
[0043] This application encodes knowledge graph relation patterns into a lexical dictionary and constrains the relation type decoding space of a large language model on this structure. The resulting relation type set satisfies the validity of relation type patterns and covers the main relations involved in the semantics of the problem, significantly reducing relation type illusion and semantic bias.
[0044] In step S130, entity recognition is performed on the reasoning problem, and the identified entities are mapped to entity nodes in the knowledge graph to obtain a set of topic entities.
[0045] For reasoning problems, entity recognition and linking are performed, and phrases that can be matched with entities in the knowledge graph are mapped to a set of topic entities T, which serves as the starting node set for graph search.
[0046] In practice, natural language processing involves word segmentation and entity recognition, and the identified entity phrases are mapped to entity nodes in the knowledge graph. For example, "a certain city" is mapped to the corresponding city entity, and "a certain target country" is mapped to the country entity. The resulting set of topic entities T will serve as the starting set for subsequent k-BET subgraph retrieval.
[0047] According to the example implementation, the entity linking model is used to map entities to entity nodes in the knowledge graph.
[0048] In step S140, the topic entity set is used as the starting point, and the k-BET reasoning subgraph retrieval algorithm is used to search the knowledge graph under the constraint of the relation type set to obtain the target reasoning subgraph.
[0049] Use the set of topic entities T as the starting set of nodes for graph search.
[0050] It is understandable that, given a set of relation types R and an integer k, this application defines: 1) If a path originates from any node in the graph Starting from the point, you travel through several edges to reach the node. 1) A path is called a k-BET path if the relation type of each edge on it belongs to R and the number of times any relation type appears in the path does not exceed k; 2) If a subgraph G'=(V',E') satisfies that the set of subject entities T contains V', and for any non-subject entity v∈V'\T in the subgraph, there exists a k-BET path from the subject entity to a non-subject entity or from a non-subject entity to the subject entity, then G' is called a k-BET subgraph; 3) If no new node or edge can be added to G' while maintaining the above constraints, then G' is called a maximal k-BET subgraph.
[0051] In other words, given the set of topic entities T, the set of relation types R, and the upper bound k of edge type repetition, a maximal subgraph satisfying the following constraints is searched from the knowledge graph: 1) The subgraph covers all topic entities; 2) There exists a path between any non-topic entity node in the subgraph and at least one topic entity, where each edge relation type on the path belongs to R, and each relation type appears no more than k times in the path. The search result is used as the target inference subgraph.
[0052] In step S150, the triples in the target reasoning subgraph are converted into a preset format, and the converted triples and the question to be reasoned are input into the pre-built reasoning result generation model to obtain the generation result.
[0053] The retrieved target reasoning subgraph G contains multiple entities and relations related to the semantics of the problem. The triples in the retrieved target reasoning subgraph G are organized into an input form suitable for model understanding (i.e., a preset format), such as a fact list organized by entity, a path set organized by reasoning path, or converted into natural language sentences.
[0054] The preset format includes structured text or templated natural language fragments. According to the example embodiment, it can be transformed into input that the inference result generation model can understand in one of the following ways: 1) Convert each triple into a short sentence, such as "City A is located in country B" or "Country B borders country C"; 2) Organize according to the reasoning path from the topic entity to the candidate answer entity, and generate a narrative text for each path; 3) Cluster the graph or group it by central entity, and list the attributes and adjacency relationships of each entity.
[0055] The reasoning result generation model is a pre-built large language model, and this application does not limit its specific architecture or model.
[0056] During the process of inputting the format-converted triples and the question to be reasoned into the pre-built reasoning result generation model, the textualized target reasoning subgraph content can be constructed together with the original question to be reasoned into the final input prompt. For example: Question part: retain the user's original question; Fact part: list several fact sentences or path descriptions; Requirement part: instruct the model to "answer the question only based on the given facts and explain the reasoning basis".
[0057] In other words, the sorted target reasoning subgraph is concatenated with the original problem (i.e. the problem to be reasoned), and then input into the reasoning result generation model for reasoning and answer generation. The resulting answer text is recorded as the generated result.
[0058] Furthermore, after step S150, the following steps are also included: performing a consistency check on the generated results, such as verifying whether all entities mentioned in the answer appear in the reasoning subgraph; if necessary, the entities in the generated results can be checked back against the knowledge graph to verify their rationality.
[0059] This application constructs a lexical dictionary based on a knowledge graph, and uses the lexical dictionary to constrain the large model relation types to generate a relation type set, thereby significantly reducing the probability of relation type illusion and achieving a faithful mapping of the question's semantics. Entity identification is performed on the question to be reasoned, and the results are mapped to the knowledge graph to obtain a set of topic entities. Starting from the entities in the topic entity set, the k-BET reasoning subgraph retrieval algorithm is used to search the knowledge graph to obtain a target reasoning subgraph. This ensures that the multi-hop paths from topic entities to candidate answer entities are as complete as possible, avoiding the loss of key edges due to fixed Top-k truncation, thus achieving structural integrity. By decoupling "model reasoning" and "graph algorithm retrieval," the large model is called only once in the relation generation stage, reducing the number of online large model calls and shrinking the retrieval scale, significantly reducing latency and computational overhead while maintaining performance. The target reasoning subgraph and the question to be reasoned are input into the reasoning result generation model to obtain the generated result, achieving structural integrity, semantic faithfulness, and a balanced approach to retrieval efficiency and resource consumption for enhanced retrieval generation.
[0060] According to some embodiments, refer to Figure 2 In step S110, a word trie is constructed based on the pre-built knowledge graph, which can be implemented through steps S210-S220.
[0061] In step S210, the names of relation types included in the knowledge graph are divided into multiple tokens according to preset rules to obtain a token sequence.
[0062] Each relation type name is segmented into several tokens according to preset rules, thus obtaining a token sequence.
[0063] According to the example implementation: using " / " and "_" as separators, country / borders_with is split into [country,borders, with].
[0064] In step S220, a multi-branch prefix tree is constructed based on the lexical sequence as a lexical dictionary tree. Each path from the root to the leaf in the multi-branch prefix tree corresponds to a relation type, and the node subset of the multi-branch prefix tree represents the set of candidate lexicals that can be expanded under the current lexical prefix.
[0065] Based on the lexical sequences of all relation types in the knowledge graph pattern, a multi-branch prefix tree (token-trie) is constructed. Each path from the root to the leaf in the tree corresponds to a valid relation type, and the node subset represents the set of candidate lexical sequences that can be expanded under the current prefix, providing structural constraints for the relation type generation process.
[0066] In the specific implementation process, starting from the root node, the lexical sequence is inserted into the prefix tree one by one. If a lexical branch does not exist, a new child node is created. The end node of the complete path is marked as the termination node, and the corresponding relation type identifier is stored. Finally, a multi-way tree structure covering all relation types is obtained, where each intermediate node represents a part of the semantic prefix, such as... Figure 3 As shown.
[0067] According to some embodiments, the knowledge graph is pre-constructed through steps S111-S113.
[0068] In step S111, multiple entities and relationships between multiple entities are extracted from multi-source data.
[0069] Multi-source data includes structured databases, semi-structured data, and unstructured text. According to the example implementation, multi-source data includes existing databases and logs.
[0070] Structured information is extracted from multi-source data. This structured information includes multiple entities and various relationships between them. According to the example implementation, entities include, for example, users, products, geographic locations, and events.
[0071] Furthermore, unstructured documents are transformed into triplet form by named entity recognition and relation extraction.
[0072] Furthermore, step S111 includes: unifying entities from multiple sources into the same identifier space through entity alignment and deduplication.
[0073] In step S112, an initial map is constructed based on multiple entities and the relationships between them.
[0074] Based on the extracted entities and relationships, a knowledge graph containing entity nodes and relationship edges is constructed, denoted as the initial graph.
[0075] In step S113, a unique identifier and a name based on the word sequence are assigned to the relation type of the initial graph to obtain the knowledge graph.
[0076] Based on the initial graph, a unified relation type schema is established, and a unique identifier and a name based on the lexical sequence are assigned to each relation type for subsequent construction of the lexical trie.
[0077] Specifically, in the implementation, readable and hierarchical naming is designed for relation types, such as location / located_in, travel / has_airport, country / borders_with, etc., which facilitates subsequent segmentation by term.
[0078] According to some embodiments, refer to Figure 4 In step S120, the problem to be reasoned and the lexical dictionary are input into the pre-built relation type generation model to obtain a set of relation types, which can be achieved through steps S410-S450.
[0079] In step S410, a model input sequence is generated based on the question to be reasoned and a predefined prompt word template.
[0080] During online reasoning, the system receives a question q to be reasoned about, such as: "Among the countries where airports serving a certain city are located, which countries border a certain target country?". This question is converted into a sequence of inputs to the model, and system prompts (i.e., predefined prompt word templates) can be attached, such as "Please predict the type of relationship related to this question based on the relationship pattern of the knowledge graph."
[0081] In step S420, the root node of the lexical trie and its corresponding lexical prefix path are added to the search queue.
[0082] The search is performed using a breadth-first search (BFS) strategy. Specifically, a queue (denoted as the search queue) is maintained using the breadth-first search strategy, and each queue element contains the current trie node and its corresponding term prefix path.
[0083] In the initial stage, the root node of the lexical trie and its corresponding lexical prefix path are added to the search queue.
[0084] In step S430, the current node is retrieved from the head of the search queue.
[0085] After retrieving the current element from the head of the search queue, a new element (i.e., the current element) is dequeued from the queue. This element includes the current node and the lexical prefix path (or lexical prefix) corresponding to the current node.
[0086] According to the example implementation, the current element includes the root node and the current decoding prefix p (initially a special root tag).
[0087] In step S440, if the current node is a termination node, the lexical prefix path corresponding to the current node is added to the relation type set.
[0088] After dequeuing an element, if the current node is the terminating node, the corresponding term prefix path (i.e., relation type) is added to the relation type set R.
[0089] In step S450, if the current node is not the terminating node, multiple sub-paths are obtained according to the pre-set trie constraint decoding steps, and the multiple sub-paths and their corresponding nodes are added to the tail of the search queue.
[0090] After dequeuing an element, if the current node is not the terminating node, expand multiple sub-paths according to the pre-set trie constraint decoding steps and enqueue them.
[0091] According to some embodiments, the trie constraint decoding step includes steps S460-S490.
[0092] In step S460, the model input sequence and the lexical prefix corresponding to the current node are input into the relation type generation model to obtain the model logical output value.
[0093] The current node's corresponding current decoding prefix p is combined with the model input sequence to generate a model, thus obtaining the logits (i.e., the model's logical output values) on the entire lexical table.
[0094] In step S470, the model logic output value is masked according to the candidate word set of the current node, and the masked model logic output value is normalized to obtain the conditional probability distribution of the candidate words in the candidate word set.
[0095] Query the set of child terms (i.e., candidate term set) of the current node in the term trie, mask the logits, and set the positions of terms that are not in the candidate term set to negative infinity.
[0096] Then, the masked logits are normalized (e.g., by softmax normalization) to obtain the conditional probability distribution of candidate lexical units in the candidate lexical unit set.
[0097] In step S480, based on the conditional probability distribution, a preset number of candidate words with probabilities greater than a preset threshold are selected as target sub-words.
[0098] Select several sub-words with a probability greater than a preset threshold δ, and retain up to a preset number b in descending order of probability, denoted as target sub-words.
[0099] In step S490, the sub-path is obtained based on the lexical prefix path of the current node and the target sub-lexical.
[0100] The prefix path of the current node and the target sub-word are used as the expansion branch for the next step, and are denoted as the sub-path.
[0101] This embodiment employs a breadth-first + bundle search decoding strategy. In each decoding step, the probability is normalized only on the set of allowed sub-words for the current node, ensuring that the generated relation type belongs to the knowledge graph relation type pattern. Through probability thresholding and bundle width control, a set R of semantically related and pattern-valid relation types is obtained. Since a single forward call can sequentially generate logits for multiple steps internally, this embodiment can ensure that the number of model calls in the relation generation stage is fixed at one by reasonably reusing model states, thereby significantly reducing online overhead.
[0102] According to some embodiments, refer to Figure 5 In step S140, the topic entity set is used as the starting point, and the k-BET reasoning subgraph retrieval algorithm is used to search in the knowledge graph under the constraint of the relation type set to obtain the target reasoning subgraph. This can be achieved through steps S1-S8.
[0103] In step S1, the relation budget vectors of the subject entities in the subject entity set are initialized to preset values, and the subject entities and their relation budget vectors are added to the search stack.
[0104] It should be noted that, when performing a depth-first search starting from the topic entity, this embodiment maintains a relation budget vector B for each currently explored path. Each dimension corresponds to a relation type in the relation type set R, with an initial value of k, representing the maximum number of times that type can still be used in the path. Whenever a path is extended along an edge, one unit of budget for the corresponding relation type is deducted. Specifically, when two different paths can reach the same node v, if the budget vector of one path is no greater than that of the other path in all dimensions, then its budget is said to be dominated by the other path. A dominated path cannot obtain a larger search space in subsequent extensions than a non-dominated path, therefore its subsequent extensions can be skipped, thus achieving pruning.
[0105] In the specific implementation process, depth-first search (DFS) is adopted, and a stack structure is maintained as the search front (denoted as the search stack), as well as a mapping structure from nodes to a set of budget vectors. The budget vector of each node is denoted as the relation budget vector.
[0106] For each topic entity v∈T, initialize its relation budget vector as a full k-vector and push (v,B) onto the stack. Here, T is the set of topic entities, and k is the upper bound of edge type repetition.
[0107] In step S2, the current entity and the current relation budget vector are retrieved from the top of the search stack.
[0108] Pop the top element (v, B) from the stack.
[0109] In step S3, the adjacent edges of the current entity in the knowledge graph are obtained.
[0110] Get the adjacent edges (v, e, v') of the node v corresponding to the current entity in the knowledge graph; where e is the edge and v' is the associated entity corresponding to the adjacent edge.
[0111] In step S4, if the relation type of the adjacent edge belongs to the relation type set and the relation budget vector of the current entity meets the preset conditions, the triple corresponding to the adjacent edge is added to the current inference subgraph, and the search stack is updated according to the triple. The triple includes the current entity, the edge, and the associated entity corresponding to the edge.
[0112] If the relation type l(e) of the adjacent edge belongs to the relation type set R and the corresponding relation budget vector satisfies the preset conditions, the triple (v,e,v') is added to the current inference subgraph G.
[0113] In step S5, if the relation type of the adjacent edge does not belong to the relation type set and / or the relation budget vector of the current entity is 0, the adjacent edge is skipped.
[0114] If the relation type l(e) of the edge is not in the relation type set R, and / or the corresponding relation budget vector B(l(e)) = 0, then skip the edge.
[0115] In step S6, steps S3-S5 are repeated until the adjacent edges of the current entity in the knowledge graph are traversed.
[0116] Iterate through all adjacent edges (v, e, v') of the node v corresponding to the current entity in the knowledge graph.
[0117] In step S7, if the search stack is not empty, proceed to step S2.
[0118] If the search stack is not empty, proceed to step S2.
[0119] In step S8, if the search stack is empty, the current inference subgraph is output as the target inference subgraph.
[0120] When the stack is empty, the resulting current inference subgraph G is the maximal k-BET inference subgraph under the given subject entity set T, relation type set R, and upper bound k of edge type repetition.
[0121] This application's embodiments, under the constraint of a set of relation types, introduce a k-BET (bounded edge type) inference subgraph model and design a retrieval algorithm based on depth-first search (DFS). Through a strategy of "relation type budget vector + budget dominance," a maximal k-BET inference subgraph is obtained by finely pruning the traversal process while reasonably controlling the search scale. During the retrieval process, a "relation type budget vector" is maintained for each candidate path originating from the topic entity, recording the remaining available times for each relation type. Pruning is performed based on the budget dominance relation, thereby significantly reducing the search space while ensuring structural integrity, preserving as many complete multi-hop paths from the entity to the candidate answer entity as possible, and reducing the loss of inference chains due to truncation.
[0122] According to some embodiments, refer to Figure 6 In step S4, if the relation type of the adjacent edge belongs to the relation type set and the relation budget vector of the current entity meets the preset conditions, the triple corresponding to the adjacent edge is added to the current inference subgraph, and the search stack is updated according to the triple. This can be achieved through steps S610-S620.
[0123] In step S610, if there is at least one element in the set of historical relation budget vectors of the associated entity such that the element is not less than the current relation budget vector in all relation type dimensions, then the associated entity is skipped.
[0124] If there exists a Bi' such that the current relational budget vector B is not greater than Bi' in all dimensions (i.e., B is dominated), then there is no need to continue expanding the associated entity v' from the current path, and it can be skipped directly.
[0125] In step S620, if for any element in the historical relation budget vector set of the associated entity, there exists at least one relation type dimension smaller than the current relation budget vector, then the current relation budget vector, the relation budget vector set of the associated entity, and the search stack are updated.
[0126] If not dominated, update the current relation budget vector, the set of relation budget vectors of associated entity v', and the search stack.
[0127] According to some embodiments, in step S620, if for any element in the historical relation budget vector set of the associated entity, there exists at least one relation type dimension smaller than the current relation budget vector, then the current relation budget vector, the relation budget vector set of the associated entity, and the search stack are updated. This can be specifically achieved through steps S621-S623.
[0128] In step S621, if for any element in the set of historical relation budget vectors of the associated entity, there exists at least one relation type dimension smaller than the current relation budget vector, then one unit budget is deducted from the current relation budget vector to form the new current relation budget vector.
[0129] If not dominated, that is, if there is no Bi' in the previous relation budget vector set {Bi'} of node v' such that the current relation budget vector B is not greater than Bi' in all dimensions, then update the current relation budget vector: subtract 1 from the dimension corresponding to relation type l(e) to obtain the new current relation budget vector Bnew.
[0130] In step S622, the associated entity and the updated current relation budget vector are added to the top of the search stack.
[0131] Push (v', Bnew) onto the stack.
[0132] In step S623, the set of relation budget vectors of the associated entities is updated using the updated current relation budget vector.
[0133] Add Bnew to the budget set of node v' and remove the old budget vectors dominated by Bnew to maintain the "maximum" of the budget set.
[0134] This application adopts a two-stage decoupled design of "relation type generation" and "subgraph structure retrieval". The large model is called only once in the relation generation stage, and the graph retrieval stage is implemented entirely by symbolic algorithms, which greatly reduces online computing power and latency overhead, and is suitable for deployment in large-scale knowledge graphs and high-concurrency online scenarios.
[0135] In one specific embodiment, the retrieval enhancement generation method of the present application embodiments is implemented based on the GraphRAG system.
[0136] In this embodiment, the GraphRAG system is deployed on a server, and the following initialization steps are included before step S110: 1) Initialize the knowledge graph data structure, loading the offline-built KG into Compressed Sparse Row (CSR) or other efficient graph storage formats. 2) Load the relation schema trie structure and relation type generation model parameters. 3) Load the GraphRAG generation model (which can be the same as or different from the relation type generation model using an LLM). 4) Provide an API interface to receive natural language questions and return the final answer and optional reasoning basis.
[0137] This application is applicable to open-domain question answering based on general knowledge graphs, as well as domain knowledge graphs and document graphs built for vertical industries, and has good portability and room for secondary development.
[0138] The following describes an apparatus embodiment of this application, which can be used to perform the method embodiment of this application. For details not disclosed in the apparatus embodiment of this application, please refer to the method embodiment of this application.
[0139] Figure 7 A block diagram of a retrieval enhancement generation apparatus according to an exemplary embodiment is shown.
[0140] Figure 7 The apparatus shown can perform the aforementioned search enhancement generation method according to the embodiments of this application.
[0141] like Figure 7 As shown, the retrieval enhancement generation apparatus may include: See Figure 7 Referring to the preceding description, the lexical dictionary unit 710 is used to construct a lexical dictionary based on a pre-built knowledge graph.
[0142] The first set unit 720 is used to input the problem to be reasoned and the lexical dictionary into a pre-built relation type generation model to obtain a relation type set.
[0143] The second set unit 730 is used to perform entity recognition on the reasoning problem and map the recognized entities to entity nodes in the knowledge graph to obtain the topic entity set.
[0144] The reasoning subgraph unit 740 is used to start with the set of topic entities and use the k-BET reasoning subgraph retrieval algorithm to search in the knowledge graph under the constraints of the set of relation types to obtain the target reasoning subgraph.
[0145] The result generation unit 750 is used to convert the triples in the target reasoning subgraph into a preset format, and input the format-converted triples and the question to be reasoned into the pre-built reasoning result generation model to obtain the generated result.
[0146] The device performs functions similar to those described above; other functions are described in the preceding descriptions and will not be repeated here.
[0147] This application discloses an electronic device, including: a processor; and a memory storing a computer program, which, when executed by the processor, causes the processor to execute the above-described instruction generation method.
[0148] For example, refer to Figure 8 , Figure 8 The illustrated electronic device 800 includes a processor 801 and a memory 803. The processor 801 and the memory 803 are connected, for example, via a bus 802. Optionally, the electronic device 800 may also include a transceiver 804. It should be noted that in practical applications, the transceiver 804 is not limited to one type, and the structure of this electronic device 800 does not constitute a limitation on the embodiments of this application.
[0149] Processor 801 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in this application. Processor 801 may also be a combination that implements computational functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0150] Bus 802 may include a pathway for transmitting information between the aforementioned components. Bus 802 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 802 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 8 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0151] The memory 803 may be a ROM (Read Only Memory) or other type of static storage device capable of storing static information and instructions, RAM (Random Access Memory) or other type of dynamic storage device capable of storing information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other storage medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto.
[0152] The memory 803 stores application code that executes the scheme of this application, and its execution is controlled by the processor 801. The processor 801 executes the application code stored in the memory 803 to implement the content shown in the foregoing method embodiments.
[0153] Figure 8 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0154] This application discloses a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, causes the processor to execute an instruction generation method.
[0155] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by 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 accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0156] The above are only some embodiments of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A method for generating enhanced search results, characterized in that, include: Construct a lexical dictionary based on a pre-built knowledge graph; The problem to be reasoned about and the lexical dictionary are input into a pre-built relation type generation model to obtain a set of relation types; Entity recognition is performed on the problem to be reasoned, and the identified entities are mapped to entity nodes of the knowledge graph to obtain a set of topic entities; Starting with the set of topic entities, the k-BET reasoning subgraph retrieval algorithm is used to search the knowledge graph under the constraints of the set of relation types to obtain the target reasoning subgraph. The triples in the target reasoning subgraph are converted into a preset format, and the converted triples and the question to be reasoned are input into a pre-built reasoning result generation model to obtain the answer text as the generation result. The preset format includes structured text or templated natural language fragments. Specifically, taking the set of topic entities as the starting point, the k-BET inference subgraph retrieval algorithm is used to search the knowledge graph under the constraints of the set of relation types to obtain the target inference subgraph, including: S1: Initialize the relation budget vector of the topic entity in the topic entity set to a preset value, and add the topic entity and its relation budget vector to the search stack; S2: Retrieve the current entity and current relation budget vector from the top of the search stack; S3: Obtain the adjacent edges of the current entity in the knowledge graph; S4: If the relation type of the adjacent edge belongs to the relation type set and the relation budget vector of the current entity satisfies the preset conditions, add the triple corresponding to the adjacent edge to the current inference subgraph and update the search stack according to the triple, wherein the triple includes the current entity, the edge and the associated entity corresponding to the edge; S5: If the relation type of the adjacent edge does not belong to the relation type set and / or the relation budget vector of the current entity is 0, skip the adjacent edge; S6: Repeat steps S3-S5 until the adjacent edges of the current entity in the knowledge graph are traversed; S7: If the search stack is not empty, proceed to step S2; S8: If the search stack is empty, output the current inference subgraph as the target inference subgraph.
2. The method according to claim 1, characterized in that, Based on the pre-built knowledge graph, construct a lexical dictionary, including: According to preset rules, the names of the relation types included in the knowledge graph are segmented into multiple lexical units to obtain a lexical unit sequence; A multi-branch prefix tree is constructed based on the lexical sequence as a lexical dictionary tree, wherein each path from the root to a leaf in the multi-branch prefix tree corresponds to a relation type, and the node subset of the multi-branch prefix tree represents the set of candidate lexicals that can be expanded under the current lexical prefix.
3. The method according to claim 1, characterized in that, The knowledge graph is pre-constructed through the following steps: Extract multiple entities and the relationships between them from multi-source data; An initial graph is constructed based on the multiple entities and the relationships between them; A unique identifier and a name based on the word sequence are assigned to the relation type of the initial graph to obtain the knowledge graph.
4. The method according to claim 1, characterized in that, The problem to be reasoned about and the lexical dictionary are input into a pre-built relation type generation model to obtain a set of relation types, including: Generate the model input sequence based on the question to be reasoned and the predefined prompt word template; Add the root node of the lexical trie and its corresponding lexical prefix path to the search queue; Retrieve the current node from the head of the search queue; If the current node is a terminating node, add the lexical prefix path corresponding to the current node to the relation type set; If the current node is not the terminating node, multiple sub-paths are obtained according to the pre-set trie constraint decoding steps, and the multiple sub-paths and their corresponding nodes are added to the tail of the search queue.
5. The method according to claim 4, characterized in that, The trie constraint decoding step includes: The model input sequence and the lexical prefix corresponding to the current node are input into the relation type generation model to obtain the model logic output value; Based on the candidate word set of the current node, the model logic output value is masked, and the masked model logic output value is normalized to obtain the conditional probability distribution of the candidate words in the candidate word set. Based on the conditional probability distribution, a preset number of candidate word elements with a probability greater than a preset threshold are selected as target sub-word elements; The sub-path is obtained based on the prefix path of the current node and the target sub-word.
6. The method according to claim 1, characterized in that, Step S4 includes: If there is at least one element in the historical relation budget vector set of the associated entity such that the element is not less than the current relation budget vector in all relation type dimensions, then the associated entity is skipped. If, for any element in the historical relation budget vector set of the associated entity, there exists at least one relation type dimension smaller than the current relation budget vector, then the current relation budget vector, the relation budget vector set of the associated entity, and the search stack are updated.
7. The method according to claim 6, characterized in that, If, for any element in the historical relation budget vector set of the associated entity, there exists at least one relation type dimension smaller than the current relation budget vector, then update the current relation budget vector, the relation budget vector set of the associated entity, and the search stack, including: If, for any element in the historical relationship budget vector set of the associated entity, there exists at least one relationship type dimension smaller than the current relationship budget vector, then one unit budget is deducted from the current relationship budget vector to form the new current relationship budget vector. Add the associated entity and the updated current relationship budget vector to the top of the search stack; The set of relation budget vectors of the associated entities is updated using the updated current relation budget vector.
8. A retrieval enhancement generation apparatus, characterized in that, include: The lexical dictionary unit is used to construct a lexical dictionary based on a pre-built knowledge graph; The first set unit is used to input the problem to be reasoned and the lexical dictionary into a pre-built relation type generation model to obtain a relation type set; The second set unit is used to perform entity recognition on the question to be reasoned, and to map the recognized entities to the entity nodes of the knowledge graph to obtain the topic entity set; The reasoning subgraph unit is used to take the set of topic entities as the starting point, and use the k-BET reasoning subgraph retrieval algorithm to search in the knowledge graph under the constraints of the set of relation types to obtain the target reasoning subgraph; The result generation unit is used to convert the triples in the target reasoning subgraph into a preset format, and input the format-converted triples and the question to be reasoned into a pre-built reasoning result generation model to obtain the answer text as the generation result. The preset format includes structured text or templated natural language fragments. The reasoning subgraph unit is used for: S1: Initialize the relation budget vector of the topic entity in the topic entity set to a preset value, and add the topic entity and its relation budget vector to the search stack; S2: Retrieve the current entity and current relation budget vector from the top of the search stack; S3: Obtain the adjacent edges of the current entity in the knowledge graph; S4: If the relation type of the adjacent edge belongs to the relation type set and the relation budget vector of the current entity satisfies the preset conditions, add the triple corresponding to the adjacent edge to the current inference subgraph and update the search stack according to the triple, wherein the triple includes the current entity, the edge and the associated entity corresponding to the edge; S5: If the relation type of the adjacent edge does not belong to the relation type set and / or the relation budget vector of the current entity is 0, skip the adjacent edge; S6: Repeat steps S3-S5 until the adjacent edges of the current entity in the knowledge graph are traversed; S7: If the search stack is not empty, proceed to step S2; S8: If the search stack is empty, output the current inference subgraph as the target inference subgraph.
9. An electronic device, characterized in that, include: One or more processors; Memory, used to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program or instructions stored thereon, characterized in that, When the computer program or instructions are executed by a processor, they implement the method as described in any one of claims 1-7.