A method, device, electronic device and storage medium for determining query results
Through the chain reasoning ability of the large language model, k-layer depth traversal and chained first-order operation logic are used to process complex queries in the knowledge graph, which solves the problem of difficulty in processing complex logical queries in the existing technology and achieves fast and accurate queries. The results confirm and improve the efficiency of graph logic reasoning.
Patent Information
- Application Number
- CN202410733526.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-07
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2044-06-07
AI Technical Summary
Existing graph logic reasoning technology is difficult to process complex logical query statements, resulting in low query result determination speed and accuracy, as well as insufficient versatility and scalability.
Through the chain reasoning capability of the large language model, k-layer deep traversal is used to extract subgraph context from the knowledge graph and convert it into contextual instructions. The query statement is decomposed into chained first-order operation logic and input to the large language model to obtain the query results. .
It realizes fast and accurate result determination of complex logical query statements, and improves the efficiency and usability of graph logical reasoning.
Smart Images

Figure CN118312533B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of knowledge graph reasoning technology, and in particular to a query result determination method, device, electronic device and storage medium. Background Art
[0002] As a structured form of knowledge expression, logical reasoning of knowledge graph is a basic and important task. Current graph logic reasoning technology, especially the mechanism of reasoning and answering questions based on first-order logic (including projection, intersection, union, negation) and their combinations, mainly uses the semantic space and hierarchical properties of the graph to encode and analyze the logical content of the query. For example, the more mainstream methods include Query2Box, HypE, PERM, BetaE, etc., which encode the entities and relationships of the graph into box shape, hyperbola shape, normal distribution, and beta distribution respectively. However, these algorithms cannot handle complex logical query statements well, and thus cannot quickly and accurately determine the query results corresponding to the query statements, and their versatility and scalability are average. Summary of the invention
[0003] The present invention provides a query result determination method, device, electronic device and storage medium, which can utilize the chain reasoning capability of a large language model to quickly and accurately obtain the query result of a query statement.
[0004] According to one aspect of the present invention, a query result determination method is provided, comprising:
[0005] In response to a query result determining event being triggered, obtaining a query statement and a knowledge graph corresponding to the query statement;
[0006] Based on the entities and relations involved in the query statement, the knowledge graph is traversed in depth at k levels, the subgraph context extracted from the knowledge graph in each level of traversal is determined, and the subgraph context is converted into corresponding context instructions respectively; wherein k is the number of jump levels of the operation logic of the query statement; the subgraph context is a triple of two entities with a relationship and the relationship between the two entities;
[0007] Decomposing the query statement into at least two chained first-order operation logics, and converting the at least two chained first-order operation logics into corresponding input instructions respectively;
[0008] The input instruction and the context instruction are input into a large language model, output results of the input instructions corresponding to the at least two chained first-order operation logics are sequentially obtained, and a query result corresponding to the query statement is determined according to the output results.
[0009] According to another aspect of the present invention, there is provided a query result determination device, comprising:
[0010] A knowledge graph acquisition module, configured to acquire a query statement and a knowledge graph corresponding to the query statement in response to a query result determining event being triggered;
[0011] A subgraph context determination module is used to perform a k-layer deep traversal of the knowledge graph based on the entities and relationships involved in the query statement, determine the subgraph context extracted from the knowledge graph in each layer of traversal, and convert the subgraph context into corresponding context instructions respectively; wherein k is the number of jump layers of the operation logic of the query statement; the subgraph context is a triple of two entities with a relationship and the relationship between the two entities;
[0012] An input instruction determination module, used to decompose the query statement into at least two chained first-order operation logics, and convert the at least two chained first-order operation logics into corresponding input instructions respectively;
[0013] A query result determination module is used to input the input instruction and the context instruction into a large language model, sequentially obtain output results of the input instructions corresponding to the at least two chained first-order operation logics, and determine the query result corresponding to the query statement according to the output results.
[0014] According to another aspect of the present invention, there is provided an electronic device, the electronic device comprising:
[0015] at least one processor; and,
[0016] a memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the query result determination method described in any embodiment of the present invention.
[0018] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the query result determination method described in any embodiment of the present invention when executed.
[0019] The query result determination scheme of the embodiment of the present invention, in response to the query result determination event being triggered, obtains a query statement and a knowledge graph corresponding to the query statement; based on the entities and relationships involved in the query statement, performs a k-layer deep traversal of the knowledge graph, determines the subgraph context extracted from the knowledge graph in each layer of traversal, and converts the subgraph context into corresponding context instructions respectively; wherein k is the number of jump layers of the operation logic of the query statement; the subgraph context is a triple of two entities with a relationship and the relationship between the two entities; decomposes the query statement into at least two chained first-order operation logics, and converts the at least two chained first-order operation logics into corresponding input instructions respectively; inputs the input instructions and the context instructions into a large language model, sequentially obtains the output results of the input instructions corresponding to the at least two chained first-order operation logics, and determines the query result corresponding to the query statement according to the output results. Through this solution, the graph logic reasoning algorithm that encodes query statements based on the semantic space and hierarchical properties of the graph is solved, which cannot handle complex logical queries well and has average versatility and scalability. The relevant subgraphs extracted from the knowledge graph are abstracted as context instructions of the large language model, and the text instructions corresponding to the first-order operation logic obtained by chain decomposition of the query statement are used as input instructions of the large language model. By utilizing the chain reasoning ability of the large language model, the query results of the query statement can be obtained quickly and accurately, making the process of complex logical reasoning of the graph more reasonable, effective and more usable.
[0020] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 is a flowchart of a query result determination method provided according to Embodiment 1 of the present invention;
[0023] Figure 2 It is a knowledge graph in the medical field constructed according to an embodiment of the present invention;
[0024] Figure 3 The embodiment of the present invention provides Figure 2The graph after abstract processing of the provided knowledge graph;
[0025] Figure 4 is a structural diagram of a query result determination device provided by Embodiment 2 of the present invention;
[0026] Figure 5 It is a structural schematic diagram of an electronic device for implementing the query result determination method of an embodiment of the present invention. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] Embodiment 1
[0030] Figure 1 A flowchart of a method for determining a query result is provided for the first embodiment of the present invention. This embodiment is applicable to the case of determining a query result corresponding to a query statement. The method can be executed by a query result determination device. The query result determination device can be implemented in the form of hardware and / or software. The query result determination device can be configured in an electronic device. Figure 1 As shown, the method includes:
[0031] S110: In response to a query result determining event being triggered, a query statement and a knowledge graph corresponding to the query statement are obtained.
[0032] In an embodiment of the present invention, when a query request or query instruction is received, it is determined that a query result determination event is triggered. In response to the query result determination event being triggered, a query statement corresponding to the query request or query instruction is obtained, and a knowledge graph corresponding to the query statement is obtained. Among them, the knowledge graph is a graph used to reflect the query result corresponding to the query statement, and the knowledge graph contains a large number of entities and relationships between entities.
[0033] S120. Based on the entities and relationships involved in the query statement, perform a k-layer deep traversal of the knowledge graph, determine the subgraph context extracted from the knowledge graph in each layer of traversal, and convert the subgraph context into corresponding context instructions respectively; wherein k is the number of jump layers of the operation logic of the query statement; the subgraph context is a triple of two entities with a relationship and the relationship between the two entities.
[0034] Optionally, before performing a k-layer deep traversal of the knowledge graph based on the entities and relationships involved in the query statement and determining the sub-graph context extracted from the knowledge graph in each layer of traversal, it also includes: abstracting the entities and relationships in the knowledge graph and the entities and relationships involved in the query statement respectively; wherein the abstraction processing is to assign a unique identifier to each entity and each relationship.
[0035] In the embodiment of the present invention, the knowledge graph Can be represented as a set of entities and relationships , ,in, Represents a collection of entities, Represents a set of relations, and Existential relationship for .right To abstract, that is, Each element in the knowledge graph is assigned a unique ID, thus completing the abstract processing of the knowledge graph. , , which can be abstracted into ,in , , , , which can be abstracted into ,in .
[0036] For example, Figure 2 The knowledge graph in the medical field constructed in the embodiment of the present invention, wherein: Figure 2The knowledge graph provided is part of the medical knowledge graph covering concepts such as surgical procedures, (Diagnosis-Related Groups) DRG, medical equipment and materials, and clinical departments. Among them, the knowledge graph can be represented as , ,in , .right To abstract, ,in: Angiography X-ray machine, Coronary artery dilatation balloon, FM19, FM29, FM39, IABP surgery, Coronary artery bypass grafting, Cardiology, Cardiovascular Surgery, Vascular Surgery, Interventional room. The device is used in DRG group, Materials used in DRG group, The DRG group includes key technologies, Department. Figure 3 The embodiment of the present invention provides Figure 2 The provided knowledge graph is an abstracted graph.
[0037] In the embodiment of the present invention, the entities and relationships involved in the query statement are abstracted based on the same abstraction processing method as the knowledge graph. "What concept does the Pacific Ocean belong to?" can be abstracted into ; Another exemplary query statement "What concepts do the Pacific Ocean and the Atlantic Ocean belong to?" can be abstracted into ; For example, the query statement "What concept is an ocean similar to the Pacific or Atlantic?" can be abstracted into .
[0038] In the embodiment of the present invention, if Figure 2 The knowledge graph shown in the figure, the query statement entered by the user includes and ,in,
[0039] “What department does the DRG group that uses the angiography X-ray machine belong to?”;
[0040] “What shutdown techniques were included in the DRG group that used both angiographic X-ray machines and coronary balloon dilation?”
[0041] This embodiment queries The entities and relationships involved are abstracted, whereby the corresponding abstract representation results can be obtained by using manual means or by inputting complex query operation logic and examples of abstract representation into a large language model to generate results, whereby Can be abstracted into , Can be abstracted into .
[0042] In the embodiment of the present invention, based on the entities and relationships involved in the query statement, the knowledge graph is Layer depth-first traversal to extract subgraph context from the knowledge graph . Optionally, based on the entities and relationships involved in the query statement, the knowledge graph is traversed in depth k layers to determine the subgraph context extracted from the knowledge graph in each layer of traversal, including: determining the entity set and relationship set involved in the query statement; taking each entity in the entity set as the initial entity, traversing the knowledge graph, and abstracting from the knowledge graph a subgraph context that has any relationship in the relationship set with the initial entity; determining a target entity based on the subgraph context, taking the target entity as a new initial entity, and traversing the knowledge graph again, abstracting from the knowledge graph a subgraph context that has any relationship in the relationship set with the initial entity, until the number of deep traversals of the knowledge graph reaches k layers; wherein the target entity is an entity in the subgraph context that has any relationship in the relationship set with the initial entity.
[0043] For example, for the query statement Abstract processing is performed, in which and Respectively represent query statements The set of entities and relationships involved, and Respectively represent Layer depth-first traversal of the entity set and relationship set involved, , then Subgraph context obtained by depth-first traversal of the layer It can be obtained by the following iteration method:
[0044]
[0045] conduct Layer depth-first traversal, that is When , the subgraph context is finally extracted Among them, the number of layers traversed For query statements The number of jump levels of the operation logic.
[0046] It is understandable that determining the entity set involved in the query statement and relationship set , respectively, with entity sets Each entity in is an initial entity, and the knowledge graph is traversed for the first time to extract the set of relationships with the initial entity from the knowledge graph. The subgraph context of any relation in The subgraph context is a triple of two entities with a relationship and the relationship between the two entities. Entity Collection The entity existence relationship set in The entity with any relationship in the target entity is used as the target entity, and the entity set constructed based on the target entity . Respectively, entity sets Each entity in is the initial entity, and the knowledge graph is deeply traversed for the second time to extract entities related to the entity set from the knowledge graph. The entity existence relationship set in The subgraph context of any relation in And so on, until k traversals of the knowledge graph are completed.
[0047] For example, in this embodiment, for a query statement ,conduct Layer depth-first traversal, where:
[0048] .
[0049] For query statements ,conduct Layer depth-first traversal, where:
[0050]
[0051] In the embodiment of the present invention, the sub-graph context Convert to the corresponding context instructions Among them, the template of the context instruction used by the subgraph context can be {Given the following triple relationship: entity Through relationships With entity Connected}, For example, the query statement The corresponding subgraph context Represented as a contextual directive :
[0052] “Given the following triple relation:
[0053] entity Through relationships With entity Connected;
[0054] entity Through relationships With entity Connected;
[0055] entity Through relationships With entity Connected;
[0056] entity Through relationships With entity Connected;
[0057] entity Through relationships With entity Connected;
[0058] entity Through relationships With entity Connected;
[0059] entity Through relationships With entity Connected;
[0060] entity Through relationships With entity Connected;
[0061] entity Through relationships With entity Connected;
[0062] entity Through relationships With entity Connected. ”
[0063] The query statement The corresponding subgraph context Represented as a contextual directive :
[0064] “Given the following triple relation:
[0065] entity Through relationships With entity Connected;
[0066] entity Through relationships With entity Connected;
[0067] entity Through relationships With entity Connected;
[0068] entity Through relationships With entity Connected;
[0069] entity Through relationships With entity Connected;
[0070] entity Through relationships With entity Connected;
[0071] entity Through relationships With entity Connected;
[0072] entity Through relationships With entity Connected. ”
[0073] S130, decomposing the query statement into at least two chained first-order operation logics, and converting the at least two chained first-order operation logics into corresponding input instructions respectively.
[0074] In the embodiment of the present invention, complex logic query The first-order logic operations included may include the following four:
[0075] (1) Projection, expressed as :
[0076]
[0077] in, .
[0078] (2) Intersection, expressed as :
[0079]
[0080] in .
[0081] (3) Union, expressed as :
[0082]
[0083] in .
[0084] (4) Negation, expressed as :
[0085]
[0086] in .
[0087] The operation logic type of the query statement is the above first-order operation logic ( , , , As shown in Table 1 below, Table 1 is the abbreviated form and decomposition form of an example of the operation logic type of a complex logic query:
[0088] Table 1: Abbreviated and decomposed forms of examples of operation logic types for complex logic queries
[0089]
[0090] In an embodiment of the present invention, a query statement is decomposed into at least two chained first-order operation logics. Optionally, the query statement is decomposed into at least two chained first-order operation logics, including: abstracting the entities and relationships involved in the query statement to generate abstract operation logic corresponding to the query statement; determining the operation logic type of the abstract operation logic; and decomposing the abstract operation logic into at least two chained first-order operation logics based on the operation logic type. In an embodiment of the present invention, the query statement is abstracted by assigning unique IDs to the entities and relationships involved in the query statement, thereby generating abstract operation logic corresponding to the query statement. Exemplarily, the query statement "What concept does the Pacific Ocean belong to?" The abstract operation logic generated after abstract processing is: ; Another exemplary query statement "What concepts do the Pacific Ocean and the Atlantic Ocean belong to?" The abstract operation logic generated after abstract processing is: ; For example, the query statement "What concept is an ocean similar to the Pacific Ocean or the Atlantic Ocean?" The abstract operation logic generated after abstract processing is . Analyze the abstract operation logic corresponding to the query statement and determine the operation logic type of the abstract operation logic For example, the query statement The operation logic type of the abstract operation logic corresponding to "What concept does the Pacific Ocean belong to?" ; and exemplary, The operation logic type of the abstract operation logic corresponding to "What concepts do the Pacific Ocean and the Atlantic Ocean belong to?" ; Again, for example, The operation logic type of the abstract operation logic corresponding to "What concept is an ocean similar to the Pacific Ocean or the Atlantic Ocean?" .
[0091] For example, for a query statement with complex logic:
[0092] “What department does the DRG group that uses the angiography X-ray machine belong to?”;
[0093] "What key technologies are included in the DRG group that uses both angiography X-ray machines and coronary dilation balloons?";
[0094] For query statements , The abstract operation logic can be classified by manual means or by inputting the operation logic classification examples into the large language model to generate results, judge the corresponding operation logic type, and obtain , .
[0095] According to the operation logic type, the abstract operation logic is decomposed into at least two chained first-order operation logics. As shown in Table 1, Table 1 shows some query operation logic types and their decomposition forms.
[0096] Optionally, decomposing the abstract operation logic into at least two chained first-order operation logics based on the operation logic type includes: determining a decomposition strategy for the abstract operation logic based on the operation logic type; and decomposing the abstract operation logic into at least two chained first-order operation logics based on the decomposition strategy. The operation logic type of the abstract operation logic , the query statement The abstract operation logic is decomposed into First-order logic . Exemplary, the decomposition strategy is: Included Layer mapping logic ( ), decomposed into A single-layer mapping logic ( ).For example: , can be decomposed into First-order logic ,in, , , ; will query Included The logic of crossover or union after mapping ( or ), decomposed into A single-layer mapping logic ( ) and 1 intersection or union logic. For example: , can be decomposed into First-order logic in, , , , . Query statement The included negation logic is the complement of the set obtained for the corresponding mapping logic, and its decomposition strategy is consistent with the decomposition strategy of the mapping logic.
[0097] In this embodiment, the query statement can be ( ) is decomposed into First-order logic :
[0098]
[0099] The query statement ( ) is decomposed into First-order logic :
[0100]
[0101] In an embodiment of the present invention, at least two chained first-order operation logics decomposed into a query statement are converted into corresponding input instructions. Exemplarily, an input instruction conversion template corresponding to the first-order operation logic is obtained, and according to the input instruction conversion template, at least two chained first-order operation logics are converted into corresponding input instructions. Optionally, the at least two chained first-order operation logics are respectively converted into corresponding input instructions, including: obtaining a second corresponding relationship between a preset first-order operation logic and an input instruction; and converting the at least two chained first-order operation logics into corresponding input instructions according to the second corresponding relationship. Exemplarily, Table 2 is a decomposition form and input instruction template of an example of an operation logic type for a complex logic query provided in an embodiment of the present invention:
[0102] Table 2 Decomposition form and input instruction template of the example of the operation logic type of complex logic query
[0103]
[0104]
[0105]
[0106] Among them, [ ] indicates the output result set obtained by the input instruction of this line . The obtained First-order logic Expressed as Input command In this embodiment, the query statement The first-order logic operation obtained by decomposition Represented as input command :
[0107] "Which entities are connected through relationships With entity Connected? Use collections . "
[0108] "Which entities are connected through relationships With Collection Are you connected to any entity in the ? Just input the entity ID. "
[0109] In this embodiment, the query statement The first-order logic operation obtained by decomposition Represented as input command :
[0110] "Which entities are connected through relationships With entity Connected? Use collections to represent these entities."
[0111] "Which entities are connected through relationships With entity Connected? Use collections to represent these entities."
[0112] Which entities belong to the collection With Collection The intersection of ? Use a set to represent these entities. ”
[0113] Which entities are related With Collection Are you connected to any entity in the ? Just input the entity ID. "
[0114] S140, inputting the input instruction and the context instruction into a large language model, sequentially obtaining output results of the input instructions corresponding to the at least two chained first-order operation logics, and determining a query result corresponding to the query statement according to the output results.
[0115] In the embodiment of the present invention, The input instructions corresponding to the first-order logic , and the contextual instructions corresponding to the subgraph context , input into the large language model, and get Output results .in, For large language models for instructions Optionally, the large language model may include GPT, LLaMA, PaLM, Gemini, BLOOM, ChatGLM and other models. For example, the query statement Corresponding instructions and Input into the large language model GPT-4, and get the following two output results in sequence :
[0116] “Based on the known information, the collection Contains the following entities: , , . "
[0117] "entity ”
[0118] The query statement Corresponding instructions and Input into the large language model GPT-4, and get the following 4 output results in sequence :
[0119] “Based on the known information, the collection Contains the following entities: , , . "
[0120] “Based on the known information, the collection Contains the following entities: . "
[0121] “Based on the known information, the collection Contains the following entities: . "
[0122] "entity ”
[0123] In an embodiment of the present invention, the query result corresponding to the query statement is determined according to the output results of the input instructions corresponding to at least two chained first-order operation logics. Optionally, determining the query result corresponding to the query statement according to the output result includes: using the output result of the last input instruction among the input instructions corresponding to the at least two chained first-order operation logics as the query result corresponding to the query statement. Exemplarily, the output result obtained is De-abstracting The unique ID in the mapping is converted into the original concept name to obtain the final logical query result For example, if you change the query "What department does the DRG group using the angiography X-ray machine belong to?" The output result is "entity " is de-abstracted to obtain the final logical query result: "Cardiovascular Medicine". Output: "What are the key technologies in the DRG group that uses both angiography X-ray machines and coronary dilation balloons?" "entity " is de-abstracted to obtain the final logical query result: "IABP surgery".
[0124] The query result determination method of the embodiment of the present invention obtains a query statement and a knowledge graph corresponding to the query statement in response to a query result determination event being triggered; based on the entities and relationships involved in the query statement, the knowledge graph is traversed in depth at k levels to determine the subgraph context extracted from the knowledge graph in each level of traversal, and the subgraph context is converted into corresponding context instructions respectively; wherein k is the number of jump levels of the operation logic of the query statement; the subgraph context is a triple of two entities with a relationship and the relationship between the two entities; the query statement is decomposed into at least two chained first-order operation logics, and the at least two chained first-order operation logics are converted into corresponding input instructions respectively; the input instruction and the context instruction are input into a large language model, the output results of the input instructions corresponding to the at least two chained first-order operation logics are obtained in sequence, and the query result corresponding to the query statement is determined according to the output results. Through this solution, the graph logic reasoning algorithm that encodes query statements based on the semantic space and hierarchical properties of the graph is solved, which cannot handle complex logical queries well and has average versatility and scalability. The relevant subgraphs extracted from the knowledge graph are abstracted as context instructions of the large language model, and the text instructions corresponding to the first-order operation logic obtained by chain decomposition of the query statement are used as input instructions of the large language model. By utilizing the chain reasoning ability of the large language model, the query results of the query statement can be obtained quickly and accurately, making the process of complex logical reasoning of the graph more reasonable, effective and more usable.
[0125] Embodiment 2
[0126] Figure 4 This is a schematic diagram of the structure of a query result determination device provided in Embodiment 2 of the present invention. Figure 4 As shown, the device comprises:
[0127] The knowledge graph acquisition module 410 is used to acquire a query statement and a knowledge graph corresponding to the query statement in response to a query result determination event being triggered;
[0128] The subgraph context determination module 420 is used to perform a k-layer deep traversal of the knowledge graph based on the entities and relationships involved in the query statement, determine the subgraph context extracted from the knowledge graph in each layer of traversal, and convert the subgraph context into corresponding context instructions respectively; wherein k is the number of jump layers of the operation logic of the query statement; the subgraph context is a triple of two entities with a relationship and the relationship between the two entities;
[0129] An input instruction determination module 430, configured to decompose the query statement into at least two chained first-order operation logics, and convert the at least two chained first-order operation logics into corresponding input instructions respectively;
[0130] The query result determination module 440 is used to input the input instruction and the context instruction into the large language model, sequentially obtain the output results of the input instructions corresponding to the at least two chained first-order operation logics, and determine the query result corresponding to the query statement according to the output results.
[0131] Optionally, the input instruction determination module includes:
[0132] An abstraction operation logic generating unit, used to perform abstraction processing on entities and relationships involved in the query statement, and generate abstraction operation logic corresponding to the query statement;
[0133] An operation logic type determination unit, used to determine the operation logic type of the abstract operation logic;
[0134] The operation logic decomposition unit is used to decompose the abstract operation logic into at least two chained first-order operation logics based on the operation logic type.
[0135] Optionally, the operation logic decomposition unit is used to:
[0136] Determining a decomposition strategy of the abstracted operation logic based on the operation logic type;
[0137] The abstract operation logic is decomposed into at least two chained first-order operation logics based on the decomposition strategy.
[0138] Optionally, the input instruction determination module is used to:
[0139] Acquire a second corresponding relationship between a preset first-order operation logic and an input instruction;
[0140] The at least two chained first-order operation logics are converted into corresponding input instructions respectively according to the second corresponding relationship.
[0141] Optionally, the subgraph context determination module is used to:
[0142] Determine the entity set and relationship set involved in the query statement;
[0143] Taking each entity in the entity set as an initial entity, traversing the knowledge graph, and abstracting a subgraph context having any one of the relationships in the relationship set with the initial entity from the knowledge graph;
[0144] Determine the target entity according to the subgraph context, take the target entity as the new initial entity, and traverse the knowledge graph again, abstract the subgraph context that has any one of the relationships in the relationship set with the initial entity from the knowledge graph, until the number of deep traversals of the knowledge graph reaches k layers; wherein the target entity is an entity in the subgraph context that has any one of the relationships in the relationship set with the initial entity.
[0145] Optionally, also include:
[0146] An abstract processing module is used to perform a k-layer deep traversal of the knowledge graph based on the entities and relationships involved in the query statement, and before determining the subgraph context extracted from the knowledge graph in each layer of traversal, perform abstract processing on the entities and relationships in the knowledge graph and the entities and relationships involved in the query statement; wherein the abstract processing is to assign a unique identifier to each entity and each relationship.
[0147] Optionally, the query result determination module is used to:
[0148] The output result of the last input instruction among the input instructions corresponding to the at least two chained first-order operation logics is used as the query result corresponding to the query statement.
[0149] The query result determination device provided in the embodiment of the present invention can execute the query result determination method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0150] Embodiment 3
[0151] Figure 5 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0152] like Figure 5As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. The input / output (I / O) interface 15 is also connected to the bus 14.
[0153] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0154] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the query result determination method.
[0155] In some embodiments, the query result determination method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the query result determination method in any other appropriate manner (e.g., by means of firmware).
[0156] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0157] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0158] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0159] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0160] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0161] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0162] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0163] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for determining a query result, characterized in that: include: In response to a query result determining event being triggered, obtaining a query statement and a knowledge graph corresponding to the query statement; Based on the entities and relations involved in the query statement, the knowledge graph is traversed in depth at k levels, the subgraph context extracted from the knowledge graph in each level of traversal is determined, and the subgraph context is converted into corresponding context instructions respectively; wherein k is the number of jump levels of the operation logic of the query statement; the subgraph context is a triple of two entities with a relationship and the relationship between the two entities; Decomposing the query statement into at least two chained first-order operation logics, and converting the at least two chained first-order operation logics into corresponding input instructions respectively; Inputting the input instruction and the context instruction into a large language model, sequentially obtaining output results of the input instructions corresponding to the at least two chained first-order operation logics, and determining a query result corresponding to the query statement according to the output results; The query statement is decomposed into at least two chained first-order operation logics, including: Abstracting the entities and relationships involved in the query statement to generate abstract operation logic corresponding to the query statement; Determining the operation logic type of the abstract operation logic; The abstract operation logic is decomposed into at least two chained first-order operation logics based on the operation logic type.
2. The method according to claim 1, characterized in that Decomposing the abstract operation logic into at least two chained first-order operation logics based on the operation logic type includes: Determining a decomposition strategy of the abstracted operation logic based on the operation logic type; The abstract operation logic is decomposed into at least two chained first-order operation logics based on the decomposition strategy.
3. The method according to claim 1, characterized in that The at least two chained first-order operation logics are respectively converted into corresponding input instructions, including: Acquire a second corresponding relationship between a preset first-order operation logic and an input instruction; The at least two chained first-order operation logics are converted into corresponding input instructions respectively according to the second corresponding relationship.
4. The method according to claim 1, characterized in that: Based on the entities and relationships involved in the query statement, the knowledge graph is traversed in k layers in depth to determine the subgraph context extracted from the knowledge graph in each layer of traversal, including: Determine the entity set and relationship set involved in the query statement; Taking each entity in the entity set as an initial entity, traversing the knowledge graph, and abstracting a subgraph context having any one of the relationships in the relationship set with the initial entity from the knowledge graph; Determine the target entity according to the subgraph context, take the target entity as the new initial entity, and traverse the knowledge graph again, abstract the subgraph context that has any one of the relationships in the relationship set with the initial entity from the knowledge graph, until the number of deep traversals of the knowledge graph reaches k layers; wherein the target entity is an entity in the subgraph context that has any one of the relationships in the relationship set with the initial entity.
5. The method according to claim 4, characterized in that Before performing a k-layer deep traversal of the knowledge graph based on the entities and relationships involved in the query statement and determining a subgraph context extracted from the knowledge graph in each layer of traversal, the method further includes: Abstract processing is performed on the entities and relationships in the knowledge graph and the entities and relationships involved in the query statement respectively; wherein the abstract processing is to assign a unique identifier to each entity and each relationship respectively.
6. The method according to any one of claims 1 to 5, characterized in that: Determining a query result corresponding to the query statement according to the output result includes: The output result of the last input instruction among the input instructions corresponding to the at least two chained first-order operation logics is used as the query result corresponding to the query statement.
7. A query result determination device, characterized in that: include: A knowledge graph acquisition module, configured to acquire a query statement and a knowledge graph corresponding to the query statement in response to a query result determining event being triggered; A subgraph context determination module is used to perform a k-layer deep traversal of the knowledge graph based on the entities and relationships involved in the query statement, determine the subgraph context extracted from the knowledge graph in each layer of traversal, and convert the subgraph context into corresponding context instructions respectively; wherein k is the number of jump layers of the operation logic of the query statement; the subgraph context is a triple of two entities with a relationship and the relationship between the two entities; An input instruction determination module, used to decompose the query statement into at least two chained first-order operation logics, and convert the at least two chained first-order operation logics into corresponding input instructions respectively; a query result determination module, configured to input the input instruction and the context instruction into a large language model, sequentially obtain output results of the input instructions corresponding to the at least two chained first-order operation logics, and determine a query result corresponding to the query statement according to the output results; Wherein, the input instruction determination module includes: An abstraction operation logic generating unit, used to perform abstraction processing on entities and relationships involved in the query statement, and generate abstraction operation logic corresponding to the query statement; An operation logic type determination unit, used to determine the operation logic type of the abstract operation logic; The operation logic decomposition unit is used to decompose the abstract operation logic into at least two chained first-order operation logics based on the operation logic type.
8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the query result determination method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the query result determination method according to any one of claims 1 to 6 when executed.
