A rag multi-hop question answering method and device based on a large language model and a conditional dependency graph
Patent Information
- Application Number
- CN202611060324.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-16
- Publication Date
- 2026-10-30
AI Technical Summary
1.串行迭代方法采用逐步推理方式,每一步基于上一步结果生成新的检索查询,虽然推理质量较高,但由于严格串行执行,在子任务较多时延迟显著增大,且无法对独立子任务进行并行优化
1.表达能力更强
Smart Images

Figure CN123012102A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of natural language processing, information retrieval, and large language model application technology, and in particular to a RAG multi-hop question answering method and device based on a large language model and conditional dependency graph. Background Technology
[0002] With the rapid development of large language model technology, multi-hop retrieval augmented generation, by retrieving relevant documents from external knowledge bases and providing them as context to the large language model, effectively alleviates the problems of model illusion and knowledge obsolescence, and has been widely applied to question answering, dialogue, and knowledge-intensive tasks. However, for complex queries involving multi-step reasoning, the traditional single-round retrieval-generation paradigm is inadequate. For example, a query like "Has a certain stock outperformed the market this year? If so, has the company been profitable for the past three years?" requires first querying and comparing the stock's price change with the market, and then deciding whether to further query the company's profitability based on the comparison result. This reasoning chain containing conditional branches cannot be completed in a single retrieval.
[0003] Existing multi-hop RAG methods mainly suffer from the following problems: 1. The serial iterative method adopts a step-by-step reasoning approach, with each step generating a new retrieval query based on the result of the previous step. Although the reasoning quality is high, the latency increases significantly when there are many subtasks due to the strict serial execution, and it is impossible to perform parallel optimization on independent subtasks.
[0004] 2. Methods based on Directed Acyclic Graphs (DAGs) organize subtasks into DAGs for parallel scheduling, reducing execution latency. However, DAGs can only express serial and parallel dependencies and cannot model conditional branches and mutually exclusive choices. For queries containing such structures, all branches must be executed, resulting in unnecessary computational overhead.
[0005] 3. Methods requiring fine-tuning achieve dynamic programming by fine-tuning the subtask planner. Although the inference quality is high, it requires thousands of labeled data and a large amount of computing resources for training, which limits its ability to be quickly deployed in new fields.
[0006] A search of Chinese Patent Publication No. CN120723869A reveals a RAG multi-hop question answering method, apparatus, system, and storage medium, comprising: training a planning model and an information extraction model; using the trained planning model to parse complex problems into retrieval subtasks and inference subtasks; combining cosine similarity algorithm and relative boundary distance algorithm to perform dual-path document retrieval, obtaining main index results and auxiliary retrieval results; processing the main index results and auxiliary index results in parallel, and sequentially concatenating the processing results to obtain the final retrieval result; wherein, the parallel processing involves integrating corresponding text fragments based on topics and performing sentence-level text filtering; using the trained information extraction model to process the retrieval subtasks and inference subtasks, and integrating all intermediate results to generate the final answer. However, the existing patent decomposes complex problems into only retrieval and reasoning subtasks, which cannot handle conditional branches and mutually exclusive choices; at the same time, the existing patent executes all subtasks in the order of the planning sequence, and all decomposed retrieval and generation steps must be completed regardless of whether the intermediate results meet certain subsequent premises; in addition, the existing patent requires low-rank fine-tuning of the planning model and information extraction model in advance using a multi-hop question-answering dataset, which relies on labeled data and training computing power.
[0007] Therefore, there is an urgent need for a multi-hop retrieval enhancement generation method and electronic device that can take into account the completeness of dependency modeling, execution efficiency, conditional branching and mutual exclusion selection processing capabilities, and ease of deployment with zero fine-tuning in external knowledge retrieval scenarios. Summary of the Invention
[0008] The purpose of this invention is to overcome the shortcomings of the existing technology and provide a RAG multi-hop question answering method and system based on a large language model and conditional dependency graph.
[0009] The objective of this invention can be achieved through the following technical solutions: According to one aspect of the present invention, a RAG multi-hop question answering method based on a large language model and conditional dependency graph is provided, comprising: Step S1: Receive a natural language query and evaluate the complexity of the natural language query; Step S2: Decompose the natural language query into multiple sub-tasks using a large language model and construct a conditional dependency graph; In the conditional dependency graph, each node represents a subtask, and each directed edge represents a dependency relationship between two subtasks. The dependency relationships include four types: serial dependency, parallel dependency, conditional dependency, and mutual exclusion dependency. Step S3: Use a topology sorting-based algorithm to perform structure verification and detection on the conditional dependency graph and eliminate directed cycles, verifying the symmetry of the conditional expressions of the conditional dependencies and the mutual exclusion dependencies; Step S4: Identify all ready tasks that have been completed and have not been skipped; Step S5: For task pairs that have the mutual exclusion dependency with the ready tasks, select one to execute and skip the other based on the conditional dependency evaluation result; Step S6: Submit the ready tasks to the thread pool for parallel execution. For each ready task, rewrite the current task description using the execution result of the predecessor task. Use the rewritten description as the retrieval document for the search query. Generate a sub-answer based on the retrieval result and the answer of the predecessor task. Step S7: After the current task is completed, evaluate the conditional dependencies of its successor tasks. If the conditional dependencies are not met, mark the successor task as skipped. Step S8: Repeat steps S4 to S7 until there are no more ready tasks; Step S9: Filter out invalid answers and perform near-duplicate deduplication on all completed subtask answers to obtain valid answers. Fuse the valid answers with the natural language query input large language model to generate the final answer and return it.
[0010] As a preferred technical solution, the conditional dependency graph is defined as a quadruple: in It is a collection of nodes, each node containing a task identifier, task description, and priority; It is a set of directed edges, each edge containing the source task, target task, and dependency type; This is a conditional mapping function that maps each conditional dependency edge to a conditional expression; Let it be a set of mutually exclusive task pairs that satisfy symmetry.
[0011] As a preferred technical solution, the method for generating the conditional dependency graph includes: a method based on prompting engineering, inputting the query and few-sample examples into a large language model, and having the model output the node and edge definitions of the CDG in JSON format; Alternatively, the method for generating the conditional dependency graph may include: a method based on a fine-tuning model, wherein the query input is a fine-tuned small language model, and the fine-tuning data is generated by a large language model based on few-sample prompts.
[0012] As a preferred technical solution, step S5 specifically includes: when two mutually exclusive tasks are ready at the same time, evaluating whether their respective conditional dependency expressions are satisfied by the result of the predecessor task; if one condition is satisfied while the other is not, then the one that satisfies the condition is executed; if both conditions are satisfied or neither is satisfied, then the one with higher priority is selected for execution; all subsequent tasks of the skipped mutually exclusive task are also marked as skipped.
[0013] As a preferred technical solution, the method for rewriting the task description is as follows: obtain the execution results of all predecessor tasks of the current subtask, replace the explicit references to the predecessor task identifiers in the task description with the actual results of the predecessor tasks, and replace the backreferences in the task description with the actual results of the predecessor tasks.
[0014] As a preferred technical solution, the retroflexion refers to using a short word or phrase to refer to a person, thing, object, or concept that has been mentioned previously.
[0015] As a preferred technical solution, the condition dependency evaluation adopts a rule-based multi-strategy method: if the subtask result begins with an affirmative or negative word, a Boolean judgment is made based on whether the condition expression contains a negative keyword; otherwise, the key entity words in the condition expression are extracted, the matching ratio of the key entity words in the subtask result is calculated, and the condition is determined to be satisfied when the matching ratio is greater than or equal to a preset threshold.
[0016] As a preferred technical solution, the process of identifying ready tasks further includes an information gain filtering step, which calculates the information gain of each ready subtask relative to the existing set of answers, and skips the subtask when the information gain is lower than a preset threshold. The information gain is calculated based on the overlap between the subtask description and the vocabulary in the original query that is not covered by existing answers.
[0017] As a preferred technical solution, the invalid answer filtering includes filtering empty answers, task identifier placeholders, and general negative replies. Approximate deduplication is based on calculating the similarity between sub-answers using normalized edit distance, and merging duplicate answers with similarity higher than a preset threshold.
[0018] According to another aspect of the present invention, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the program to implement the method described thereon.
[0019] Compared with the prior art, the present invention has the following beneficial effects: 1. Stronger communication skills Traditional DAGs only support serial and parallel dependencies. The conditional dependency graph proposed in this invention adds two new edge types: conditional dependency and mutual exclusion dependency, supporting a total of four types of dependency relationships: serial, parallel, conditional, and mutual exclusion. It can accurately model complex queries that include conditional branches and mutual exclusion choices, covering more real-world reasoning logic.
[0020] 2. Higher execution efficiency and reduced redundancy overhead 1) Introduce a conditional pruning mechanism: By evaluating conditions based on rules, subsequent tasks that do not meet the conditions are directly marked as skipped, avoiding the execution of useless branches and reducing the number of document retrieval and large language model calls; 2) Supports parallel scheduling: Ready tasks without dependencies can be submitted to the thread pool for parallel execution, which significantly reduces end-to-end latency compared to traditional serial iterative methods; 3) Add information gain filtering: ready subtasks with information gain below the threshold are skipped directly to further reduce invalid computation.
[0021] 3. Low deployment cost and strong portability CDG generation adopts a prompting engineering approach, which only requires inputting the query and a few sample examples into a large language model to output the CDG structure. No task-specific labeled data is required for fine-tuning. It can be directly adapted to any large language model backend and different business domains, achieving zero-fine-tuning plug-and-play functionality and reducing development and maintenance costs.
[0022] 4. High-quality answers The final answer generation stage includes invalid answer filtering and near-duplicate deduplication steps: filtering empty answers, placeholders, and general negative responses, merging highly similar duplicate answers, and then combining them with the original query to ensure the accuracy and completeness of the final output. Attached Figure Description
[0023] Figure 1 This is a flowchart illustrating the overall process of the method of the present invention. Figure 2 This is a schematic diagram of the condition dependency graph (CDG) of the present invention; Figure 3 This is a flowchart of the CDG scheduling execution process of the present invention; Figure 4 This is a schematic diagram illustrating the conditional pruning process of the present invention; Figure 5 This is a schematic diagram of the execution of a traditional DAG. Detailed Implementation
[0024] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments. These embodiments are based on the technical solution of the present invention and provide detailed implementation methods and specific operating procedures. However, the scope of protection of the present invention is not limited to the following embodiments.
[0025] Example 1: like Figure 1 The overall flowchart of the method of the present invention shown includes: Step S1: Receive natural language queries; Step S2: Based on a weighted score of interrogative word density, conditional word existence, entity density, query length, and number of clauses, evaluate the complexity of the query. If the score is lower than a preset threshold, it is determined to be a simple query, and a single-round retrieval enhancement is performed to generate and return the answer; otherwise, proceed to the next step. Step S3: Use a large language model to decompose the natural language query into multiple sub-tasks and construct a condition dependency graph; In the conditional dependency graph, each node represents a subtask, and each directed edge represents a dependency relationship between two subtasks. The dependency relationships include four types: serial dependency, parallel dependency, conditional dependency, and mutual exclusion dependency. Step S4: The topology sorting-based algorithm is used to perform structural verification and detection on the condition dependency graph and eliminate directed cycles, verifying the symmetry of the conditional expression of the condition dependency and the mutual exclusion dependency. Step S5: Identify ready tasks that have been completed and not skipped by all predecessor tasks, and calculate the information gain of each ready subtask relative to the existing answer set. Skip the subtask when the information gain is lower than a preset threshold. The information gain is calculated based on the word overlap between the subtask description and the part of the original query that is not covered by existing answers. Step S6: For task pairs that have the mutual exclusion dependency with the ready tasks, select one to execute and skip the other based on the conditional dependency evaluation result; Step S7: Submit the ready tasks to the thread pool for parallel execution. For each ready task, rewrite the current task description using the execution result of the predecessor task. Use the rewritten description as the retrieval document for the search query. Generate a sub-answer based on the retrieval result and the answer of the predecessor task. Step S8: After the current task is completed, evaluate the conditional dependency of its subsequent tasks. If the conditional dependency is not met, mark the subsequent task as skipped. Step S9, repeat steps S5 to S8 until there are no ready tasks; Step S10: Filter out invalid answers and perform near-duplicate deduplication on all completed subtask answers to obtain valid answers. Then, fuse the valid answers with the natural language query input large language model to generate the final answer and return it.
[0026] The CDG definition proposed in this invention is a quadruple. , in: It is a set of nodes, each node This represents a sub-task and includes a task identifier. Task Description And priority ; Let be a set of directed edges, where For each edge, there is a set of dependency types. Indicates from the source task To the target task Dependencies; This is a condition mapping function that maps each conditional dependency edge to a condition expression. ; It is a set of mutually exclusive task pairs that satisfy symmetry, i.e. If and only if .
[0027] Task At any moment A task is considered ready if and only if all its predecessor tasks have been completed or skipped, and It was not marked as skipped.
[0028] Conditional dependency evaluation uses rule-based matching degree calculation, and the matching ratio is calculated using the following formula: in This is the set of keywords for a conditional expression. This is the text representing the subtask result. When... (default The condition is met when the condition is met.
[0029] The formula for calculating the information gain is: in This is the set of keywords from the original query. This is the set of words that have not yet been covered by existing answers. This is the set of keywords describing the candidate subtasks. When... Skip the subtask.
[0030] The formula for calculating the query complexity score is: in For interrogative word density, For the existence of condition words, For solid density, This is the length-normalized value. This is the normalized value for the number of clauses.
[0031] like Figure 2 The diagram shown is a schematic representation of the condition dependency graph (CDG) of this invention: The task is broken down into three sub-tasks: T1 (determine whether today's RMB / USD exchange rate is higher than the same period last year), T2 (calculate the RMB / USD appreciation rate), and T3 (calculate the RMB / USD depreciation rate). T1 and 2 are conditionally dependent, T2 and T3 are mutually exclusive, and T1 and T3 are conditionally dependent.
[0032] like Figure 3 The diagram shown is a flowchart of the CDG scheduling execution process of this invention. Start scheduling; S5, scan CDG, identify all ready tasks; Is the ready task set empty? If so, exit the loop and proceed to answer fusion in S10; Otherwise, proceed to S6 to check if there is a pair of mutually exclusive tasks among the ready tasks. If they exist, select one to execute based on the condition evaluation result and skip the other. S7: Submit all ready tasks to the thread pool for parallel execution. Each task executes description rewriting, document retrieval, and answer generation in sequence. S8, traverse all successor edges of the completed task and evaluate the conditional dependency (keep if satisfied, mark as skipped if not satisfied). S9, return to S5 and continue the loop.
[0033] like Figure 4 , 5 The diagram shows a comparison between the conditional pruning execution of this invention and the traditional DAG execution: As can be seen, for the same query, the traditional DAG requires 3 searches and 3 LLM calls, while the conditional pruning execution only requires 2 searches and 2 LLM calls, which improves efficiency by 33%.
[0034] Example 2: This embodiment uses a query involving mutual exclusion selection as an example to illustrate the execution process of condition pruning and mutual exclusion resolution in a conditional dependency scenario. This embodiment also uses a multi-hop query involving conditional branches as an example to illustrate the complete execution flow of the method of this invention.
[0035] S1, receives user queries The system receives a natural language query from the user: "Has the stock price increase of a certain technology stock outperformed the CSI 300 Index this year? If so, what was its net profit for the most recent year?" S2, Query Complexity Evaluation The system scores the complexity of the query. The query contains two interrogative words ("whether" and "how much") and one conditional word ("if"), and its length exceeds 20 words. The score exceeds the preset threshold, so it is judged as a complex query and enters the CDG decomposition process.
[0036] S3, CDG generation The system inputs the query and few-sample examples into the large language model, and the model outputs CDG in JSON format, with the following structure: { "query": "Has the stock price increase of a certain technology stock outperformed the CSI 300 Index this year? If so, what is its net profit for the most recent year?", "nodes": [ {"task_id": "T1", "description": "Find the stock price increase of this technology stock this year and the increase of the CSI 300 Index during the same period", "priority": 1}, {"task_id": "T2", "description": "Determine whether the increase of this technology stock in T1 is higher than the increase of the CSI 300 Index", "priority": 2}, {"task_id": "T3", "description": "Find the net profit of this technology stock for the most recent year", "priority": 3} ], "edges": [ {"source": "T1", "target": "T2", "dep_type": "serial"}, {"source": "T2", "target": "T3", "dep_type": "conditional","condition_expr": "The result of T2 is that the increase of this technology stock is higher than that of the CSI 300"} ]}.
[0037] S4, CDG Structure Verification The system uses the Kahn algorithm to perform topological sorting verification of the CDG, confirming that there is no directed cycle, and verifying that the conditional dependency edge T2 to T3 is associated with a valid conditional expression, thus the verification is successful.
[0038] S5, Identify Ready Tasks The system scanned CDG and found that T1 had no predecessor task and was in a ready state.
[0039] S6, Mutual Exclusion Conflict Resolution If there are no mutually exclusive task pairs among the currently ready tasks, skip this step.
[0040] S7, Execute ready tasks in parallel. The system executes T1, using the task description to search for "the year-to-date stock price increase of this technology stock and the year-to-date increase of the CSI 300 Index" as search queries. It retrieves relevant documents from the document library and generates a sub-answer based on the search results: "The technology stock has increased by 34% this year, while the CSI 300 Index has increased by 12% during the same period."
[0041] S8, Condition Dependency Evaluation For successor edges of type T1 that have no unconditional dependency, skip this step.
[0042] S9, repeat S5 to S8 The system re-identifies ready tasks. The predecessor task T1 of T2 has been completed, and T2 is now in a ready state. No mutual exclusion conflict; The system rewrites the description of T2, changing "determine whether the increase of the technology stock in T1 is higher than the increase of the CSI 300 index" to "determine whether the increase of the technology stock of 34% is higher than the increase of the CSI 300 index of 12%". Execute T2 to generate the sub-answer "Yes, the tech stock's gains are higher than the CSI 300 Index"; After T2 is completed, the system evaluates the conditional dependency of its subsequent task T3. The conditional expression is "the result of T2 is that the increase of the technology stock is higher than the CSI 300". The keyword "higher than the CSI 300" is extracted and matched with the result of T2 "yes, the increase of the technology stock is higher than the CSI 300 index". If the match is successful, the condition is satisfied and T3 is not skipped. The system continues to identify ready tasks; T3 is ready. The system rewrites the description of T3, changing "find the net profit of this technology stock in T1 for the most recent year" to "find the net profit of this technology stock (code XXXXXX) for the most recent year"; Execute T3 to generate the sub-answer "The technology stock's net profit in the most recent year was XX billion yuan". No more ready tasks; exit the loop. If the length of the previous agent's response is less than or equal to the preset threshold, it indicates that the user may have interrupted the conversation quickly. This is then identified as an interruption intention and used to continue supplementing the unfinished speech.
[0043] S10, Answer Integration The system performs invalid answer filtering and deduplication checks on the three sub-answers, and all three answers are valid and non-repeating. The system integrates the sub-answers with the original query input large language model to generate the final answer: "The stock price of this technology company has increased by 34% this year, outperforming the CSI 300 Index by 12%, and its net profit in the most recent year was XX billion yuan."
[0044] Example 3: This embodiment uses a query containing mutual exclusion selection as an example to illustrate the execution process of condition pruning and mutual exclusion resolution in a mutually exclusive dependency scenario.
[0045] S1, receives user queries The system receives user inquiries such as: "Is today's RMB / USD exchange rate higher than the same period last year? If so, by what percentage? If not, by what percentage?" S2, Query Complexity Evaluation The query contains the conditional word "if", so it is classified as a complex query.
[0046] S3, CDG generation The system inputs the query and few-sample examples into the large language model, and the model outputs CDG in JSON format, with the following structure: { "query": "Is today's RMB / USD exchange rate higher than the same period last year? If so, by what percentage? If not, by what percentage?", "nodes": [ {"task_id": "T1", "description": "Compare today's RMB / USD exchange rate with the exchange rate at the same time last year", "priority": 1}, {"task_id": "T2", "description": "Calculate the appreciation of RMB against USD", "priority": 2}, {"task_id": "T3","description": "Calculate the depreciation of RMB against USD", "priority": 2} ], "edges": [ {"source": "T1", "target": "T2", "dep_type": "conditional", "condition_expr": "The result of T1 is yes"}, {"source": "T1", "target": "T3", "dep_type": "conditional", "condition_expr": "The result of T1 is no"}, {"source": "T2", "target": "T3", "dep_type": "T3", "dep_type": "mutex"} ]}.
[0047] S4, CDG Structure Verification The verification passed, confirming that the mutually exclusive edge T2↔T3 satisfies symmetry.
[0048] S5, Identify Ready Tasks The system scanned CDG and found that T1 had no predecessor task and was in a ready state.
[0049] S6, Mutual Exclusion Conflict Resolution If there are no mutually exclusive task pairs among the currently ready tasks, skip this step.
[0050] S7, Execute ready tasks in parallel. Execute T1 to generate the sub-answer "No, today's exchange rate is lower than the same period last year".
[0051] S8, Condition Dependency Evaluation After T1 is completed, the system evaluates the conditional dependencies of subsequent tasks; The condition for T2 is "the result of T1 is yes". Since the result of T1 starts with "no", the condition is not met, and T2 is marked as skipped. The condition for T3 is "the result of T1 is not". If the result of T1 starts with "not", the condition is met, and T3 will not skip it.
[0052] S9, repeat S5 to S8 The system re-identifies ready tasks. T2 has been skipped. The predecessor task T1 of T3 has been completed. T3 is ready. The system checks the mutual exclusion relationship. The mutual exclusion task T2 of T3 has been skipped, so there is no conflict. Execute T3 to generate the sub-answer "The RMB has depreciated by approximately 3.2% against the US dollar compared to the same period last year"; No more tasks are ready; exit the loop. In this embodiment, T2 is skipped, saving one document retrieval and one large language model call.
[0053] S10, Answer Integration After filtering out invalid answers, the system merges the valid sub-answers to generate the final answer: "Today's RMB exchange rate against the US dollar is lower than the same period last year, and the RMB has depreciated by about 3.2% compared to the same period last year."
[0054] Example 4: This embodiment takes a query that includes both parallel execution and serial dependencies as an example to illustrate the execution process of parallel scheduling in a mixed parallel and conditional scenario.
[0055] S1, receives user queries The system receives natural language queries from users: "What are the current mortgage and car loan interest rates? Which loan has a lower interest rate? What is the maximum repayment period for this type of loan?" S2, Query Complexity Evaluation The query contains the conjunction "and" and has a high density of interrogative words, thus it is classified as a complex query.
[0056] S3, CDG generation The system inputs the query and few-sample examples into the large language model, and the model outputs CDG in JSON format, with the following structure: { "query": "What are the current mortgage and auto loan interest rates? Which loan has a lower interest rate? What is the maximum repayment period for this type of loan?", "nodes": [ {"task_id": "T1", "description": "Query current mortgage interest rates", "priority": 1}, {"task_id": "T2", "description": "Query current auto loan interest rates", "priority": 1}, {"task_id": "T3", "description": "Compare mortgage and auto loan interest rates to determine which is lower", "priority": 2}, {"task_id": "T4", "description": "Query the maximum repayment period for the lower interest rate loan type", "priority": 3} ], "edges": [ {"source": "T1","target": "T3", "dep_type": "serial"}, {"source": "T2", "target": "T3", "dep_type": "serial"}, {"source": "T3", "target": "T4", "dep_type": "serial"} ]}.
[0057] S4, CDG Structure Verification The system uses the Kahn algorithm to perform topological sorting verification of CDG, and the verification is successful.
[0058] S5, Identify Ready Tasks The system scanned the CDG and found no predecessor tasks for T1 and T2, and both were ready.
[0059] S6, Mutual Exclusion Conflict Resolution If there are no mutually exclusive task pairs among the currently ready tasks, skip this step.
[0060] S7, Execute ready tasks in parallel. The system submits T1 and T2 to the thread pool for parallel execution. T1 generates the sub-answer "The current mortgage interest rate is approximately 3.5%", and T2 generates the sub-answer "The current car loan interest rate is approximately 5.0%".
[0061] S8, Condition Dependency Evaluation Since neither T1 nor T2 has a conditionally dependent successor edge, skip this step.
[0062] S9, repeat S5 to S8 The system re-identifies ready tasks: T1 and T2 have both been completed, and T3 is ready. No mutual exclusion conflicts. The system rewrites the description of T3, injects the predecessor result, executes T3, and generates the sub-answer "lower mortgage interest rate"; T3 unconditionally depends on its successor; The system continues to identify ready tasks; T3 is complete, and T4 is ready. The system rewrites the description of T4, replacing "loan type with lower interest rate" with "mortgage," executes T4, and generates the sub-answer "maximum repayment period is 30 years." No more tasks are ready, so the loop exits. In this embodiment, T1 and T2 are executed in parallel, saving one round of scheduling latency compared to serial execution.
[0063] S10, Answer Integration The system merges the four sub-answers to generate the final answer: "The current mortgage interest rate is about 3.5%, the car loan interest rate is about 5.0%, the mortgage interest rate is lower, and its maximum repayment period is 30 years."
[0064] Example 5: Furthermore, embodiments of the present invention also provide an electronic device including a central processing unit (CPU), which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) or loaded from a storage unit into a random access memory (RAM). The RAM may also store various programs and data required for device operation. The CPU, ROM, and RAM are interconnected via a bus. Input / output (I / O) interfaces are also connected to the bus.
[0065] Multiple components in the device are connected to the I / O interface, including: input units such as keyboards and mice; output units such as various types of displays and speakers; storage units such as disks and optical discs; and communication units such as network interface cards (NICs), modems, and wireless transceivers. The communication unit allows the device to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0066] The processing unit performs the various methods and processes described above, such as the methods of the present invention. For example, in some embodiments, the methods of the present invention may be implemented as computer software programs tangibly contained in a machine-readable medium, such as a storage unit. In some embodiments, part or all of the computer program may be loaded and / or installed on the device via ROM and / or a communication unit. When the computer program is loaded into RAM and executed by the CPU, one or more steps of the methods of the present invention described above may be performed. Alternatively, in other embodiments, the CPU may be configured to execute the methods of the present invention by any other suitable means (e.g., by means of firmware).
[0067] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.
[0068] The program code used to implement the methods of the present invention can be written in any combination of one or more programming languages. This program code can be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code can be executed entirely on the machine, partially on the machine, as a standalone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0069] The preferred embodiments of the present invention have been described in detail above. It should be understood that those skilled in the art can make numerous modifications and variations based on the concept of the present invention without creative effort. Therefore, all technical solutions that can be obtained by those skilled in the art based on the concept of the present invention through logical analysis, reasoning, or limited experimentation on the basis of existing technology should be within the scope of protection defined by the claims.
Claims
1. A RAG multi-hop question answering method based on a large language model and conditional dependency graph, characterized in that, include: Step S1: Receive a natural language query and evaluate the complexity of the natural language query; Step S2: Decompose the natural language query into multiple sub-tasks using a large language model and construct a conditional dependency graph; In the conditional dependency graph, each node represents a subtask, and each directed edge represents a dependency relationship between two subtasks. The dependency relationships include four types: serial dependency, parallel dependency, conditional dependency, and mutual exclusion dependency. Step S3: Use a topology sorting-based algorithm to perform structure verification and detection on the conditional dependency graph and eliminate directed cycles, verifying the symmetry of the conditional expressions of the conditional dependencies and the mutual exclusion dependencies; Step S4: Identify all ready tasks that have been completed and have not been skipped; Step S5: For task pairs that have the mutual exclusion dependency with the ready tasks, select one to execute and skip the other based on the conditional dependency evaluation result; Step S6: Submit the ready tasks to the thread pool for parallel execution. For each ready task, rewrite the current task description using the execution result of the predecessor task. Use the rewritten description as the retrieval document for the search query. Generate a sub-answer based on the retrieval result and the answer of the predecessor task. Step S7: After the current task is completed, evaluate the conditional dependencies of its successor tasks. If the conditional dependencies are not met, mark the successor task as skipped. Step S8: Repeat steps S4 to S7 until there are no more ready tasks; Step S9: Filter out invalid answers and perform near-duplicate deduplication on all completed subtask answers to obtain valid answers. Fuse the valid answers with the natural language query input large language model to generate the final answer and return it.
2. The RAG multi-hop question answering method based on a large language model and conditional dependency graph as described in claim 1, characterized in that, The conditional dependency graph is defined as a quadruple: in It is a collection of nodes, each node containing a task identifier, task description, and priority; It is a set of directed edges, each edge containing the source task, target task, and dependency type; This is a conditional mapping function that maps each conditional dependency edge to a conditional expression; Let it be a set of mutually exclusive task pairs that satisfy symmetry.
3. The RAG multi-hop question answering method based on a large language model and conditional dependency graph as described in claim 1, characterized in that, The method for generating the conditional dependency graph includes: a method based on prompting engineering, in which the query and few-sample examples are input into a large language model, and the model outputs the node and edge definitions of the CDG in JSON format; Alternatively, the method for generating the conditional dependency graph may include: a method based on a fine-tuning model, wherein the query input is a fine-tuned small language model, and the fine-tuning data is generated by a large language model based on few-sample prompts.
4. The RAG multi-hop question answering method based on a large language model and conditional dependency graph as described in claim 1, characterized in that, Step S5 specifically includes: when two mutually exclusive tasks are ready at the same time, evaluating whether their respective conditional dependency expressions are satisfied by the result of the predecessor task. If one condition is satisfied while the other is not, the one that satisfies the condition is executed. If both conditions are satisfied or not satisfied, the one with higher priority is selected for execution. All subsequent tasks of the skipped mutually exclusive task are also marked as skipped.
5. The RAG multi-hop question answering method based on a large language model and conditional dependency graph as described in claim 1, characterized in that, The method for rewriting the task description is as follows: obtain the execution results of all predecessor tasks of the current subtask, replace the explicit references to the predecessor task identifiers in the task description with the actual results of the predecessor tasks, and replace the backreferences in the task description with the actual results of the predecessor tasks.
6. The RAG multi-hop question answering method based on a large language model and conditional dependency graph as described in claim 5, characterized in that, The term "anaphora" refers to using a short word or phrase to refer to a person, thing, object, or concept that has already been mentioned in the preceding text.
7. The RAG multi-hop question answering method based on a large language model and conditional dependency graph as described in claim 1, characterized in that, The conditional dependency evaluation adopts a rule-based multi-strategy approach: if the subtask result begins with an affirmative or negative word, a Boolean judgment is made based on whether the conditional expression contains a negative keyword; Otherwise, extract the key entity words in the conditional expression, calculate the matching ratio of the key entity words in the subtask results, and determine that the condition is met when the matching ratio is greater than or equal to the preset threshold.
8. The RAG multi-hop question answering method based on a large language model and conditional dependency graph as described in claim 1, characterized in that, The process of identifying ready tasks also includes an information gain filtering step, which calculates the information gain of each ready subtask relative to the existing set of answers, and skips the subtask when the information gain is lower than a preset threshold. The information gain is calculated based on the overlap between the subtask description and the vocabulary in the original query that is not covered by existing answers.
9. The RAG multi-hop question answering method based on a large language model and conditional dependency graph as described in claim 1, characterized in that, The invalid answer filtering includes filtering empty answers, task identifier placeholders, and general negative replies. Approximate deduplication is based on the normalized edit distance to calculate the similarity between sub-answers, and duplicate answers with similarity higher than a preset threshold are merged.
10. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1 to 9.
Citation Information
Patent Citations
RAG multi-hop question and answer method, device and system and storage medium
CN120723869A
