A knowledge graph multi-hop path reasoning method, device, equipment and storage medium

By introducing large models and Prompt templates and combining the knowledge graph ontology structure, the problems of difficulty in expanding multi-hop path inference technology of traditional knowledge graphs are solved, and more efficient and accurate inference path generation and evaluation are achieved.

CN119761496APending Publication Date: 2025-04-04THE FIFTH RES INST OF TELECOMM SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411552042.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-01
Publication Date
2025-04-04

AI Technical Summary

Technical Problem

Traditional knowledge graph multi-hop path inference technology has problems such as difficulty in scaling, high cost, low efficiency and unstable training.

Method used

By constructing questions, document libraries, knowledge graphs, big models, entity linkers and Prompt templates, we use big models to enhance retrieval and inference path generation, and combine the knowledge graph ontology structure to complete the inference path generation and evaluation of the question-to-answer problem.

Benefits of technology

It realizes a more accurate understanding of the question information of the knowledge graph intelligent question-and-answer problem, reduces the cost of reasoning training, improves the inference efficiency, and can capture deep semantic correlations between entities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119761496A_ABST
    Figure CN119761496A_ABST
Patent Text Reader

Abstract

The present invention discloses a knowledge graph multi-hop path reasoning method, device, equipment and storage medium, including: filling a first prompt template according to a question and a related document paragraph to obtain a first instruction, inputting the first instruction into a large model to obtain an enhanced retrieval answer to the question; using the entity type set and the relationship type set of the question and the knowledge graph to fill a second prompt template to obtain a second instruction, inputting the second instruction into the large model to obtain a possible reasoning path set of the question on the knowledge graph; finding a union of the path set and the reasoning path set to obtain a new path set, querying along the path in the new path set to obtain a path traversal set after the query; texting the path traversal set into a string to obtain a text representation; filling a third prompt template according to the question and the text representation to obtain a third instruction, and inputting the third instruction into the large model to obtain a multi-hop path reasoning answer to the question. The present invention has relatively low cost, higher reasoning efficiency and better effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of knowledge graph question answering technology, and in particular to a knowledge graph multi-hop path reasoning method, device, equipment and storage medium. Background Art

[0002] Traditional knowledge graph multi-hop path reasoning technology methods have certain limitations. When the knowledge graph expands in scale or the domain changes, the rule writing and maintenance of rule-based methods become very difficult and difficult to expand effectively; for large knowledge graphs, the graph search method has a huge search space, high computational cost, and low efficiency; traditional machine learning-based methods have difficulty capturing deep semantic associations; multi-hop path reasoning training of knowledge graphs based on reinforcement learning is expensive, converges slowly, is prone to falling into local optimal solutions, and has unstable training.

[0003] Therefore, a knowledge graph multi-hop path reasoning method, device, equipment and storage medium are developed to solve the above problems. Summary of the invention

[0004] The present invention proposes a knowledge graph multi-hop path reasoning method, device, equipment and storage medium to solve the current problems of difficult expansion, high cost, low efficiency and unstable training.

[0005] The present invention achieves the above-mentioned purpose through the following technical solutions:

[0006] On one hand, the present invention provides a knowledge graph multi-hop path reasoning method, comprising:

[0007] Build questions, document library, knowledge graph, large model, entity linker, first prompt template, second prompt template and third prompt template;

[0008] Retrieving a document set related to the question from the document library, and then concatenating the document set to obtain relevant document paragraphs;

[0009] Fill the first prompt template according to the question and the relevant document paragraphs to obtain a first instruction, input the first instruction into the macro model to obtain an enhanced retrieval answer to the question;

[0010] Linking the question, the entities in the enhanced retrieval answer, and the related entities in the knowledge graph to obtain linked entities, and querying the knowledge graph for a subgraph matching the linked entity;

[0011] Traversing the subgraph to obtain a path set;

[0012] Fill a second prompt template with the question and the entity type set and the relationship type set of the knowledge graph to obtain a second instruction, and input the second instruction into the large model to obtain a possible reasoning path set for the question on the knowledge graph;

[0013] Calculate the union of the path set and the reasoning path set to obtain a new path set, and start from the entities in the problem entity set, query along the paths in the new path set to obtain a path traversal set after the query;

[0014] Convert the path traversal set to a string to obtain a text representation;

[0015] The third prompt template is filled in according to the question and the text representation to obtain a third instruction, and the third instruction is input into the large model to obtain a multi-hop path reasoning answer to the question.

[0016] Specifically, the method for retrieving a document set related to the question from the document library may adopt one of a semantic similarity algorithm, a BM2.5 algorithm, a keyword matching algorithm, and a literal similarity algorithm.

[0017] Specifically, the document library is a vector document database.

[0018] Specifically, the vector document database is one of the Faiss vector document database, the Milvus vector document database, and the Elasticsearch vector document database.

[0019] Furthermore, the entities in the question and the enhanced search answer are linked with related entities in the knowledge graph to obtain linked entities, and a subgraph matching the linked entity is searched in the knowledge graph, including:

[0020] Linking the question, entities in the enhanced retrieval answer, and related entities in the knowledge graph to obtain linked entities;

[0021] Obtain a question entity set in the question and an answer entity set in the enhanced retrieval answer, wherein the answer entity set includes the final answer entity of the question

[0022] Querying a subgraph matching the linked entity in the knowledge graph, wherein the subgraph is composed of the entity set and a set of relationships between entities in the entity set, and the entity set is composed of the question entity set and the answer entity set;

[0023] Furthermore, the subgraph is traversed to obtain a path set, including:

[0024] Obtaining a knowledge graph path set from the question entity set to the final answer entity in the subgraph;

[0025] The paths in the knowledge graph path set are represented in the form of a tuple list to obtain the path set.

[0026] Furthermore, the entities in the question and the enhanced retrieval answer are linked to related entities in the knowledge graph through an entity linker, the subgraph matching the linked entity is queried through a graph queryer, the subgraph is traversed through a graph path traverser, and the query is performed along the path in the new path set starting from the entity in the question entity set through a graph path queryer.

[0027] A second aspect of the present invention provides a knowledge graph multi-hop path reasoning device, comprising:

[0028] A construction module, wherein the construction module is used to construct questions, a document library, a knowledge graph, a large model, an entity linker, a first prompt template, a second prompt template, and a third prompt template;

[0029] A retrieval and splicing module, the retrieval and splicing module is used to retrieve a document set related to the question from the document library, and then splice the document set to obtain relevant document paragraphs;

[0030] A first filling module, the first filling module is used to fill the first prompt template according to the question and the relevant document paragraphs to obtain a first instruction, and input the first instruction into the large model to obtain an enhanced retrieval answer to the question;

[0031] A first query module, the first query module is used to link the entities in the question and the enhanced search answer with the related entities in the knowledge graph to obtain linked entities, and search the knowledge graph for a subgraph matching the linked entity;

[0032] A traversal module, the traversal module is used to traverse the subgraph to obtain a path set;

[0033] A second filling module, the second filling module is used to fill a second prompt template with the question and the entity type set and the relationship type set of the knowledge graph to obtain a second instruction, and input the second instruction into the large model to obtain a possible reasoning path set of the question on the knowledge graph;

[0034] A second query module, the second query module is used to obtain a new path set by obtaining a union of the path set and the reasoning path set, and to query along the paths in the new path set from the entities in the problem entity set to obtain a post-query path traversal set;

[0035] A text module, the text module is used to convert the path traversal set into a string to obtain a text representation;

[0036] A third filling module is used to fill in the third Prompt template according to the question and the text representation to obtain a third instruction, and input the third instruction into the large model to obtain a multi-hop path reasoning answer to the question.

[0037] The third aspect of the present invention provides a knowledge graph multi-hop path reasoning device, including a memory for storing a computer program; and a processor for implementing the steps of a knowledge graph multi-hop path reasoning method when executing the computer program.

[0038] A fourth aspect of the present invention provides a storage medium, which is a readable storage medium and stores a computer program. When the computer program is executed by a processor, it implements the steps of a knowledge graph multi-hop path reasoning method as described in the claim.

[0039] The beneficial effects of the present invention are:

[0040] The knowledge graph multi-hop path reasoning method, device, equipment and storage medium proposed in the present invention introduce a large model into the knowledge graph multi-hop path reasoning, which can help to more accurately understand the question information of the knowledge graph intelligent question and answer, and complete the generation, selection and evaluation of the reasoning path from question to answer in combination with the knowledge graph ontology structure. Since the knowledge graph multi-hop path reasoning method based on large model enhancement does not need to perform reasoning on the entire knowledge graph and retrain the large model, its reasoning training cost is relatively low. Compared with traditional methods, it has higher reasoning efficiency and better effect, and can better capture the deep semantic associations between entities. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 This is a flowchart of a knowledge graph multi-hop path reasoning method in an embodiment of the present application;

[0042] Figure 2 This is a logic diagram of a knowledge graph multi-hop path reasoning method in an embodiment of the present application. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0044] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0045] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0046] In the description of the present invention, it should be understood that the terms "upper", "lower", "inside", "outside", "left", "right", etc. indicate directions or positional relationships based on the directions or positional relationships shown in the accompanying drawings, or are directions or positional relationships in which the product of the invention is usually placed when in use, or are directions or positional relationships commonly understood by those skilled in the art. These directions or positional relationships are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore should not be understood as a limitation on the present invention.

[0047] Furthermore, the terms “first”, “second”, etc. are merely used for distinguishing descriptions and should not be understood as indicating or implying relative importance.

[0048] In the description of the present invention, it is also necessary to explain that, unless otherwise clearly specified and limited, the terms such as "setting" and "connection" should be understood in a broad sense. For example, "connection" can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or an indirect connection through an intermediate medium, or it can be the internal communication of two elements. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0049] The specific implementation modes of the present invention are described in detail below in conjunction with the accompanying drawings.

[0050] Combination Figure 1 As shown, a knowledge graph multi-hop path reasoning method includes:

[0051] S1: Build questions, document library, knowledge graph, large model, entity linker, first prompt template, second prompt template and third prompt template;

[0052] Define the problem as q, the large language model LLM, and the document library D = {d1,…,d n}, where d iThe vector representing the i-th document in the document library defines the first prompt template t r , define the knowledge graph G = {E, R}, where E represents the set of entities in the graph, R represents the set of relationships in the graph, define the entity connector EL, and define the second prompt template t p And the third prompt template a .

[0053] S2: Retrieving a document set related to the question from the document library, and then concatenating the document set to obtain relevant document paragraphs;

[0054] Using RAG (retrieval-augmented generation) technology, we retrieve a document set C = {c1,…,c n}, then concatenate the relevant document set C to obtain the relevant document paragraph C p ;

[0055] Specifically, the method for retrieving a document set related to the question from the document library can adopt one of a semantic similarity algorithm, a BM2.5 algorithm, a keyword matching algorithm, and a literal similarity algorithm. The document library is a vector document database, and the vector document database is one of a Faiss vector document database, a Milvus vector document database, and an Elasticsearch vector document database.

[0056] S3: Fill the first prompt template according to the question and the relevant document paragraphs to obtain a first instruction, and input the first instruction into the big model to obtain an enhanced retrieval answer to the question;

[0057] Using question q and document paragraph C p Fill in the first prompt template r Get instructions r , and the instruction s r Input the large model LMM to get the enhanced retrieval answer a of the question r :

[0058] a r =LLM(s r )

[0059] S4: Linking the entities in the question and the enhanced retrieval answer with the related entities in the knowledge graph to obtain linked entities, and querying the knowledge graph for a subgraph matching the linked entity;

[0060] Specifically, it includes: linking the question, the entities in the enhanced search answer and the related entities in the knowledge graph to obtain a linked entity; obtaining a question entity set in the question and an answer entity set in the enhanced search answer, wherein the answer entity set includes the final answer entity of the question; querying a subgraph matching the linked entity in the knowledge graph, wherein the subgraph is composed of the entity set and the set of relationships between entities in the entity set, and the entity set is composed of the question entity set and the answer entity set;

[0061] Use the entity linker to link question q and answer a r The entities in the question are linked to the related entities in the knowledge graph G, and the entity set E in the question q is recorded. q ={e q,1 ,…,e q,2} and answer a r The entity set E in a ={e a,1 ,…e a,q ,…,e a,n}, where e q,i represents the i-th entity in question q, e a,i Represents answer a r The i-th entity in e a,q Represents answer a r The final answer to question q refers to the entity (intermediate entity on the non-reasoning path). Use the graph query engine to query the subgraph G for linked entity matching s ={E s ,R s}, where E s Represents a question q and an answer a r The entity set in R s Represents E s The set of relationships between entities.

[0062] S5: traverse the subgraph to obtain a path set;

[0063] Use the graph path traversal to obtain the problem entity set E q To the final answer entity e a,q The knowledge graph path set is represented by a tuple list, and the path set P is obtained. r ={p r,1 ,…,p r,n}, where p r,i Represents the path set P r The i-th path in is represented by [(entity type, relationship type, entity type), …, (entity type, relationship type, entity type)].

[0064] Specifically, it includes: obtaining a knowledge graph path set from the question entity set to the final answer entity in the subgraph, representing the paths in the knowledge graph path set in the form of a tuple list, and obtaining the path set.

[0065] S6: Fill a second prompt template with the question and the entity type set and the relationship type set of the knowledge graph to obtain a second instruction, and input the second instruction into the large model to obtain a set of possible reasoning paths for the question on the knowledge graph;

[0066] Using question q and knowledge graph G, we can get entity type set E T and the set of relation types R T Fill in the second prompt template p Get instructions p , and the instruction s p Input the large model LMM to obtain the possible reasoning path set P of the problem on the knowledge graph q ={p q,1 ,…,p q,n}The text representation of P q , where p q,i Represents the path set P q The i-th path in is represented by [(entity type, relationship type, entity type), …, (entity type, relationship type, entity type)].

[0067] S7: finding a union of the path set and the reasoning path set to obtain a new path set, starting from the entities in the problem entity set, querying along the paths in the new path set to obtain a post-query path traversal set;

[0068] For the path set P r and P q Find the union and aggregate to get a new path set P = {p1,..,p n}. Use the graph path query to find the problem entity set E q Starting from the entity in, query along the path in the path set P, and obtain the path traversal set P after the query t ={p t,1 ,…,p t,n}, where p t,i Indicates P t The list of entity-relationship tuples that the i-th path passes through is represented by [(head entity, relationship, tail entity), ..., (head entity, relationship, tail entity)]. t Convert the text to a string to get the text c p .

[0069] S8: Convert the path traversal set into a character string to obtain a text representation;

[0070] S9: Fill the third prompt template according to the question and the text representation to obtain a third instruction, and input the third instruction into the large model to obtain a multi-hop path reasoning answer to the question.

[0071] Using the text representation of the question q and the list of reasoning paths c p Filling template a Get instructions a , and the instruction s a Input the large model LMM to get the multi-hop path reasoning answer a p :

[0072] a p =LLM(s a )

[0073] Among them, the entities in the question and the enhanced retrieval answer are linked to the relevant entities in the knowledge graph through an entity linker, the subgraph matching the linked entity is queried through a graph queryer, the subgraph is traversed through a graph path traverser, and the graph path queryer starts from the entities in the question entity set and queries along the paths in the new path set.

[0074] like Figure 2As shown in the figure, the document library is used to recall relevant documents based on semantic similarity. It is usually a vector document library, which is used to convert text content into high-dimensional vectors, so that efficient similarity calculation and retrieval can be performed in the vector space. Typical vector document databases include Faiss, Milvus, Elasticsearch, etc. Knowledge graphs are used for multi-hop path query and analysis. Knowledge graphs usually store knowledge in the form of triples. Each triple includes a head entity, a tail entity, and relationship information. Databases commonly used to store knowledge graphs include graph databases such as neo4j, ArangoDB, and OrentDB. Graph databases are databases that store and query data in a graph structure. Compared with traditional relational databases, they are better at processing highly related data. Entity connectors are used to link text and knowledge graph entities. Entity connection aims to identify named entities in text and accurately match them with corresponding entities in the knowledge base or knowledge graph. Large language models are used for semantic parsing reasoning. Large language models have huge parameters and strong representation capabilities. By learning massive text data on the Internet, they can absorb and understand a wide range of knowledge and analyze and understand the deep semantic information of text. On the other hand, by cleverly designing input prompts to guide large pre-trained language models, large models can better understand and perform specific tasks without changing or fine-tuning the model structure. Utilizing the semantic understanding ability and prompt learning ability of large models can help better perform multi-hop path reasoning on knowledge graphs. The current mainstream large language models include Qwen2, ERNIE, Llama3, etc. The Prompt template library is used to generate reasoning instructions for large language models. The template library contains three types of templates: one is the RAG template, which is the first Prompt template, used for enhanced retrieval generation of initial answers to questions; one is the path reasoning template, which is the second Prompt template, used to directly reason from questions to multi-hop paths for querying answers in knowledge graphs; and one is the path evaluation template, which is the third Prompt template, used to select the best reasoning path and reason about the answer to the question.

[0075] This embodiment also provides a knowledge graph multi-hop path reasoning device, including:

[0076] A construction module, wherein the construction module is used to construct questions, a document library, a knowledge graph, a large model, an entity linker, a first prompt template, a second prompt template, and a third prompt template;

[0077] A retrieval and splicing module, the retrieval and splicing module is used to retrieve a document set related to the question from the document library, and then splice the document set to obtain relevant document paragraphs;

[0078] A first filling module, the first filling module is used to fill the first prompt template according to the question and the relevant document paragraphs to obtain a first instruction, and input the first instruction into the large model to obtain an enhanced retrieval answer to the question;

[0079] A first query module, the first query module is used to link the entities in the question and the enhanced search answer with the related entities in the knowledge graph to obtain linked entities, and search the knowledge graph for a subgraph matching the linked entity;

[0080] A traversal module, the traversal module is used to traverse the subgraph to obtain a path set;

[0081] A second filling module, the second filling module is used to fill a second prompt template with the question and the entity type set and the relationship type set of the knowledge graph to obtain a second instruction, and input the second instruction into the large model to obtain a possible reasoning path set of the question on the knowledge graph;

[0082] A second query module, the second query module is used to obtain a new path set by obtaining a union of the path set and the reasoning path set, and to query along the paths in the new path set from the entities in the problem entity set to obtain a post-query path traversal set;

[0083] A text module, the text module is used to convert the path traversal set into a string to obtain a text representation;

[0084] A third filling module is used to fill in the third Prompt template according to the question and the text representation to obtain a third instruction, and input the third instruction into the large model to obtain a multi-hop path reasoning answer to the question.

[0085] An embodiment of the present invention also provides a knowledge graph multi-hop path reasoning device, comprising a memory for storing a computer program; and a processor for implementing the steps of the knowledge graph multi-hop path reasoning method when executing the computer program.

[0086] An embodiment of the present invention also provides a storage medium, which is a readable storage medium. A computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of a knowledge graph multi-hop path reasoning method as described in the claim are implemented.

[0087] The present invention is further described below by taking the practical application of the present invention as an example:

[0088] Use vector similarity algorithm, BM2.5 algorithm, keyword matching, literal similarity and other algorithms to recall the document set related to the question in the document library. For example, for question q, use the text similarity model to recall the relevant document set C from the document library D, splice the document set and input it into the prompt template t r Get instructions r :

[0089] [Given the context, answer the question based on the above content. Please answer the question step by step and output the answer to the question in the following way: "Reasoning process: {{Description of the reasoning process}}, Final answer: {{Entity of the final answer}}"]

[0090] The instruction s r Send it to the large language model LLM to get the initial answer a r = "Reasoning process, final answer"

[0091] Using entity connectors, identify the initial answer a r =Entities in "reasoning process, final answer" and link them to the knowledge graph to obtain the subgraph formed by the linked entities. Starting from the entity in question q, traverse the path that can reach the final answer entity in the linked subgraph. Then get its reasoning path on the knowledge graph, and use a tuple list to represent the reasoning path set P r , use the entity type set and relationship type set of the knowledge graph and the question to fill in the template t p , get the instruction s p :

[0092] [Given that the knowledge graph contains entity types and relationship types], please parse the possible knowledge graph triple reasoning path of the sentence based on the given entity type and relationship type, and use the tuple set [(entity type, relationship type, entity type), ..., (entity type, relationship type, entity type)] to represent the reasoning path. 】

[0093] Input command p To the large language model LLM, get the inference result P q ;

[0094] The reasoning path set P converted into a tuple list q .

[0095] The reasoning path set P obtained by reasoning r And the reasoning path set P obtained by step 3 q Find the union and aggregate to get the final reasoning path set P.

[0096] Then, the graph path queryer is used to query the results of each reasoning path in the knowledge graph starting from the problem entity, and the entity relationship path set P is obtained.t And text to get text c p ;

[0097] Using c p Filling template a Get instructions a :

[0098] [The following list of knowledge graph reasoning paths is known. Given a problem, please choose the best reasoning path based on the above content and reason about the problem step by step. ]

[0099] The instruction s a Input into the large language model for final path selection and evaluation, and finally obtain the multi-hop path reasoning answer a p :

[0100] [The most likely reasoning path for the answer is:]

[0101] Since the related documents recalled from the document library in the prior art may contain factual errors due to the timeliness and incompleteness of the document knowledge, even if there is a correct answer among the candidate answers recalled from the knowledge graph, the large language model cannot select the correct question from the candidate answers based on the wrong contextual knowledge. Therefore, this method first uses enhanced retrieval generation and thinking chain prompts based on the document knowledge base to gradually infer the answer to the question based on the context of the document library. The answer may be incorrect due to the timeliness and incompleteness of the document knowledge base, but the large model's step-by-step reasoning process for the question can be used as a clue to find the final correct answer, that is, the subgraph formed in the knowledge graph by the entities in the question and the entities that appear in the step-by-step reasoning process can be used to help find the candidate reasoning path of the question. Finally, the candidate reasoning path is used as the context for reasoning, avoiding reasoning errors caused by the timeliness and incompleteness of the document knowledge base.

[0102] Existing technologies have ignored the role of knowledge graph ontology structure information in multi-hop path reasoning. Therefore, this method proposes a method for multi-path recall of knowledge graph multi-hop reasoning paths, combining knowledge graph ontology structure information and the problem itself, using the reasoning ability of the large model itself to obtain candidate reasoning paths, and then aggregating the multi-hop reasoning path set obtained by reasoning to obtain all possible candidate reasoning paths in the end, thereby enhancing the recall ability of candidate multi-hop reasoning paths.

[0103] The knowledge graph multi-hop path reasoning method, device, equipment and storage medium proposed in the present invention introduce a large model into the knowledge graph multi-hop path reasoning, which can help to more accurately understand the question information of the knowledge graph intelligent question and answer, and complete the generation, selection and evaluation of the reasoning path from question to answer in combination with the knowledge graph ontology structure. Since the knowledge graph multi-hop path reasoning method based on large model enhancement does not need to perform reasoning on the entire knowledge graph and retrain the large model, its reasoning training cost is relatively low. Compared with traditional methods, it has higher reasoning efficiency and better effect, and can better capture the deep semantic associations between entities.

[0104] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A knowledge graph multi-hop path reasoning method, characterized in that: include: Build questions, document library, knowledge graph, large model, entity linker, first prompt template, second prompt template and third prompt template; Retrieving a document set related to the question from the document library, and then concatenating the document set to obtain relevant document paragraphs; Fill the first prompt template according to the question and the relevant document paragraphs to obtain a first instruction, input the first instruction into the macro model to obtain an enhanced retrieval answer to the question; Linking the question, the entities in the enhanced search answer, and the related entities in the knowledge graph to obtain linked entities, and querying the knowledge graph for a subgraph matching the linked entity; Traversing the subgraph to obtain a path set; Fill a second prompt template with the question and the entity type set and the relationship type set of the knowledge graph to obtain a second instruction, and input the second instruction into the large model to obtain a set of possible reasoning paths for the question on the knowledge graph; Calculate the union of the path set and the reasoning path set to obtain a new path set, and start from the entities in the problem entity set, query along the paths in the new path set to obtain a path traversal set after the query; Convert the path traversal set to a string to obtain a text representation; The third prompt template is filled in according to the question and the text representation to obtain a third instruction, and the third instruction is input into the large model to obtain a multi-hop path reasoning answer to the question.

2. A knowledge graph multi-hop path reasoning method according to claim 1, characterized in that: The method for retrieving a document set related to the question from the document library may adopt one of a semantic similarity algorithm, a BM2.5 algorithm, a keyword matching algorithm, and a literal similarity algorithm.

3. A knowledge graph multi-hop path reasoning method according to claim 1, characterized in that: The document library is a vector document database.

4. A knowledge graph multi-hop path reasoning method according to claim 3, characterized in that: The vector document database is one of the Faiss vector document database, the Milvus vector document database, and the Elasticsearch vector document database.

5. A knowledge graph multi-hop path reasoning method according to claim 1, characterized in that: Linking the question, the entities in the enhanced search answer and the related entities in the knowledge graph to obtain linked entities, and querying the knowledge graph for a subgraph matching the linked entity, including: Linking the question, entities in the enhanced retrieval answer, and related entities in the knowledge graph to obtain linked entities; Obtain a question entity set in the question and an answer entity set in the enhanced retrieval answer, wherein the answer entity set includes the final answer entity of the question A subgraph matching the linked entity is queried in the knowledge graph, wherein the subgraph is composed of the entity set and a set of mutual relationships between entities in the entity set, and the entity set is composed of the question entity set and the answer entity set.

6. A knowledge graph multi-hop path reasoning method according to claim 5, characterized in that: Traverse the subgraph to obtain a path set, including: Obtaining a knowledge graph path set from the question entity set to the final answer entity in the subgraph; The paths in the knowledge graph path set are represented in the form of a tuple list to obtain the path set.

7. A knowledge graph multi-hop path reasoning method according to claim 1, characterized in that: The entities in the question and the enhanced retrieval answer are linked to the related entities in the knowledge graph through an entity linker, the subgraph matching the linked entity is queried through a graph queryer, the subgraph is traversed through a graph path traverser, and the query is performed along the path in the new path set starting from the entity in the question entity set through a graph path queryer.

8. A knowledge graph multi-hop path reasoning device, characterized in that: include: A construction module, wherein the construction module is used to construct questions, a document library, a knowledge graph, a large model, an entity linker, a first prompt template, a second prompt template, and a third prompt template; A retrieval and splicing module, the retrieval and splicing module is used to retrieve a document set related to the question from the document library, and then splice the document set to obtain relevant document paragraphs; A first filling module, the first filling module is used to fill the first prompt template according to the question and the relevant document paragraphs to obtain a first instruction, and input the first instruction into the large model to obtain an enhanced retrieval answer to the question; A first query module, the first query module is used to link the entities in the question and the enhanced search answer with the related entities in the knowledge graph to obtain linked entities, and search the knowledge graph for a subgraph matching the linked entity; A traversal module, the traversal module is used to traverse the subgraph to obtain a path set; A second filling module, the second filling module is used to fill a second prompt template with the question and the entity type set and the relationship type set of the knowledge graph to obtain a second instruction, and input the second instruction into the large model to obtain a possible reasoning path set of the question on the knowledge graph; A second query module, the second query module is used to obtain a new path set by obtaining a union of the path set and the reasoning path set, and to query along the paths in the new path set from the entities in the problem entity set to obtain a post-query path traversal set; A text module, the text module is used to convert the path traversal set into a string to obtain a text representation; A third filling module is used to fill in the third Prompt template according to the question and the text representation to obtain a third instruction, and input the third instruction into the large model to obtain a multi-hop path reasoning answer to the question.

9. A knowledge graph multi-hop path reasoning device, characterized in that: It includes a memory for storing a computer program; and a processor for implementing the steps of a knowledge graph multi-hop path reasoning method as described in any one of claims 1 to 7 when executing the computer program.

10. A storage medium, characterized in that: The storage medium is a readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of a knowledge graph multi-hop path reasoning method as described in any one of claims 1 to 7 are implemented.