Question and answer retrieval method
By embedding vector model and vector similarity matching technology, subgraphs in large-scale knowledge graphs are constructed, which solves the problem of low retrieval efficiency of multi-hop graphs and realizes a faster and more efficient question-and-answer process.
Patent Information
- Application Number
- CN202510229364.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-28
- Publication Date
- 2025-06-20
AI Technical Summary
The search for multi-hop graphs of large-scale knowledge graphs has problems such as low search efficiency and slow speed, which leads to low efficiency in answering questions from big models.
By embedding vector models to encode the problem to be queried, the vector representation of entities and relationships is determined, and the vector similarity is used to match the associated entities and relationships, a subgraph in a large-scale knowledge graph is constructed, and the subgraph is input into the large language model to generate answers.
Reduces the time to directly search all relevant entities and relationships on a large-scale knowledge graph, and improves the speed and efficiency of searching Q&A.
Smart Images

Figure CN120179773A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of natural language processing question answering, and particularly relates to a retrieval question answering method. Background Art
[0002] An important advantage of the new retrieval augmented generation model Graph RAG compared to the text RAG is that it can utilize the structured knowledge contained in the knowledge graph. Through multi-hop graph retrieval and reasoning, it can provide more accurate and rich information for the large model to answer more complex questions.
[0003] A key part in Graph RAG is graph retrieval. However, when retrieving in large-scale knowledge graphs, for example, the Chinese medical knowledge graph cmekg has 140,000 nodes and 1 million edges in the complete graph; the medical knowledge graph BIOS has 46 million nodes and 99 million edges. Whether it is path matching or the ego-centered network ego, if the number of hops "is too large" (more than 2), the retrieval time increases sharply. Here, the number of hops refers to the number of edges between the starting node and the ending node of the retrieval.
[0004] Currently, the methods of multi-hop graph retrieval in Graph RAG mainly include graph database retrieval, graph theory algorithms, LLM graph reasoning, graph neural network GNN, etc. However, these methods all have the problems of low retrieval efficiency and slow speed when performing multi-hop graph retrieval on large-scale knowledge graphs, resulting in low efficiency of the large model in answering questions. Therefore, the speed of multi-hop graph retrieval on large-scale knowledge graphs remains an urgent problem to be solved. Summary of the Invention
[0005] This application provides a retrieval question answering method to solve the problems of low retrieval efficiency and slow speed in multi-hop graph retrieval of large-scale knowledge graphs.
[0006] An embodiment of this application provides a retrieval question answering method, and the method includes:
[0007] For a to-be-query question, input the to-be-query question into a vector encoder of an embedding vector model to obtain a first vector corresponding to each first entity in the to-be-query question, and a second vector corresponding to a first relationship between each first entity.
[0008] For each of the first entities, determine the first similarity between the first vector corresponding to the first entity and the third vectors corresponding to the respective second entities stored in the vector database, and determine the respective associated entities corresponding to the first entity according to the respective first similarities; for the first relationship between each of the first entities, determine the second similarity between the second vector corresponding to the first relationship and the fourth vectors corresponding to the respective second relationships stored in the vector database, and determine the respective associated relationships corresponding to the first relationship according to the respective second similarities;
[0009] According to the respective associated entities and the respective associated relationships, determine a first subgraph corresponding to the query problem in the pre-constructed large-scale knowledge graph;
[0010] Input the first subgraph into the graph encoder in the large language model to obtain the graph text corresponding to the first subgraph; input the graph text into the large language model to generate the answer corresponding to the query problem.
[0011] Further, determining the first subgraph corresponding to the query problem in the pre-constructed large-scale knowledge graph according to the respective associated entities and the respective associated relationships includes:
[0012] Correspondingly match the respective associated entities and the respective associated relationships with the respective third entities and the respective third relationships in the large-scale knowledge graph, and determine a first candidate subgraph corresponding to the query problem in the large-scale knowledge graph;
[0013] Determine the one-hop connection entities of each fourth entity in the first candidate subgraph and the shortest paths between each fourth entity to obtain the first subgraph corresponding to the query problem.
[0014] Further, determining the first subgraph corresponding to the query problem in the pre-constructed large-scale knowledge graph according to the respective associated entities and the respective associated relationships includes:
[0015] According to the corresponding relationship between each entity and the entity identifier stored in advance, determine the respective associated entity identifiers corresponding to the respective associated entities; according to the corresponding relationship between each relationship and the relationship identifier stored in advance, determine the respective associated relationship identifiers corresponding to the respective associated relationships;
[0016] According to the respective associated entity identifiers, the respective associated relationship identifiers, and the graph structure corresponding to the pre-stored large-scale knowledge graph, determine a second candidate subgraph corresponding to the query problem in the graph structure through the PageRank algorithm; wherein, the graph structure includes each entity identifier and each relationship identifier;
[0017] Map the entity identifiers and relationship identifiers in the second candidate subgraph to corresponding entities and relationships to obtain the first subgraph corresponding to the query problem.
[0018] Further, after determining the first subgraph corresponding to the query problem in the pre-constructed large-scale knowledge graph according to the respective associated entities and associated relationships, and before inputting the first subgraph into the graph encoder in the large language model to obtain the graph text corresponding to the first subgraph, the method further includes:
[0019] For each fifth entity in the first subgraph, determine the third similarity between the fifth entity and the corresponding first entity; for each fourth relationship in the first subgraph, determine the fourth similarity between the fourth relationship and the corresponding first relationship.
[0020] According to the third similarity corresponding to each fifth entity in the first subgraph and the fourth similarity corresponding to each fourth relationship, determine the second subgraph through the graph theory algorithm PCST, and use the second subgraph as the first subgraph to perform the step of inputting the first subgraph into the graph encoder in the large language model to obtain the graph text corresponding to the first subgraph.
[0021] Further, determining the third similarity between each fifth entity in the first subgraph and the corresponding first entity includes:
[0022] For each fifth entity in the first subgraph, if the fifth entity is an associated entity, determine the first similarity between the fifth entity and the corresponding first entity as the third similarity between the fifth entity and the corresponding first entity.
[0023] If the fifth entity is not an associated entity, determining the third similarity between the fifth entity and the corresponding first entity includes:
[0024] Respectively determine the fifth similarity between the fifth entity and each first entity, and determine the maximum fifth similarity as the third similarity between the fifth entity and the corresponding first entity.
[0025] Further, the respectively determining the fifth similarity between the fifth entity and each first entity includes:
[0026] Determine the first entity type corresponding to the fifth entity, and obtain the first entity type vector corresponding to the first entity type stored in advance.
[0027] For each of the first entities, determine the second entity type corresponding to the first entity, and obtain the second entity type vector corresponding to the second entity type pre - saved; determine the similarity between the first entity type vector and the second entity type vector as the fifth similarity between the fifth entity and the first entity.
[0028] Further, determining the fourth similarity between each fourth relationship in the first sub - graph and the corresponding first relationship includes:
[0029] For each fourth relationship in the first sub - graph, if the fourth relationship is an association relationship, determine the second similarity between the fourth relationship and the corresponding first relationship as the fourth similarity between the fourth relationship and the corresponding first relationship;
[0030] If the fourth relationship is not an association relationship, determining the fourth similarity between the fourth relationship and the corresponding first relationship includes:
[0031] Respectively determine the sixth similarity between the fourth relationship and each first relationship, and determine the maximum sixth similarity as the fourth similarity between the fourth relationship and the corresponding first relationship.
[0032] Further, the process of respectively determining the sixth similarity between the fourth relationship and each first relationship includes:
[0033] Determine the first relationship type corresponding to the fourth relationship, and obtain the first relationship type vector corresponding to the first relationship type pre - saved;
[0034] For each of the first relationships, determine the second relationship type corresponding to the first relationship, and obtain the second relationship type vector corresponding to the second relationship type pre - saved; determine the similarity between the first relationship type vector and the second relationship type vector as the sixth similarity between the fourth relationship and the first relationship.
[0035] Further, the process of determining the second vector corresponding to the first relationship between each pair of first entities includes:
[0036] For each first relationship, input the first relationship and the two first entities corresponding to the first relationship into the vector encoder to obtain the second vector corresponding to the first relationship.
[0037] Further, according to the third similarity corresponding to each fifth entity in the first sub - graph and the fourth similarity corresponding to each of the fourth relationships, determine the second sub - graph through the graph - theoretic algorithm PCST, including:
[0038] According to the first sub - graph and the graph - theory algorithm PCST, each third candidate sub - graph is obtained. According to the third similarity corresponding to each of the fifth entities and the fourth similarity corresponding to each of the fourth relationships, the similarity sum value corresponding to each third candidate sub - graph is determined; the third candidate sub - graph corresponding to the largest similarity sum value is determined as the second sub - graph.
[0039] An embodiment of the present application provides a device for retrieving answers to questions. The device includes:
[0040] A processing module, configured to input the question to be queried into a vector encoder of an embedding vector model for the question to be queried, to obtain a first vector corresponding to each first entity in the question to be queried, and a second vector corresponding to a first relationship between each pair of first entities.
[0041] A determination module, configured to, for each first entity, determine a first similarity between the first vector corresponding to the first entity and third vectors corresponding to each second entity stored in a vector database, and determine each associated entity corresponding to the first entity according to each first similarity; for each first relationship between each pair of first entities, determine a second similarity between the second vector corresponding to the first relationship and fourth vectors corresponding to each second relationship stored in the vector database, and determine each associated relationship corresponding to the first relationship according to each second similarity; and determine a first sub - graph corresponding to the question to be queried in a pre - constructed large - scale knowledge graph according to each associated entity and each associated relationship.
[0042] A generation module, configured to input the first sub - graph into a graph encoder in a large - language model to obtain a graph text corresponding to the first sub - graph; and input the graph text into the large - language model to generate an answer corresponding to the question to be queried.
[0043] Further, the determination module is specifically configured to perform corresponding matching between each associated entity and each associated relationship and each third entity and each third relationship in the large - scale knowledge graph, to determine a first candidate sub - graph corresponding to the question to be queried in the large - scale knowledge graph; and determine one - hop connection entities of each fourth entity in the first candidate sub - graph and the shortest path between each pair of fourth entities, to obtain a first sub - graph corresponding to the question to be queried.
[0044] Further, the determining module is specifically configured to determine the respective associated entity identifiers corresponding to the respective associated entities according to the pre-stored corresponding relationships between the respective entities and entity identifiers; determine the respective relationship identifiers corresponding to the respective associated relationships according to the pre-stored corresponding relationships between the respective relationships and relationship identifiers; determine a second candidate subgraph corresponding to the query problem in the graph structure through the PageRank algorithm according to the respective associated entity identifiers, the respective associated relationship identifiers, and the pre-stored graph structure of the large-scale knowledge graph; wherein the graph structure includes respective entity identifiers and respective relationship identifiers; map the entity identifiers and relationship identifiers in the second candidate subgraph to corresponding entities and relationships to obtain a first subgraph corresponding to the query problem.
[0045] Further, the determining module is further configured to determine a third similarity between each fifth entity in the first subgraph and a corresponding first entity; determine a fourth similarity between each fourth relationship in the first subgraph and a corresponding first relationship; determine a second subgraph through the PCST graph theory algorithm according to the respective third similarities corresponding to the respective fifth entities in the first subgraph and the respective fourth similarities corresponding to the respective fourth relationships, and use the second subgraph as the first subgraph to perform the step of inputting the first subgraph into a graph encoder of a large language model to obtain a graph text corresponding to the first subgraph.
[0046] Further, the determining module is specifically configured to, for each fifth entity in the first subgraph, if the fifth entity is an associated entity, determine the first similarity between the fifth entity and the corresponding first entity as the third similarity between the fifth entity and the corresponding first entity; if the fifth entity is not an associated entity, determining the third similarity between the fifth entity and the corresponding first entity includes: respectively determining a fifth similarity between the fifth entity and each first entity, and determining the maximum fifth similarity as the third similarity between the fifth entity and the corresponding first entity.
[0047] Further, the determining module is specifically configured to determine a first entity type corresponding to the fifth entity and obtain a first entity type vector corresponding to the pre-stored first entity type; for each first entity, determine a second entity type corresponding to the first entity and obtain a second entity type vector corresponding to the pre-stored second entity type; determine the similarity between the first entity type vector and the second entity type vector as the fifth similarity between the fifth entity and the first entity.
[0048] Further, the determining module is specifically configured to, for each fourth relationship in the first sub-graph, if the fourth relationship is an association relationship, determine the second similarity between the fourth relationship and the corresponding first relationship as the fourth similarity between the fourth relationship and the corresponding first relationship; if the fourth relationship is not an association relationship, determining the fourth similarity between the fourth relationship and the corresponding first relationship includes: respectively determining the sixth similarity between the fourth relationship and each first relationship, and determining the maximum sixth similarity as the fourth similarity between the fourth relationship and the corresponding first relationship.
[0049] Further, the determining module is specifically configured to determine the first relationship type corresponding to the fourth relationship, and obtain the first relationship type vector corresponding to the first relationship type pre-stored; for each first relationship, determine the second relationship type corresponding to the first relationship, and obtain the second relationship type vector corresponding to the second relationship type pre-stored; determine the similarity between the first relationship type vector and the second relationship type vector as the sixth similarity between the fourth relationship and the first relationship.
[0050] Further, the determining module is specifically configured to input, for each first relationship, the first relationship and the two first entities corresponding to the first relationship into the vector encoder to obtain the second vector corresponding to the first relationship.
[0051] Further, the determining module is specifically configured to obtain each third candidate sub-graph according to the first sub-graph and the graph theory algorithm PCST, and determine the similarity sum value corresponding to each third candidate sub-graph according to the third similarity corresponding to each fifth entity and the fourth similarity corresponding to each fourth relationship; determine the third candidate sub-graph corresponding to the maximum similarity sum value as the second sub-graph.
[0052] An embodiment of the present application further provides an electronic device, where the electronic device includes a processor, and the processor is configured to implement the retrieval and question-answering method as described in any one of the above when executing a computer program stored in a memory.
[0053] An embodiment of the present application further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and the computer program, when executed by a processor, implements the retrieval and question-answering method as described in any one of the above.
[0054] An embodiment of the present application further provides a computer program product, where the computer program product includes: computer program code, and when the computer program code runs on a computer, the computer is caused to execute the retrieval and question-answering method as described in any one of the above.
[0055] In the present application, for each first entity in the query problem, the associated entities of the first entity are determined through the first similarity between the first entity and each second entity stored in the vector database; for each first relationship in the query problem, the associated relationships of the first relationship are determined through the second similarity between the first relationship and each second relationship stored in the vector database; according to the associated entities corresponding to the first entity and the associated relationships corresponding to the first relationship in the query problem, a first subgraph corresponding to the query problem in the pre-constructed large-scale knowledge graph is determined, and the first subgraph includes the associated entities and associated relationships related to the query problem; according to the graph text corresponding to the first subgraph, an answer corresponding to the query problem is generated, thereby reducing the time for directly retrieving all entities and relationships related to the query problem in the large-scale knowledge graph, and thus improving the retrieval and question-answering speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0057] Figure 1 It is a schematic diagram of a retrieval and question-answering process provided by an embodiment of the present application;
[0058] Figure 2 It is a schematic diagram of a process for determining a first subgraph provided by an embodiment of the present application;
[0059] Figure 3 It is another schematic diagram of a process for determining a first subgraph provided by an embodiment of the present application;
[0060] Figure 4 It is a schematic diagram of a process for optimizing a first subgraph provided by an embodiment of the present application;
[0061] Figure 5 It is a schematic diagram of a process for calculating the third similarity corresponding to each fifth entity in a first subgraph provided by an embodiment of the present application;
[0062] Figure 6 It is a schematic diagram of a process for determining the fifth similarity between a fifth entity and each first entity provided by an embodiment of the present application;
[0063] Figure 7 It is a schematic diagram of a process for calculating the fourth similarity corresponding to each fourth relationship in a first subgraph provided by an embodiment of the present application;
[0064] Figure 8Schematic diagram of a process for determining the sixth similarity between the fourth relationship and each first relationship provided by an embodiment of the present application;
[0065] Figure 9 Schematic diagram of the main process of a retrieval question and answer provided by an embodiment of the present application;
[0066] Figure 10 Schematic diagram of the device structure of a retrieval question and answer provided by an embodiment of the present application;
[0067] Figure 11 Schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0068] To make the purpose and implementation manners of the present application clearer, the following will clearly and completely describe the exemplary implementation manners of the present application with reference to the accompanying drawings in the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only a part of the embodiments of the present application, rather than all of the embodiments.
[0069] It should be noted that the brief description of the terms in the present application is only for the convenience of understanding the subsequent described implementation manners, rather than intending to limit the implementation manners of the present application. Unless otherwise specified, these terms should be understood in their ordinary and common meanings.
[0070] The terms "first", "second", "third", etc. in the specification, claims and the above accompanying drawings of the present application are used to distinguish similar or like objects or entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise noted. It should be understood that such terms can be interchanged under appropriate circumstances.
[0071] The terms "comprising" and "having" and any variations thereof are intended to cover but not exclude inclusion. For example, a product or device comprising a series of components does not necessarily have to be limited to all the clearly listed components, but may include other components not clearly listed or inherent to these products or devices.
[0072] The term "module" refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic or a combination of hardware or / and software code that can perform functions related to the element.
[0073] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.
[0074] For ease of explanation, the above description has been made in connection with specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or to limit the embodiments to the specific forms disclosed above. According to the above teachings, various modifications and variations can be obtained. The selection and description of the above embodiments are for the purpose of better explaining the principles and practical applications, so that those skilled in the art can better use the embodiments and various different variations of the embodiments suitable for specific use considerations.
[0075] Before introducing the retrieval question-answering method provided by the embodiments of the present application, first summarize the disadvantages of the existing technology below.
[0076] The methods of Graph RAG multi-hop graph retrieval mainly include graph database retrieval, graph theory algorithms, large model LLM graph reasoning, graph neural network GNN, etc. However, when performing multi-hop graph retrieval on large-scale knowledge graphs, these methods all have the problems of low retrieval efficiency and slow speed. For example, the method of graph database retrieval has problems such as low query efficiency for knowledge graphs with tens of millions of levels, the need to equip huge servers, etc. At the same time, the retrieved subgraph is too large and contains too much redundant information, resulting in slow retrieval speed, etc. The method of graph theory algorithms has the problems of less consideration of user input semantic information, high algorithm complexity, and slow speed. The method of large model LLM graph reasoning has the problem that each retrieval path needs to call the large model once, resulting in a large number of large model calls and slow speed. The method of graph neural network GNN has the problem that it needs to be retrained every time it is applied, resulting in slow retrieval speed.
[0077] Embodiment 1:
[0078] Figure 1 A schematic diagram of a retrieval question-answering process provided by an embodiment of the present application is as Figure 1 shown, and this process includes the following steps:
[0079] S101: For the question to be queried, input the question to be queried into the vector encoder of the embedding vector model to obtain the first vector corresponding to each first entity in the question to be queried, and the second vector corresponding to the first relationship between each first entity.
[0080] A retrieval and question - answering method provided by an embodiment of this application is applied to an electronic device, which can be a server, a PC, etc.
[0081] The question to be queried refers to the question input by the user. For example, whether aspirin can treat left - chest pain, what drugs can treat left - chest pain, what can aspirin treat, etc. Among them, the question to be queried input by the user can be one question or multiple questions.
[0082] The first entity is the entity in the question to be queried input by the user, where the entity refers to a specific thing or object, and the first relationship refers to the connection between each pair of first entities in the question to be queried, that is, the edge connecting two entities. The question to be queried input by the user may contain one first entity or multiple first entities; in addition, the question to be queried input by the user may contain one first relationship or multiple first relationships. For example, if the question to be queried input by the user is "whether aspirin can treat left - chest pain", then the first entities are "aspirin" and "left - chest", and the first relationship is "can treat".
[0083] The vector encoder of the embedding vector model is a pre - trained model that can encode an entity or a relationship into a vector of a fixed length, such as the graph neural network GAT, etc.
[0084] Input the question to be queried into the vector encoder of the embedding vector model to obtain the first vector corresponding to each first entity in the question to be queried, and the second vector corresponding to the first relationship between each pair of first entities. For example, input the question to be queried "whether aspirin can treat left - chest pain" input by the user into the vector encoder of the embedding vector model to obtain the first vector a corresponding to the first entity "aspirin", the first vector b corresponding to the first entity "left - chest", and the second vector c corresponding to the first relationship "can treat".
[0085] In a possible implementation, after receiving the query problem A input by the user, before inputting the query problem A into the vector encoder of the embedding vector model, the system inputs the query problem A into the large language model to obtain the query problem B after question disambiguation, where question disambiguation refers to determining the specific meaning of a question through the semantic information of the context. Taking the query problem B after question disambiguation as the query problem A input by the user, input it into the vector encoder of the embedding vector model, and perform subsequent steps, so as to reduce the occurrence of the problem that the vector encoder generates incorrect vectors due to the diversity of the query problems input by the user. For example, if the query problem A input by the user is "What medicine can treat left chest pain", input the query problem A into the large language model to obtain the query problem B after question disambiguation "What medicine can treat left chest pain", and then input "What medicine can treat left chest pain" into the vector encoder of the embedding vector model and perform subsequent steps.
[0086] In a possible implementation, after receiving the query problem input by the user, before inputting the query problem into the vector encoder of the embedding vector model, each first entity in the query problem is determined through the named entity recognition technology NER, and each first entity in the query problem and the vector encoder of the embedding vector model for the query problem are input to perform subsequent steps, so that the vector encoder can accurately generate the vector corresponding to the first entity in the query problem. The process of determining each first entity in the query problem through the named entity recognition technology NER will not be elaborated here.
[0087] S102: For each first entity, determine the first similarity between the first vector corresponding to the first entity and the third vectors corresponding to each second entity stored in the vector database, and determine each associated entity corresponding to the first entity according to each first similarity.
[0088] For each first entity in the query problem, determine the first vector corresponding to the first entity. For example, if the query problem input by the user contains the first entity 1, the first entity 2, and the first entity 3, then determine the first vector a1 corresponding to the first entity 1, the first vector b1 corresponding to the first entity 2, and the first vector c1 corresponding to the first entity 3.
[0089] All second entities in the large-scale knowledge graph and the third vectors corresponding to each second entity are pre-stored in the vector database. For each first entity in the query problem, according to the first vector corresponding to the first entity and the third vectors corresponding to each second entity stored in the vector database, the first similarity between the first entity and each second entity is determined through the cosine similarity algorithm.
[0090] For each first entity, according to the respective first similarities between the first entity and each second entity, determine the respective associated entities corresponding to the first entity. An associated entity refers to an entity that has a relatively high relevance to the first entity in the query problem. Specifically, according to the pre-set selection quantity, select the second entities corresponding to the first similarities with high rankings of the pre-set quantity as the associated entities corresponding to the first entity. Optionally, a similarity threshold can also be pre-set, and according to the pre-set similarity threshold, select the second entities corresponding to the first similarities greater than the similarity threshold as the associated entities corresponding to the first entity.
[0091] For example, in the query problem input by the user, there are first entity 1, first entity 2, and first entity 3. In the vector database, there are second entity 1 and the third vector corresponding to second entity 1, second entity 2 and the third vector corresponding to second entity 2, second entity 3 and the third vector corresponding to second entity 3, second entity 4 and the third vector corresponding to second entity 4, and second entity 5 and the third vector corresponding to second entity 5. Taking the first entity 1 in the query problem as an example for explanation, for the first entity 1 in the query problem, through the cosine similarity algorithm, according to the first vector a1 corresponding to the first entity 1 and the third vector corresponding to the second entity 1 in the vector database, calculate the first similarity S between the first entity 1 and the second entity 1 11 = 1; according to the first vector a1 corresponding to the first entity 1 and the third vector corresponding to the second entity 2, calculate the first similarity S between the first entity 1 and the second entity 2 12 = 0.8; according to the first vector a1 corresponding to the first entity 1 and the third vector corresponding to the second entity 3, calculate the first similarity S between the first entity 1 and the second entity 3 13 = 0.7; according to the first vector a1 corresponding to the first entity 1 and the third vector corresponding to the second entity 4, calculate the first similarity S between the first entity 1 and the second entity 4 14 = 0.5; according to the first vector a1 corresponding to the first entity 1 and the third vector corresponding to the second entity 5, calculate the first similarity S between the first entity 1 and the second entity 5 15= 0.3; If the pre-set selection quantity is 3, then for the associated entities corresponding to the first entity 1 in the problem to be queried, they are the second entity 1, the second entity 2, and the second entity 3; Optionally, if the pre-set similarity threshold is 0.6, then for the associated entities corresponding to the first entity 1 in the problem to be queried, they are the second entity 1, the second entity 2, and the second entity 3. When the similarity threshold is set to be larger, the number of associated entities determined corresponding to the first entity 1 in the problem to be queried is smaller and the similarity is higher. That is to say, the relevance of these associated entities to the first entity 1 in the problem to be queried is higher; When the similarity threshold is set to be smaller, the number of associated entities determined corresponding to the first entity 1 in the problem to be queried is larger. That is to say, the number of associated entities determined corresponding to the first entity 1 in the problem to be queried is larger, that is, the coverage is wider.
[0092] S103: For each first relationship between the first entities, determine the second similarity between the second vector corresponding to the first relationship and the fourth vectors corresponding to each second relationship stored in the vector database, and determine each associated relationship corresponding to the first relationship according to each second similarity.
[0093] For each first relationship of each first entity in the problem to be queried, determine the second vector corresponding to this first relationship. For example, if the problem to be queried input by the user contains the first entity 1, the first entity 2, and the first entity 3, then the first relationships include the first relationship 1 between the first entity 1 and the first entity 2, the first relationship 2 between the first entity 1 and the first entity 3, and the first relationship 3 between the first entity 2 and the first entity 3, and determine the second vector a2 corresponding to the first relationship 1, the second vector b2 corresponding to the first entity 2, and the second vector c2 corresponding to the first entity 3.
[0094] All second relationships in the large-scale knowledge graph and the fourth vectors corresponding to each second relationship are pre-stored in the vector database. For each first relationship, according to the second vector corresponding to this first relationship and the fourth vectors corresponding to each second relationship stored in the vector database, through the cosine similarity algorithm, determine the second similarity between this first relationship and each second relationship.
[0095] For each first relationship, determine each associated relationship corresponding to this first relationship according to each second similarity between this first relationship and each second relationship. The associated relationship refers to the relationship with a relatively high relevance to the first relationship in the problem to be queried. Specifically, according to the pre-set selection quantity, select the second relationships corresponding to the pre-set quantity of top-ranked second similarities as the associated relationships corresponding to this first relationship. Optionally, a similarity threshold can also be pre-set, and according to the pre-set similarity threshold, select the second relationships corresponding to the second similarities greater than this similarity threshold as the associated relationships corresponding to this first relationship.
[0096] For example, the problem to be queried entered by the user contains the first relationship 1, the first relationship 2, and the first relationship 3. The vector database contains the second relationship 1 and the fourth vector corresponding to the second relationship 1, the second relationship 2 and the fourth vector corresponding to the second relationship 2, the second relationship 3 and the fourth vector corresponding to the second relationship 3, the second relationship 4 and the fourth vector corresponding to the second relationship 4, and the second relationship 5 and the fourth vector corresponding to the second relationship 5. Taking the first relationship 1 in the problem to be queried as an example for explanation, for the first relationship 1 in the problem to be queried, through the cosine similarity algorithm, according to the second vector a2 corresponding to the first relationship 1 and the fourth vector corresponding to the second relationship 1 in the vector database, the second similarity S between the first relationship 1 and the second relationship 1 is calculated. 21 = 1; According to the second vector a2 corresponding to the first relationship 1 and the fourth vector corresponding to the second relationship 2, the second similarity S between the first relationship 1 and the second relationship 2 is calculated. 22 = 0.8; According to the second vector a2 corresponding to the first relationship 1 and the fourth vector corresponding to the second relationship 3, the second similarity S between the first relationship 1 and the second relationship 3 is calculated. 23 = 0.7; According to the second vector a2 corresponding to the first relationship 1 and the fourth vector corresponding to the second relationship 4, the second similarity S between the first relationship 1 and the second relationship 4 is calculated. 24 = 0.5; According to the second vector a2 corresponding to the first relationship 1 and the fourth vector corresponding to the second relationship 5, the second similarity S between the first relationship 1 and the second relationship 5 is calculated. 25 = 0.3; If the preset selection quantity is 3, then the associated relationships corresponding to the first relationship 1 in the problem to be queried are the second relationship 1, the second relationship 2, and the second relationship 3; Optionally, if the preset similarity threshold is 0.6, then the associated relationships corresponding to the first relationship 1 in the problem to be queried are the second relationship 1, the second relationship 2, and the second relationship 3. When the similarity threshold is set larger, the number of associated relationships determined corresponding to the first relationship 1 in the problem to be queried is fewer and the similarity is higher. That is to say, these associated relationships have a higher relevance to the first relationship 1 in the problem to be queried; when the similarity threshold is set smaller, the number of associated relationships determined corresponding to the first relationship 1 in the problem to be queried is more. That is to say, the number of associated relationships determined corresponding to the first relationship 1 in the problem to be queried is more, that is, the coverage is wider.
[0097] S104: According to each associated entity and each associated relationship, determine the first subgraph corresponding to the problem to be queried in the pre-constructed large-scale knowledge graph.
[0098] A pre - constructed large - scale knowledge graph refers to a large - scale knowledge graph generated based on the saved original graph files, where the original graph files refer to files related to the query problem, such as medical files. According to the text content in the original graph files, all the third entities and all the third relationships in the original graph files are determined, and a large - scale knowledge graph is constructed based on all the third entities and all the third relationships.
[0099] According to each associated entity determined in step 102 and each associated relationship determined in step 103, determine the first sub - graph corresponding to the query problem in the pre - constructed large - scale knowledge graph, where the first sub - graph includes each associated entity and each associated relationship.
[0100] S105: Input the first sub - graph into the graph encoder in the large - language model to obtain the graph text corresponding to the first sub - graph; input the graph text into the large - language model to generate the answer corresponding to the query problem.
[0101] Input the first sub - graph corresponding to the query problem into the graph encoder in the large - language model to obtain the graph text corresponding to the first sub - graph. That is to say, convert the first sub - graph into multiple graph texts corresponding to the first sub - graph, that is, convert all the information in the first sub - graph into the form of triples, such as the form of entity 1 - relationship 1 - entity 2, entity 1 - relationship 2 - entity 3. The role of the graph encoder is to convert the structural information (entities and relationships) of the first sub - graph into text representation (i.e., graph text) so that subsequent natural language processing tasks (such as question - answering, reasoning, etc.) can directly utilize this information.
[0102] Input all the graph texts into the large - language model to generate the answer corresponding to the query problem.
[0103] In the embodiment of the present application, for each first entity in the query problem, each associated entity of the first entity is determined by the first similarity between the first entity and each second entity saved in the vector database; for each first relationship in the query problem, each associated relationship of the first relationship is determined by the second similarity between the first relationship and each second relationship saved in the vector database; according to each associated entity corresponding to the first entity in the query problem and each associated relationship corresponding to the first relationship, determine the first sub - graph corresponding to the query problem in the pre - constructed large - scale knowledge graph, and the first sub - graph includes the associated entities and associated relationships related to the query problem; according to the graph text corresponding to the first sub - graph, generate the answer corresponding to the query problem, thereby reducing the time to directly retrieve all the entities and relationships related to the query problem in the large - scale knowledge graph, and thus improving the retrieval and question - answering speed.
[0104] Embodiment 2:
[0105] On the basis of improving the retrieval and question-answering speed, in order to enable the first sub-graph determined in step 104 to cover more entities and relationships related to the question to be queried, so that the large language model can accurately generate the answer corresponding to the question to be queried according to this first sub-graph. The embodiments of the present application define the process of determining the first sub-graph corresponding to the question to be queried in the pre-constructed large-scale knowledge graph according to the respective associated entities and respective associated relationships, so that the first sub-graph covers more entities and relationships related to the question to be queried. Figure 2 FIG. 2 is a schematic diagram of a process for determining a first sub-graph provided by an embodiment of the present application. This process includes the following steps:
[0106] S201: Corresponding and matching each associated entity and each associated relationship with each third entity and each third relationship in the large-scale knowledge graph, and determining a first candidate sub-graph corresponding to the question to be queried in the large-scale knowledge graph.
[0107] Corresponding and matching each associated entity determined in step 102 and each associated relationship determined in step 103 with each third entity and each third relationship in the large-scale knowledge graph. The third entity refers to the existing entities (nodes) in the large-scale knowledge graph, and the third relationship refers to the existing relationships (edges) in the large-scale knowledge graph. Through the corresponding matching method, determine the third entity and the third relationship corresponding to the question to be queried in the large-scale knowledge graph, and merge them into a first candidate sub-graph, that is, the first candidate sub-graph includes the third entity and the third relationship corresponding to the question to be queried.
[0108] S202: Determine the one-hop connection entities of each fourth entity in the first candidate sub-graph and the shortest path between each two fourth entities, and obtain the first sub-graph corresponding to the question to be queried.
[0109] For each fourth entity in the first candidate sub-graph determined in step 201, determine the one-hop connection entity of this fourth entity, where the fourth entity is the third entity corresponding to the question to be queried. The one-hop connection entity refers to other entities directly connected to the fourth entity. For example, if the first candidate sub-graph contains the fourth entity 1 and the fourth entity 2, then in the large-scale knowledge graph, determine all the entities directly connected to the fourth entity 1 and all the entities directly connected to the fourth entity 2 respectively. At the same time, determine the shortest path between each two fourth entities in the first candidate sub-graph. The shortest path refers to the path with the fewest relationships (number of edges) connecting two entities in the large-scale knowledge graph. Among them, the shortest path may be formed by one-hop connection or multi-hop connection. For example, the shortest path between the fourth entity 1 and the fourth entity 2 is the fourth entity 1 - the third entity q - the third entity w - the fourth entity 2. That is to say, use nebula to detect the shortest path / n-hop path / 1-hop sub-graph of each entity in pairs... and merge them into a graph.
[0110] In a possible implementation, a high-performance Nebula Graph distributed graph database is selected, and the one-hop connection entities of each fourth entity in the first candidate subgraph and the shortest paths between each fourth entity are retrieved by Nebula distribution, and then merged into the first subgraph. Among them, the better the server performance of Nebula distributed retrieval, the faster the graph retrieval speed.
[0111] In the embodiments of the present application, by corresponding and matching each associated entity and each associated relationship with each third entity and each third relationship in the large-scale knowledge graph, the first candidate subgraph corresponding to the query problem in the large-scale knowledge graph is determined, and then the one-hop connection entities of each fourth entity in the first candidate subgraph and the shortest paths between each fourth entity are determined, so as to expand the scope of the first candidate subgraph, further optimize the structure of the first candidate subgraph, ensure that the determined first subgraph does not miss possible relevant information, and accurately reflect the core relationship of the query problem, and then enable the large language model to accurately generate the answer corresponding to the query problem according to the first subgraph.
[0112] Embodiment 3:
[0113] In order to enable the large language model to quickly and accurately generate the answer corresponding to the query problem according to the first subgraph. The embodiments of the present application also provide another method for determining the first subgraph, so that the system can determine the first subgraph faster. Figure 3 FIG. 3 is a schematic diagram of another process for determining the first subgraph provided by the embodiments of the present application, and this process includes the following steps:
[0114] S301: Determine the respective associated entity identifiers corresponding to the respective associated entities according to the pre-stored corresponding relationship between each entity and the entity identifier.
[0115] The pre-stored corresponding relationship between each entity and the entity identifier, that is, the entity list, which includes all the second entities in the original graph file, the identifiers corresponding to the second entities, and the entity types of the second entities. According to each associated entity determined in step 102, through this entity list, determine the respective associated entity identifiers corresponding to each associated entity. For example, if the entity identifier corresponding to the entity "heart" is 1, then the associated entity identifier corresponding to the associated entity "heart" is 1; if the entity identifier corresponding to the entity "head" is 2, then the associated entity identifier corresponding to the associated entity "head" is 2.
[0116] S302: Determine the respective associated relationship identifiers corresponding to the respective associated relationships according to the pre-stored corresponding relationship between each relationship and the relationship identifier.
[0117] The corresponding relationship between each pre - saved relationship and the relationship identifier, that is, the relationship list. The relationship list includes all the second relationships in the original graph file, the identifiers corresponding to the second relationships, and the relationship types of the second relationships. According to each associated relationship determined in step 102, through this relationship list, determine each associated relationship identifier corresponding to each associated relationship. For example, if the relationship identifier corresponding to the relationship "treatment" is m, then the associated relationship "treatment" corresponds to the associated relationship identifier m; if the relationship identifier corresponding to the relationship "hindrance" is n, then the associated relationship "hindrance" corresponds to the associated relationship identifier n.
[0118] S303: According to each associated entity identifier, each associated relationship identifier, and the graph structure corresponding to the pre - saved large - scale knowledge graph, determine the second candidate sub - graph corresponding to the query problem in the graph structure through the PageRank algorithm for page sorting; where the graph structure includes each entity identifier and each relationship identifier.
[0119] The graph structure corresponding to the pre - saved large - scale knowledge graph refers to the graph structure generated by mapping through the entities and relationships in the large - scale knowledge graph, using the entity list and the relationship list. Among them, the graph structure includes each entity identifier and each relationship identifier.
[0120] The PageRank algorithm for page sorting is a classical graph sorting algorithm. Its core idea is to measure the importance of web pages and can also be extended and applied to any graph structure. Specifically, by calculating the PageRank value of each entity in the graph structure, determine which entities have higher influence or importance in the graph structure, and according to the PageRank value of each entity, screen out the entities and relationships with higher PageRank values.
[0121] The specific process of calculating the PageRank value of each entity identifier in the graph structure corresponding to the pre - saved large - scale knowledge graph through the PageRank algorithm for page sorting is as follows: (1) Initialize a PageRank value for each entity identifier in the graph structure corresponding to the large - scale knowledge graph. Usually, an identical initial value is set for each entity identifier. (2) For each entity identifier, through Iterative calculation until the PageRank value corresponding to the entity identifier is obtained, where PR(u) is the PageRank value of the entity identifier corresponding to entity u; d is the damping factor (usually taken as 0.85), representing the probability of randomly jumping to other entity identifiers; N is the total number of entity identifiers in the large - scale knowledge graph; M(u) is the set of all entity identifiers pointing to the entity identifier corresponding to entity u; L(v) is the out - degree of the entity identifier corresponding to entity v (that is, the number of entity identifiers pointed to by the entity identifier corresponding to entity v).
[0122] In this application, according to each associated entity identifier determined in step 102, each associated relationship identifier determined in step 103, and the graph structure corresponding to the pre-stored large-scale knowledge graph, in the graph structure of the large-scale knowledge graph, each associated entity identifier and each associated relationship identifier are determined; and for each associated entity identifier, centering on this associated entity identifier, according to the PageRank value corresponding to each entity identifier and a preset PageRank threshold, the first entity identifier corresponding to the PageRank value greater than the preset PageRank threshold is filtered out, as well as the first relationship identifier between this associated entity identifier and this first entity identifier, where the first entity identifier refers to each entity identifier in the graph structure corresponding to the pre-stored large-scale knowledge graph; the first relationship identifier refers to each relationship identifier in the graph structure corresponding to the pre-stored large-scale knowledge graph. These first entity identifiers may be directly connected or indirectly connected to this associated entity identifier. If there is a direct connection between this associated entity identifier and the first entity identifier corresponding to the PageRank value greater than the preset PageRank threshold determined, then the first relationship identifier connecting this associated entity identifier and this first entity identifier is selected; if there is an indirect connection between this associated entity identifier and the first entity identifier corresponding to the PageRank value greater than the preset PageRank threshold determined, then the first entity identifier and the first relationship identifier included in the shortest path between this associated entity identifier and this first entity identifier are selected.
[0123] According to the determined each associated entity identifier, each associated relationship identifier, and the first entity identifier and the first relationship identifier related to the query problem in the determined graph structure, a second candidate subgraph is formed, where the second candidate subgraph not only includes the associated entity identifier and the associated relationship identifier directly related to the query problem, but also includes the related first entity identifier and the first relationship identifier filtered out by the PageRank algorithm, so as to ensure the integrity and relevance of the second candidate subgraph.
[0124] In a possible implementation manner, in order to accelerate the speed of graph retrieval, this application can also use a graphics processing unit (GPU) to accelerate the PageRank algorithm to extract a dense graph, that is, the second candidate subgraph. That is to say, use GPU (nvidia cuGraph) to accelerate ppr (pagerank) to extract a dense graph.
[0125] S304: Map the entity identifier and the relationship identifier in the second candidate subgraph to the corresponding entity and relationship to obtain the first subgraph corresponding to the query problem.
[0126] According to the entity list and the relationship list, map the entity identifiers and relationship identifiers in the second candidate subgraph to the corresponding entities and relationships to obtain the first subgraph corresponding to the query problem.
[0127] In the embodiment of the present application, by converting a large-scale knowledge graph that occupies a large amount of memory into a graph structure corresponding to a large-scale knowledge graph that occupies less memory, and using a graphics processing unit (GPU), according to each associated entity identifier, each associated relationship identifier, and the graph structure corresponding to the pre-stored large-scale knowledge graph, determine the second candidate subgraph corresponding to the query problem in the graph structure through the PageRank algorithm. Map the entity identifiers and relationship identifiers in the second candidate subgraph to the corresponding entities and relationships to obtain the first subgraph corresponding to the query problem, so as to efficiently and accurately extract the first subgraph corresponding to the query problem, and then enable the large language model to quickly and accurately generate the answer corresponding to the query problem according to the first subgraph.
[0128] Embodiment 4:
[0129] In order to enable the large language model to quickly and accurately generate the answer corresponding to the query problem according to the first subgraph, after determining the first subgraph in the present application, before inputting the first subgraph into the graph encoder in the large language model, the first subgraph is further optimized to further improve the quality of the first subgraph corresponding to the query problem. Figure 4 The process schematic diagram for optimizing the first subgraph provided by the embodiment of the present application, this process includes the following steps:
[0130] S401: For each fifth entity in the first subgraph, determine the third similarity between the fifth entity and the corresponding first entity.
[0131] The first entity is the entity in the query problem. The fifth entity is the entity in the first subgraph determined in step 202 or step 304.
[0132] In a possible implementation manner, for each fifth entity in the first subgraph, calculate the similarity between the fifth entity and each first entity in the query problem, and select the maximum similarity value as the third similarity between the fifth entity and the corresponding first entity.
[0133] In a possible implementation manner, according to the fifth entity and the corresponding first entity, calculate the semantic similarity between the fifth entity and the corresponding first entity through a pre-trained semantic model (such as a BERT embedding model), and determine the third similarity between the fifth entity and the corresponding first entity with the semantic similarity.
[0134] S402: For each fourth relationship in the first subgraph, determine the fourth similarity between the fourth relationship and the corresponding first relationship.
[0135] The first relationship is the relationship in the problem to be queried. The fourth relationship is the relationship in the first subgraph determined in step 202 or step 304.
[0136] In a possible implementation, for each fourth relationship in the first subgraph, calculate the similarity between the fourth relationship and each first relationship in the problem to be queried, and select the maximum similarity value as the fourth similarity of the fourth relationship.
[0137] In a possible implementation, according to the fourth relationship and the corresponding first relationship, calculate the semantic similarity between the fourth relationship and the corresponding first relationship through a pre-trained semantic model (such as a BERT embedding model), and determine the fourth similarity between the fourth relationship and the corresponding first relationship with this semantic similarity.
[0138] S403: According to the third similarity corresponding to each fifth entity in the first subgraph and the fourth similarity corresponding to each fourth relationship, determine the second subgraph through the graph theory algorithm PCST, and use the second subgraph as the first subgraph to input the first subgraph into the graph encoder of the large language model to obtain the graph text corresponding to the first subgraph.
[0139] The third similarity corresponding to the fifth entity refers to the third similarity between the fifth entity and the corresponding first entity. The fourth similarity corresponding to the fourth relationship refers to the fourth similarity between the fourth relationship and the corresponding first relationship.
[0140] The graph theory algorithm PCST (Prize-Collecting Steiner Tree) is a graph optimization algorithm used to find a subtree in a graph that maximizes the weights (i.e., similarities) of the nodes (entities) and edges (relationships) included in the subtree while minimizing the interference of irrelevant nodes and edges.
[0141] According to the third similarity corresponding to each fifth entity in the first subgraph and the fourth similarity corresponding to each fourth relationship, through the graph theory algorithm PCST, an optimized second subgraph is obtained. The entities and relationships in the second subgraph are more relevant to the first entity and the first relationship in the problem to be queried, and the second subgraph better reflects the core of the problem to be queried.
[0142] After obtaining the optimized second subgraph, use it as the new first subgraph and input it into the graph encoder of the large language model.
[0143] In the embodiments of the present application, by using the third similarity corresponding to each fifth entity in the first sub-graph and the fourth similarity corresponding to each fourth relationship, the second sub-graph is determined through the graph theory algorithm PCST. While removing redundant entities and relationships, the second sub-graph also retains the part most relevant to the query problem, thereby improving the quality of the second sub-graph. The second sub-graph is used as the first sub-graph and input into the graph encoder of the large language model, so that the large language model can quickly and accurately generate the answer corresponding to the query problem according to the first sub-graph.
[0144] Embodiment 5:
[0145] To accelerate the speed of graph retrieval and retrieval-based question answering, when calculating the third similarity corresponding to each fifth entity in the first sub-graph, the present application also limits the calculation process, thereby reducing the system calculation time. Figure 5 FIG. is a schematic diagram of the process for calculating the third similarity corresponding to each fifth entity in the first sub-graph provided by the embodiments of the present application. The process includes the following steps:
[0146] S501: For each fifth entity in the first sub-graph, if the fifth entity is an associated entity, the first similarity between the fifth entity and the corresponding first entity is determined as the third similarity between the fifth entity and the corresponding first entity.
[0147] The fifth entity is the entity in the first sub-graph determined in step 202 or step 304, that is, the associated entity directly corresponding to each first entity in the query problem or the non-associated entity indirectly corresponding thereto. For example, according to associated entity 1, fourth entity 1 is determined in the large-scale knowledge graph, and according to associated entity 2, fourth entity 2 is determined in the large-scale knowledge graph. The shortest path between fourth entity 1 and fourth entity 2 is fourth entity 1 - third entity q - third entity w - fourth entity 2. Then fourth entity 1 and fourth entity 2 are the associated entities directly corresponding to each first entity in the query problem, and third entity q and third entity w are the non-associated entities indirectly corresponding to each first entity in the query problem. Another example is that according to associated entity 1, fourth entity 1 is determined in the large-scale knowledge graph, and the one-hop connected entities of fourth entity 1 are third entity e, third entity f, and third entity g respectively. Then fourth entity 1 is the associated entity directly corresponding to each first entity in the query problem, and third entity e, third entity f, and third entity g are the non-associated entities indirectly corresponding to each first entity in the query problem.
[0148] For each fifth entity in the first sub - graph, if the fifth entity is an associated entity, directly determine the first similarity between the fifth entity and the corresponding first entity as the third similarity between the fifth entity and the corresponding first entity. That is, directly determine the first similarity between the first entity corresponding to the second entity (i.e., the fifth entity) determined in step 102 as the third similarity between the fifth entity and the corresponding first entity. Therefore, the workload of recalculating some fifth entities is reduced.
[0149] S502: If the fifth entity is not an associated entity, respectively determine the fifth similarity between the fifth entity and each first entity, and determine the maximum fifth similarity as the third similarity between the fifth entity and the corresponding first entity.
[0150] If the fifth entity is not an associated entity, that is, the fifth entity is a non - associated entity, which means that the similarity of the fifth entity has not been calculated before. Then, respectively determine the fifth similarity between the fifth entity and each first entity, and determine the maximum fifth similarity as the third similarity between the fifth entity and the corresponding first entity. Specifically: for each fifth entity (non - associated entity), determine the fifth similarity between the fifth entity and each first entity in the query problem, and select the maximum fifth similarity as the third similarity between the fifth entity and the corresponding first entity.
[0151] In the embodiment of the present application, by determining whether each fifth entity in the first sub - graph is an associated entity, according to different similarity calculation strategies, the third similarity between each fifth entity and the corresponding first entity is determined. Specifically, if the fifth entity is an associated entity, directly determine the first similarity between the first entity corresponding to the second entity (i.e., the fifth entity) determined in step 102 as the third similarity between the fifth entity and the corresponding first entity. Therefore, the workload of recalculating some fifth entities is reduced, thereby accelerating the speed of graph retrieval and retrieval - based question - answering.
[0152] Embodiment 6:
[0153] In order to accelerate the speed of graph retrieval and retrieval - based question - answering, when respectively determining the fifth similarity between the fifth entity and each first entity, the present application also limits the calculation process, thereby reducing the calculation time of the system. Figure 6 The figure is a schematic diagram of a process for determining the fifth similarity between a fifth entity and each first entity provided by an embodiment of the present application. The process includes the following steps:
[0154] S601: Determine the first entity type corresponding to the fifth entity, and obtain the first entity type vector corresponding to the first entity type pre - stored.
[0155] The entity type refers to the category of an entity in the knowledge graph (such as "organ", "drug", etc.). For example, if the fifth entity is "heart", its corresponding first entity type is "organ"; if the fifth entity is "aspirin", its corresponding first entity type is "drug".
[0156] For each fifth entity, that is, the fifth entity belonging to the non-associated entities, according to the entity list, determine the first entity type corresponding to the fifth entity, and obtain the first entity type vector corresponding to the first entity type pre-stored in the vector database. Among them, in the vector database, the entity types corresponding to all entities in the large-scale knowledge graph and the entity type vectors corresponding to each entity type are pre-stored, that is, the entity type vectors can be pre-calculated and stored, and directly called when used, avoiding the time-consuming of real-time calculation.
[0157] In a large-scale knowledge graph, the number of entities may reach millions or even tens of millions, but the number of entity types is usually only a few hundred. By calculating the similarity based on entity types, the amount of calculation can be greatly reduced. For example, in a large-scale knowledge graph with 10,000 entities but only 100 entity types, the similarity calculation only needs to be carried out between 100 type vectors, rather than between 10,000 entities.
[0158] S602: For each first entity, determine the second entity type corresponding to the first entity, and obtain the second entity type vector corresponding to the second entity type pre-stored; determine the similarity between the first entity type vector and the second entity type vector as the fifth similarity between the fifth entity and the first entity.
[0159] For each first entity in the query problem to be queried, through the entity list, determine the second entity type corresponding to the first entity, and obtain the second entity type vector corresponding to the second entity type pre-stored in the vector database.
[0160] For each fifth entity (non-associated entity) and each first entity in the query problem to be queried, according to the first entity type vector and the second entity type vector corresponding to the first entity determined in step 601, determine the fifth similarity between the fifth entity and the first entity through the cosine similarity algorithm.
[0161] In a possible implementation, the similarity between the entity types corresponding to each first entity in the question to be queried and the entity types corresponding to each second entity stored in the vector database can also be pre-saved. That is, the similarity between the entity types of each pair of first entities and the entity types corresponding to each second entity stored in the vector database can also be pre-computed and saved, and directly called when in use, avoiding the time-consuming of real-time calculation. When determining the fifth similarity between the fifth entity and each first entity, for each fifth entity, according to the first entity type corresponding to the fifth entity, the similarity between the first entity type corresponding to the fifth entity and the second entity types corresponding to each first entity can be directly read from the database, so as to determine the fifth similarity between the fifth entity and the first entity.
[0162] For ease of understanding, the process of directly reading from the database the similarity between the first entity type corresponding to the fifth entity and the second entity types corresponding to each first entity according to the first entity type corresponding to the fifth entity is explained in the following table. Table 1 includes the entity type a corresponding to the first entity 1 in the question to be queried, the entity type b corresponding to the first entity 2, the entity type c corresponding to the first entity 3, the entity types corresponding to each second entity stored in the vector database, such as entity type A, entity type B, entity type C, entity type D, entity type E, and the similarity between the entity types corresponding to each first entity and the entity types corresponding to each second entity stored in the vector database.
[0163] Entity type A Entity type B Entity type C Entity type D Entity type E Entity type a <![CDATA[X 11 > <![CDATA[X 12 > <![CDATA[X 13 > <![CDATA[X 14 > <![CDATA[X 15 > Entity type b <![CDATA[Y 11 > <![CDATA[Y 12 > <![CDATA[Y 13 > <![CDATA[Y 14 > <![CDATA[Y 15 > Entity type c <![CDATA[W 11 > <![CDATA[W 12 > <![CDATA[W 13 > <![CDATA[W 14 > <![CDATA[W 15 >
[0164] For each fifth entity (non-associated entity), if the first entity type corresponding to the fifth entity is entity type C, then directly read X 13 、Y 13 、W 13 and determine the fifth similarity between the fifth entity and each first entity to be X 13 、Y 13 、W 13 .
[0165] In the embodiments of the present application, through the similarity calculation based on entity types, the amount of calculation for entities is greatly reduced, and the entity type vectors are pre-saved and directly called when in use, avoiding the time-consuming of real-time calculation, thereby improving the speed of accelerating graph retrieval and retrieval Q&A.
[0166] Embodiment 7:
[0167] In order to accelerate the speed of graph retrieval and retrieval Q&A, when calculating the fourth similarity corresponding to each fourth relationship in the first subgraph, the present application also limits the calculation process, thereby reducing the system calculation time. Figure 7Schematic diagram of the process for calculating the fourth similarity corresponding to each fourth relationship in the first sub - graph provided by the embodiment of the present application. This process includes the following steps:
[0168] S701: For each fourth relationship in the first sub - graph, if the fourth relationship is an associated relationship, determine the second similarity between the fourth relationship and the corresponding first relationship as the fourth similarity between the fourth relationship and the corresponding first relationship.
[0169] The fourth relationship is the relationship in the first sub - graph determined in step 202 or step 304, that is, the associated relationship directly corresponding to each first relationship in the query problem or the non - associated relationship indirectly corresponding to it.
[0170] For each fourth relationship in the first sub - graph, if the fourth relationship is an associated relationship, directly determine the second similarity between the fourth relationship and the corresponding first relationship as the fourth similarity between the fourth relationship and the corresponding first relationship. That is, directly determine the second similarity between the first relationship corresponding to the second relationship (i.e., the fourth relationship) determined in step 102 as the fourth similarity between the fourth relationship and the corresponding first relationship. Therefore, the workload of recalculating some fourth relationships is reduced.
[0171] S702: If the fourth relationship is not an associated relationship, respectively determine the sixth similarity between the fourth relationship and each first relationship, and determine the maximum sixth similarity as the fourth similarity between the fourth relationship and the corresponding first relationship.
[0172] If the fourth relationship is not an associated relationship, that is, the fourth relationship is a non - associated relationship, which means that the similarity of this fourth relationship has not been calculated before. Then, respectively determine the sixth similarity between the fourth relationship and each first relationship, and determine the maximum sixth similarity as the fourth similarity between the fourth relationship and the corresponding first relationship. Specifically: for each fourth relationship (non - associated relationship), determine the sixth similarity between the fourth relationship and each first relationship in the query problem, and select the maximum sixth similarity as the fourth similarity between the fourth relationship and the corresponding first relationship.
[0173] In the embodiment of the present application, by judging whether each fourth relationship in the first sub - graph is an associated relationship, according to different similarity calculation strategies, determine the fourth similarity between each fourth relationship and the corresponding first relationship. Specifically, if the fourth relationship is an associated relationship, directly determine the second similarity between the first relationship corresponding to the second relationship (i.e., the fourth relationship) determined in step 102 as the fourth similarity between the fourth relationship and the corresponding first relationship. Therefore, the workload of recalculating some fourth relationships is reduced, thus accelerating the speed of graph retrieval and retrieval - based question - answering.
[0174] Example 8:
[0175] To accelerate graph retrieval and retrieval question - answering speed, when determining the sixth similarity between the fourth relationship and each first relationship respectively, the present application also limits the calculation process, thereby reducing the system calculation time. Figure 8 FIG. 451 is a schematic diagram of a process for determining the sixth similarity between a fourth relationship and each first relationship provided by an embodiment of the present application. This process includes the following steps:
[0176] S801: Determine the first relationship type corresponding to the fourth relationship, and obtain the first relationship type vector corresponding to the first relationship type pre - stored.
[0177] The relationship type refers to the category of the relationship in the knowledge graph (such as "treatment plan", "etiology", etc.). For example, if the fourth relationship is "alleviation", the corresponding first relationship type is "treatment plan"; if the fourth relationship is "aggravation", the corresponding first relationship type is "etiology".
[0178] For each fourth relationship, that is, the fourth relationship belonging to the non - associated relationship, according to the relationship list, determine the first relationship type corresponding to this fourth relationship, and obtain the first relationship type vector corresponding to this first relationship type pre - stored in the vector database. The vector database pre - stores the relationship types corresponding to all relationships in the large - scale knowledge graph and the relationship type vectors corresponding to each relationship type. That is, the relationship type vectors can be pre - calculated and stored, and directly called when used, avoiding the time consumption of real - time calculation.
[0179] In a large - scale knowledge graph, the number of relationships may reach tens of thousands or even millions, but the number of relationship types is usually only a few hundred. By calculating similarity based on relationship types, the calculation amount can be greatly reduced. For example, there are 10,000 relationships in a large - scale knowledge graph, but only 100 relationship types, then the similarity calculation only needs to be carried out between 100 type vectors instead of between 10,000 relationships.
[0180] S802: For each of the first relationships, determine the second relationship type corresponding to the first relationship, and obtain the second relationship type vector corresponding to the second relationship type pre - stored; determine the similarity between the first relationship type vector and the second relationship type vector as the sixth similarity between the fourth relationship and the first relationship.
[0181] For each first relationship in the query question to be answered, through the relationship list, determine the second relationship type corresponding to this first relationship, and obtain the second relationship type vector corresponding to the second relationship type pre - stored in the vector database.
[0182] For each of the fourth relationships (non - associated relationships) and each of the first relationships in the query problem, according to the first relationship type vector determined in step 601 and the second relationship type vector corresponding to the first relationship, the fifth similarity between the fourth relationship and the first relationship is determined through the cosine similarity algorithm.
[0183] In a possible implementation manner, the similarities between the relationship types corresponding to each of the first relationships in the query problem and the relationship types corresponding to each of the second relationships stored in the vector database can also be pre - saved. That is, the similarities between the relationship types of each pair of first relationships and the relationship types corresponding to each of the second relationships stored in the vector database can also be pre - calculated and saved, and directly called when used, avoiding the time consumption of real - time calculation. When determining the fifth similarity between the fourth relationship and each of the first relationships, for each of the fourth relationships, according to the first relationship type corresponding to the fourth relationship, the similarity between the first relationship type corresponding to the fourth relationship and the second relationship types corresponding to each of the first relationships can be directly read from the database, so as to determine the fifth similarity between the fourth relationship and the first relationship.
[0184] For the sake of easy understanding, the process of directly reading from the database the similarity between the first relationship type corresponding to the fourth relationship and the second relationship types corresponding to each of the first relationships is explained below in the form of a table. Table 1 includes the relationship type e corresponding to the first relationship 1 in the query problem, the relationship type f corresponding to the first relationship 2, the relationship type g corresponding to the first relationship 3, the relationship types corresponding to each of the second relationships stored in the vector database, such as relationship type R, relationship type T, relationship type U, relationship type V, relationship type Z, and the similarities between the relationship types corresponding to each of the first relationships and the relationship types corresponding to each of the second relationships stored in the vector database.
[0185] Relationship type R Relationship type T Relationship type U Relationship type V Relationship type Z Relationship type e <![CDATA[F 21 > <![CDATA[F 22 > <![CDATA[F 23 > <![CDATA[F 24 > <![CDATA[F 25 <!-- 17 -->]]> Relationship type f <![CDATA[G 21 > <![CDATA[G 22 > <![CDATA[G 23 > <![CDATA[G 24 > <![CDATA[G 25 > Relationship type g <![CDATA[H 21 > <![CDATA[H 22 > <![CDATA[H 23 > <![CDATA[H 24 > <![CDATA[H 25 >
[0186] For each of the fourth relationships (non - associated relationships), if the first relationship type corresponding to the fourth relationship is relationship type U, then directly read F 23 、G 23 、H 23 , and determine that the fifth similarity between the fourth relationship and each of the first relationships is F 23 、G 23 、H 23 .
[0187] In the embodiments of the present application, through the similarity calculation based on the relationship type, the amount of calculation for relationships is greatly reduced, and the relationship type vectors are pre - saved and directly called when used, avoiding the time consumption of real - time calculation, thereby further improving the speed of accelerating graph retrieval and retrieval - based question - answering.
[0188] Example 9:
[0189] To make the semantic information of the relationship more accurate and support complex queries (reasoning of multi-hop relationships), the present application also defines the process of determining the second vector corresponding to the first relationship between each first entity, so as to make the semantic information of each first relationship more accurate and improve the quality of retrieval and question answering.
[0190] Specifically: for each first relationship, input the first relationship and the two first entities corresponding to the first relationship into the vector encoder to obtain the second vector corresponding to the first relationship.
[0191] The first relationship refers to the relationship in the question to be queried. For example, "treatment". The two first entities corresponding to the first relationship refer to the two entities connected by the first relationship. For example, aspirin - treatment - chest, then "aspirin" and "chest" are the two entities connected by the first relationship.
[0192] When calculating the relationship vector, input the first relationship and the two first entities corresponding to the first relationship into the vector encoder to obtain the second vector corresponding to the first relationship. That is to say, input "aspirin", "treatment", and "chest" into the vector encoder, and the vector encoder outputs the second vector corresponding to "treatment".
[0193] In the embodiment of the present application, by inputting the first relationship and the two first entities corresponding to the first relationship into the vector encoder, the second vector corresponding to the first relationship is obtained, thereby making the semantic information of each first relationship more accurate and improving the quality of retrieval and question answering.
[0194] Example 10:
[0195] For ease of understanding, the embodiment of the present application explains the determination of the second subgraph by the graph theory algorithm PCST according to the third similarity corresponding to each fifth entity in the first subgraph and the fourth similarity corresponding to each fourth relationship. Specifically: obtain each third candidate subgraph according to the first subgraph and the graph theory algorithm PCST, and determine the similarity sum value corresponding to each third candidate subgraph according to the third similarity corresponding to each fifth entity and the fourth similarity corresponding to each fourth relationship; determine the third candidate subgraph corresponding to the largest similarity sum value as the second subgraph.
[0196] According to the first subgraph and the graph theory algorithm PCST, the first subgraph is divided into multiple third candidate subgraphs. For example, if the first subgraph includes 100 fifth entities and 50 fourth relationships, then the obtained third candidate subgraph may be a third candidate subgraph composed of 50 fifth entities and 20 fourth relationships Figure 1, the third candidate subgraph composed of 55 fifth entities and 23 fourth relationships Figure 2 and so on.
[0197] Determine the similarity sum value corresponding to each third candidate subgraph according to the third similarity corresponding to each fifth entity determined in step 401 and step 402 and the fourth similarity corresponding to each fourth relationship.
[0198] Select the third candidate subgraph corresponding to the maximum similarity sum value as the second subgraph according to the similarity sum value corresponding to each third candidate subgraph. That is, assign the similarity between the user query retrieved by vector retrieval and the entity and edge (relationship) to the first subgraph, and apply the PCST method to generate a connected tree to maximize the sum of rewards of nodes (entities) and edges (relationships).
[0199] Embodiment 11:
[0200] This embodiment of the present application briefly describes the overall process of the retrieval and question-answering method of the present application. Figure 9 It is a schematic diagram of the main process of a retrieval and question-answering provided by an embodiment of the present application. As Figure 9 shown, in the offline preparation stage / production stage, obtain the knowledge graph, entity list (Node list), and relationship list (Edgelist) from the original graph file in the graph database, then restore the knowledge graph file (Build cmekg index), and obtain the embedding vectors of entities and relationships (Node / Edge embedding dict) through the embedding vector model. Save the original entity list, relationship list, and the embedding vectors of entities and relationships to the vector database.
[0201] In the actual application stage, for the input query problem to be queried, optionally, perform LLM question disambiguation on the query problem to be queried, or perform entity recognition through named recognition technology (SLM / LLM NER) to obtain the entities in the query problem to be queried. Then, through the vector retrieval service (Faiss retrieval), that is, in step 102, for each of the first entities, determine the first similarity between the first vector corresponding to the first entity and the third vectors corresponding to each of the second entities stored in the vector database, and determine each associated entity corresponding to the first entity according to each first similarity; in step 103, for the first relationship between each of the first entities, determine the second similarity between the second vector corresponding to the first relationship and the fourth vectors corresponding to each of the second relationships stored in the vector database, and determine each associated relationship corresponding to the first relationship according to each second similarity, to obtain a preset number of entities and relationships (TOP k Nodes / edges), that is, a preset number of associated entities and associated relationships; according to the preset number of associated entities and associated relationships, perform knowledge graph retrieval service (knowledge retrieval) and PCST graph theory algorithm pruning through the multi-hop graph retrieval service to obtain a second subgraph (Sub graph); according to the entity list and relationship list, determine the graph text (triple) corresponding to the second subgraph through the graph encoder (Build graph or Encode graph); input the graph text (triple) corresponding to the second subgraph into the large language model LLM to generate an answer corresponding to the query problem to be queried.
[0202] Embodiment 12:
[0203] Based on the same inventive concept, an embodiment of the present application provides a retrieval and question-answering device. Figure 10 For the structural schematic diagram of a retrieval and question-answering device provided by an embodiment of the present application, please refer to Figure 10 , the device includes:
[0204] A processing module 1001, configured to input the query problem to be queried into a vector encoder of an embedding vector model for the query problem to be queried, to obtain a first vector corresponding to each first entity in the query problem to be queried, and a second vector corresponding to the first relationship between each of the first entities.
[0205] A determination module 1002, configured to determine, for each of the first entities, a first similarity between the first vector corresponding to the first entity and the third vectors corresponding to the respective second entities stored in the vector database, and determine the respective associated entities corresponding to the first entity according to the respective first similarities; for the first relationship between each of the first entities, determine a second similarity between the second vector corresponding to the first relationship and the fourth vectors corresponding to the respective second relationships stored in the vector database, and determine the respective associated relationships corresponding to the first relationship according to the respective second similarities; and determine a first subgraph corresponding to the query problem in a pre-constructed large-scale knowledge graph according to the respective associated entities and the respective associated relationships.
[0206] A generation module 1003, configured to input the first subgraph into a graph encoder in a large language model to obtain a graph text corresponding to the first subgraph; and input the graph text into the large language model to generate an answer corresponding to the query problem.
[0207] Further, the determination module 1002 is specifically configured to perform corresponding matching between the respective associated entities and the respective associated relationships and the respective third entities and the respective third relationships in the large-scale knowledge graph, and determine a first candidate subgraph corresponding to the query problem in the large-scale knowledge graph; and determine one-hop connection entities of the respective fourth entities in the first candidate subgraph and the shortest paths between the respective fourth entities to obtain a first subgraph corresponding to the query problem.
[0208] Further, the determination module 1002 is specifically configured to determine the respective associated entity identifiers corresponding to the respective associated entities according to the corresponding relationship between each entity and the entity identifier stored in advance; determine the respective associated relationship identifiers corresponding to the respective associated relationships according to the corresponding relationship between each relationship and the relationship identifier stored in advance; determine a second candidate subgraph corresponding to the query problem in the graph structure according to the respective associated entity identifiers, the respective associated relationship identifiers, and the graph structure corresponding to the large-scale knowledge graph stored in advance through the PageRank algorithm for page sorting, where the graph structure includes each entity identifier and each relationship identifier; and map the entity identifiers and relationship identifiers in the second candidate subgraph to the corresponding entities and relationships to obtain a first subgraph corresponding to the query problem.
[0209] Further, the determining module 1002 is further configured to determine, for each fifth entity in the first sub-graph, a third similarity between the fifth entity and the corresponding first entity; determine, for each fourth relationship in the first sub-graph, a fourth similarity between the fourth relationship and the corresponding first relationship; determine a second sub-graph through the graph theory algorithm PCST according to the third similarity corresponding to each fifth entity in the first sub-graph and the fourth similarity corresponding to each fourth relationship, and use the second sub-graph as the first sub-graph to perform the step of inputting the first sub-graph into the graph encoder of the large language model to obtain the graph text corresponding to the first sub-graph.
[0210] Further, the determining module 1002 is specifically configured to, for each fifth entity in the first sub-graph, if the fifth entity is an associated entity, determine the first similarity between the fifth entity and the corresponding first entity as the third similarity between the fifth entity and the corresponding first entity; if the fifth entity is not an associated entity, determining the third similarity between the fifth entity and the corresponding first entity includes: respectively determining a fifth similarity between the fifth entity and each first entity, and determining the maximum fifth similarity as the third similarity between the fifth entity and the corresponding first entity.
[0211] Further, the determining module 1002 is specifically configured to determine the first entity type corresponding to the fifth entity, and obtain the first entity type vector corresponding to the first entity type saved in advance; for each first entity, determine the second entity type corresponding to the first entity, and obtain the second entity type vector corresponding to the second entity type saved in advance; determine the similarity between the first entity type vector and the second entity type vector as the fifth similarity between the fifth entity and the first entity.
[0212] Further, the determining module 1002 is specifically configured to, for each fourth relationship in the first sub-graph, if the fourth relationship is an associated relationship, determine the second similarity between the fourth relationship and the corresponding first relationship as the fourth similarity between the fourth relationship and the corresponding first relationship; if the fourth relationship is not an associated relationship, determining the fourth similarity between the fourth relationship and the corresponding first relationship includes: respectively determining a sixth similarity between the fourth relationship and each first relationship, and determining the maximum sixth similarity as the fourth similarity between the fourth relationship and the corresponding first relationship.
[0213] Further, the determining module 1002 is specifically configured to determine a first relationship type corresponding to the fourth relationship, and obtain a first relationship type vector corresponding to the first relationship type that is pre-stored; for each of the first relationships, determine a second relationship type corresponding to the first relationship, and obtain a second relationship type vector corresponding to the second relationship type that is pre-stored; and determine the similarity between the first relationship type vector and the second relationship type vector as the sixth similarity between the fourth relationship and the first relationship.
[0214] Further, the determining module 1002 is specifically configured to input, for each first relationship, the first relationship and two first entities corresponding to the first relationship into the vector encoder, so as to obtain a second vector corresponding to the first relationship.
[0215] Further, the determining module 1002 is specifically configured to obtain each third candidate subgraph according to the first subgraph and the graph theory algorithm PCST, determine a similarity sum value corresponding to each third candidate subgraph according to the third similarity corresponding to each of the fifth entities and the fourth similarity corresponding to each of the fourth relationships; and determine the third candidate subgraph corresponding to the maximum similarity sum value as the second subgraph.
[0216] Embodiment 13:
[0217] Based on the same inventive concept, an embodiment of the present application provides an electronic device, and this device can implement the steps of the retrieval and question-answering method discussed above. Figure 11 FIG. is a schematic structural diagram of an electronic device provided by an embodiment of the present application, as Figure 11 shown, including: a processor 1101, a communication interface 1102, a memory 1103, and a communication bus 1104. Among them, the processor 1101, the communication interface 1102, and the memory 1103 communicate with each other through the communication bus 1104;
[0218] A computer program is stored in the memory 1103. When the program is executed by the processor 1101, the processor 1101 is caused to execute the following steps:
[0219] For a to-be-query problem, input the to-be-query problem into a vector encoder of an embedding vector model to obtain a first vector corresponding to each first entity in the to-be-query problem, and a second vector corresponding to a first relationship between each pair of first entities;
[0220] For each of the first entities, determine the first similarity between the first vector corresponding to the first entity and the third vectors corresponding to the respective second entities stored in the vector database. Based on the respective first similarities, determine the respective associated entities corresponding to the first entity; for the first relationship between each pair of the first entities, determine the second similarity between the second vector corresponding to the first relationship and the fourth vectors corresponding to the respective second relationships stored in the vector database. Based on the respective second similarities, determine the respective associated relationships corresponding to the first relationship;
[0221] Based on the respective associated entities and respective associated relationships, determine a first subgraph corresponding to the query problem in a pre-constructed large-scale knowledge graph;
[0222] Input the first subgraph into a graph encoder in a large language model to obtain a graph text corresponding to the first subgraph; input the graph text into the large language model to generate an answer corresponding to the query problem.
[0223] Further, determining a first subgraph corresponding to the query problem in a pre-constructed large-scale knowledge graph based on the respective associated entities and respective associated relationships includes:
[0224] Perform corresponding matching between the respective associated entities and respective associated relationships and the respective third entities and respective third relationships in the large-scale knowledge graph to determine a first candidate subgraph corresponding to the query problem in the large-scale knowledge graph;
[0225] Determine the one-hop connection entities of each fourth entity in the first candidate subgraph and the shortest paths between each pair of the fourth entities to obtain a first subgraph corresponding to the query problem.
[0226] Further, determining a first subgraph corresponding to the query problem in a pre-constructed large-scale knowledge graph based on the respective associated entities and respective associated relationships includes:
[0227] Based on the corresponding relationship between each entity and entity identifier pre-stored, determine the respective associated entity identifiers corresponding to the respective associated entities; based on the corresponding relationship between each relationship and relationship identifier pre-stored, determine the respective associated relationship identifiers corresponding to the respective associated relationships;
[0228] Based on the respective associated entity identifiers, the respective associated relationship identifiers, and the graph structure corresponding to the pre-stored large-scale knowledge graph, determine a second candidate subgraph corresponding to the query problem in the graph structure through the PageRank algorithm; wherein, the graph structure includes each entity identifier and each relationship identifier;
[0229] Map the entity identifiers and relationship identifiers in the second candidate subgraph to corresponding entities and relationships to obtain the first subgraph corresponding to the query problem.
[0230] Further, after determining the first subgraph corresponding to the query problem in the pre-constructed large-scale knowledge graph according to the respective associated entities and associated relationships, and before inputting the first subgraph into the graph encoder in the large language model to obtain the graph text corresponding to the first subgraph, the method further includes:
[0231] For each fifth entity in the first subgraph, determine the third similarity between the fifth entity and the corresponding first entity; for each fourth relationship in the first subgraph, determine the fourth similarity between the fourth relationship and the corresponding first relationship.
[0232] According to the third similarity corresponding to each fifth entity in the first subgraph and the fourth similarity corresponding to each fourth relationship, determine the second subgraph through the graph theory algorithm PCST, and use the second subgraph as the first subgraph to perform the step of inputting the first subgraph into the graph encoder in the large language model to obtain the graph text corresponding to the first subgraph.
[0233] Further, determining the third similarity between each fifth entity in the first subgraph and the corresponding first entity includes:
[0234] For each fifth entity in the first subgraph, if the fifth entity is an associated entity, determine the first similarity between the fifth entity and the corresponding first entity as the third similarity between the fifth entity and the corresponding first entity.
[0235] If the fifth entity is not an associated entity, determining the third similarity between the fifth entity and the corresponding first entity includes:
[0236] Respectively determine the fifth similarity between the fifth entity and each first entity, and determine the maximum fifth similarity as the third similarity between the fifth entity and the corresponding first entity.
[0237] Further, the respectively determining the fifth similarity between the fifth entity and each first entity includes:
[0238] Determine the first entity type corresponding to the fifth entity, and obtain the first entity type vector corresponding to the first entity type saved in advance.
[0239] For each of the first entities, determine the second entity type corresponding to the first entity, and obtain the second entity type vector corresponding to the second entity type pre-stored; determine the similarity between the first entity type vector and the second entity type vector as the fifth similarity between the fifth entity and the first entity.
[0240] Further, determining the fourth similarity between each fourth relationship in the first subgraph and the corresponding first relationship includes:
[0241] For each fourth relationship in the first subgraph, if the fourth relationship is an association relationship, determine the second similarity between the fourth relationship and the corresponding first relationship as the fourth similarity between the fourth relationship and the corresponding first relationship;
[0242] If the fourth relationship is not an association relationship, determining the fourth similarity between the fourth relationship and the corresponding first relationship includes:
[0243] Respectively determine the sixth similarity between the fourth relationship and each first relationship, and determine the maximum sixth similarity as the fourth similarity between the fourth relationship and the corresponding first relationship.
[0244] Further, the respectively determining the sixth similarity between the fourth relationship and each first relationship includes:
[0245] Determine the first relationship type corresponding to the fourth relationship, and obtain the first relationship type vector corresponding to the first relationship type pre-stored;
[0246] For each of the first relationships, determine the second relationship type corresponding to the first relationship, and obtain the second relationship type vector corresponding to the second relationship type pre-stored; determine the similarity between the first relationship type vector and the second relationship type vector as the sixth similarity between the fourth relationship and the first relationship.
[0247] Further, the process of determining the second vector corresponding to the first relationship between each pair of first entities includes:
[0248] For each first relationship, input the first relationship and the two first entities corresponding to the first relationship into the vector encoder to obtain the second vector corresponding to the first relationship.
[0249] Further, according to the third similarity corresponding to each fifth entity in the first subgraph and the fourth similarity corresponding to each of the fourth relationships, determine the second subgraph through the graph theory algorithm PCST, including:
[0250] According to the first sub - figure and the graph - theory algorithm PCST, each third candidate sub - figure is obtained. According to the third similarity corresponding to each of the fifth entities and the fourth similarity corresponding to each of the fourth relationships, the similarity sum value corresponding to each third candidate sub - figure is determined; the third candidate sub - figure corresponding to the maximum similarity sum value is determined as the second sub - figure.
[0251] Since the principle of the above - mentioned electronic device for solving problems is similar to that of the retrieval and question - answering method, the implementation of the above - mentioned electronic device can refer to the embodiments of the method, and the repeated parts will not be elaborated.
[0252] The communication bus mentioned in the above - mentioned electronic device can be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience of representation, only a thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface 1102 is used for communication between the above - mentioned electronic device and other devices. The memory can include a Random Access Memory (RAM), and can also include a Non - Volatile Memory (NVM), such as at least one disk memory. Optionally, the memory can also be at least one storage device located far from the aforementioned processor.
[0253] The above - mentioned processor can be a general - purpose processor, including a central processing unit, a Network Processor (NP), etc.; it can also be a Digital Signal Processing (DSP), an application - specific integrated circuit, a field - programmable gate array, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0254] Embodiment 14:
[0255] Based on the same inventive concept, an embodiment of the present application provides a computer - readable storage medium. The computer - readable storage medium stores a computer program executable by a processor. When the program runs on the processor, it causes the processor to execute the retrieval and question - answering method described in any of the foregoing discussions. Since the principle of the above - mentioned computer - readable storage medium for solving problems is similar to that of the retrieval and question - answering method, the implementation of the above - mentioned computer - readable storage medium can refer to the implementation of the method, and the repeated parts will not be elaborated.
[0256] Embodiment 15:
[0257] Based on the same application concept, an embodiment of the present application further provides a computer program product, which includes computer program code. When the computer program code runs on a computer, it causes the computer to execute the retrieval and question-answering method described in any of the foregoing discussions. Since the principle of solving problems by the above computer program product is similar to that of the retrieval and question-answering method, the implementation of the above computer program product can refer to the implementation of the method, and the repeated parts will not be described again.
[0258] In the present application, for each first entity in the question to be queried, various associated entities of the first entity are determined through the first similarity between the first entity and each second entity stored in the vector database; for each first relationship in the question to be queried, various associated relationships of the first relationship are determined through the second similarity between the first relationship and each second relationship stored in the vector database; according to the various associated entities corresponding to the first entity and the various associated relationships corresponding to the first relationship in the question to be queried, a first sub-graph corresponding to the question to be queried in the pre-constructed large-scale knowledge graph is determined. The first sub-graph includes associated entities and associated relationships related to the question to be queried; according to the graph text corresponding to the first sub-graph, an answer corresponding to the question to be queried is generated, thereby reducing the time for directly retrieving all entities and relationships related to the question to be queried in the large-scale knowledge graph, and thus improving the retrieval and question-answering speed.
[0259] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0260] The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or block in the flowcharts and / or block diagrams, and the combination of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate means for implementing the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0261] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means embodying the functionality specified in the flowchart Figure 1 one or more flowcharts and / or boxes Figure 1 specified in the box or boxes.
[0262] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, whereby the instructions executed on the computer or other programmable apparatus provide steps for implementing the functionality specified in the flowchart Figure 1 one or more flowcharts and / or boxes Figure 1 specified in the box or boxes.
[0263] Obviously, those skilled in the art can make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalent technologies, this application is also intended to include these modifications and variations.
Claims
1. A retrieval question answering method, characterized in that: The method comprises: For the question to be queried, input the question to be queried into a vector encoder of an embedding vector model to obtain a first vector corresponding to each first entity in the question to be queried and a second vector corresponding to a first relationship between each first entity; For each of the first entities, determine a first similarity between a first vector corresponding to the first entity and a third vector corresponding to each of the second entities stored in a vector database, and determine each of the associated entities corresponding to the first entity according to each of the first similarities; for a first relationship between each of the first entities, determine a second similarity between a second vector corresponding to the first relationship and a fourth vector corresponding to each of the second relationships stored in the vector database, and determine each of the associated relationships corresponding to the first relationship according to each of the second similarities; According to the associated entities and the associated relationships, determine a first subgraph corresponding to the query question in a pre-constructed large-scale knowledge graph; The first subgraph is input into a graph encoder in a large language model to obtain a graph text corresponding to the first subgraph; and the graph text is input into the large language model to generate an answer corresponding to the question to be queried.
2. The method according to claim 1, characterized in that: Determining, according to the associated entities and the associated relationships, a first subgraph corresponding to the to-be-queried question in a pre-constructed large-scale knowledge graph includes: Match the associated entities and associated relationships with the third entities and third relationships in the large-scale knowledge graph, and determine a first candidate subgraph in the large-scale knowledge graph corresponding to the query question; A one-hop connection entity of each fourth entity in the first candidate subgraph and a shortest path between each fourth entity are determined to obtain a first subgraph corresponding to the question to be queried.
3. The method according to claim 1, characterized in that Determining, according to the associated entities and the associated relationships, a first subgraph corresponding to the to-be-queried question in a pre-constructed large-scale knowledge graph includes: Determine the associated entity identifiers corresponding to the associated entities according to the pre-stored correspondence between the entities and the entity identifiers; determine the associated relationship identifiers corresponding to the associated relationships according to the pre-stored correspondence between the relationships and the relationship identifiers; According to the associated entity identifiers, the associated relationship identifiers, and the pre-saved graph structure corresponding to the large-scale knowledge graph, a second candidate subgraph corresponding to the query question in the graph structure is determined by a page ranking algorithm PageRank; wherein the graph structure includes the entity identifiers and the relationship identifiers; The entity identifiers and relationship identifiers in the second candidate subgraph are mapped to corresponding entities and relationships to obtain a first subgraph corresponding to the question to be queried.
4. The method according to any one of claims 1 to 3, characterized in that: After determining a first subgraph corresponding to the query question in a pre-constructed large-scale knowledge graph according to each associated entity and each associated relationship, and inputting the first subgraph into a graph encoder in a large language model, before obtaining a graph text corresponding to the first subgraph, the method further includes: For each fifth entity in the first subgraph, determining a third similarity between the fifth entity and the corresponding first entity; for each fourth relationship in the first subgraph, determining a fourth similarity between the fourth relationship and the corresponding first relationship; According to the third similarities corresponding to each fifth entity in the first subgraph and the fourth similarities corresponding to each fourth relationship, the second subgraph is determined by the graph theory algorithm PCST, and the second subgraph is used as the first subgraph. The first subgraph is input into the graph encoder in the large language model to obtain the graph text corresponding to the first subgraph.
5. The method according to claim 4, characterized in that For each fifth entity in the first subgraph, determining a third similarity between the fifth entity and the corresponding first entity includes: For each fifth entity in the first subgraph, if the fifth entity is an associated entity, determining the first similarity between the fifth entity and the corresponding first entity as the third similarity between the fifth entity and the corresponding first entity; If the fifth entity is not a related entity, determining a third similarity between the fifth entity and the corresponding first entity includes: The fifth similarities between the fifth entity and each first entity are determined respectively, and the greatest fifth similarity is determined as the third similarity between the fifth entity and the corresponding first entity.
6. The method according to claim 5, characterized in that The determining the fifth similarity between the fifth entity and each first entity respectively comprises: Determine a first entity type corresponding to the fifth entity, and obtain a pre-saved first entity type vector corresponding to the first entity type; For each of the first entities, determine the second entity type corresponding to the first entity, and obtain a pre-saved second entity type vector corresponding to the second entity type; and determine the similarity between the first entity type vector and the second entity type vector as the fifth similarity between the fifth entity and the first entity.
7. The method according to claim 4, characterized in that For each fourth relationship in the first subgraph, determining a fourth similarity between the fourth relationship and the corresponding first relationship includes: For each fourth relationship in the first subgraph, if the fourth relationship is an association relationship, determine the second similarity between the fourth relationship and the corresponding first relationship as the fourth similarity between the fourth relationship and the corresponding first relationship; If the fourth relationship is not an association relationship, determining a fourth similarity between the fourth relationship and the corresponding first relationship includes: The sixth similarities between the fourth relationship and each first relationship are determined respectively, and the largest sixth similarity is determined as the fourth similarity between the fourth relationship and the corresponding first relationship.
8. The method according to claim 7, characterized in that The determining the sixth similarity between the fourth relationship and each first relationship respectively comprises: Determine a first relationship type corresponding to the fourth relationship, and obtain a pre-saved first relationship type vector corresponding to the first relationship type; For each of the first relationships, determine the second relationship type corresponding to the first relationship, and obtain a pre-saved second relationship type vector corresponding to the second relationship type; and determine the similarity between the first relationship type vector and the second relationship type vector as the sixth similarity between the fourth relationship and the first relationship.
9. The method according to claim 1, characterized in that: The process of determining the second vector corresponding to the first relationship between each first entity includes: For each first relationship, the first relationship and two first entities corresponding to the first relationship are input into the vector encoder to obtain a second vector corresponding to the first relationship.
10. The method according to claim 4, characterized in that According to the third similarities corresponding to each fifth entity in the first subgraph and the fourth similarities corresponding to each fourth relationship in the first subgraph, the second subgraph is determined by the graph theory algorithm PCST to include: According to the first subgraph and the graph theory algorithm PCST, each third candidate subgraph is obtained, and according to the third similarities corresponding to each of the fifth entities and the fourth similarities corresponding to each of the fourth relationships, the similarities and values corresponding to each of the third candidate subgraphs are determined; the third candidate subgraph corresponding to the largest similarity and value is determined as the second subgraph.
Citation Information
Cited By
Text retrieval method, medium, computer equipment and program product
CN120429430A
Multi-stage retrieval enhancement generation method, computer system and computer readable storage medium
CN121388078A
Multi-stage search enhancement generation method, computer system, and computer-readable storage medium
CN121388078B
Knowledge query method and device, computer equipment and storage medium
CN122240817A
A knowledge query method and device, computer equipment and a storage medium
CN122240817B