A knowledge graph-based local information retrieval method and device, and a storage medium
By employing a knowledge graph-based local information retrieval method, utilizing community detection algorithms and large language models, this approach addresses the challenge of traditional RAG technology in understanding deep relationships within complex queries. This results in high-quality answer generation and enhances the accuracy and reliability of the answers.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING YUCHEN SHIMEI SCI & TECH
- Filing Date
- 2026-03-13
- Publication Date
- 2026-06-19
AI Technical Summary
Traditional Retrieval Augmentation (RAG) techniques struggle to capture deep relationships between entities scattered across different documents when faced with complex queries involving deep logical reasoning and association analysis. They lack a structured understanding of knowledge relationships, and the returned context often contains a large amount of redundant and noisy information, affecting the generation and reliability of answers.
The knowledge graph-based local information retrieval method locates entities in the knowledge graph and extracts multi-dimensional related information, including target entities, candidate graph tiles, candidate relationships, and candidate original text blocks. It uses a multi-dimensional, structured set of candidate information, combined with community detection algorithms and a pre-set large language model, to generate high-quality prompt context to generate the answer.
It improves the accuracy and reliability of answer output for complex queries, overcomes the shortcomings of traditional retrieval enhancement generation technology in processing deep logic and related information, and generates logically coherent, interpretable answers that directly meet user information needs.
Smart Images

Figure CN122240773A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent retrieval technology, and in particular to a method, device and storage medium for local information retrieval based on knowledge graphs. Background Technology
[0002] With the rapid development of artificial intelligence technology, Retrieval-Augmented Generation (RAG) systems have been widely applied in the field of question answering. Traditional RAG techniques typically segment a document corpus into text blocks, then retrieve several semantically related text blocks based on vector similarity to form a context, which is then fed into a large language model to generate the answer. This method is highly effective in answering simple, explicit factual questions.
[0003] However, when faced with complex queries that require deep logical reasoning and correlation analysis, traditional RAG technology has obvious shortcomings. It relies solely on semantic matching on the surface of the text, making it difficult to capture the deep relationships between entities scattered across different documents. It lacks a structured understanding of knowledge relationships, cannot support reasoning based on networked knowledge, and the returned context often contains a lot of redundant and noisy information, affecting the generation and reliability of answers. Summary of the Invention
[0004] To address the aforementioned technical problems, this invention provides a local information retrieval method, device, and storage medium based on knowledge graphs. By locating entities in the knowledge graph and extracting multi-dimensional related information, it achieves accurate and interpretable information retrieval covering both micro and macro levels, thereby improving the reliability of answer output when processing domain information that is structurally dispersed and highly related.
[0005] According to a first aspect of the present invention, a local information retrieval method based on a knowledge graph is provided, comprising the following steps: S1, based on the user query, retrieve at least one target entity from the pre-built knowledge graph; wherein, the nodes of the knowledge graph include entities and events extracted from several original texts, the edges represent the relationships between entities and between entities and events, and the knowledge graph is divided into several blocks, each block corresponding to a block description text.
[0006] S2, based on each target entity, obtain a set of candidate information from the knowledge graph; the information units in the set of candidate information include candidate graph blocks containing any target entity, candidate relationships connected to any target entity, and candidate original text blocks containing any target entity.
[0007] S3, according to the preset sorting rules corresponding to each information unit, sort and filter the candidate image blocks, candidate relationships and candidate original text blocks respectively, to obtain a number of sorted and filtered information units.
[0008] S4. The sorted and filtered information units are integrated to generate a prompt context, and the prompt context is input into a preset large language model to generate the final answer for the user query.
[0009] According to a second aspect of the present invention, a non-transitory computer-readable storage medium is provided, wherein at least one instruction or at least one program is stored therein, the at least one instruction or the at least one program being loaded and executed by a processor to implement the above-described knowledge graph-based local information retrieval method.
[0010] According to a third aspect of the present invention, an electronic device is provided, including a processor and the aforementioned non-transitory computer-readable storage medium.
[0011] The present invention has at least the following beneficial effects: This invention provides a local information retrieval method based on a knowledge graph. First, based on a user query, at least one target entity is retrieved from a pre-constructed knowledge graph, achieving the location of key information and overcoming the semantic drift problem that easily occurs in complex queries in traditional full-text retrieval. Then, based on the target entity, a candidate information set is obtained from the knowledge graph, including candidate graph tiles containing any target entity, candidate relationships connected to any target entity, and candidate original text blocks containing any target entity. By constructing a multi-dimensional, structured candidate information set, the method covers the micro-facts of entities and relationships in text blocks as well as the macro-themes of graph tiles, enabling the system to have stronger context awareness and depth. The layered semantic understanding capability effectively overcomes the shortcomings of traditional retrieval enhancement generation in processing deep logic and related information. Furthermore, by sorting and filtering each information unit separately, the information quality of the input model is significantly improved. Finally, the filtered information units are integrated to generate a prompt context, which is then input into a preset large language model to generate the final answer for the user query. By synthesizing structured, high-quality information fragments into a coherent prompt context, the final generated answer is ensured to be not only accurate and well-founded but also logically coherent and directly meet the user's information needs. This overcomes the limitations of traditional retrieval enhancement generation technology in processing structurally dispersed and complexly related domain information. Attached Figure Description
[0012] To more clearly illustrate the technical solutions in the embodiments of the present invention, 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 the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0013] Figure 1 A flowchart of a knowledge graph-based local information retrieval method provided in an embodiment of the present invention. Detailed Implementation
[0014] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0015] This invention provides a local information retrieval method based on knowledge graphs, such as... Figure 1 As shown, the method includes the following steps: S1, based on user queries, retrieve at least one target entity from a pre-constructed knowledge graph; wherein, the nodes of the knowledge graph include entities and events extracted from several original texts, the edges represent the relationships between entities and between entities and events, and the knowledge graph is divided into several blocks, each block corresponding to a block description text; it can be understood that: the original text refers to the real texts publicly available in the target domain, such as news texts published by mainstream media, social media, etc.
[0016] As described above, by accurately anchoring the target entities related to the user query in the knowledge graph, an accurate semantic starting point is established for subsequent retrieval. Only a local retrieval method is needed, which improves retrieval efficiency and ensures that the retrieval process always revolves around key information directly related to the question. This overcomes the semantic drift problem that traditional full-text retrieval is prone to in complex queries, thereby improving the accuracy and reliability of subsequent answer output.
[0017] Specifically, the knowledge graph is constructed through the following steps: S10: Extract entities, events, and relationships from several original texts to generate an initial graph. Events with semantic similarity greater than a second preset similarity threshold are aggregated into the same cluster, and these clusters are merged as an event node in the initial graph. This can be understood as follows: for any event in a cluster, there is at least one event with a semantic similarity greater than the second preset similarity threshold. When calculating semantic similarity, events are represented using dense vectors that include information such as their type, trigger words, and core arguments. Those skilled in the art can set the second preset similarity threshold according to actual needs, which will not be elaborated here.
[0018] Specifically, a sequence labeling method based on a pre-trained language model is used to identify entities in the original text. Within the pre-trained language model, a fine-grained entity type system is defined to suit the characteristics of news data. For example, "organization" is further subdivided into "public welfare organizations," "enterprises," and "media," to support more accurate subsequent relationship and event analysis.
[0019] After entity extraction, ambiguity is resolved for different entities, and they are associated with unique, normalized entity IDs within their context, employing a two-stage process of recall and ranking. In the recall stage, an entity alias dictionary built using Elasticsearch is used for rapid initial screening, obtaining a set of candidate entities based on surface string matching of entity names. In the ranking stage, a self-trained Zero-shot dual-tower vector model is used for precise matching. This model consists of a query tower encoding textual references and their context, and an entity tower encoding entity descriptions from a knowledge base. By calculating the similarity between the two vectors, the most relevant entity is selected from the candidate entities. The advantage of this method is that it does not require training data for specific link samples; it can achieve high-precision linking solely based on the entity's descriptive text, making it ideal for scenarios where new entities emerge frequently.
[0020] When extracting events, a sequence-to-sequence generation framework based on pre-trained language models, such as UIE and T5, is used. This model can generate structured event records end-to-end, including event type, trigger words, and elements such as time, location, participants, and reasons. This approach avoids the error accumulation defects of traditional pipeline methods and significantly improves extraction accuracy.
[0021] When extracting relations, a relation classification method based on a pre-trained language model is adopted. Entity pairs in the sentence and their context are input into the model, which then determines whether a predefined relation exists between the two entities and gives the specific relation type. In order to capture implicit, cross-sentence relations in the text, a document-level relation extraction technique is also introduced. This technique can identify the relations between entities scattered in different locations in the document by constructing a document-level context representation and using a graph neural network model for reasoning.
[0022] S20, the initial graph is divided into several communities using a community detection algorithm, each community is used as a partitioned graph tile, and a preset large language model is called to generate corresponding graph tile description text for each graph tile to generate a knowledge graph; wherein, the graph tile description text contains all entities, relations and assertions extracted from the original text within the corresponding graph tile.
[0023] The preferred community detection algorithm is the Leiden community detection algorithm.
[0024] The community detection algorithm described above can group a subset of nodes with tightly connected internal nodes and relatively sparse connections to external nodes into a community. Furthermore, the hierarchical nature of this algorithm allows for graph partitioning at different resolution levels. For example, lower-level communities are larger in scale and have broader themes, while higher-level communities are more granular and have more specific themes. Through community partitioning, fragmented information from different entities and relationships at different levels can be integrated. This multi-granularity community structure provides a reliable data foundation for subsequent semantic retrieval.
[0025] Further, in step S1, retrieving at least one target entity from the pre-constructed knowledge graph includes the following steps: S101, the text corresponding to the user query is converted into a query vector, the semantic similarity between the query vector and the description vector corresponding to each entity in the knowledge graph is calculated, and several first candidate entities are recalled according to a first preset similarity threshold. Those skilled in the art can set the first preset similarity threshold according to actual needs, which will not be elaborated here.
[0026] S102, based on the knowledge graph, performs keyword matching on entity mentions in the user query, and expands the matched entities along the edges of the knowledge graph within a preset hop range to recall several second candidate entities. For example, the preset hop range can be one hop or two hops.
[0027] S103, deduplicatize all first candidate entities and all second candidate entities recalled, and encode the user query, each deduplicated candidate entity, and the local neighborhood information of the candidate entity in the knowledge graph. Input the encoded data into the pre-trained language model and calculate the context relevance score of each deduplicated candidate entity to the user query. The pre-trained language model can be a BERT model.
[0028] Specifically, the local neighborhood information includes the neighboring entities and relationships of the candidate entity within a preset number of hops.
[0029] S104, select candidate entities whose context-related scores exceed a preset score threshold as the retrieved target entities.
[0030] As described above, by fusing breadth recall based on semantic vectors and keyword matching recall based on graph structures, the comprehensiveness of the target entity set is ensured. Furthermore, by utilizing local neighborhood information of entities for filtering, a set of core entities most relevant to the query intent can be dynamically identified, thus ensuring the accuracy of the retrieved target entities.
[0031] In a preferred embodiment, the step of calling a preset large language model to generate corresponding tile description text for each tile includes the following steps: S021, for any tile, if the original information context contained in the tile exceeds the context window limit threshold of the preset large language model, then based on the hierarchical community structure generated by the community detection algorithm, each lower sub-community is traversed in descending order of the number of entities contained in the lower sub-community, and the pre-generated descriptive text summary of the currently traversed lower sub-community replaces the original information context contained in the lower sub-community itself, so as to generate the compressed original information context corresponding to the tile.
[0032] Specifically, the original information context contained in a tile includes the original nodes and relational information within the tile.
[0033] S022, after each replacement, determine the current length of the current compressed original information context; if the current length does not exceed the context window limit threshold, stop traversing and proceed to step S024.
[0034] S023, if after traversing all the lower-level sub-communities corresponding to the tile, the length of the compressed original information context still exceeds the context window limit threshold, then the remaining original node information in the compressed original information context is sorted by importance according to the degree centrality of the nodes, and the nodes and their associated relationships are removed from back to front until the length of the compressed original information context does not exceed the context window limit threshold.
[0035] S024, take the current compressed original information context as the final context and input it into the preset large language model to generate the tile description text corresponding to the tile.
[0036] The above approach effectively addresses the context window limitation problem when large language models process large-scale knowledge graph communities by using a dynamic context compression mechanism for large or complex communities containing a large number of entities and relationships. It adopts a strategy that combines hierarchical summary priority replacement with core structure order-preserving pruning, which significantly reduces the input length while maximizing the preservation of the core semantic information of the community, ensuring generation efficiency, and generating high-quality graph description text.
[0037] S2, based on each target entity, obtain a set of candidate information from the knowledge graph; the information units in the set of candidate information include candidate graph blocks containing any target entity, candidate relationships connected to any target entity, and candidate original text blocks containing any target entity.
[0038] As described above, by expanding the retrieval scope to include entity-related tiles, relationships, and original evidence, a multi-dimensional and structured set of candidate information is constructed. This achieves an upgrade in retrieval from point-entity to surface-local graph structure, while also covering the micro-facts of entities and relationships in text blocks and the macro-themes of tiles. This enables the system to have stronger context awareness and deep semantic understanding capabilities, ensuring the completeness and richness of the direct and indirect related information required for answer generation. It effectively overcomes the shortcomings of traditional retrieval-enhanced generation in processing deep logic and related information.
[0039] S3, according to the preset sorting rules corresponding to each information unit, sort and filter the candidate image blocks, candidate relationships and candidate original text blocks respectively, to obtain a number of sorted and filtered information units; it can be understood as: according to the sorting results, using the filtering threshold corresponding to each information unit, filtering out a number of candidate image blocks, candidate relationships and candidate original text blocks.
[0040] Specifically, the preset sorting rules corresponding to each information unit are as follows: S301, for candidate map tiles, sort them in descending order according to their corresponding weights; wherein, the weights of the candidate map tiles meet the following conditions: W c =α×log(F c +1)+β×(U c / N), where W c Let F be the weight of the c-th candidate patch. c Let U be the total frequency of the target entity contained in the c-th candidate tile across all text units. c α represents the number of non-repeating text units covered by the target entity contained in the c-th candidate tile, N is the total number of text units, and α and β are preset weighting coefficients.
[0041] When ranking candidate map tiles, the frequency and distribution of target entities within each community are considered. The community weights calculated in this way are more accurate and reliable, thus making the ranking results of candidate map tiles more reasonable and selecting candidate map tiles with more relevant information.
[0042] S302, for candidate relations, intra-network relations connecting two target entities take precedence over extra-network relations connecting one target entity and one non-target entity; wherein, intra-network relations are sorted in descending order according to the sum of the degrees of the two target entities corresponding to the intra-network relations, and extra-network relations are sorted in descending order according to the number of target entities connected to the non-target entity nodes corresponding to the extra-network relations.
[0043] S303, for candidate original text blocks, sort them in descending order based on the maximum context relevance score between the target entities associated with the candidate original text block and the user query; wherein, when the maximum context relevance scores of two candidate original text blocks are the same, sort them in descending order according to the total number of candidate relations associated with the candidate original text blocks.
[0044] The above-mentioned method, which adopts a multi-criteria ranking method based on graph topology and semantic relevance, performs hierarchical ranking and intelligent filtering of candidate information sets, effectively solving the context window limitation faced by large language models. Furthermore, it prioritizes the retention of content with high information density, strong relevance, and conclusive evidence during ranking, significantly improving the information quality of the input model and the reliability of the output.
[0045] In another implementation, the candidate original text blocks are further sorted by the following steps: S310, For each candidate original text block, calculate the corresponding sorting feature vector; the sorting feature vector includes at least the following dimensions.
[0046] Semantic similarity feature: cosine similarity between the candidate original text block and the query vector corresponding to the user query.
[0047] Community importance feature: the average degree centrality of the set of nodes of the graph to which the candidate original text block belongs.
[0048] Evidence connectivity feature: the edge density of the minimum connected subgraph containing the target entities associated with the candidate original text block; it can be understood as: the minimum connected subgraph is the graph that contains all target entities associated with the candidate original text block and has the fewest number of edges.
[0049] Specifically, the edge density of the minimum connected subgraph satisfies the following condition: D = 2E / (V×(V-1)), where D is the edge density of the minimum connected subgraph, E is the number of edges in the minimum connected subgraph, and V is the number of nodes in the minimum connected subgraph.
[0050] Path saliency feature: the reciprocal of the average shortest path length of the target entity associated with the candidate original text block in the knowledge graph.
[0051] S320, the ranking feature vector corresponding to each candidate original text block is input into a pre-trained scoring model to obtain the final ranking score of each candidate original text block. The scoring model can be a weighted linear model, a weighted nonlinear model, or a neural network model; there are no restrictions on which one is used.
[0052] S330, Sort all candidate original text blocks in descending order according to the final sorting score.
[0053] The above-mentioned method accurately quantifies the comprehensive value of candidate original text blocks as evidence for the answer from multiple dimensions by evaluating their global position in the graph structure, the closeness of the internal evidence, and the potential relevance of the entities involved. This allows for the selection of text evidence that is rich in information and strongly supported by logic for the subsequent generation of answers.
[0054] In another embodiment, steps S2 and S3 are replaced by the following steps: F1 determines the query semantic pattern category corresponding to the user query; the query semantic pattern category is at least one of fact confirmation type, causal analysis type, impact assessment type, and process description type.
[0055] F2, based on the query semantic pattern category, selects the corresponding target expansion strategy from a number of predefined graph expansion strategies; the number of predefined graph expansion strategies includes pathfinding strategies for locating direct relationships, causal traversal strategies for tracing causes or results, influence propagation strategies for assessing the scope of influence, and temporal association strategies for constructing event sequences.
[0056] Specifically, when a user query is a fact-confirming query, a pathfinding strategy is adopted: the core is to find and merge all the nodes and edges involved in the shortest path whose length does not exceed a preset length threshold among entity pairs in the target node set, forming an initial subgraph.
[0057] When a user query is causal analysis type, a causal traversal strategy is adopted: a directed, multi-hop graph traversal is performed along causal relationship edges of specific types such as "cause", "influence", and "originate from". During the traversal, a propagation weight is maintained for each path. This weight decays as the number of hops increases and is dynamically adjusted based on the credibility of the edge itself and its semantic relevance to the user query.
[0058] When a user query is for impact assessment, an impact propagation strategy is adopted: a random walk algorithm based on personalized PageRank is used to calculate the personalized PageRank score of all nodes in the graph relative to these target nodes, starting from each target entity, and selecting nodes whose scores are higher than a preset score threshold.
[0059] When a user query is a process description, a temporal association strategy is adopted: prioritize expanding temporal relationship edges such as "occurred before" and "followed by" to construct a sequence of events.
[0060] F3, using each target entity as an anchor point, calculates the score of each node to be evaluated within a preset hop range based on the selected target expansion strategy and a preset scoring function. The preset scoring function integrates the semantic similarity between the description text of the node to be evaluated and the user query, the structural importance of the node in the current subgraph, and the fit between the node and the query semantic pattern category. It can be understood as a weighted sum of semantic similarity, structural importance, and fit. For example, in causal analysis, nodes of type event with a large number of causal in-and-out edges will receive a higher fit.
[0061] Specifically, the preset scoring threshold is inversely proportional to the expansion depth. For example, the preset scoring threshold decreases exponentially as the expansion depth increases; the expansion depth refers to the number of node hops during the expansion.
[0062] Specifically, the structural importance of the node to be evaluated in the current subgraph meets the following conditions: G = λ × (d1 / d max ) + μ×K, where G represents the structural importance of any node to be evaluated in the current subgraph, d1 is the degree of the node to be evaluated in the current subgraph, and d max λ represents the maximum degree of a node in the current subgraph, K represents the betweenness centrality of the node to be evaluated in the current subgraph, and λ and μ are preset weight coefficients, respectively.
[0063] F4 expands the nodes to be evaluated with scores greater than the preset scoring threshold into the current subgraph to extend the evidence subgraph from the knowledge graph; the current subgraph refers to the real-time graph obtained when the nodes are expanded.
[0064] F5: Extract the description information corresponding to each node and edge in the evidence subgraph from the knowledge graph and integrate them to generate a prompt context to replace the prompt context in step S4.
[0065] As mentioned above, since the rules for constructing the candidate set are relatively static, such as including the target entity's community and relationships, they may be over-expanded, leading to the introduction of noise, or under-expanded, resulting in the loss of key indirect evidence. The new alternative scheme transforms the query semantic pattern into an executable graph traversal strategy and introduces a real-time evaluation mechanism that integrates semantics, structure, and intent fit. This enables the accurate and efficient extraction of evidence subgraphs closely related to the question logic from the knowledge graph, overcoming the shortcomings of information overload or insufficient association in traditional static retrieval. This significantly optimizes the contextual relevance and logical integrity of the prompts, thereby greatly improving the accuracy and interpretability of answers to complex reasoning questions.
[0066] S4. The sorted and filtered information units are integrated to generate a prompt context, and the prompt context is input into a preset large language model to generate the final answer for the user query.
[0067] Specifically, the prompt context includes at least the filtered tile description text summary, entity relationship pairs, and original text information.
[0068] As described above, by synthesizing structured, high-quality information fragments into a coherent prompting context, the pre-set large language model is guided to play the role of an accurate reasoning engine, ensuring that the final generated answer is not only accurate and well-founded, but also logically coherent and can directly meet the user's information needs. This overcomes the limitations of traditional retrieval enhancement generation technology in processing structurally dispersed and complexly related information.
[0069] In one specific implementation, prior to step S1, the method further includes: S01, the user query is input into a pre-trained query intent classification model to identify the intent of the user query and output the query intent category; wherein, the query intent category is either a specific question or a broad question.
[0070] S02, when the query intent category is a specific question, execute steps S1 to S4 to generate the final answer for the user query.
[0071] Furthermore, when the query intent category is a broad question, the following steps are performed: P1, randomly rearrange the communities and divide them into several community combinations, and obtain the community combination description text corresponding to each community combination.
[0072] This step employs a random rearrangement and grouping strategy, effectively breaking the sequential dependency of community processing and avoiding potential biases caused by a fixed processing order. It generates comprehensive descriptive text for each community combination, expanding the micro-level entity relationship network into a meso-level topic semantic summary. This enables efficient and comprehensive understanding of topic information scattered in complex knowledge networks, facilitating the generation of comprehensive and insightful answers for broad topic queries.
[0073] In a preferred embodiment, the step of randomly rearranging the plurality of communities and dividing them into several community combinations includes the following steps: P101, obtain the weight of each community; wherein, the weight of a community is determined based on at least one of the following methods: the total frequency of the entity in the community appearing in all text units, and the number of different text units covered by the entity in the community.
[0074] On page 102, several communities are sorted in descending order according to their weights and then divided into several windows on an equal basis. If the number of communities is insufficient to divide the windows equally, the number of communities in any two windows shall not differ by more than 1.
[0075] P103, perform local random swaps of communities within adjacent windows to obtain several community combinations; for example, perform local random swaps of communities within the first and second windows, and local random swaps of communities within the third and fourth windows. After the swaps are completed, the set of communities within the same window is taken as the community combination.
[0076] The above approach first sorts the communities in descending order of weight, ensuring that high-weight communities tend to appear in earlier batches during grouping, thus potentially being processed earlier. This facilitates obtaining high-quality intermediate answers quickly, improving overall efficiency. Furthermore, the introduction of random swapping within adjacent windows largely maintains the overall trend of weights while breaking the strict linear order, providing a foundation for subsequent parallel processing.
[0077] Furthermore, the community combination description text corresponding to each community combination is obtained through the following steps: P110, for any community combination, if the concatenation of the original information context of each community in the community combination exceeds the context window limit threshold of the preset large language model, then the communities are traversed in descending order of the number of entities contained in each community in the community combination, and the original information context of the community itself is replaced by the pre-generated community-specific description text summary of the currently traversed community, so as to generate the compressed original information context corresponding to the community combination.
[0078] P120: After each replacement, determine the current length of the current compressed original information context; if the current length does not exceed the context window limit threshold, stop traversing and proceed to step P140.
[0079] P130, if after traversing all communities within the community group, the length of the compressed original information context still exceeds the context window limit threshold, then the remaining original node information in the compressed original information context is sorted by importance according to the degree centrality of the nodes, and the nodes and their associated relationships are removed sequentially from back to front until the length of the compressed original information context does not exceed the context window limit threshold.
[0080] P140: The current compressed original information context is used as the final context and input into the preset large language model to generate the community combination description text corresponding to the community combination.
[0081] The above approach addresses the context window limitation problem in large language models when processing large-scale community combinations, which are complex and contain a lot of information. It effectively solves this problem by using a dynamic context compression mechanism. The approach combines summary-priority replacement with core structure order-preserving pruning, which significantly reduces the input length while maximizing the preservation of the core semantic information of the community, and can generate high-quality community combination description text.
[0082] P2, based on the user query, the description text of each community combination is input as a separate context into the preset large language model, so that the preset large language model generates an intermediate answer for the user query based on each separate context, and generates an answer relevance score for each intermediate answer.
[0083] As described above, by submitting different combinations of communities as independent contextual backgrounds to the large language model, the large language model is guided to generate preliminary insights related to user queries from the local perspective of different community combinations. This enables rapid and low-cost exploration of multiple thematic dimensions of the knowledge graph. Furthermore, by using relevance scoring, highly relevant answers to user queries can be selected to improve the accuracy and reliability of subsequent overall answers.
[0084] In another implementation, step P2 is replaced by the following steps: P21. Based on the user query, the community combinations are traversed in descending order of importance. The description text of the community combination corresponding to the community combination is input as a separate context into the preset large language model. The preset large language model generates an intermediate answer for the user query based on each individual context input, and generates an answer relevance score for each intermediate answer. The importance of the community combination is the sum of the weights of all communities in the community combination.
[0085] P22. After generating an intermediate answer for each community combination, calculate the question coverage and average relevance score of all currently generated intermediate answers.
[0086] Preferably, the question coverage is the semantic similarity between the query vector corresponding to the user query and the vectors corresponding to all intermediate answers.
[0087] On page 23, if both the problem coverage and the average relevance score reach their respective preset convergence thresholds, the traversal stops, and the process proceeds directly to step S4; otherwise, the traversal continues to the next community combination. Those skilled in the art can set the preset convergence thresholds for problem coverage and average relevance score according to actual needs, which will not be elaborated here.
[0088] The above steps, by introducing an ordered traversal and dynamic evaluation mechanism based on the importance of community combinations, realize intelligent scheduling of computing resources and early convergence of the global retrieval process. It not only prioritizes high-weight core topic communities to ensure answer quality, but also actively terminates subsequent retrieval when the quality of the obtained answers is high. Thus, while ensuring retrieval results, it significantly improves the system's response efficiency when handling broad and macro queries.
[0089] P3 sorts and filters all intermediate answers based on the relevance score of each intermediate answer. It then concatenates the selected intermediate answers to form a comprehensive context and inputs the comprehensive context into a preset large language model to generate the final answer for the user query.
[0090] Specifically, when splicing together several selected intermediate answers, they are spliced in descending order of their relevance scores.
[0091] As described above, by screening intermediate answers, noise and low-quality information are effectively filtered out. By splicing together several intermediate answers, information from multiple perspectives is gathered. By utilizing the comprehensive inductive ability of the large language model, multi-perspective and fragmented intermediate answers are integrated to generate a coherent, comprehensive, and generalized answer that can cover multiple topics involved in the query. This completes the transformation from distributed information retrieval to high-quality knowledge extraction, overcoming the limitations of traditional retrieval enhancement generation technology in processing domain information that is structurally dispersed and complexly related.
[0092] Furthermore, the method also includes the following steps: P01, when the query intent category is a broad question, obtain the confidence level of the query intent category output by the pre-trained query intent classification model.
[0093] P02. When the confidence level is greater than the preset confidence threshold, the P1 step is executed after selecting a higher-level community from the hierarchical community structure generated by the community discovery algorithm. Otherwise, the P1 step is executed after selecting a lower-level community.
[0094] As described above, by combining the confidence level of query classification with the hierarchical structure of the knowledge graph, the adaptive allocation of global retrieval granularity is achieved. When the system is highly confident in its judgment of a broad question, it directly selects a high-level community for macro-level generalization, improving efficiency and the abstractness of the answer. When the judgment is doubtful, it selects a more specific low-level community, providing answers that are closer to specific facts while retaining the global retrieval framework. This enhances the robustness and practicality of the system in scenarios where the query intent is ambiguous.
[0095] In summary, by integrating local information retrieval and global retrieval methods, a complete knowledge-enhanced retrieval and generation system has been constructed, significantly improving the overall capability when processing structurally dispersed and highly interconnected domain information. The local information retrieval method, through a local deep association retrieval mechanism, demonstrates a unique advantage in accurately tracing the source of information when handling specific and complex factual and logical reasoning queries. The global retrieval method, through a global topic fusion retrieval mechanism, demonstrates the core value of comprehensive summarization when handling broad and macro-level topic summarization and trend analysis queries. These two methods complement each other, enabling the system to output highly reliable answers that combine accuracy, logic, and insight for information needs of different granularities and types. Both methods improve the reliability of answer output when processing structurally dispersed and highly interconnected domain information, and each has different advantages in handling specific information and macro-level topics.
[0096] Embodiments of the present invention also provide a non-transitory computer-readable storage medium, which can be disposed in an electronic device to store at least one instruction or at least one program related to implementing a method in the method embodiments, wherein the at least one instruction or the at least one program is loaded and executed by the processor to implement the knowledge graph-based local information retrieval method provided in the above embodiments.
[0097] Embodiments of the present invention also provide an electronic device, including a processor and the aforementioned non-transitory computer-readable storage medium.
[0098] While specific embodiments of the invention have been described in detail by way of example, those skilled in the art should understand that the examples are for illustrative purposes only and not intended to limit the scope of the invention. It should also be understood that various modifications can be made to the embodiments without departing from the scope and spirit of the invention. The scope of the invention is defined by the appended claims.
Claims
1. A local information retrieval method based on knowledge graphs, characterized in that, The method includes the following steps: S1, based on user query, retrieve at least one target entity from a pre-built knowledge graph; wherein, the nodes of the knowledge graph include entities and events extracted from several original texts, the edges represent the relationships between entities and between entities and events, and the knowledge graph is divided into several blocks, each block corresponding to a block description text; S2, based on each target entity, obtain a set of candidate information from the knowledge graph; the information units in the set of candidate information include candidate graph blocks containing any target entity, candidate relationships connected to any target entity, and candidate original text blocks containing any target entity. S3, according to the preset sorting rules corresponding to each information unit, sort and filter the candidate image blocks, candidate relationships and candidate original text blocks respectively to obtain a number of sorted and filtered information units. S4. The sorted and filtered information units are integrated to generate a prompt context, and the prompt context is input into a preset large language model to generate the final answer for the user query.
2. The local information retrieval method based on knowledge graphs according to claim 1, characterized in that, In step S1, retrieving at least one target entity from a pre-built knowledge graph includes the following steps: S101, convert the text corresponding to the user query into a query vector, calculate the semantic similarity between the query vector and the description vector corresponding to each entity in the knowledge graph, and recall several first candidate entities according to a first preset similarity threshold; S102, Based on the knowledge graph, perform keyword matching on the entity mentions in the user query, and expand the matched entities along the edges of the knowledge graph by a preset number of hops to recall several second candidate entities. S103, deduplicate all recalled first candidate entities and all second candidate entities, and encode the user query, each deduplicated candidate entity, and the local neighborhood information of the candidate entity in the knowledge graph, inputting them into the pre-trained language model to calculate the context relevance score of each deduplicated candidate entity to the user query; wherein, the local neighborhood information includes the adjacent entities and relationships of the candidate entity within a preset number of hops. S104, select candidate entities whose context-related scores exceed a preset score threshold as the retrieved target entities.
3. The local information retrieval method based on knowledge graphs according to claim 1, characterized in that, The knowledge graph is constructed using the following steps: S10: Extract entities, events, and relationships from several original texts to generate an initial graph; wherein, events with semantic similarity greater than a second preset similarity threshold are aggregated into the same cluster, and the clusters are merged as an event node in the initial graph; S20, the initial graph is divided into several communities using a community detection algorithm, each community is used as a partitioned graph tile, and a preset large language model is called to generate corresponding graph tile description text for each graph tile to generate a knowledge graph; wherein, the graph tile description text contains all entities, relations and assertions extracted from the original text within the corresponding graph tile.
4. The local information retrieval method based on knowledge graphs according to claim 3, characterized in that, The step of calling a preset large language model to generate corresponding tile description text for each tile includes the following steps: S021, for any tile, if the original information context contained in the tile exceeds the context window limit threshold of the preset large language model, then based on the hierarchical community structure generated by the community detection algorithm, each lower sub-community is traversed in descending order of the number of entities contained in the lower sub-community, and the pre-generated descriptive text summary of the currently traversed lower sub-community replaces the original information context contained in the lower sub-community itself to generate the compressed original information context corresponding to the tile. S022, after each replacement, determine the current length of the current compressed original information context; If the current length does not exceed the context window limit threshold, then stop traversing and proceed to step S024; S023, if after traversing all the lower-level sub-communities corresponding to the tile, the length of the compressed original information context still exceeds the context window limit threshold, then the remaining original node information in the compressed original information context is sorted by importance according to the degree centrality of the nodes, and the nodes and their associated relationships are removed from back to front until the length of the compressed original information context does not exceed the context window limit threshold. S024, take the current compressed original information context as the final context and input it into the preset large language model to generate the tile description text corresponding to the tile.
5. The local information retrieval method based on knowledge graphs according to claim 1, characterized in that, The preset sorting rules corresponding to each information unit are as follows: S301, for candidate map tiles, sort them in descending order according to their corresponding weights; wherein, the weights of the candidate map tiles meet the following conditions: W c =α×log(F c +1)+β×(U c / N), where W c Let F be the weight of the c-th candidate patch. c Let U be the total frequency of the target entity contained in the c-th candidate tile across all text units. c The number of non-repeating text units covered by the target entity contained in the c-th candidate tile, where N is the total number of text units, and α and β are preset weighting coefficients, respectively. S302, for candidate relations, intra-network relations connecting two target entities take precedence over extra-network relations connecting one target entity and one non-target entity; wherein, intra-network relations are sorted in descending order according to the sum of the degrees of the two target entities corresponding to the intra-network relations, and extra-network relations are sorted in descending order according to the number of target entities connected to the non-target entity nodes corresponding to the extra-network relations. S303, for candidate original text blocks, sort them in descending order based on the maximum context relevance score between the target entities associated with the candidate original text block and the user query; wherein, when the maximum context relevance scores of two candidate original text blocks are the same, sort them in descending order according to the total number of candidate relations associated with the candidate original text blocks.
6. The local information retrieval method based on knowledge graphs according to claim 1, characterized in that, The candidate original text blocks are also sorted using the following steps: S310, For each candidate original text block, calculate the corresponding sorting feature vector; the sorting feature vector includes at least the following dimensions: Semantic similarity feature: cosine similarity between the candidate original text block and the query vector corresponding to the user query; Community importance feature: the average degree centrality of the set of nodes of the tile to which the candidate original text block belongs; Evidence connectivity feature: edge density of the minimum connected subgraph containing the target entities associated with the candidate original text block; Path saliency feature: the reciprocal of the average shortest path length of the target entity associated with the candidate original text block in the knowledge graph; S320, input the sorting feature vector corresponding to each candidate original text block into a pre-trained scoring model to obtain the final sorting score of each candidate original text block; S330, Sort all candidate original text blocks in descending order according to the final sorting score.
7. The local information retrieval method based on knowledge graphs according to claim 1, characterized in that, Steps S2 and S3 are replaced by the following steps: F1 determines the query semantic pattern category corresponding to the user query; the query semantic pattern category is at least one of fact confirmation type, causal analysis type, impact assessment type, and process description type. F2, based on the query semantic pattern category, selects the corresponding target expansion strategy from a number of predefined graph expansion strategies; the number of predefined graph expansion strategies includes pathfinding strategies for locating direct relationships, causal traversal strategies for tracing causes or results, influence propagation strategies for assessing the scope of influence, and temporal association strategies for constructing event sequences; F3 uses each target entity as an anchor point and, based on the selected target expansion strategy, calculates the score of each node to be evaluated within a preset hop range corresponding to the target entity according to a preset scoring function. The preset scoring function integrates the semantic similarity between the description text of the node to be evaluated and the user query, the structural importance of the node to be evaluated in the current subgraph, and the fit between the node to be evaluated and the query semantic pattern category. The preset scoring threshold is inversely proportional to the expansion depth. F4 expands the nodes to be evaluated with scores greater than a preset scoring threshold into the current subgraph to extend the evidence subgraph from the knowledge graph; the current subgraph refers to the real-time graph obtained when the nodes are expanded. F5: Extract the description information corresponding to each node and edge in the evidence subgraph from the knowledge graph and integrate them to generate a prompt context to replace the prompt context in step S4.
8. The local information retrieval method based on knowledge graphs according to claim 1, characterized in that, Prior to step S1, the method further includes: S01, the user query is input into a pre-trained query intent classification model to identify the intent of the user query and output the query intent category; wherein, the query intent category is either a specific question or a broad question; S02, when the query intent category is a specific question, execute steps S1 to S4 to generate the final answer for the user query.
9. A non-transitory computer-readable storage medium, wherein the storage medium stores at least one instruction or at least one program segment, characterized in that, The at least one instruction or the at least one program segment is loaded and executed by the processor to implement the knowledge graph-based local information retrieval method as described in any one of claims 1-8.
10. An electronic device, characterized in that, Includes a processor and the non-transitory computer-readable storage medium as described in claim 9.