A multi-agent-based complex natural language query conversion method and system
By decomposing and iteratively processing natural language queries through a multi-agent system, the semantic understanding and error correction problems of complex query transformation in existing technologies are solved, and SPARQL query generation with high accuracy and robustness is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-30
- Publication Date
- 2026-03-17
AI Technical Summary
Existing technologies struggle to accurately convert complex natural language queries into SPARQL queries, exhibiting limitations in semantic understanding, insufficient context awareness, weak error correction capabilities, and poor scalability, particularly in multi-hop reasoning and multi-domain applications.
A multi-agent system is adopted, including an orchestration agent, a query decomposition and planning agent, a dynamic GraphRAG retrieval agent, a SPARQL generation agent, and a verification and synthesis agent. By decomposing the query intent, iterative retrieval, and verification mechanisms, syntactically and semantically correct SPARQL queries are generated.
It improves the accuracy and robustness of query transformation, supports multi-hop inference, has self-debugging capabilities, reduces the error rate, and enhances the interpretability and scalability of the system.
Smart Images

Figure CN121434372B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the technical field of natural language processing, knowledge graph and large language model interaction, and specifically relates to a complex natural language query conversion method and system based on multi-agent intelligence. Background Technology
[0002] Knowledge graphs (KGs), such as DBpedia and Wikidata, store massive amounts of valuable structured and semantically related information. SPARQL is the standard query language for knowledge graphs, providing powerful expressive capabilities for users to retrieve the information and knowledge they need on demand. However, the complex syntax of SPARQL itself, and the requirement for users to have a deep understanding of the schema information (such as concepts and attributes) of the knowledge graph, pose a significant challenge to users' efficient access to knowledge graphs. For example, a question that seems simple in natural language, such as "Who was the executive chairman of Company A at the end of 2011?", may require an extremely complex SPARQL query on Wikidata. For instance, the user must know that the predicate corresponding to "position" is P39, the qualifier for "start time" is "P580", and must construct complex date filtering logic while also handling the case of "still in office" (i.e., no end date). Research and practice both show that even for domain experts, writing SPARQL queries is considered difficult and time-consuming. Therefore, a key technological gap is that a vast amount of valuable knowledge is locked in knowledge graphs, and the vast majority of users cannot access this knowledge through natural language.
[0003] To address this issue, a conversion system from natural language queries to SPARQL queries has been developed to bridge the gap between humans and structured data. However, existing conversion methods suffer from the following key problems: (1) limited semantic understanding, making it difficult to accurately understand complex multi-hop queries, nested relationships, and implicit semantics, resulting in a high conversion error rate; (2) insufficient context awareness, lacking a deep understanding of the knowledge graph ontology structure, making it impossible to dynamically adjust query strategies based on graph features; (3) weak error correction capabilities, with the generated SPARQL queries lacking self-verification and correction mechanisms; and (4) poor scalability, requiring model retraining for knowledge graphs in different domains, leading to high migration costs. Existing methods based on deep learning and other technologies have low accuracy when processing complex queries, failing to meet the needs of practical applications.
[0004] In recent years, Large Language Models (LLMs) have demonstrated powerful capabilities in natural language understanding and generation, providing new avenues for the conversion of natural language into SPARQL queries. However, single-pass generation methods based on LLMs quickly revealed their limitations. Existing research indicates that while LLMs perform reasonably well in generating syntactically correct SPARQL queries, they face significant challenges in generating semantically correct queries. This typically manifests as: (1) structural inconsistencies. For example, the lack of key triples when multi-hop reasoning is required; and (2) semantic inaccuracies. For example, the use of incorrect entity URIs or incorrect attribute URIs even when the syntactic structure is correct. These challenges become even more severe when queries become complex, such as multi-hop reasoning, fuzzy queries, or when generalization to domain knowledge graph patterns is required. The root cause lies in the "contextual gap." For example, LLMs may not know that the predicate for a specific knowledge graph "position" is "P39." Without this specific pattern knowledge, LLMs can only guess. Guessing leads to illusions, which inevitably result in semantically incorrect queries.
[0005] To address the knowledge limitations of LLMs, Retrieval-Augmented Generation (RAG) has been proposed. RAG improves the accuracy and timeliness of answers by retrieving relevant information from external knowledge bases (such as documents and web pages) and injecting it into the context of the LLM before generating the answer. However, standard RAG is designed for unstructured data and relies primarily on vector embeddings and semantic similarity to retrieve unstructured text blocks. This approach often fails to correctly answer complex queries requiring relational reasoning. For example, standard RAG can answer "Who is Van Gogh?", but cannot reliably answer "What museums are in the capital of the country where Van Gogh was born?" (a multi-hop relational query). This is because relevant information may be distributed across multiple modules.
[0006] GraphRAG technology is an improvement on standard RAG technology, replacing text block retrieval with subgraph retrieval. By retrieving structured subgraphs, GraphRAG provides LLMs with the context needed for their queries. Therefore, this invention introduces GraphRAG technology into the conversion process from natural language queries to SPARQL queries. However, relying solely on GraphRAG technology, it is difficult to convert complex queries into syntactically and semantically correct SPARQL queries. The main reasons are: (1) Failure of complex multi-hop reasoning. When the query involves multi-hop reasoning, Boolean operations, time constraints, etc., GraphRAG may have difficulty retrieving all relevant evidence chains scattered in different regions of the graph at once; (2) Error accumulation. During the sequential generation or transformation process, an early error will irreversibly propagate, leading to the final generation of an incorrect SPARQL query (syntactic or semantic error); (3) Context overload or loss. The subgraphs retrieved by GraphRAG are either too large and noisy, making it impossible to link the words in the natural language query to the correct concepts or attributes in the knowledge graph, or the subgraphs are too limited, losing the long-distance dependencies required to answer the question; (4) Lack of verification and repair. Most GraphRAG technologies are feedforward and lack a unified iterative verification and repair process, which may result in the final generated SPARQL query being syntactically invalid or semantically inaccurate, for example, using the wrong concepts or attributes. The above problems are also the core pain points that this invention aims to solve.
[0007] Meanwhile, multi-agent systems (MAS) based on large models have been proposed for handling complex tasks. By breaking down a large or complex task into subtasks completed collaboratively by multiple specialized agents, MAS has shown great potential in code generation and complex reasoning. Furthermore, when a human user constructs a SPARQL query based on their needs, the construction process is typically exploratory and iterative. The user writes a part of the query, executes it, observes the results (e.g., whether the statement is correct, whether the result is empty), debugs the query, and then expands it until a semantically correct SPARQL query is constructed.
[0008] In summary, the existing technologies have the following technical problems: (1) complex natural language queries are difficult to accurately convert into SPARQL queries; (2) existing models cannot make full use of knowledge graph structures; (3) single agent methods are difficult to complete multi-stage reasoning and verification; (4) RAG methods cannot cover graph structure relationship paths; (5) existing methods lack reliable self-correction mechanisms. Summary of the Invention
[0009] To address the aforementioned technical problems, this invention provides a method and system for complex natural language query transformation based on multiple agents, which solves the technical problems in the prior art.
[0010] In a first aspect, the present invention provides the following technical solution: a method for complex natural language query transformation based on multiple agents, comprising:
[0011] Construct a multi-agent system, which includes an orchestration agent, a query decomposition and planning agent, a dynamic GraphRAG retrieval agent, a SPARQL generation agent, and a verification and synthesis agent;
[0012] The orchestration agent receives natural language queries from users and creates query-shared context instances.
[0013] The orchestration agent invokes the query decomposition and planning agent to identify the query intent, and converts the natural language query into a dependency-aware subquery sequence and an execution plan containing logical dependencies based on the query intent.
[0014] The orchestration agent initiates a state-aware iterative loop and, based on the query context instance and the execution plan, invokes a dynamic GraphRAG retrieval agent and a SPARQL generation agent to iteratively process each subquery in the subquery sequence to obtain a local query SPARQL fragment.
[0015] The orchestration agent invokes the verification and synthesis agent to perform semantic consistency verification on all local SPARQL fragments based on ontology constraints, and merges the local query SPARQL fragments into a complete SPARQL query based on the verification results and the execution plan.
[0016] If the SPARQL query is executed successfully but returns an empty result set, an exploratory retry mechanism based on feedback is triggered. Candidate predicates are obtained by retrieving the ontology layer for dynamic rewriting and retrying.
[0017] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0018] The multi-agent framework features clear division of labor, enhancing robustness: The conversion process from complex natural language to SPARQL is broken down into independent modules such as intent analysis, semantic graph construction, and query generation, each completed by a dedicated agent, working together under the coordination of a higher-level management agent. This multi-agent framework assigns cognitive tasks to different expert agents, achieving better interpretability, scalability, and robustness compared to a single, holistic approach.
[0019] Enhanced GraphRAG Structured Retrieval Reduces Illusions: This invention employs the GraphRAG retrieval module, utilizing the structured context of a knowledge graph for entity relationship retrieval, thereby providing accurate background information for generation. GraphRAG can discover implicit associations that are often not obvious but are crucial for answer reasoning, improving the relevance of retrieval results. Introducing graph-structured retrieval significantly improves answer accuracy, especially for fuzzy queries. Through structured retrieval background, the method proposed in this invention effectively reduces erroneous information (illusions) generated by LLM, ensuring the correctness of the answer.
[0020] Enhanced multi-hop reasoning capability: Combining GraphRAG's relation mining capabilities and multi-agent collaborative processes, this invention naturally supports multi-hop reasoning for entities. The subgraphs obtained by the GraphRAG retrieval module contain rich multi-hop path information, providing a basis for agents to construct complete semantic graphs. The division of labor among multiple agents allows each agent to focus on a reasoning task with a certain number of hops, resulting in a strong overall multi-constraint reasoning capability, which is well-suited for handling complex multi-hop queries;
[0021] The modules exhibit good interpretability: Because each module has a single responsibility and the intermediate output results are easy to monitor and interpret, the system of this invention has good interpretability. Compared with end-to-end black-box methods, the modular design of multiple agents facilitates post-event auditing, error detection, and module optimization.
[0022] Possessing human-like self-debugging and correction capabilities: Traditional methods typically report errors directly when encountering empty results. This invention treats empty results as a pattern detection signal, and by introducing a pattern exploration retry mechanism, it simulates the debugging process of human experts consulting ontology documents and trying synonymous attributes when a query fails, significantly improving adaptability to heterogeneous knowledge graph patterns;
[0023] Eliminating context drift: Through anchor-driven iterative retrieval, this invention utilizes prior reasoning to strictly constrain the scope of subsequent retrieval, thus solving the problem of easy divergence and noise introduction in multi-hop queries in traditional GraphRAG.
[0024] Preferably, the step of receiving natural language queries from users and creating query-shared context instances through the orchestration agent specifically involves:
[0025] Through the orchestration agent Receive a natural language query from the user and create a unique, shared query context instance. .
[0026] Preferably, the step of invoking the query decomposition and planning agent through the orchestration agent to identify the query intent, and converting the natural language query into a dependency-aware subquery sequence and an execution plan containing logical dependencies based on the query intent, specifically includes:
[0027] Through the orchestration agent Calling the query decomposition and planning intelligent agent Through the query decomposition and planning intelligent agent Identify the natural language query The query intent and the natural language query based on the query intent Decompose into query sequences with logical dependencies. And generate the execution plan for the subquery. ,in, For the first Subquery, the execution plan This includes the logical relationships between subqueries and their execution order.
[0028] Preferably, the step of initiating a state-aware iterative loop through the orchestration agent and calling a dynamic GraphRAG retrieval agent and a SPARQL generation agent based on the query context instance and the execution plan to iteratively process each subquery in the subquery sequence to obtain a local query SPARQL fragment includes:
[0029] Through the orchestration agent According to the execution plan From the subquery sequence Select the next subquery to process. ;
[0030] Through the orchestration agent Calling Dynamic GraphRAG to retrieve agents and subquery Query context instance The previous subquery The transformation result is passed to the dynamic GraphRAG retrieval agent as the anchor point of the current retrieval. ;
[0031] The agent is retrieved via the dynamic GraphRAG. And based on the subquery Previous subquery The context execution, centered on the anchor point, performs restricted neighborhood subgraph retrieval within the knowledge graph to construct an accurate restricted relevance subgraph. ;
[0032] Through the orchestration agent Using SPARQL to generate intelligent agents Combined with subqueries Semantic intent and limitation related subgraph Generate local SPARQL query fragments and update to the context instance. ;
[0033] Generating agents using SPARQL And based on subqueries and the corresponding limitation-related subgraph Generate SPARQL fragments for partial queries The local query SPARQL fragment Write to query context instance In this process, the subquery processing is iterated repeatedly until all subqueries are converted into local query SPARQL fragments.
[0034] Preferably, the step of invoking the verification and synthesis agent through the orchestration agent to perform semantic consistency verification on all local SPARQL fragments based on ontology constraints, and merging the local query SPARQL fragments into a complete SPARQL query according to the verification results and the execution plan, specifically includes:
[0035] Through the orchestration agent Invoke the verification and synthesis agent Through the aforementioned verification and synthesis of intelligent agents From the query context instance Read all local query SPARQL fragments and verify and synthesize the agent. Read the execution plan and understand the logical relationships between subqueries. Based on these relationships, perform semantic consistency checks on the local SPARQL fragments and merge them into a single SPARQL query. Through the aforementioned verification and synthesis of intelligent agents For the SPARQL query Perform syntax and semantic validation. If both syntax and semantic validations are successful, directly output the SPARQL query. If syntax validation or semantic validation fails, the result is returned to the validation and synthesis agent. .
[0036] Preferably, if the SPARQL query is executed successfully but returns an empty result set, a feedback-based exploratory retry mechanism is triggered. The specific steps of dynamically rewriting and retrying by retrieving candidate predicates from the ontology layer are as follows:
[0037] Through the orchestration agent The SPARQL query is passed to the SPARQL query engine and executed on a graph database or SPARQL endpoint, through an orchestration agent. Analyze the generated query results; if the query results indicate execution failure, then orchestrate the intelligent agent. If the query results show successful execution and return a non-empty result set, the query results are returned directly. If the query results show successful execution and return an empty result set, the empty result set is used as an actionable signal to trigger a feedback-based exploratory retry mechanism. The mechanism analyzes the triplet patterns leading to zero matches, instructs the retrieval agent to search for candidate synonymous predicates at the ontology layer, and drives the SPARQL-generated agent. Perform dynamic rewriting and retries.
[0038] Secondly, the present invention provides the following technical solution: a complex natural language query conversion system based on multiple agents, the system comprising:
[0039] A multi-agent creation module is used to construct a multi-agent system, which includes an orchestration agent, a query decomposition and planning agent, a dynamic GraphRAG retrieval agent, a SPARQL generation agent, and a verification and synthesis agent.
[0040] The context management module is used to receive natural language queries from users through the orchestration agent and create query-shared context instances;
[0041] The dependency planning module is used to call the query decomposition and planning agent through the orchestration agent to identify the query intent, and convert the natural language query into a dependency-aware subquery sequence and an execution plan containing logical dependencies according to the query intent.
[0042] The iterative retrieval and generation module is used to initiate a state-aware iterative loop through the orchestration agent and call the dynamic GraphRAG retrieval agent and the SPARQL generation agent based on the query context instance and the execution plan to iteratively process each subquery in the subquery sequence to obtain a local query SPARQL fragment.
[0043] The verification and synthesis module is used to call the verification and synthesis agent through the orchestration agent to perform semantic consistency verification of all local SPARQL fragments based on ontology constraints, and to merge the local query SPARQL fragments into a complete SPARQL query according to the verification results and the execution plan.
[0044] The feedback correction module is used to execute the SPARQL query. If the query is executed successfully but returns an empty result set, it triggers an exploratory retry mechanism based on feedback, which obtains candidate predicates by retrieving the ontology layer for dynamic rewriting and retrying.
[0045] Preferably, the creation module is specifically used for:
[0046] Through the orchestration agent Receive a natural language query from the user and create a unique, shared query context instance. .
[0047] Thirdly, the present invention provides the following technical solution: a computer, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the complex natural language query conversion method based on multiple agents as described above.
[0048] Fourthly, the present invention provides the following technical solution: a storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the complex natural language query conversion method based on multiple agents as described above. Attached Figure Description
[0049] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0050] Figure 1 A flowchart of a complex natural language query conversion method based on multiple agents provided in Embodiment 1 of the present invention;
[0051] Figure 2 This is a structural block diagram of a complex natural language query and conversion system based on multiple agents provided in Embodiment 2 of the present invention;
[0052] Figure 3 This is a schematic diagram of the hardware structure of a computer provided for another embodiment of the present invention.
[0053] The embodiments of the present invention will be further described below with reference to the accompanying drawings. Detailed Implementation
[0054] Embodiments of the present invention are described in detail below, examples of which are illustrated in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain embodiments of the present invention, and should not be construed as limiting the present invention.
[0055] Example 1
[0056] In Embodiment 1 of the present invention, as Figure 1 As shown, a complex natural language query transformation method based on multi-agent systems includes:
[0057] S1. Construct a multi-agent system, which includes an orchestration agent, a query decomposition and planning agent, a dynamic GraphRAG retrieval agent, a SPARQL generation agent, and a verification and synthesis agent.
[0058] Specifically, this invention innovatively provides a method for converting natural language queries to SPARQL queries by combining GraphRAG and a multi-agent collaborative mechanism, thereby improving the semantic accuracy and robustness of the conversion results, especially for complex queries involving multiple constraints and multi-hop reasoning. This provides support for maximizing the release and unlocking of knowledge and information in the knowledge graph. This invention provides a framework based on a multi-agent system. This framework decomposes the complex natural language query to SPARQL query conversion (NL2SPARQL) process into discrete subtasks handled by multiple agents, including query analysis and decomposition, dynamic retrieval, iterative construction, and verification refinement. Unlike techniques that use GraphRAG as a single-pass pipeline, this invention uses GraphRAG as a tool that is invoked in a scoped and iterative manner by one or more agents. For the multi-agent approach in this application, it includes:
[0059] orchestration agents Used to receive initial natural language queries from users, manage the overall task flow and state transitions between agents;
[0060] Query Decomposition and Planning Intelligent Agent It is used to break down a complex natural language query (such as a multi-hop, aggregate, or Boolean logic query) into a series of simpler, manageable, dependency-aware subqueries and generate an execution plan that includes logical relationships.
[0061] Dynamic GraphRAG retrieval agent As a callable tool, it performs scoped subgraph retrieval. It responds to specific subqueries generated by the query decomposition agent and uses validated results from previous steps as anchors to retrieve relevant subgraphs from the knowledge graph.
[0062] SPARQL Generates Intelligent Agents Its task is significantly simplified. It takes a simple subquery and a limited relevance subgraph context provided by the retrieval agent, and generates a syntactically and semantically correct SPARQL query fragment;
[0063] Verification and Synthetic Agents This agent is responsible for two phases of operation. (a) Validation: Immediately after the SPARQL subquery fragments are generated, their syntax and semantics are validated to avoid the propagation and accumulation of errors; (b) Synthesis: After all the subquery fragments have passed validation, the agent merges multiple validated fragments into a single, logically consistent and executable final SPARQL query according to the generated execution plan.
[0064] Intelligent agents communicate and manage their states through a shared and dynamically updated query context object.
[0065] S2. Receive natural language queries from users through the orchestration agent and create query-shared context instances;
[0066] Specifically, step S2 is as follows:
[0067] Through the orchestration agent Receive a natural language query from the user and create a unique, shared query context instance. .
[0068] S3. The orchestration agent calls the query decomposition and planning agent to identify the query intent, and converts the natural language query into a dependency-aware subquery sequence and an execution plan containing logical dependencies based on the query intent.
[0069] Specifically, step S3 is as follows:
[0070] Through the orchestration agent Calling the query decomposition and planning intelligent agent Through the query decomposition and planning intelligent agent Identify the natural language query The query intent and the natural language query based on the query intent Decompose into query sequences with logical dependencies. And generate the execution plan for the subquery. ,in, For the first Subquery, the execution plan This includes the logical relationships between subqueries and their execution order;
[0071] Specific, complex queries are difficult to generate in one go. Orchestrator agents Calling the query decomposition and planning intelligent agent . Analyze user natural language queries The intent, such as SELECT ("Who...?", "Where...?"), AGGREGATE (such as "How many...?"), and will Decomposed into a sequence of dependency-aware subqueries And generate an execution plan that includes logical relational subqueries. The logical relationships and execution order between subqueries, such as query intent, will guide the SPARQL agent in constructing the query structure.
[0072] S4. The orchestration agent initiates a state-aware iterative loop and, based on the query context instance and the execution plan, calls a dynamic GraphRAG retrieval agent and a SPARQL generation agent to iteratively process each subquery in the subquery sequence to obtain a local query SPARQL fragment.
[0073] Step S4 includes:
[0074] S41, through the orchestration agent According to the execution plan From the subquery sequence Select the next subquery to process. ;
[0075] S42, through the orchestration agent Calling Dynamic GraphRAG to retrieve agents and subquery Query context instance The previous subquery The transformation result is passed to the dynamic GraphRAG retrieval agent as the anchor point of the current retrieval. ;
[0076] Specifically, the purpose of this is to ensure that the same words in different subqueries can be linked to the same concepts, attributes, or entities.
[0077] S43, Retrieve agents through the dynamic GraphRAG. And based on the subquery Previous subquery The context execution, centered on the anchor point, performs restricted neighborhood subgraph retrieval within the knowledge graph to construct an accurate restricted relevance subgraph. ;
[0078] Specifically, the core of this step is generating correct logical triples. The key to generating correct logical triples is knowing which predicate in the graph to use. This is also the biggest challenge in generating semantically and syntactically correct SPARQL queries. Without contextual support, an LLM-based AI can guess a predicate; however, the guessed predicate is very likely to lead to an incorrect SPARQL query. This invention utilizes the ability to retrieve context on the fly to avoid the model guessing or fabricating predicates.
[0079] S44, through the orchestration agent Using SPARQL to generate intelligent agents Combined with subqueries Semantic intent and limitation related subgraph Generate local SPARQL query fragments and update to the context instance. .
[0080] S45. Generating agents via SPARQL And based on subqueries and the corresponding limitation-related subgraph Generate SPARQL fragments for partial queries The local query SPARQL fragment Write to query context instance In this process, the subquery processing is iterated repeatedly until all subqueries are converted into local query SPARQL fragments;
[0081] In step S45, to prevent the propagation of errors, Calling Verification and Synthetic Agents For the generated SPARQL subqueries Perform grammatical and semantic correctness verification and return the verification result (success or failure). If the verification fails, This state will be detected, and corrective actions will be performed, for example, triggering... Retry, or request A new plan needs to be developed.
[0082] S5. The orchestration agent calls the verification and synthesis agent to perform semantic consistency verification on all local SPARQL fragments based on ontology constraints, and merges the local query SPARQL fragments into a complete SPARQL query according to the verification results and the execution plan.
[0083] Step S5 includes:
[0084] Through the orchestration agent Invoke the verification and synthesis agent Through the aforementioned verification and synthesis of intelligent agents From the query context instance Read all local query SPARQL fragments and verify and synthesize the agent. Read the execution plan and understand the logical relationships between subqueries. Based on these relationships, perform semantic consistency checks on the local SPARQL fragments and merge them into a single SPARQL query. Through the aforementioned verification and synthesis of intelligent agents For the SPARQL query Perform syntax and semantic validation. If both syntax and semantic validations are successful, directly output the SPARQL query. If syntax validation or semantic validation fails, the result is returned to the validation and synthesis agent. ;
[0085] The syntax verification process is as follows: Call external libraries such as Jena or RDFLib to parse It will then verify whether the parsing conforms to the SPARQL 1.1 syntax specification; if parsing fails, a "syntax error" message will be returned. .
[0086] The semantic validation process is as follows: Many generated SPARQL queries are syntactically correct but semantically meaningless, for example, by using predicates and concepts that do not exist in the knowledge graph or ontology. Semantic validation, based on pattern information from the knowledge graph and ontology, uses similarity calculations and semantic relationships between concepts in the ontology to replace misused words in the SPARQL with words from the knowledge graph and ontology.
[0087] S6. Execute the SPARQL query. If the query is executed successfully but returns an empty result set, trigger a feedback-based exploratory retry mechanism. Retrieve candidate predicates from the ontology layer for dynamic rewriting and retrying.
[0088] Specifically, step S6 is as follows:
[0089] Through the orchestration agent The SPARQL query is passed to the SPARQL query engine and executed on a graph database or SPARQL endpoint, through an orchestration agent. Analyze the generated query results; if the query results indicate execution failure, then orchestrate the intelligent agent. If the query results show successful execution and return a non-empty result set, the query results are returned directly. If the query results show successful execution and return an empty result set, the empty result set is used as an actionable signal to trigger a feedback-based exploratory retry mechanism. The mechanism analyzes the triplet patterns leading to zero matches, instructs the retrieval agent to search for candidate synonymous predicates at the ontology layer, and drives the SPARQL-generated agent. Perform dynamic rewriting and retries.
[0090] Specifically, the orchestrator intelligent agent Will pass grammatical and semantic checks Passed to the SPARQL query engine, executed on a graph database or SPARQL Endpoint. , Further analysis of the query results reveals that SPARQL Endpoint is a network interface that provides SPARQL query services via the HTTP protocol. It can be understood as a "database query API" and is specifically used to query related data and knowledge graphs. Analyze the execution results to provide smarter feedback than a simple "failure". If an execution error occurs, such as a timeout or permission denied, It will return an "execution error" feedback; if the query can be executed successfully, but returns an empty result set, unlike previous technologies, Instead of returning a "query failed" response, the empty result set is treated as an actionable signal, instructing the query SPARQL generating agent to retry (step S3). The SPARQL generating agent initiates a dynamic GraphRAG call to select a new link predicate for the entities in the subquery. This feedback-driven iterative refining process enables the system to autonomously debug and explore the KG pattern to find the correct answer, thereby realizing the trial and error process of model domain experts in the SPARQL query construction process.
[0091] The complex natural language query transformation method based on multi-agent provided in Embodiment 1 of this invention breaks down the transformation process from complex natural language to SPARQL into independent modules such as intent analysis, semantic graph construction, and query generation. These modules are completed by dedicated agents, working together under the coordination of a higher-level management agent. The multi-agent framework assigns cognitive tasks to different expert agents, achieving better interpretability, scalability, and robustness compared to a single, holistic approach. This invention employs a GraphRAG retrieval module, utilizing the structured context of a knowledge graph to retrieve entity relationships, thereby providing accurate background information for generation. GraphRAG can discover implicit associations that are often subtle but crucial for answer reasoning, improving the relevance of retrieval results. The introduction of graph-structured retrieval significantly improves answer accuracy, especially for fuzzy queries. Through structured retrieval background, the proposed method effectively reduces erroneous information (illusions) generated by LLM, ensuring the correctness of answers. Combining GraphRAG's relationship mining capabilities and the multi-agent collaborative process, this invention naturally supports multi-hop entity reasoning. The subgraphs obtained by the GraphRAG retrieval module contain rich multi-hop path information, providing a basis for agents to construct complete semantic graphs. The division of labor among multiple agents allows each agent to focus on a reasoning task with a certain number of hops, resulting in strong overall multi-constraint reasoning capabilities, making it well-suited for handling complex multi-hop queries. Because each module has a single responsibility and the intermediate output results are easy to monitor and interpret, the system of this invention has good interpretability. Compared to end-to-end black-box methods, the modular design of multiple agents facilitates post-audit, error detection, and module optimization.
[0092] Example 2
[0093] like Figure 2 As shown, in Embodiment 2 of the present invention, a complex natural language query conversion system based on multiple agents is provided, the system comprising:
[0094] Multi-agent creation module 1 is used to construct a multi-agent system, which includes an orchestration agent, a query decomposition and planning agent, a dynamic GraphRAG retrieval agent, a SPARQL generation agent, and a verification and synthesis agent.
[0095] Context management module 2 is used to receive natural language queries from users through the orchestration agent and create query-shared context instances;
[0096] The dependency planning module 3 is used to call the query decomposition and planning agent through the orchestration agent to identify the query intent, and convert the natural language query into a dependency-aware subquery sequence and an execution plan containing logical dependencies according to the query intent.
[0097] The iterative retrieval and generation module 4 is used to initiate a state-aware iterative loop through the orchestration agent and call the dynamic GraphRAG retrieval agent and the SPARQL generation agent based on the query context instance and the execution plan to iteratively process each subquery in the subquery sequence to obtain a local query SPARQL fragment.
[0098] The verification and synthesis module 5 is used to call the verification and synthesis agent through the orchestration agent to perform semantic consistency verification of all local SPARQL fragments based on ontology constraints, and to merge the local query SPARQL fragments into a complete SPARQL query according to the verification results and the execution plan.
[0099] Feedback correction module 6 is used to execute the SPARQL query. If the query is executed successfully but returns an empty result set, a feedback-based exploratory retry mechanism is triggered. Candidate predicates are obtained by retrieving the ontology layer for dynamic rewriting and retrying.
[0100] Specifically, the context management module 2 is used for:
[0101] Through the orchestration agent Receive a natural language query from the user and create a unique, shared query context instance. .
[0102] Specifically, the dependency planning module 3 is used for:
[0103] Through the orchestration agent Calling the query decomposition and planning intelligent agent Through the query decomposition and planning intelligent agent Identify the natural language query The query intent and the natural language query based on the query intent Decompose into query sequences with logical dependencies. And generate the execution plan for the subquery. ,in, For the first Subquery, the execution plan This includes the logical relationships between subqueries and their execution order.
[0104] Specifically, the iterative retrieval and generation module 4 is used for:
[0105] Through the orchestration agent According to the execution plan From the subquery sequence Select the next subquery to process. ;
[0106] Through the orchestration agent Calling Dynamic GraphRAG to retrieve agents and subquery Query context instance The previous subquery The transformation result is passed to the dynamic GraphRAG retrieval agent as the anchor point of the current retrieval. ;
[0107] The agent is retrieved via the dynamic GraphRAG. And based on the subquery Previous subquery The context execution, centered on the anchor point, performs restricted neighborhood subgraph retrieval within the knowledge graph to construct an accurate restricted relevance subgraph. ;
[0108] Through the orchestration agent Using SPARQL to generate intelligent agents Combined with subqueries Semantic intent and limitation related subgraph Generate local SPARQL query fragments and update to the context instance. ;
[0109] Generating agents using SPARQL And based on subqueries and the corresponding limitation-related subgraph Generate SPARQL fragments for partial queries The local query SPARQL fragment Write to query context instance In this process, the subquery processing is iterated repeatedly until all subqueries are converted into local query SPARQL fragments.
[0110] Specifically, the verification and synthesis module 5 is used for:
[0111] Through the orchestration agent Invoke the verification and synthesis agent Through the aforementioned verification and synthesis of intelligent agents From the query context instance Read all local query SPARQL fragments and verify and synthesize the agent. Read the execution plan and understand the logical relationships between subqueries. Based on these relationships, perform semantic consistency checks on the local SPARQL fragments and merge them into a single SPARQL query. Through the aforementioned verification and synthesis of intelligent agents For the SPARQL query Perform syntax and semantic validation. If both syntax and semantic validations are successful, directly output the SPARQL query. If syntax validation or semantic validation fails, the result is returned to the validation and synthesis agent. .
[0112] Specifically, the feedback correction module 6 is used for:
[0113] Through the orchestration agent The SPARQL query is passed to the SPARQL query engine and executed on a graph database or SPARQL endpoint, through an orchestration agent. Analyze the generated query results; if the query results indicate execution failure, then orchestrate the intelligent agent. If the query results show successful execution and return a non-empty result set, the query results are returned directly. If the query results show successful execution and return an empty result set, the empty result set is used as an actionable signal to trigger a feedback-based exploratory retry mechanism. The mechanism analyzes the triplet patterns leading to zero matches, instructs the retrieval agent to search for candidate synonymous predicates at the ontology layer, and drives the SPARQL-generated agent. Perform dynamic rewriting and retries.
[0114] In other embodiments of the present invention, the present invention provides the following technical solution: a computer, including a memory 102, a processor 101, and a computer program stored in the memory 102 and executable on the processor 101, wherein the processor 101 executes the computer program to implement the complex natural language query conversion method based on multiple agents as described above.
[0115] Specifically, the processor 101 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of the present invention.
[0116] The memory 102 may include a large-capacity memory for data or instructions. For example, and not limitingly, the memory 102 may include a hard disk drive (HDD), a floppy disk drive, a solid-state drive (SSD), flash memory, an optical disk drive, a magneto-optical disk drive, magnetic tape, or a Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, the memory 102 may include removable or non-removable (or fixed) media. Where appropriate, the memory 102 may be internal or external to a data processing device. In a particular embodiment, the memory 102 is non-volatile memory. In a particular embodiment, the memory 102 includes read-only memory (ROM) and random access memory (RAM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable read-only memory (PROM), an erasable read-only memory (EPROM), an electrically erasable read-only memory (EEPROM), an electrically alterable read-only memory (EAROM), or flash memory, or a combination of two or more of these. Where appropriate, the RAM can be Static Random-Access Memory (SRAM) or Dynamic Random-Access Memory (DRAM). DRAM can be Fast Page Mode Dynamic Random Access Memory (FPMDRAM), Extended Data Out Dynamic Random Access Memory (EDODRAM), Synchronous Dynamic Random-Access Memory (SDRAM), etc.
[0117] The memory 102 can be used to store or cache various data files that need to be processed and / or used for communication, as well as possible computer program instructions executed by the processor 101.
[0118] The processor 101 reads and executes the computer program instructions stored in the memory 102 to implement the above-mentioned complex natural language query conversion method based on multiple agents.
[0119] In some embodiments, the computer may further include a communication interface 103 and a bus 100. For example, Figure 3 As shown, the processor 101, memory 102, and communication interface 103 are connected through bus 100 and communicate with each other.
[0120] The communication interface 103 is used to enable communication between the various modules, devices, units, and / or equipment in the embodiments of the present invention. The communication interface 103 can also enable data communication with other components such as external devices, image / data acquisition devices, databases, external storage, and image / data processing workstations.
[0121] Bus 100 includes hardware, software, or both, that couples components of a computer device together. Bus 100 includes, but is not limited to, at least one of the following: data bus, address bus, control bus, expansion bus, and local bus. For example, and not as a limitation, bus 100 may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an InfiniBand interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses, or a combination of two or more of these. Where appropriate, bus 100 may include one or more buses. Although specific buses are described and illustrated in the embodiments of the present invention, the present invention is contemplated by any suitable bus or interconnect.
[0122] The computer can execute the multi-agent-based complex natural language query conversion method of the present invention based on the acquired multi-agent-based complex natural language query conversion system, thereby realizing multi-agent-based complex natural language query conversion.
[0123] In some further embodiments of the present invention, in conjunction with the above-described complex natural language query conversion method based on multiple agents, the present invention provides the following technical solution: a storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the above-described complex natural language query conversion method based on multiple agents.
[0124] Those skilled in the art will understand that the logic and / or steps represented in the flowcharts or otherwise described herein, for example, can be considered as a ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can mean any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device.
[0125] More specific examples of readable media (a non-exhaustive list) include: electrical connections (electronic devices) with one or more wires, portable computer disk drives (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which the program can be printed, since the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.
[0126] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0127] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0128] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this invention patent should be determined by the appended claims.
Claims
1. A multi-agent based complex natural language query conversion method, characterized in that, Comprise: Construct a multi-agent system, the multi-agent system includes orchestration agent, query decomposition and planning agent, dynamic GraphRAG retrieval agent, SPARQL generation agent and verification and synthesis agent; Through the orchestration agent, receive natural language query from user and create query shared context instance; Through the orchestration agent, call query decomposition and planning agent to identify query intent, and convert natural language query into dependent-aware subquery sequence and execution plan containing logical dependency according to the query intent; Through the orchestration agent, start state-aware iterative cycle and call dynamic GraphRAG retrieval agent, SPARQL generation agent to iteratively process each subquery in the subquery sequence based on query context instance and the execution plan, to obtain local query SPARQL fragment, which specifically comprises: by the orchestration agent according to the execution plan from the sequence of subqueries selecting the next subquery requiring processing ; by the orchestration agent calling a dynamic GraphRAG retrieval agent and passing the transformation result of the previous subquery , the query context instance the previous subquery as an anchor point for the current retrieval to the dynamic GraphRAG retrieval agent ; retrieving an agent by the dynamic GraphRAG and according to the subquery the context of the previous subquery executed with the anchor point at the center, a restricted neighborhood subgraph retrieval is performed in the knowledge graph to construct an accurate limited relevant subgraph ; by the orchestration agent calling a SPARQL generating agent , combining the semantic intent with the sub-query related sub-graphs generating local SPARQL query fragments and updating to the context instance ; Generating agents through sparql and based on subqueries and corresponding limitation-related subgraphs generating partial query sparql fragments writing the partial query sparql fragments into a query context instance wherein the process of iterating through the repeated subqueries is repeated until all subqueries are converted into partial query sparql fragments Through the orchestration agent, call the verification and synthesis agent to perform semantic consistency checking based on ontology constraints on all local SPARQL fragments, and fuse the local query SPARQL fragments into complete SPARQL query according to the test result and the execution plan; Execute the SPARQL query, if query execution is successful but returns empty result set, trigger feedback-based exploratory retry mechanism, obtain candidate predicates through ontology layer retrieval for dynamic rewriting and retry. 2.The multi-agent based complex natural language query conversion method of claim 1, wherein, The step of receiving natural language query from user through the orchestration agent and creating query shared context instance specifically comprises: By the orchestration agent Receiving a natural language query from a user And creating a unique shared query context instance . 3.The multi-agent based complex natural language query conversion method of claim 1, wherein, The step of calling query decomposition and planning agent through the orchestration agent to identify query intent, and converting natural language query into dependent-aware subquery sequence and execution plan containing logical dependency according to the query intent specifically comprises: by the orchestration agent invoking a query decomposition and planning agent by the query decomposition and planning agent identifying a query intent of the natural language query and decomposing the natural language query into a sequence of queries with logical dependencies according to the query intent and generating an execution plan for the sub-queries wherein, is a thsub-query, the execution plan includes logical relationships and execution order among the sub-queries. 4.The multi-agent based complex natural language query conversion method of claim 1, wherein, The step of calling the verification and synthesis agent through the orchestration agent to perform semantic consistency checking based on ontology constraints on all local SPARQL fragments, and fusing the local query SPARQL fragments into complete SPARQL query according to the test result and the execution plan specifically comprises: by the orchestration agent calling the verification and synthesis agent , by the verification and synthesis agent reading all local query SPARQL fragments from the query context instance , by the verification and synthesis agent reading the execution plan and understanding the logical relationship between subqueries, performing semantic consistency check and fusion of the local query SPARQL fragments into a SPARQL query based on the logical relationship between subqueries , by the verification and synthesis agent performing syntax check and semantic check on the SPARQL query , if the syntax check is successful and the semantic check is successful, directly outputting the SPARQL query , if the syntax check fails or the semantic check fails, returning the result to the verification and synthesis agent .
5. The multi-agent based complex natural language query conversion method according to claim 1, wherein, The step of executing the SPARQL query, if query execution is successful but returns empty result set, trigger feedback-based exploratory retry mechanism, obtain candidate predicates through ontology layer retrieval for dynamic rewriting and retry specifically comprises: by the orchestration agent passing the SPARQL query to a SPARQL query engine, executing the SPARQL query on a graph database or a SPARQL Endpoint, by the orchestration agent analyzing the query result, if the query result shows a failure of execution, the orchestration agent returning a feedback of failure of execution, if the query result shows a success of execution and returns a non-empty result set, directly returning the query result, if the query result shows a success of execution and returns an empty result set, taking the empty result set as an actionable signal, triggering a feedback-based exploratory retry mechanism, analyzing the triple pattern leading to zero matches, instructing the retrieval agent to retrieve candidate synonymous predicates at the ontology level, and driving the SPARQL generation agent performing dynamic rewriting and retry.
6. A multi-agent based complex natural language query conversion system, the system employing the multi-agent based complex natural language query conversion method as claimed in claim 1, characterized in that, The system comprises: Multi-agent creation module, for constructing a multi-agent system, the multi-agent system includes orchestration agent, query decomposition and planning agent, dynamic GraphRAG retrieval agent, SPARQL generation agent and verification and synthesis agent; Context management module, for receiving natural language query from user through the orchestration agent and creating query shared context instance; Dependency planning module, for calling query decomposition and planning agent through the orchestration agent to identify query intent, and converting natural language query into dependent-aware subquery sequence and execution plan containing logical dependency according to the query intent; The iteration retrieval and generation module is configured to start a state-aware iteration cycle by the orchestration agent, and call a dynamic GraphRAG retrieval agent, a SPARQL generation agent, and iteratively process each of the subquery sequences based on a query context instance and the execution plan to obtain a local query SPARQL fragment. The verification and synthesis module is configured to call the verification and synthesis agent by the orchestration agent to perform semantic consistency verification based on an ontology constraint on all the local SPARQL fragments, and fuse the local query SPARQL fragments into a complete SPARQL query according to a verification result and the execution plan. The feedback correction module is configured to execute the SPARQL query, and if the query execution is successful but returns an empty result set, trigger a feedback-based exploratory retry mechanism to obtain a candidate predicate from the ontology layer to perform dynamic rewriting and retry.
7. The multi-agent based complex natural language query conversion system of claim 6, wherein, The context management module is specifically configured to: By the orchestration agent Receiving a natural language query from a user And creating a unique shared query context instance .
8. A computer comprising a memory, a processor, and a computer program stored on the memory and capable of running on the processor, characterized in that, The processor executes the computer program to implement the multi-agent-based complex natural language query conversion method in any one of claims 1 to 5.
9. A storage medium, characterized by The storage medium has the computer program stored thereon, and the computer program is executed by the processor to implement the multi-agent-based complex natural language query conversion method in any one of claims 1 to 5.
Citation Information
Patent Citations
Enterprise-level schedule planning and knowledge base oriented intelligent collaborative question-answering system and method
CN120296140A
Data analysis method and device based on multi-agent cooperation and storage medium
CN121073371A