CN-122019579-A - Method and system for converting natural language into knowledge-graph query statement through AI
Abstract
The application discloses a method and a system for converting natural language into a knowledge graph query statement through AI, wherein the method comprises the steps of carrying out standardized processing on the natural language query statement input by a user to obtain an optimized query statement, carrying out intention analysis on the optimized query statement through a routing agent to determine one or more information fields related to the optimized query statement, determining at least one target field expert agent required to be called from a plurality of field expert agents, wherein each field expert agent is configured to process the query of a specific information field, calling the at least one target field expert agent to enable each called target field expert agent to generate a corresponding query fragment based on the optimized query statement, carrying out constraint combination processing on all generated query fragments to obtain an executable query statement, and executing the executable query statement in a knowledge graph database to obtain a query result.
Inventors
- LENG XUEFENG
- DONG SHUANG
- LI JIANG
Assignees
- 广联达科技股份有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260213
Claims (10)
- 1. A method for converting natural language into a knowledge-graph query statement via AI, the method comprising: carrying out standardized processing on natural language query sentences input by a user to obtain optimized query sentences; Performing intent analysis on the optimized query statement through a routing agent to determine one or more information fields related to the optimized query statement, and determining at least one target field expert agent to be called from a plurality of field expert agents, wherein each field expert agent is configured to process the query of a specific information field; invoking the at least one target domain expert agent to cause each invoked target domain expert agent to generate a corresponding query segment based on the optimized query statement; Performing constraint combination processing on all the generated query fragments to obtain executable query sentences; executing the executable query statement in the knowledge graph database, and acquiring a query result.
- 2. The method for converting natural language into knowledge-graph query terms through AI according to claim 1, wherein the normalizing the natural language query terms input by the user to obtain optimized query terms comprises: Receiving a natural language query statement input by a user; identifying an object name from the natural language query sentence, and carrying out synonym expansion and/or misplacement word correction on the identified object name by using a preset dictionary; identifying the spoken language expression from the natural language query sentence, and carrying out standardized conversion on the spoken language expression to obtain an optimized query sentence.
- 3. The method for converting natural language into a knowledge-graph query term via AI of claim 1, wherein said constrained combining all query segments generated to obtain an executable query term comprises: analyzing the variables defined and used in each query segment, and inserting intermediate variable transfer clauses between query segments needing variable transfer based on the dependency relationship between the variables so that the variables in the previous query segment can be used by the next query segment; Merging the designated return fields in each inquiry fragment, and performing de-duplication treatment on the merged fields to form a return result clause; And combining the query fragments, the intermediate variable transfer clauses and the returned result clauses according to a preset query logic sequence to generate the executable query statement, wherein the matching modes, the filtering conditions and the relationship types in all the query fragments are kept unchanged during the combination.
- 4. The method of converting natural language into a knowledge-graph query term via AI of claim 1, wherein executing the executable query term in a knowledge-graph database and obtaining a query result comprises: analyzing a target entity and at least one target attribute name from the executable query statement, wherein the knowledge graph database stores a plurality of entity nodes and a plurality of attribute nodes, the entity nodes and the attribute nodes are connected through relationship edges, and the relationship edges are provided with type labels; inquiring a plurality of relation edges which start from a target entity node and are matched with the target attribute names in the knowledge graph database, wherein the type label of each relation edge consists of an attribute name part and a time sequence number part; extracting corresponding time sequence number parts from the type labels of the queried relation edges; Determining, based on the extracted time sequence number portion, attribute nodes connected by a plurality of relationship edges corresponding to the same time sequence number portion as a set of attribute nodes belonging to the same time sequence stage; And forming a query result based on one or more groups of attribute nodes corresponding to the time sequence stage.
- 5. The method of converting natural language into a knowledge-graph query term via AI of claim 1, wherein executing the executable query term in a knowledge-graph database and obtaining a query result comprises: Step 1, executing the executable query statement according to an accurate matching mode to obtain an accurate matching result set, wherein the accurate matching mode is character string matching based on attribute values; Step 2, judging whether the accurate matching result set is empty, if so, switching to a vector matching mode, and executing the step 3, and if not, taking the accurate matching result set as a query result; Step 3, when executing the executable query statement according to a vector matching mode, firstly identifying query conditions which are matched based on attribute values and contain conceptual descriptors in the executable query statement, converting the conceptual descriptors into vector representations, rewriting the corresponding query conditions which are matched based on the attribute values in the executable query statement into similarity retrieval conditions based on vector indexes based on the vector representations to generate a vector matching query statement, and executing the vector matching query statement according to the vector matching mode to acquire a vector matching result set, wherein the vector matching mode is a query based on semantic similarity calculation of a vector space; And 4, judging whether the vector matching result set is empty, and if not, taking the vector matching result set as a query result.
- 6. The method of converting natural language into a knowledge-graph query term via AI of claim 5, wherein executing the executable query term in a knowledge-graph database and obtaining a query result further comprises: And if the vector matching result set is empty, executing a demotion return flow, wherein the demotion return flow comprises at least one strategy of the following: Modifying the vector matching query statement into partial conditions, and regenerating and executing a new query statement based on the modified conditions; A second strategy is used for expanding the query scope, namely, the vector is matched with the accurate condition in the query statement, the precise condition is modified into a fuzzy condition with wider semantic scope, and a new query statement is regenerated and executed based on the modified condition; And thirdly, providing a similar result, namely returning a matching result closest to the vector matching query statement.
- 7. The method for converting natural language into a knowledge-graph query statement via AI of claim 1, wherein after executing the executable query statement in a knowledge-graph database and obtaining a query result, the method further comprises: Selecting a target expression mode from a plurality of preset expression modes based on the data quantity and the type of the query result, wherein the plurality of preset expression modes comprise a complete sentence description for a single record, an enumerated description for a small number of records and a tabular description for a large number of records; based on the identity information corresponding to the current user, generating personalized calls according to a preset call conversion rule; Generating a complete natural language reply based on the target expression mode and the personalized title, wherein the beginning of the natural language reply comprises the personalized title, the text comprises query result content converted based on the target expression mode, and the end of the natural language reply is added with a workflow identifier corresponding to the current query processing process.
- 8. A system for converting natural language into knowledge-graph query statements via AI, the system comprising: the input preprocessing module is used for carrying out standardized processing on natural language query sentences input by a user to obtain optimized query sentences; The query generation module is used for carrying out intent analysis on the optimized query statement through the routing agent to determine one or more information fields related to the optimized query statement, and determining at least one target field expert agent to be called from a plurality of field expert agents, wherein each field expert agent is configured to process the query of a specific information field; The query optimization module is used for carrying out constraint type combination processing on all the generated query fragments so as to obtain executable query sentences; The query execution module is used for executing the executable query statement in the knowledge graph database and acquiring a query result; And the output conversion module is used for converting the structured query result into natural language reply.
- 9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the steps of the method according to any one of claims 1 to 7 when the computer program is executed by the processor.
- 10. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method according to any one of claims 1 to 7.
Description
Method and system for converting natural language into knowledge-graph query statement through AI Technical Field The application relates to the technical field of data processing, in particular to a method and a system for converting natural language into a knowledge-graph query sentence through AI. Background Currently, three main technical paths exist for converting a user natural language query into an executable query on a knowledge graph (e.g., a graph database). Firstly, a document question-answering scheme based on retrieval enhancement generation (RAG) can process semantic similarity, but is essentially to retrieve text fragments, can not generate structural query sentences, and is difficult to deal with complex multi-hop relation query in a knowledge graph. Secondly, a natural language to SQL (NL 2 SQL) scheme is good at generating accurate structured query, but is oriented to relational database design, so that vector matching capability on inaccurate semantic concepts is not only lacked, but also complex graph relations and multi-hop traversal in a knowledge graph are difficult to express efficiently. Thirdly, a single agent diagram retrieval enhancement generation (GraphRAG) scheme is adopted, which tries to combine the advantages of the two, and semantic understanding and diagram query generation are finished end to end by utilizing one agent. However, these schemes are difficult to combine semantic understanding with accuracy of structured query, or because a single and general processing mechanism is adopted, when facing to complex query involving multi-domain information, there are problems of inaccurate query results, poor controllability of the generation process, low overall efficiency, and the like. Disclosure of Invention The application aims to provide a method and a system for converting natural language into a knowledge graph query sentence through AI, which are completed under the support of projects with the topic name of 'construction engineering large model construction and application key technology' and the topic number of '2024 YFC 3811200', and realize high-accuracy conversion from natural language to structured query sentence through decomposing a query generation task into a plurality of specialized agent levels. According to one aspect of the present application, there is provided a method of converting natural language into a knowledge-graph query sentence through AI, the method comprising: carrying out standardized processing on natural language query sentences input by a user to obtain optimized query sentences; Performing intent analysis on the optimized query statement through a routing agent to determine one or more information fields related to the optimized query statement, and determining at least one target field expert agent to be called from a plurality of field expert agents, wherein each field expert agent is configured to process the query of a specific information field; invoking the at least one target domain expert agent to cause each invoked target domain expert agent to generate a corresponding query segment based on the optimized query statement; Performing constraint combination processing on all the generated query fragments to obtain executable query sentences; executing the executable query statement in the knowledge graph database, and acquiring a query result. Optionally, the normalizing the natural language query sentence input by the user to obtain the optimized query sentence includes: Receiving a natural language query statement input by a user; identifying an object name from the natural language query sentence, and carrying out synonym expansion and/or misplacement word correction on the identified object name by using a preset dictionary; identifying the spoken language expression from the natural language query sentence, and carrying out standardized conversion on the spoken language expression to obtain an optimized query sentence. Optionally, the performing constraint combination processing on all the generated query fragments to obtain an executable query statement includes: analyzing the variables defined and used in each query segment, and inserting intermediate variable transfer clauses between query segments needing variable transfer based on the dependency relationship between the variables so that the variables in the previous query segment can be used by the next query segment; Merging the designated return fields in each inquiry fragment, and performing de-duplication treatment on the merged fields to form a return result clause; And combining the query fragments, the intermediate variable transfer clauses and the returned result clauses according to a preset query logic sequence to generate the executable query statement, wherein the matching modes, the filtering conditions and the relationship types in all the query fragments are kept unchanged during the combination. Optionally, the executing the executable query sentence i