User query complexity self-adaptive knowledge graph retrieval enhancement generation method

By jointly quantifying user query complexity and reinforcing learning to screen knowledge reasoning paths, the problem of insufficient adaptability of knowledge graph retrieval methods in existing technologies to user query complexity is solved, flexible knowledge retrieval scope and strategy adjustment are achieved, and the accuracy and efficiency of retrieval are improved.

CN120687577AActive Publication Date: 2025-09-23CHINA UNIV OF MINING & TECH

Patent Information

Application Number
CN202510953714.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-10
Publication Date
2025-09-23
Estimated Expiration
2045-07-10

AI Technical Summary

Technical Problem

Existing knowledge graph retrieval enhancement generation methods have a trade-off problem between flexibility and retrieval quality, and cannot adapt to the complexity of different user queries, resulting in unnecessary knowledge redundancy and necessary knowledge loss, affecting the relevance of retrieval results.

Method used

By jointly quantifying the complexity of user queries through multiple indicators, adaptively adjusting the knowledge graph retrieval scope and retrieval strategy, combining reinforcement learning to screen the optimal knowledge reasoning path, and using a large language model to answer user queries.

Benefits of technology

It realizes the flexible adjustment of knowledge retrieval scope and strategy according to the complexity of user query, improves retrieval accuracy and efficiency, takes into account both retrieval accuracy and efficiency, and enhances the flexibility of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120687577A_ABST
    Figure CN120687577A_ABST
Patent Text Reader

Abstract

The invention discloses a user query complexity adaptive knowledge graph retrieval enhancement generation method, which comprises the following steps of: firstly, quantifying user query complexity according to a complexity measurement index contained in user query, and analyzing and complementing hidden logic of the user query; then, establishing a corresponding relationship between the user query complexity and the knowledge graph retrieval range and between the user query complexity and the knowledge graph retrieval strategy, and adaptively adjusting the knowledge graph retrieval range in combination with the user query complexity; then, adaptively screening out an optimal group of knowledge reasoning paths in the determined knowledge graph retrieval range based on reinforcement learning; and finally, answering the user query based on the selected knowledge reasoning path by utilizing a large language model. According to the method, the static limitation of the existing knowledge retrieval strategy is broken, the knowledge retrieval range and the retrieval strategy can be flexibly determined according to the query complexity of the user, and the retrieval precision and the retrieval efficiency are both considered.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a knowledge graph retrieval enhancement generation method that is adaptive to user query complexity, and involves natural language processing, knowledge graph and large language model technology. Background Art

[0002] Currently, generative AI technologies, represented by large language models (LLMs), have made significant progress in areas such as machine translation, question-answering systems, and logical reasoning, leveraging natural language human-computer interaction. However, during industry customization, large language models are limited by the scope of their training data and a lack of domain knowledge, leading to hallucinations and errors. This significantly reduces their reliability and poses security risks. For example, the general base model GPT-4o's training data is current as of October 2023. If it is asked about events in 2025 or disease diagnosis, it may pretend to understand the 2025 events and answer questions that did not happen, or it may make an incorrect diagnosis due to a lack of background knowledge about the disease.

[0003] To alleviate these issues, retrieval-augmented generation (RAG) techniques have garnered widespread attention. These techniques decompose the query-answering process into two phases: retrieval and generation. In the retrieval phase, relevant textual knowledge is retrieved from unstructured data sources such as external text and web pages. In the generation phase, the retrieved textual knowledge is used to guide large language models in generating higher-quality responses. Conventional RAG techniques rely heavily on unstructured text data, making it difficult to directly capture the most relevant knowledge and potentially introducing noise, which hinders the effective reasoning of large language models. Consequently, knowledge graphs (KGs) have been increasingly integrated into RAG methods as external knowledge sources, resulting in the development of knowledge graph retrieval-augmented generation (KG-RAG). Knowledge graphs such as Freebase, Wikidata, and MMpedia illustrate the context and multi-level relationships between entities in a triple format, providing rich and explicit knowledge. The knowledge graph retrieval-enhancement-generation technology first retrieves the most relevant reasoning paths from the knowledge graph, and then adds these reasoning paths to prompts to provide concise and structured context information, enhancing the reasoning ability of the large language model. Figure 1The article demonstrates the differences between large language models, retrieval-augmentation-generation technology, and knowledge graph retrieval-augmentation-generation technology in answering user queries. It can be seen that knowledge graph retrieval-augmentation-generation technology can provide more direct and relevant knowledge for large language models. It is a key technology to promote the implementation of large language models in different industries and has important research value.

[0004] At present, the knowledge graph retrieval-enhancement-generation technology can still be divided into two stages: retrieval and generation; the retrieval stage generally includes three sub-stages: preprocessing, knowledge positioning, and knowledge selection. Figure 2 As shown in the figure, the preprocessing sub-stage preprocesses the user query and knowledge graph through operations such as entity recognition, relationship extraction, and embedding coding. The knowledge positioning sub-stage locates the retrieval scope of the target knowledge in the knowledge graph through operations such as entity linking, similarity matching, and node classification. The knowledge selection sub-stage selects the most relevant reasoning paths by evaluating the relevance between the entities, relations, and triples in the retrieval scope and the user query. The reasoning path of the retrieval stage is defined as the query entity e0 and the candidate answer entity e a The three tuples are connected end to end in the form of "e0, r1, e1, r2, ..., e a "Entity-relationship sequence; the generation stage is to provide the retrieved knowledge reasoning path to the large language model as the context background knowledge of the user query, so that the large language model can accurately answer the user query based on this knowledge.

[0005] The paper "FRAG: A Flexible Modular Framework for Retrieval-Augmented Generation based on Knowledge Graphs" proposes a flexible modular framework for retrieval-augmented generation based on knowledge graphs. FRAG aims to address the trade-off between flexibility and retrieval quality in existing knowledge graph retrieval-augmented generation techniques. The basic steps include:

[0006] (1) A classifier is trained based on the number of hops in the knowledge reasoning path to classify user queries into two categories: “simple” and “complex”. Query numbers less than or equal to 2-hop are classified as simple queries, and otherwise as complex queries.

[0007] (2) Artificially set a set of fixed knowledge reasoning path retrieval steps for “simple” and “complex” respectively;

[0008] (3) For “simple” queries, we first extract a 2-hop knowledge subgraph using the Personalized PageRank (PPR) algorithm and perform subgraph pruning. We then directly traverse all knowledge reasoning paths on the 2-hop subgraph and rank all reasoning paths by relevance. Finally, we construct Prompts, select the m most relevant knowledge reasoning paths, and use the large language model to answer the user’s query.

[0009] (4) For complex queries, the Personalized PageRank (PPR) algorithm is first used to extract a 4-hop knowledge subgraph and perform subgraph pruning. Then, the Dijkstra algorithm is used on the 4-hop subgraph to retrieve the shortest reasoning path between the "entity in the user query" and "any other entity", and all shortest reasoning paths are ranked by relevance. Finally, Prompts is constructed, the m most relevant knowledge reasoning paths are selected, and the large language model is used to answer the user query.

[0010] However, the FRAG method artificially divides user queries into two categories, which is too simple; and it sets a fixed retrieval process for each category, which cannot adapt to user queries of various levels of difficulty.

[0011] Existing knowledge graph retrieval enhancement generation methods divide the process of answering user queries into two stages: retrieval and generation. In the retrieval stage, relevant background knowledge (knowledge reasoning path) is retrieved from the external knowledge graph; in the generation stage, the retrieved relevant background knowledge is used to guide the large language model to generate higher quality responses. Existing knowledge graph retrieval enhancement generation methods still have the disadvantage of insufficient flexibility in knowledge retrieval scope and retrieval strategy. That is, existing knowledge graph retrieval enhancement generation methods usually use the same knowledge retrieval strategy to process all user queries within a fixed retrieval scope without considering the influence of the complexity of user queries. Specifically: (1) For simple queries, only a small amount of the most relevant target knowledge needs to be identified within a small scope. The retrieval scope is small, the target knowledge is small, and the retrieval strategy is simple; (2) For complex queries, a larger amount of target knowledge needs to be identified within a larger scope. The retrieval scope is large, the target knowledge is large, and the retrieval strategy is complex. Therefore, the existing methods lack flexibility in knowledge retrieval scope and retrieval strategy, which may lead to the problems of "unnecessary knowledge redundancy" and "necessary knowledge loss", seriously affecting the relevance of retrieval results. Although some studies have guided the retrieval process by predicting the number of hops to the target knowledge, they only consider the number of hops as a factor and have not established an adaptive correspondence between "user query complexity" and "knowledge retrieval scope and retrieval strategy". They are still in the preliminary exploration stage and urgently need further research.

[0012] Technical terms

[0013] Knowledge graph: A knowledge graph organizes real-world knowledge in the form of a graph, representing entities and their relationships through nodes and edges.

[0014] Large language model: A large language model is an artificial intelligence model trained using large amounts of text data. It can understand and generate natural language and answer user queries; for example, GPT-3 and ChatGPT.

[0015] Retrieval-enhanced generation: Retrieval-enhanced generation combines the retrieval system and the generative model to enhance the accuracy of the content generated by the large language model through retrieval information; for example, using the retrieved document content to generate a report using the large language model.

[0016] Knowledge graph retrieval enhanced generation: Knowledge graph retrieval enhanced generation combines the structured information of the knowledge graph and the generative model, and optimizes the generation results of the large language model through the graph information; for example, an intelligent question-answering system based on the knowledge graph.

[0017] Knowledge reasoning path: The knowledge reasoning path is the logical process of deriving from one entity to another through the relationships and entities in the knowledge graph; for example, “e0, r1, e1, r2, …, e a ” entity-relationship sequence.

[0018] Entity: An entity is a basic element in a knowledge graph, representing a specific thing, object, or concept; for example, a person's name, a place name, a company name, etc.

[0019] Relationship: A relationship is an association connecting two entities in a knowledge graph, representing the interaction between them; for example, the relationship between Zhang San (entity 1) and Li Si (entity 2) is "friends" (relationship).

[0020] Triple: In the instance layer of the knowledge graph, a data structure composed of entities, relationships, and entities describes the basic facts in the knowledge graph; for example, the triple (Zhang San, friend, Li Si) means "Zhang San (entity 1) is Li Si (entity 2)'s friend (relationship)"; the instance layer is a specific instantiation of the concept layer.

[0021] Query conditions: Query conditions are rules or standards used to limit or filter the retrieved data; for example, retrieve faculty members who are older than 30 years old.

[0022] Number of hops in the knowledge reasoning path: The number of hops in the knowledge reasoning path refers to the number of relationships crossed during the reasoning process; for example, the number of hops in the knowledge reasoning path "Zhang San" → "Company" → "Beijing" is 2 (the arrow represents the "relationship").

[0023] Reinforcement learning: Reinforcement learning is a type of machine learning that uses rewards and penalties to help the model autonomously learn optimal strategies. For example, autonomous driving systems use rewards and penalties to adjust their driving strategies.

[0024] Traversal: Traversal is the systematic process of visiting every node or element in a graph, tree, or other structure; for example, visiting every user in a social network exactly once and in a certain order without repeating the steps.

[0025] Ontology: At the conceptual level of the knowledge graph, the basic knowledge system and descriptive language of a certain field are outlined through a set of normalizations of concepts, terms, and their relationships. For example, "person" → "born in" → "place" indicates that a person-type entity and a place-type entity may have the "born in" relationship. At the conceptual level, it generally refers to the two types of entities: person and place. Summary of the Invention

[0026] Purpose of the invention: In order to overcome the deficiencies in the prior art, the present invention provides a knowledge graph retrieval enhancement generation method that is adaptive to the complexity of user queries. The complexity of user queries is quantified by multiple indicators, and the knowledge retrieval scope and retrieval strategy are adaptively determined according to the complexity, breaking the static limitations of existing knowledge retrieval strategies. The knowledge retrieval scope and retrieval strategy are flexibly determined according to the complexity of user queries, taking into account both retrieval accuracy and retrieval efficiency.

[0027] Technical solution: To achieve the above purpose, the technical solution adopted by the present invention is:

[0028] A knowledge graph retrieval enhancement generation method that is adaptive to user query complexity. First, the user query complexity is accurately quantified based on the complexity measurement indicators contained in the user query, and the hidden logic of the user query is analyzed and completed. Then, a correspondence is established between the user query complexity and the knowledge graph retrieval scope and knowledge graph retrieval strategy (including the number of knowledge reasoning paths and the number of knowledge reasoning path hops). The knowledge graph retrieval scope is adaptively adjusted based on the user query complexity. Then, based on reinforcement learning, the optimal set of knowledge reasoning paths is adaptively screened within the determined knowledge graph retrieval scope. Finally, a large language model is used to accurately answer the user query based on the selected knowledge reasoning paths.

[0029] Specifically, the complexity measurement indicators include the number of entities, the number of query conditions, the number of knowledge reasoning path hops, and the requirements for advanced statistical operations, which are specifically defined as follows:

[0030] The number of entities: Entities are extracted from user queries using named entity recognition technology. The greater the number of entities, the richer the knowledge content involved and the more complex the user query;

[0031] The number of query conditions: Analyze the query conditions in the user query through dependency syntax analysis and semantic role labeling, including limiting conditions, modifying conditions, etc. The more query conditions there are, the more knowledge restrictions are involved, and the more complex the user query is;

[0032] The number of hops in the knowledge reasoning path: parsing the user query, counting or predicting the number of hops in the knowledge reasoning path in the user query. The more hops in the knowledge reasoning path, the more complex the knowledge logic involved, and the more complex the user query;

[0033] The advanced statistical operation requirements: parse the user query and determine whether there are advanced statistical operation requirements such as summation, averaging, sorting or summary in the user query. User queries with advanced statistical operation requirements are more complex.

[0034] Specifically, neural networks, large language models, or heuristic rules are used to quantify user query complexity; or neural networks, large language models, and heuristic rules are used to quantify user query complexity separately, and then the quantification results of the three methods are integrated to obtain a joint quantitative score, which is used as the user query complexity used in subsequent adjustments to the knowledge graph range and determination of knowledge reasoning paths.

[0035] (1) Use CNN, Transformer, BERT and other neural networks to extract the semantic features of user queries and predict the user query complexity S through the fully connected layer nn ;

[0036] S nn =σ(Linear(Encoder(q)))×Bound

[0037] Where: q represents the user query, Encoder(·) represents the neural network encoder, Linear(·) represents the fully connected layer, σ(·) represents the sigmoid activation function, and Bound represents the maximum value of the user query complexity score used for normalization;

[0038] (2) Constructing prompt 1 , using open source large language models such as LLaMA, Qwen, and DeepSeek to analyze user queries and output the user query complexity S within the specified value range llm :

[0039] S llm =LLM(prompt,q,Bound)

[0040] Where: prompt 1Indicates the constructed hint of using a large language model to evaluate the complexity of user queries. LLM(·) represents an open-source large language model encoder such as LLaMA, Qwen, and DeepSeek.

[0041] (3) According to the complexity measurement indicators, analyze the number of entities in the user query, the number of query conditions, the number of knowledge reasoning path hops and the demand for advanced statistical operations, and design heuristic rules to calculate the user query complexity S rule :

[0042]

[0043] Among them, E(q), C(q), and H(q) represent the number of entities, the number of query conditions, and the number of hops in the inference path, respectively. A(q)∈{0,1} indicates whether the user query requires advanced statistical operations. A(q)=1 indicates that advanced statistical operations are required, and A(q)=0 indicates that advanced statistical operations are not required. E(q) max 、C max 、H max They represent the maximum number of entities, the number of query conditions, and the number of hops in the inference knowledge path used for normalization, respectively. α, β, γ, and δ represent the normalization hyperparameters, satisfying α+β+γ+δ=1.0. Their values ​​are manually set according to the importance of the four indicators.

[0044] (4) Through weighted operation, the user query complexity scores obtained by the three methods are integrated to obtain the joint quantitative score S 0 :

[0045] S 0 =ω nn ·S nn +ω llm ·S llm +ω rule ·S rule

[0046] Where: nn 、ω llm and ω rule Represents the weight coefficient, satisfying ω nn +ω llm +ω rule =1.0;

[0047] (5) Collect a user query training set D containing various user query complexity scores (including at least two categories: simple and complex), compare the difference between the predicted results and the preset labels, calculate the loss value L, and use the stochastic gradient descent algorithm to optimize the calculation model of the user query complexity S; the loss function is:

[0048]

[0049] Where: user query complexity S is used as the prediction result. For the case where a single user query complexity is used to adjust the scope of the subsequent knowledge graph and determine the knowledge reasoning path, S is S nn 、S llm or S rule , for the case of using joint quantitative scoring for subsequent knowledge graph range adjustment and knowledge reasoning path determination, S is S 0 ; I(q) represents the preset label of the user query complexity; represents the regularization term, and λ represents the regularization coefficient.

[0050] Specifically, neural networks, large language models, and symbolic rules are used to analyze and complete the hidden logic of user queries, including the following steps:

[0051] (1) Analyze the semantic structure of user query q, complete the syntactic and grammatical components that may be missing in user query q, and obtain the preliminary completed user query q 1 ;

[0052] (2) Analyze the user query training set D through manual or large language models, identify common hidden logic, define the symbolic rules corresponding to the hidden logic, and establish a symbolic rule database; for example, map implicit subjective conditions such as "nearby", "popular", "affordable", and "delicious" to specific ranges or standards, and map fuzzy query conditions such as "which ones" and "how many" to "there are advanced operations"; in the initial completion of the user query q 1 Based on the correspondence between hidden logic and symbol rules, the user query q is preliminarily completed through symbol rule matching completion. 1 The hidden logic that may be missing in the query is obtained by completing the user query q twice. 2 ;

[0053] (3) Using open source large language models such as LLaMA, Qwen, and DeepSeek to complete the user query q 2 Perform chain thinking and complete the user query q twice 2 Decompose it into a group of subqueries, and complete the secondary completion user query q according to the logical relationship between the subqueries 2 The hidden logic not explicitly expressed in the query is used to obtain the complete user query q new ;

[0054] (4) Complete the user query q new Verify and complete all hidden logic that meets the symbol rules as completely as possible without omission, repeat the relevant steps (multiple rounds of completion) according to the set conditions until the user query q is completely completed new Passed verification.

[0055] Specifically, based on the user query complexity S, the heuristic rules are first used to preliminarily adjust the knowledge graph search scope, and several candidate knowledge subgraphs are extracted from them. Then, the knowledge graph search scope is further adjusted using three indicators: the number of candidate knowledge hops, the number of entities, and the semantic coverage area. This achieves adaptive adjustment of the knowledge graph search scope, including the following steps:

[0056] (1) Based on prior knowledge or pre-experimental results, the heuristic rules are used to preliminarily adjust the knowledge graph search range. In order to improve the efficiency of adaptive adjustment, the knowledge graph search range after the preliminary adjustment is required to be large enough for the user query q and small enough for the entire knowledge graph;

[0057] (2) Estimate the rough range of candidate knowledge hop counts and determine the minimum hop count h min and the maximum number of hops h max , based on the user query complexity score S, determine the upper limit h(q) of candidate knowledge hops for user query q:

[0058]

[0059] in: Indicates rounding up, c h is an additional constant regarding the number of candidate knowledge hops;

[0060] (3) Estimate the rough range of the number of entities and determine the minimum number of entities n min and the maximum number of entities n max , based on the user query complexity S, determine the upper limit n(q) of the number of entities in the candidate knowledge subgraph:

[0061]

[0062] Where: c n is an additional constant related to the number of entities;

[0063] (4) Using encoders such as Transformer, graph neural network, and knowledge graph embedding models (such as TransE and TransH), the user query q and all entities within the knowledge graph retrieval range are first embedded into a dense vector space. Then, the semantic relevance between the user query q and each entity is calculated in the dense vector space. Finally, the upper limit of the candidate knowledge hop count h(q) and the upper limit of the entity number n(q) are broken through, and the related entities exceeding the threshold are identified to obtain the related entity set E. sim (q):

[0064] sim q,e =Cosine(Encoder(q),Encoder(e))

[0065] Among them: sim q,e Represents the semantic relevance between the user query q and the current entity e, Cosine(·) represents the cosine similarity function; if sim q,e >δ(q), then add the current entity e to the related entity set E sim (q), δ(q) is the set threshold;

[0066] (5) For the complete user query q new , using natural language analysis tools such as HanNLP and StanfordNLP to identify the entity set E(q new ); for the entity set E(q new ), within the upper limit of candidate knowledge hops h(q), traverse to the end or reach the upper limit of entity number n(q) using breadth-first or depth-first principle to form a candidate knowledge subgraph P 1 ;

[0067] (6) For E sim (q)-E(q new ) set, within the upper limit of candidate knowledge hops h(q), traverse to the end or reach the upper limit of entity number n(q) using breadth-first or depth-first principle to form a candidate knowledge subgraph P 2 ;

[0068] (7) Merge candidate knowledge subgraph P 1 and candidate knowledge subgraph P 2 , and obtain the adaptively adjusted knowledge graph retrieval range P = P 1 UP 2 .

[0069] Specifically, on each candidate knowledge subgraph within the knowledge graph retrieval range, the sequential decision of the knowledge reasoning path is performed based on reinforcement learning, the number of hops of the knowledge reasoning path is adaptively determined, and a set of optimal knowledge reasoning paths is screened out; firstly, based on the reinforcement learning paradigm, the sequential decision task of the knowledge reasoning path is converted into a set of E sim (q)UE(q new) as the starting point, a stopping condition is introduced in the sequential decision process of each entity to adaptively determine the number of knowledge reasoning paths, and a beam search strategy is used to prevent falling into local optimality, so as to screen out a group of knowledge reasoning paths; then, the screened knowledge reasoning paths are verified based on the ontology and predefined reasoning path rules, and the knowledge reasoning paths that fail to pass the verification are corrected or removed; then, the pre-trained large language model is used to calculate the semantic relevance between the user query q and each knowledge reasoning path, and the knowledge reasoning paths are sorted according to the semantic relevance; at the same time, the user query complexity S is used to determine the number K of knowledge reasoning paths that need to be returned; finally, the K knowledge reasoning paths with the largest semantic relevance are taken as the optimal knowledge reasoning paths.

[0070] Specifically, based on the reinforcement learning paradigm, the sequential decision-making task of the knowledge reasoning path is converted into a set E sim (q)UE(q new ) is a sequential decision task starting from each entity in the , the reinforcement learning paradigm includes the current state s at the decision time t t , action space A t 、Strategy networkπ((r i , e i )|s t ), state transition strategy s t →s t+1 and reward function R(q new , e0);

[0071] The current state s t , by fully completing the user query q new , starting node e0, historical decision path h from starting time 0 to decision time t t and the current node e t Composition, expressed as s t =[q new ,e0,h t , e t ]; where, the user query q is fully completed new The starting node e0 is the global information that does not change with the decision time t, and the historical decision path h t and the current node e t is the local information that changes with the decision time t;

[0072] The action space A t , is the current node e t is the set of all candidate actions of the head node, and the stop condition (stop, -) is introduced, which is represented by A i ={(r1, e1), (r2, e2), ...}∪{(stop, -)}; the candidate action includes the head node et , tail node e i and the relationship between the two nodes r i , expressed as (r i , e i ), the embedded vector of each candidate action is composed of the relation embedded vector and entity embedded vector obtained by knowledge graph embedding models such as TransE and TransH; the stopping condition (stop, -) is implemented by introducing a reflexive relation self-loop for each entity, defined as (self-loop, e t );

[0073] The policy network π((r i , e i )|s t ), refers to the current state s t Calculate the action space A t The execution probability of all candidate actions in:

[0074]

[0075] Where: f(s t (r i , e i )) represents the scoring function, which is used to judge the current state s t Next candidate action (r i , e i ) can be implemented using Transformer, attention mechanism, and multi-layer perceptron.

[0076] The state transition strategy s t →s t+1 , refers to the policy network π((r i , e i )|s t ) selects the candidate action with the highest execution probability (r * , e * ) and execute, the current state is s t Then it is converted to the next state s t+1 =[q new ,e0,h t+1 , e t+1 ], e t+1 That is e * , h t+1 =h t ∪{(r * , e * )}, the historical decision path h0 at the starting time 0 is defined as {(-, e0)};

[0077] The reward function R(qnew , e0), when the entity's sequential decision process meets the stopping condition (stop, -), if the node e at the stop time T T If it is consistent with the preset entity, it receives a reward value of 1, otherwise it receives a reward value of 0; the reward value R at the decision time t t A continuously shrinking discount factor μ is used as the main reward, that is, μ T-t ·R(q new , e0), and using the historical decision path h t Complete the user query q new The relevance of is an additional reward, namely Similarity(h t ,q new ), then R t =μ T-t ·R(q new ,e0)+Similarity(h t ,q new ), the reinforcement learning paradigm can be optimized using the REINFORCE or Actor-Critic algorithm. The optimization goal is to maximize the reward value R at the decision time t t .

[0078] Specifically, a beam search strategy is used to prevent the reinforcement learning paradigm from falling into local optimality. Each sequential decision task starting from an entity returns M sequential decision paths, which are used as knowledge reasoning paths to screen out a total of |E sim (q)∪E(q new )|×M knowledge reasoning paths; where M represents a hyperparameter determined by each sequential decision task and used to determine the number of knowledge reasoning paths.

[0079] Furthermore, the screened knowledge reasoning paths are verified based on the ontology and predefined reasoning path rules. For knowledge reasoning paths that fail the verification, they are corrected or directly removed with the help of the ontology and symbolic rules. The reasoning path rules meet the following requirements: ① The reasoning path contains the entities and relationships in the user query; ② The reasoning path contains the target entity type in the user query; ③ The relationships and entities in the reasoning path conform to the type constraints in the ontology; ④ The reasoning path conforms to the combination condition constraints in the user query.

[0080] Furthermore, a pre-trained large language model such as BERT or RoBERTa can be used to fully complete the user query q new Embed it into the same vector space as the knowledge reasoning path h, and use the cosine similarity function to calculate the semantic relevance between the two:

[0081]

[0082] in: Indicates the complete completion of the user query q new The semantic relevance between and the knowledge reasoning path h, and PLM(·) represents the pre-trained large language model.

[0083] Furthermore, a linear mapping method, a nonlinear mapping method or a piecewise function mapping method is used to determine the number K of knowledge reasoning paths that need to be returned;

[0084] In the linear mapping method, Among them, K max It is a hyperparameter set according to prior knowledge or pre-experimental results, indicating the maximum number of knowledge reasoning paths returned. k is a constant bias term;

[0085] In the nonlinear mapping method, Among them, α k and β k It is a hyperparameter set based on prior knowledge or pre-experimental results, which is used to control the growth rate of the number of knowledge reasoning paths. k is a constant bias term;

[0086] In the piecewise function mapping method, Among them, S1 and S2 are thresholds set according to prior knowledge for dividing different user query complexity intervals, α1 and α2 are hyperparameters set according to prior knowledge or pre-experimental results to control the growth rate of the number of knowledge reasoning paths, c1 and c2 are constant bias terms, and K min It is a hyperparameter set based on prior knowledge or pre-experimental results, indicating the minimum number of returned knowledge reasoning paths.

[0087] Beneficial effects: Compared with the existing technology that usually adopts the same strategy to process all user queries, resulting in insufficient flexibility in the knowledge retrieval scope and retrieval strategy, the user query complexity adaptive knowledge graph retrieval enhancement generation method provided by the present invention has the following advantages: 1. Taking into account the influence of user query complexity, the present invention can adaptively adjust the knowledge retrieval scope and retrieval strategy according to the query complexity to enhance the flexibility of the model; 2. For simple user queries, the required target knowledge is less, and the retrieval scope and retrieval strategy can be appropriately tightened to ensure retrieval accuracy and speed up retrieval efficiency; 3. For complex user queries, the required target knowledge is more, and the retrieval scope and retrieval strategy can be appropriately relaxed to ensure retrieval efficiency and improve retrieval accuracy; 4. The present invention breaks the static limitations of existing knowledge retrieval strategies, realizes the flexible determination of knowledge retrieval scope and retrieval strategy according to the complexity of user queries, and achieves the purpose of taking into account both retrieval accuracy and retrieval efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0088] Figure 1Comparison between large language models, retrieval-augmentation-generation, and knowledge graph retrieval-augmentation-generation;

[0089] Figure 2 This is a flowchart of the knowledge graph retrieval steps;

[0090] Figure 3 Schematic diagram of the implementation process of the method of the present invention;

[0091] Figure 4 A schematic diagram of the implementation process for expanding the method of the present invention to a multimodal knowledge graph scenario. DETAILED DESCRIPTION

[0092] The present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.

[0093] A knowledge graph retrieval enhancement generation method that is adaptive to user query complexity assumes that the relevant background knowledge retrieved from the external knowledge graph exists in the form of "knowledge reasoning path". Therefore, the "knowledge reasoning path" in the subsequent description is the retrieved relevant background knowledge. Figure 3 As shown in the figure, the basic implementation process of this method is as follows: First, the complexity of the user query is accurately quantified based on complexity metrics such as the number of entities contained in the user query, the number of query conditions, the number of knowledge reasoning path hops, and the need for advanced statistical operations. The hidden logic of the user query is then analyzed and completed. Then, a correspondence is established between the user query complexity and the knowledge graph search scope and knowledge graph search strategy (including the number of knowledge reasoning paths and the number of knowledge reasoning path hops). The knowledge graph search scope is adaptively adjusted based on the user query complexity. Next, the optimal set of knowledge reasoning paths is adaptively selected within the determined knowledge graph search scope based on reinforcement learning. Finally, a prompt is constructed, and a large language model is used to accurately answer the user query based on the selected knowledge reasoning path. The following is a further explanation of this method with reference to the specific implementation steps.

[0094] Step 1: Quantify user query complexity

[0095] Use neural networks, large language models or heuristic rules to quantify user query complexity; or use neural networks, large language models and heuristic rules to quantify user query complexity separately, and then combine the quantification results of the three methods to obtain a joint quantitative score, and use the joint quantitative score as the subsequent adjustment of the knowledge graph range and the determination of the user query complexity used in the knowledge reasoning path.

[0096] (11) Use CNN, Transformer, BERT and other neural networks to extract the semantic features of user queries and predict the complexity of user queries S through the fully connected layer nn :

[0097] S nn =σ(Linear(Encoder(q)))×Bound

[0098] Where: q represents the user query, Encoder(·) represents the neural network encoder, Linear(·) represents the fully connected layer, σ(·) represents the sigmoid activation function, and Bound represents the maximum value of the user query complexity score used for normalization.

[0099] (12) Construct prompt 1 , using open source large language models such as LLaMA, Qwen, and DeepSeek to analyze user queries and output the user query complexity S within the specified value range llm :

[0100] S llm =LLM(prompt,q,Bound)

[0101] Where: prompt 1 represents the constructed hint of using a large language model to evaluate the complexity of the user query. LLM(·) represents the open source large language model encoder such as LLaMA, Qwen, and DeepSeek.

[0102] (13) According to the complexity measurement indicators, analyze the number of entities in the user query, the number of query conditions, the number of knowledge reasoning path jumps and the demand for advanced statistical operations, and design heuristic rules to calculate the user query complexity S rule :

[0103]

[0104] Among them, E(q), C(q), and H(q) represent the number of entities, the number of query conditions, and the number of hops in the inference path, respectively. A(q)∈{0,1} indicates whether the user query requires advanced statistical operations. A(q)=1 indicates that advanced statistical operations are required, and A(q)=0 indicates that advanced statistical operations are not required. E(q) max 、C max 、H max They represent the maximum number of entities, the number of query conditions, and the number of hops in the inference knowledge path used for normalization, respectively. α, β, γ, and δ represent the normalization hyperparameters, satisfying α+β+γ+δ=1.0. Their values ​​are manually set according to the importance of the four indicators.

[0105] (14) Through weighted operation, the user query complexity scores obtained by the three methods are integrated to obtain the joint quantitative score S 0 :

[0106] S 0=ω nn ·S nn +ω llm ·S llm +ω rule ·S rule

[0107] Where: nn 、ω llm and ω rule Represents the weight coefficient, satisfying ω nn +ω llm +ω rule =1.0; The weight coefficient can be selected in two ways: one is to determine a fixed static weight value based on the results of the pre-experimental experiment, and the other is to design a meta-learning module g(·) to adaptively allocate dynamic weights, [ω nn ,ω llm ,ω rule ]=softmax(g(q)).

[0108] (15) Collect a user query training set D containing various user query complexity scores (including at least two categories: simple and complex), compare the difference between the predicted results and the preset labels, calculate the loss value L, and use the stochastic gradient descent algorithm to optimize the calculation model of the user query complexity S; the loss value L is:

[0109]

[0110] Where: user query complexity S is used as the prediction result. For the case where a single user query complexity is used to adjust the scope of the subsequent knowledge graph and determine the knowledge reasoning path, S is S nn 、S llm or S rule , for the case of using joint quantitative scoring for subsequent knowledge graph range adjustment and knowledge reasoning path determination, S is S 0 ; I(q) represents the preset label of the user query complexity; represents the regularization term, and λ represents the regularization coefficient.

[0111] Step 2: Analyze and complete the hidden logic of user queries

[0112] User queries usually contain relevant constraint information of hidden logic, such as default time, price range, emotional tendency, complex conditions, user preferences, etc. Analyzing and completing the hidden logic not only helps to accurately understand user needs, but also provides additional supplementary information for the subsequent knowledge graph retrieval process; comprehensively utilize neural networks, large language models and symbolic rules to analyze the hidden logic of user queries, and analyze and complete the hidden logic of user queries.

[0113] (21) Use CNN, Transformer and other neural networks to build a semantic parsing model for user query q, or use open source neural network natural language analysis tools such as HanNLP and StanfordNLP to perform dependency syntactic analysis and semantic role labeling on user query q, parse the semantic structure of user query q, complete the syntactic and grammatical components that may be missing in user query q, and obtain a preliminary completed user query q. 1 .

[0114] (22) Analyze the user query training set D through artificial or large language models, identify common hidden logic, define the symbolic rules corresponding to the hidden logic, and establish a symbolic rule database; for example, map implicit subjective conditions such as "nearby", "popular", "affordable", and "delicious" to specific ranges or standards, and map fuzzy query conditions such as "which ones" and "how many" to "there are advanced operations"; in the initial completion of the user query q 1 Based on the correspondence between hidden logic and symbol rules, the user query q is preliminarily completed through symbol rule matching completion. 1 The hidden logic that may be missing in the query is obtained by completing the user query q twice. 2 .

[0115] (23) Using open source large language models such as LLAMA, Qwen, and DeepSeek to complete the user query q 2 Perform chain thinking and complete the user query q twice 2 Decompose it into a group of subqueries, and complete the secondary completion user query q according to the logical relationship between the subqueries 2 The hidden logic not explicitly expressed in the query is used to obtain the complete user query q new .

[0116] When using open source large language models such as LLaMA, Qwen, and DeepSeek to complete the user query q, it is necessary to first construct a prompt that uses the large language model to complete the hidden logic. 2 , such as “Given a user query q, please base your prediction on the hidden logic set H that may be missing or not explicitly expressed in the user query q. logic , rewrite or complete the user query q", and finally get the fully completed user query q new =LLM(prompt 2 ,q,H logic ).

[0117] (24) Complete the user query q new Verify and complete all hidden logic that meets the symbol rules as completely as possible without omission, repeat the relevant steps (multiple rounds of completion) according to the set conditions until the user query q is completely completednew Passed verification.

[0118] Step 3: Adaptively adjust the knowledge graph search scope

[0119] According to the user query complexity S, the heuristic rules are first used to preliminarily adjust the knowledge graph retrieval scope, and several candidate knowledge subgraphs are extracted from them. Then, the three indicators of candidate knowledge hop count, number of entities, and semantic coverage area are used to further adjust the knowledge graph retrieval scope to achieve adaptive adjustment of the knowledge graph retrieval scope.

[0120] (31) Based on prior knowledge or preliminary experimental results, the heuristic rules are used to preliminarily adjust the knowledge graph retrieval range. In order to improve the efficiency of adaptive adjustment, the knowledge graph retrieval range after preliminary adjustment is required to be large enough for the user query q and small enough for the entire knowledge graph.

[0121] (32) Estimate the rough range of candidate knowledge hop counts and determine the minimum hop count h min and the maximum number of hops h max , based on the user query complexity score S, determine the upper limit h(q) of candidate knowledge hops for user query q:

[0122]

[0123] in: Indicates rounding up, c h is an additional constant regarding the number of candidate knowledge hops.

[0124] (33) Estimate the rough range of the number of entities and determine the minimum number of entities n min and the maximum number of entities n max , based on the user query complexity S, determine the upper limit n(q) of the number of entities in the candidate knowledge subgraph:

[0125]

[0126] Where: c n is an additional constant related to the number of entities.

[0127] (34) Using encoders such as Transformer, graph neural network, and knowledge graph embedding models (such as TransE and TransH), the user query q and all entities within the knowledge graph retrieval range are first embedded into a dense vector space. Then, the semantic relevance between the user query q and each entity is calculated in the dense vector space. Finally, the upper limit of the candidate knowledge hop count h(q) and the upper limit of the number of entities n(q) are broken through, and the related entities exceeding the threshold are identified to obtain the related entity set E. sim (q):

[0128] simq,e =Cosine(Encoder(q),Encoder(e))

[0129] Among them: sim q,e Represents the semantic relevance between the user query q and the current entity e, Cosine(·) represents the cosine similarity function; if sim q,e >δ(q), then add the current entity e to the related entity set E sim In (q), δ(q) is the set threshold. The threshold δ(q) can be specified as a fixed value based on prior knowledge or pre-experimental results, or it can be determined based on the joint quantitative score S. ξ is a hyperparameter.

[0130] (35) For the complete user query q new , using natural language analysis tools such as HanNLP and StanfordNLP to identify the entity set E(q new ); for the entity set E(q new ), within the upper limit of candidate knowledge hops h(q), traverse to the end or reach the upper limit of entity number n(q) using breadth-first or depth-first principle to form a candidate knowledge subgraph P 1 .

[0131] (36) For E sim (q)-E(q new ) set, within the upper limit of candidate knowledge hops h(q), traverse to the end or reach the upper limit of entity number n(q) using breadth-first or depth-first principle to form a candidate knowledge subgraph P 2 .

[0132] (37) Merge candidate knowledge subgraph P 1 and candidate knowledge subgraph P 2 , and obtain the adaptively adjusted knowledge graph retrieval range P = P 1 UP 2 .

[0133] Step 4: Adaptively select the optimal knowledge reasoning path

[0134] On each candidate knowledge subgraph within the knowledge graph retrieval range, the sequential decision of the knowledge reasoning path is made based on reinforcement learning, the number of hops of the knowledge reasoning path is adaptively determined, and a set of optimal knowledge reasoning paths is screened out; firstly, based on the reinforcement learning paradigm, the sequential decision task of the knowledge reasoning path is converted into a set of E sim (q)UE(q new) as the starting point, a stopping condition is introduced in the sequential decision process of each entity to adaptively determine the number of knowledge reasoning paths, and a beam search strategy is used to prevent falling into local optimality, so as to screen out a group of knowledge reasoning paths; then, the screened knowledge reasoning paths are verified based on the ontology and predefined reasoning path rules, and the knowledge reasoning paths that fail to pass the verification are corrected or removed; then, the pre-trained large language model is used to calculate the semantic relevance between the user query q and each knowledge reasoning path, and the knowledge reasoning paths are sorted according to the semantic relevance; at the same time, the user query complexity S is used to determine the number K of knowledge reasoning paths that need to be returned; finally, the K knowledge reasoning paths with the largest semantic relevance are taken as the optimal knowledge reasoning paths.

[0135] (41) Building a reinforcement learning paradigm

[0136] Construct a reinforcement learning paradigm to transform the sequential decision-making task of the knowledge reasoning path into a set E sim (q)UE(q new ) is a sequential decision task starting from each entity in the , the reinforcement learning paradigm includes the current state s at the decision time t t , action space A t 、Strategy networkπ((r i , e i )|s t ), state transition strategy s t →s t+1 and reward function R(q new , e0).

[0137] The current state s t , by fully completing the user query q new , starting node e0, historical decision path h from starting time 0 to decision time t t and the current node e t Composition, expressed as s t =[q new ,e0,h t , e i ]; where, the user query q is fully completed new The embedded vector representation is obtained through pre-trained large language models such as BERT; the candidate knowledge subgraph where the starting node e0 is located obtains the embedded vector representation of each entity and each relationship through knowledge graph embedding models such as TransE and TransH; the historical decision path h t The embedded vector representation is obtained through long short-term memory network LSTM encoding.

[0138] The action space A t , is the current node e tis the set of all candidate actions of the head node, and the stop condition (stop, -) is introduced, which is represented by A t ={(r1, e1), (r2, e2), ...}∪{(stop, -)}; the candidate action includes the head node e t , tail node e i and the relationship between the two nodes r i , expressed as (r i , e i ), the embedded vector of each candidate action is composed of the relation embedded vector and entity embedded vector obtained by knowledge graph embedding models such as TransE and TransH; the stopping condition (stop, -) is implemented by introducing a reflexive relation self-loop for each entity, defined as (self-loop, e t ).

[0139] The policy network π((r i , e i )|s t ), refers to the current state s t Calculate the action space A t The execution probability of all candidate actions in:

[0140]

[0141] Where: f(s t (r i , e i )) represents the scoring function, which is used to judge the current state s t Next candidate action (r i , e i ) can be implemented using Transformer, attention mechanism, and multi-layer perceptron.

[0142] The state transition strategy s t →s t+1 , refers to the policy network π((r i , e i )|s t ) selects the candidate action with the highest execution probability (r * , e * ) and execute, the current state is s t Then it is converted to the next state s t+1 =[q new ,e0,h t+1 , e t+1 ], e t+1 That is e * , h t+1 =h t ∪{(r* , e * )}, the historical decision path h0 at the starting time 0 is defined as {(-, e0)}.

[0143] The reward function R(q new , e0), when the entity's sequential decision process meets the stopping condition (stop,-), if the node e at the stop time T T If it is consistent with the preset entity, it receives a reward value of 1, otherwise it receives a reward value of 0; the reward value R at the decision time t t A continuously shrinking discount factor μ is used as the main reward, that is, μ T-t ·R(q new , e0), and using the historical decision path h t Complete the user query q new The relevance of is an additional reward, namely Similarity(h t ,q new ), then R t =μ T-t ·R(q new ,e0)+Similarity(h t ,q new ).

[0144] The reinforcement learning paradigm can be optimized using the REINFORCE or Actor-Critic algorithm. The optimization goal is to maximize the reward value R at the decision time t. t .

[0145] (42) Using beam search strategy to prevent reinforcement learning paradigm from falling into local optimality

[0146] The beam search strategy is used to prevent the reinforcement learning paradigm from falling into local optimality. Each sequential decision task starting from an entity returns M sequential decision paths, which are used as knowledge reasoning paths to screen out a total of |E sim (q)∪E(q new )|×M knowledge reasoning paths; where M represents a hyperparameter determined by each sequential decision task and used to determine the number of knowledge reasoning paths.

[0147] (43) Predefined reasoning path rule library

[0148] The reasoning path rules meet the following requirements: ① The reasoning path contains the entities and relationships in the user query; ② The reasoning path contains the target entity type in the user query; ③ The relationships and entities in the reasoning path conform to the type constraints in the ontology; ④ The reasoning path conforms to the combination condition constraints in the user query.

[0149] The screened knowledge reasoning paths are verified based on the ontology and predefined reasoning path rules. For knowledge reasoning paths that fail the verification, they are corrected or directly removed with the help of ontology and symbolic rules.

[0150] (44) Calculate the semantic relevance between the fully completed user query and the knowledge reasoning path

[0151] Using a pre-trained large language model such as BERT or RoBERTa will fully complete the user query q new Embed it into the same vector space as a certain knowledge reasoning path h, and use the cosine similarity function to calculate the semantic relevance between the two:

[0152]

[0153] in: Indicates the complete completion of the user query q new The semantic relevance between and the knowledge reasoning path h, and PLM(·) represents the pre-trained large language model.

[0154] In addition, all the relationship categories in the knowledge reasoning path h can also be extracted to form the relationship path h r , using the relationship path h r Replace the knowledge reasoning path h and use the formula Calculate the complete user query q new With the relationship path h r The semantic relevance between and follow the next steps.

[0155] (45) Determine the number of knowledge reasoning paths that need to be returned

[0156] A linear mapping method, a nonlinear mapping method or a piecewise function mapping method is used to determine the number K of knowledge reasoning paths that need to be returned.

[0157] In the linear mapping method, Among them, K max It is a hyperparameter set according to prior knowledge or pre-experimental results, indicating the maximum number of knowledge reasoning paths returned. k is a constant bias term.

[0158] In the nonlinear mapping method, Among them, α k and β k It is a hyperparameter set based on prior knowledge or pre-experimental results, which is used to control the growth rate of the number of knowledge reasoning paths. k is a constant bias term.

[0159] In the piecewise function mapping method, Among them, S1 and S2 are thresholds set according to prior knowledge for dividing different user query complexity intervals, α1 and α2 are hyperparameters set according to prior knowledge or pre-experimental results to control the growth rate of the number of knowledge reasoning paths, c1 and c2 are constant bias terms, and K min It is a hyperparameter set based on prior knowledge or pre-experimental results, indicating the minimum number of returned knowledge reasoning paths.

[0160] (46) Determine the optimal knowledge reasoning path

[0161] The K knowledge reasoning paths with the greatest semantic relevance are taken as the optimal knowledge reasoning paths.

[0162] Step 5: Answer user queries

[0163] Construct prompts that use large language models to answer user queries 3 , using a large language model to accurately answer user queries based on the selected knowledge reasoning path, prompting 3 It includes task description, user query, selected optimal knowledge reasoning path and output format.

[0164] Step 6: Use scenario expansion

[0165] By adding a unified embedding encoding step and a semantic feature alignment step for multimodal knowledge, the usage scenario of this method is extended to the multimodal knowledge graph scenario; in the multimodal knowledge graph scenario, text modal information is used as the main knowledge, and other modal information such as pictures, videos, and audio are used as supplementary knowledge.

[0166] (61) Unified Embedding Coding Steps

[0167] For text modal information, Transformer, graph neural network or knowledge graph embedding model is used to encode the graph structure of the text to obtain embedded vector representations of all entities and relationships involved in the text.

[0168] For image modality information, a pre-trained visual model such as CLIP is used to encode the image to obtain an embedded vector representation of the image. If the image is only used as an attribute of the entity, no relationship is involved. If the image is used as an entity, then the relationship is involved. For the head entity e in the triplet to which the relationship belongs, head and tail entity e tail The embedded vector is linearly transformed to obtain the embedded vector representation r of the relationship image :

[0169] r image =Linear([Embed(e head );Embed(e tail )])

[0170] Among them: Embed(·) means obtaining the embedded vector representation of the entity, and Linear(·) means the fully connected layer.

[0171] For video or audio modal information, an open source pre-trained Transformer is used to encode the video or audio to obtain an embedded vector representation of the video or audio; if a relationship is involved, the embedded vectors of the head entity and tail entity in the triplet to which the relationship belongs are linearly transformed to obtain the embedded vector representation of the relationship.

[0172] (62) Semantic feature alignment step

[0173] Through contrastive learning methods, the embedded vectors of image, video, audio, and text modal information are aligned to the same semantic feature space: First, text-image, text-video, and text-audio alignment data are extracted from the multimodal knowledge graph scene; then, contrastive loss functions are constructed to align images, videos, and audio with the corresponding text, and algorithms such as gradient descent are used for optimization to ensure that the relative distance between the embedded vectors of each modality is shortened under the same semantic conditions. The contrastive loss function is:

[0174]

[0175] Where: L contrastive represents the contrast loss between text and samples; E text Embedded vector representation of text, E i and E i Represents the embedding vector representation of the sample, τ is a hyperparameter, N represents the total number of samples in the sample library, and the samples in the sample library are all pictures, or all videos, or all audio.

[0176] (63) Adjust the scope of knowledge graph search

[0177] When adjusting the knowledge graph search scope, the semantic relevance calculation between text and non-text is added in the process of identifying related entities; Figure 4 As shown, other parts do not need to be changed to realize the application of multimodal knowledge graph scenarios.

[0178] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the above embodiments do not limit the present invention in any form, and any technical solutions obtained by equivalent replacement or equivalent transformation fall within the scope of protection of the present invention.

Claims

1. A knowledge graph retrieval enhancement generation method that is adaptive to user query complexity, characterized by: First, the complexity of user queries is quantified based on the complexity measurement indicators contained in the user queries, and the hidden logic of the user queries is analyzed and completed; then, a correspondence between the complexity of user queries and the knowledge graph retrieval scope and knowledge graph retrieval strategy is established, and the knowledge graph retrieval scope is adaptively adjusted based on the complexity of user queries; then, based on reinforcement learning, the optimal set of knowledge reasoning paths is adaptively screened within the determined knowledge graph retrieval scope; finally, the large language model is used to answer user queries based on the selected knowledge reasoning paths.

2. The user query complexity adaptive knowledge graph retrieval enhancement generation method according to claim 1 is characterized by: Quantify user query complexity using neural networks, large language models, or heuristic rules; or quantify user query complexity using neural networks, large language models, and heuristic rules separately, then combine the quantification results of the three methods to obtain a joint quantitative score, and use the joint quantitative score as the user query complexity used in subsequent adjustments to the knowledge graph scope and determination of knowledge reasoning paths; (1) Use neural networks to extract the semantic features of user queries and predict the user query complexity S through the fully connected layer nn : S nn =σ(Linear(Encoder(q)))×Bound Where: q represents the user query, Encoder(·) represents the neural network encoder, Linear(·) represents the fully connected layer, σ(·) represents the sigmoid activation function, and Bound represents the maximum value of the user query complexity score used for normalization; (2) Constructing prompt 1 , use the large language model to analyze user queries and output the user query complexity S within the specified value range llm : S llm =LLM(prompt,q,Bound) Where: prompt 1 represents the constructed hint for evaluating the complexity of user queries using a large language model, and LLM(·) represents the large language model encoder; (3) According to the complexity measurement indicators, analyze the number of entities in the user query, the number of query conditions, the number of knowledge reasoning path hops and the requirements of advanced statistical operations, and design heuristic rules to calculate the user query complexity S rule : Among them, E(q), C(q), and H(q) represent the number of entities, the number of query conditions, and the number of hops in the inference path, respectively. A(q)∈{0,1} indicates whether the user query requires advanced statistical operations. A(q)=1 indicates that advanced statistical operations are required, and A(q)=0 indicates that advanced statistical operations are not required. E(q) max 、C max 、H max They represent the maximum number of entities, the number of query conditions, and the number of hops in the inference knowledge path used for normalization, respectively. α, β, γ, and δ represent the normalization hyperparameters, satisfying α+β+γ+δ=1.

0. (4) Through weighted operation, the user query complexity scores obtained by the three methods are integrated to obtain the joint quantitative score S 0 : S 0 =ω nn ·S nn +oh llm ·S llm +oh rule ·S rule Where: nn 、ω llm and ω rule Represents the weight coefficient, satisfying ω nn +ω llm +ω rule =1.0; (5) Collect a user query training set D containing various user query complexity scores, compare the difference between the predicted results and the preset labels, calculate the loss value L, and use the stochastic gradient descent algorithm to optimize the calculation model of the user query complexity S; the loss function is: Where: user query complexity S is used as the prediction result. For the case where a single user query complexity is used to adjust the scope of the subsequent knowledge graph and determine the knowledge reasoning path, S is S nn 、S llm or S rule , for the case of using joint quantitative scoring for subsequent knowledge graph range adjustment and knowledge reasoning path determination, S is S 0 ; I(q) represents the preset label of the user query complexity; represents the regularization term, and λ represents the regularization coefficient.

3. The user query complexity adaptive knowledge graph retrieval enhancement generation method according to claim 1 is characterized by: Comprehensively utilize neural networks, large language models, and symbolic rules to analyze and complete the hidden logic of user queries, including the following steps: (1) Analyze the semantic structure of user query q, complete the missing syntactic and grammatical components in user query q, and obtain the preliminary completed user query q 1 ; (2) Analyze the user query training set D through the large language model, identify the hidden logic, define the symbolic rules corresponding to the hidden logic, and establish a symbolic rule database; in the initial completion of the user query q 1 Based on the correspondence between hidden logic and symbol rules, the user query q is preliminarily completed through symbol rule matching completion. 1 The hidden logic that may be missing in the query is obtained by completing the user query q twice. 2 ; (3) Using a large language model to secondary complete the user query q 2 Perform chain thinking and complete the user query q twice 2 Decompose it into a group of subqueries, and complete the secondary completion user query q according to the logical relationship between the subqueries 2 The hidden logic not explicitly expressed in the query is used to obtain the complete user query q new ; (4) Complete the user query q new Verify and repeat the relevant steps according to the set conditions until the user query q is fully completed new Passed verification.

4. The user query complexity adaptive knowledge graph retrieval enhancement generation method according to claim 1 is characterized by: Based on the user query complexity S, the heuristic rules are first used to preliminarily adjust the knowledge graph search scope, and several candidate knowledge subgraphs are extracted from them. Then, the knowledge graph search scope is further adjusted using three indicators: the number of candidate knowledge hops, the number of entities, and the semantic coverage area. This achieves adaptive adjustment of the knowledge graph search scope, including the following steps: (1) Based on prior knowledge or pre-experimental results, use heuristic rules to preliminarily adjust the knowledge graph search scope; (2) Estimate the rough range of candidate knowledge hop counts and determine the minimum hop count h min and the maximum number of hops h max , based on the user query complexity score S, determine the upper limit h(q) of candidate knowledge hops for user query q: in: Indicates rounding up, c h is an additional constant regarding the number of candidate knowledge hops; (3) Estimate the rough range of the number of entities and determine the minimum number of entities n min and the maximum number of entities n max , based on the user query complexity S, determine the upper limit n(q) of the number of entities in the candidate knowledge subgraph: Where: c n is an additional constant related to the number of entities; (4) First, embed the user query q and all entities within the knowledge graph retrieval range into a dense vector space, then calculate the semantic relevance between the user query q and each entity in the dense vector space, and finally break through the upper limit of candidate knowledge hops h(q) and the upper limit of the number of entities n(q), identify related entities that exceed the threshold, and obtain the related entity set E sim (q): sim q,e =Cosine(Encoder(q),Encoder(e)) Among them: sim q,e Represents the semantic relevance between the user query q and the current entity e, Cosine(·) represents the cosine similarity function; if sim q,e >δ(q), then add the current entity e to the related entity set E sim (q), δ(q) is the set threshold; (5) For the complete user query q new , identify the entity set E(q new ); for the entity set E(q new ), within the upper limit of candidate knowledge hops h(q), traverse to the end or reach the upper limit of entity number n(q) using breadth-first or depth-first principle to form a candidate knowledge subgraph P 1 ; (6) For E sim (q)-E(q new ) set, within the upper limit of candidate knowledge hops h(q), traverse to the end or reach the upper limit of entity number n(q) using breadth-first or depth-first principle to form a candidate knowledge subgraph P 2 ; (7) Merge candidate knowledge subgraph P 1 and candidate knowledge subgraph P 2 , and obtain the adaptively adjusted knowledge graph retrieval range P = P 1 ∪P 2 .

5. The user query complexity adaptive knowledge graph retrieval enhancement generation method according to claim 1 is characterized by: On each candidate knowledge subgraph within the knowledge graph retrieval range, the sequential decision of the knowledge reasoning path is made based on reinforcement learning, the number of hops of the knowledge reasoning path is adaptively determined, and a set of optimal knowledge reasoning paths is screened out; firstly, based on the reinforcement learning paradigm, the sequential decision task of the knowledge reasoning path is converted into a set of E sim (q)∪E(q new ) as the starting point, a stopping condition is introduced in the sequential decision process of each entity to adaptively determine the number of knowledge reasoning paths, and a beam search strategy is used to prevent falling into local optimality, so as to screen out a group of knowledge reasoning paths; then, the screened knowledge reasoning paths are verified based on the ontology and predefined reasoning path rules, and the knowledge reasoning paths that fail to pass the verification are corrected or removed; then, the pre-trained large language model is used to calculate the semantic relevance between the user query q and each knowledge reasoning path, and the knowledge reasoning paths are sorted according to the semantic relevance; at the same time, the user query complexity S is used to determine the number K of knowledge reasoning paths that need to be returned; finally, the K knowledge reasoning paths with the largest semantic relevance are taken as the optimal knowledge reasoning paths.

6. The user query complexity adaptive knowledge graph retrieval enhancement generation method according to claim 5 is characterized by: Based on the reinforcement learning paradigm, the sequential decision-making task of the knowledge reasoning path is converted into a set E sim (q)∪E(q new ) is a sequential decision task starting from each entity in the , and the reinforcement learning paradigm includes the current state s at the decision time t t , action space A t 、Strategy networkπ((r t , e i )|s t ), state transition strategy s t →s t+1 and reward function R(q new , e0); The current state s t , by fully completing the user query q new , starting node e0, historical decision path h from starting time 0 to decision time t t and the current node e t Composition, expressed as s t =[q new ,e0,h t , e t ]; The action space A t , is the current node e t is the set of all candidate actions of the head node, and the stop condition (stop, -) is introduced, which is represented by A t ={(r1, e1), (r2, e2), ...}∪{(stop, -)}; the candidate action includes the head node e t , tail node e i and the relationship between the two nodes r i , expressed as (r i , e i ); The stopping condition (stop,-) is realized by introducing a reflexive relation self-loop for each entity, which is defined as (self-loop, e t ); The policy network π((r i , e i )|s t ), refers to the current state s t Calculate the action space A t The execution probability of all candidate actions in: Where: f(s t (r i , e i )) represents the scoring function, which is used to judge the current state s t Next candidate action (r i , e i )’s execution probability score; The state transition strategy s t →s t+1 , refers to the policy network π((r i , e i )|s t ) Select the candidate action (r*, e*) with the highest execution probability and execute it. The current state s t Then it is converted to the next state s t+1 =[q new ,e0,h t+1 , e t+1 ], e t+1 That is, e*, h t+1 =h t ∪{(r*, e*)}, the historical decision path h0 at the starting time 0 is defined as {(-, e0)}; The reward function R(q new , e0), when the entity's sequential decision process meets the stopping condition (stop, -), if the node e at the stop time T T If it is consistent with the preset entity, it receives a reward value of 1, otherwise it receives a reward value of 0; the reward value R at the decision time t t A continuously shrinking discount factor μ is used as the main reward, that is, μ T-t ·R(q new , e0), and using the historical decision path h t Complete the user query q new The relevance of is an additional reward, namely Similarity(h t ,q new ), then R t =μ T-t ·R(q new ,e0)+Similarity(h t ,q new ).

7. The user query complexity adaptive knowledge graph retrieval enhancement generation method according to claim 5 is characterized by: The beam search strategy is used to prevent the reinforcement learning paradigm from falling into local optimality. Each sequential decision task starting from an entity returns M sequential decision paths, which are used as knowledge reasoning paths to screen out a total of |E sim (q)∪E(q new )|×M knowledge reasoning paths; where M represents a hyperparameter determined by each sequential decision task and used to determine the number of knowledge reasoning paths.

8. The user query complexity adaptive knowledge graph retrieval enhancement generation method according to claim 5 is characterized by: The screened knowledge reasoning paths are verified based on the ontology and predefined reasoning path rules. For knowledge reasoning paths that fail the verification, they are corrected or directly removed with the help of the ontology and symbolic rules. The reasoning path rules meet the following requirements: ① The reasoning path contains the entities and relationships in the user query; ② The reasoning path contains the target entity type in the user query; ③ The relationships and entities in the reasoning path conform to the type constraints in the ontology; ④ The reasoning path conforms to the combination condition constraints in the user query.

9. The user query complexity adaptive knowledge graph retrieval enhancement generation method according to claim 5, characterized in that: Using the pre-trained large language model to fully complete the user query q new Embed it into the same vector space as the knowledge reasoning path h, and use the cosine similarity function to calculate the semantic relevance between the two: in: Indicates the complete completion of the user query q new The semantic relevance between and the knowledge reasoning path h, and PLM(·) represents the pre-trained large language model.

10. The user query complexity adaptive knowledge graph retrieval enhancement generation method according to claim 5, characterized in that: The number K of knowledge reasoning paths that need to be returned is determined by using a linear mapping method, a nonlinear mapping method, or a piecewise function mapping method; In the linear mapping method, Among them, K max It is a hyperparameter set according to prior knowledge or pre-experimental results, indicating the maximum number of knowledge reasoning paths returned. k is a constant bias term; In the nonlinear mapping method, Among them, α k and β k It is a hyperparameter set based on prior knowledge or pre-experimental results, which is used to control the growth rate of the number of knowledge reasoning paths. k is a constant bias term; In the piecewise function mapping method, Among them, S1 and S2 are thresholds set according to prior knowledge for dividing different user query complexity intervals, α1 and α2 are hyperparameters set according to prior knowledge or pre-experimental results to control the growth rate of the number of knowledge reasoning paths, c1 and c2 are constant bias terms, and K min It is a hyperparameter set based on prior knowledge or pre-experimental results, indicating the minimum number of returned knowledge reasoning paths.

Citation Information

Patent Citations

  • Aviation standard question and answer optimization method and system based on atlas and document data

    CN119621894A

  • Multi-hop search for entity relationships

    US20220164679A1

Cited By

  • Knowledge base-based large model retrieval enhancement method and system

    CN121009180A

  • Relationship-driven self-adaptive knowledge graph question answering and path guiding method and system

    CN121094145A

  • Self-adaptive regulation generation method based on case reasoning and transfer learning

    CN121212293A

  • Information enhancement retrieval method and system based on large model and vector knowledge base

    CN121256108A

  • Information retrieval method and system based on large model and vector knowledge base

    CN121256108B