Knowledge retrieval method and device based on knowledge graph, equipment and storage medium

By distributing knowledge from a large language model to knowledge graph nodes and using transition matrices and node recall rules for knowledge retrieval, the problem of cumbersome knowledge graph construction is solved, and efficient knowledge retrieval and training are achieved.

CN117667974BActive Publication Date: 2026-07-31ATHENAEYES CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
ATHENAEYES CO LTD
Filing Date
2023-12-04
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

In existing technologies, the construction process of knowledge graphs is cumbersome and semi-automatic, making it difficult to efficiently abstract knowledge from large language models into entities and relationships in knowledge graphs, resulting in low knowledge retrieval efficiency.

Method used

The knowledge in the large language model is distributed to nodes in the knowledge graph. By setting knowledge graph nodes to store knowledge vectors, identity vectors and transition matrices, the transition matrix is ​​used to map query vectors, and knowledge retrieval is performed in combination with preset node recall rules, replacing the traditional FFN parameters.

Benefits of technology

It improves the training and retrieval efficiency of knowledge retrieval, reduces the dependence on FFN parameters, and enhances the generalization ability of knowledge retrieval.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117667974B_ABST
    Figure CN117667974B_ABST
Patent Text Reader

Abstract

This application discloses a knowledge retrieval method, apparatus, device, and storage medium based on knowledge graphs, relating to the field of deep learning and applied to large language models. The method includes: setting up several knowledge graph nodes based on a preset knowledge graph, and storing knowledge vectors, identity vectors, and transition matrices in the knowledge graph nodes; obtaining an input vector and mapping a query vector based on the transition matrix and the input vector; determining whether the current knowledge retrieval is the first round of knowledge retrieval; if not, determining the first knowledge graph node from the previous round, and performing node recall based on the first knowledge graph node and the query vector according to a preset node recall rule to obtain several second knowledge graph nodes; and generating the output vector of the large language model based on the several second knowledge graph nodes. By combining knowledge graphs and large language models, the knowledge in the large language model is distributed across the nodes of the knowledge graph, improving the efficiency of training and retrieval.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of deep learning, and in particular to a knowledge retrieval method, apparatus, device, and storage medium based on knowledge graphs. Background Technology

[0002] Knowledge graphs store high-level abstract knowledge (called "entities" in the knowledge graph) and the relationships between knowledge (called "relationships") to achieve the function of "retrieving related knowledge from one piece of knowledge," which is undoubtedly the most efficient retrieval method. However, the construction of knowledge graphs is extremely cumbersome, and most are implemented in a semi-automatic manner. Therefore, how to abstract the knowledge of large language models into entities in knowledge graphs and automatically construct the relationships between knowledge to improve the efficiency of knowledge retrieval is a problem that needs to be solved in this field. Summary of the Invention

[0003] In view of this, the purpose of this invention is to provide a knowledge retrieval method, apparatus, device, and storage medium based on knowledge graphs, combining knowledge graph and large language model technologies. This allows the knowledge in the large language model to be distributed across nodes in the knowledge graph, thereby improving training and retrieval efficiency. The specific solution is as follows:

[0004] Firstly, this application provides a knowledge retrieval method based on knowledge graphs, applied to large language models, including:

[0005] Several knowledge graph nodes are set up based on a preset knowledge graph, and preset knowledge vectors, identity vectors and transition matrices are stored in the knowledge graph nodes; the identity vector is used to represent the identity corresponding to the knowledge graph node, so as to retrieve the knowledge graph node by querying the vector;

[0006] Obtain the input vector input to the large language model, and map the query vector based on the transition matrix and the input vector;

[0007] Determine whether the current knowledge retrieval is the first round of knowledge retrieval. If not, determine the first knowledge graph node retrieved in the previous round, and based on the first knowledge graph node and the query vector, perform node retrieval according to the preset node retrieval rules to obtain several second knowledge graph nodes.

[0008] The output vector of the large language model is generated based on several nodes of the second knowledge graph.

[0009] Optionally, before saving the preset knowledge vector, identity vector, and transition matrix in the knowledge graph node, the method further includes:

[0010] Based on the knowledge graph nodes, generate corresponding low-rank and full-rank matrices, and use the low-rank and full-rank matrices as the transition matrices of several knowledge graph nodes;

[0011] Accordingly, mapping the query vector based on the transition matrix and the input vector includes:

[0012] The query vector is mapped from the full-rank matrix and the input vector.

[0013] Optionally, generating the corresponding low-rank and full-rank matrices based on the knowledge graph nodes includes:

[0014] The same number of low-rank matrices and one full-rank matrix are generated based on several knowledge graph nodes, so as to control the knowledge graph nodes by combining the low-rank matrices with the full-rank matrix.

[0015] Optionally, the step of recalling nodes based on the first knowledge graph node and the query vector according to a preset node recall rule includes:

[0016] Based on the query vector and the first knowledge graph node, the target query vector for the current round is determined, and the target query vector and the identity vector of the first knowledge graph node are multiplied by a dot product to obtain the attention level of several third knowledge graph nodes.

[0017] Based on the attention level of the third knowledge graph node and the query vector, node recall is performed according to the preset node recall rules.

[0018] Optionally, determining the target query vector for the current round based on the query vector and the first knowledge graph node includes:

[0019] The target query vector for the current round is determined by the attention level and the low-rank matrix corresponding to each of the first knowledge graph nodes.

[0020] Optionally, the step of retrieving nodes based on the first knowledge graph node and the query vector according to a preset node retrieval rule to obtain a plurality of second knowledge graph nodes includes:

[0021] The third knowledge graph nodes are sorted according to their level of attention.

[0022] Based on the sorting result of the third knowledge graph node, the second knowledge graph node is recalled according to the preset node recall rule; the number of nodes in the second knowledge graph node is the same as the number of nodes in the first knowledge graph node.

[0023] Optionally, generating the output vector of the large language model based on several nodes of the second knowledge graph includes:

[0024] According to the preset calculation rules, a merged vector is obtained through several second knowledge graph nodes and the knowledge vectors corresponding to the second knowledge graph nodes, and the merged vector and the input vector are summed to obtain the output vector of the large language model.

[0025] Secondly, this application provides a knowledge retrieval device based on a knowledge graph, comprising:

[0026] The node setting module is used to set up a number of knowledge graph nodes based on a preset knowledge graph, and to store preset knowledge vectors, identity vectors and transition matrices in the knowledge graph nodes; the identity vector is used to represent the identity corresponding to the knowledge graph node, so as to retrieve the knowledge graph node by querying the vector;

[0027] The vector mapping module is used to obtain the input vector input to the large language model and map the query vector based on the transition matrix and the input vector.

[0028] The node recall module is used to determine whether the current knowledge retrieval is the first round of knowledge retrieval. If not, it determines the first knowledge graph node retrieved in the previous round, and performs node recall based on the first knowledge graph node and the query vector according to the preset node recall rules to obtain several second knowledge graph nodes.

[0029] The vector generation module is used to generate the output vector of the large language model based on several nodes of the second knowledge graph.

[0030] Thirdly, this application provides an electronic device, which includes a processor and a memory; wherein the memory is used to store a computer program, which is loaded and executed by the processor to implement the aforementioned knowledge graph-based knowledge retrieval method.

[0031] Fourthly, this application provides a computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the aforementioned knowledge graph-based knowledge retrieval method.

[0032] This application sets up several knowledge graph nodes based on a preset knowledge graph, and stores preset knowledge vectors, identity vectors, and transition matrices in the knowledge graph nodes. The identity vector is used to represent the identity corresponding to the knowledge graph node, so that the knowledge graph node can be retrieved through the query vector. The input vector of the large language model is obtained, and the query vector is mapped based on the transition matrix and the input vector. It is determined whether the current knowledge retrieval is the first round of knowledge retrieval. If not, the first knowledge graph node retrieved in the previous round is determined, and node retrieval is performed based on the first knowledge graph node and the query vector according to the preset node retrieval rules to obtain several second knowledge graph nodes. The output vector of the large language model is generated based on the several second knowledge graph nodes. In this way, a large language model is constructed, which combines the two technologies of knowledge graph and large language model, so that the knowledge in the large language model can be distributed in the nodes of the knowledge graph. It no longer requires a large number of knowledge sharing the same FFN (Position-wise Feed-Forward Networks) parameters, which improves the efficiency of training and knowledge retrieval. Attached Figure Description

[0033] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0034] Figure 1 A flowchart of a knowledge retrieval method based on knowledge graphs is provided for this application;

[0035] Figure 2 This application provides a schematic diagram of knowledge retrieval using a large language model.

[0036] Figure 3 This application provides a schematic diagram of knowledge retrieval using a large language model.

[0037] Figure 4 A flowchart of a specific knowledge retrieval method based on knowledge graphs is provided for this application;

[0038] Figure 5 This application provides a schematic diagram of a large language model structure that integrates knowledge graph structure;

[0039] Figure 6 This application provides a schematic diagram of a traditional large language model structure;

[0040] Figure 7A schematic diagram of a knowledge retrieval device based on a knowledge graph is provided for this application;

[0041] Figure 8 This application provides a structural diagram of an electronic device. Detailed Implementation

[0042] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0043] In large language models, a large number of knowledge-sharing parameters from FFNs can interfere with each other during training, resulting in slow training and inference. Furthermore, the number of retrieval conditions in the knowledge graph is too small (based on the current entity and the relationship to be queried), lacking generalization ability. Therefore, this application constructs a large language model based on a knowledge graph, combining these two technologies. This allows the knowledge in the large language model to be distributed across nodes in the knowledge graph, eliminating the need for a large number of knowledge-sharing parameters from the same FFNs, thus improving the efficiency of training and knowledge retrieval.

[0044] See Figure 1 As shown, this embodiment of the invention discloses a knowledge retrieval method based on knowledge graphs, applied to large language models, including:

[0045] Step S11: Set up several knowledge graph nodes based on a preset knowledge graph, and store preset knowledge vectors, identity vectors and transition matrices in the knowledge graph nodes; the identity vector is used to represent the identity corresponding to the knowledge graph node, so as to retrieve the knowledge graph node by querying the vector.

[0046] In this embodiment, a large number of knowledge graph nodes are first set up based on a preset knowledge graph, and two types of preset data are stored in the knowledge graph nodes: vectors and matrices: knowledge vectors, identity vectors, and transition matrices. The knowledge vector *v* is used to output the knowledge related to the corresponding knowledge graph node. The identity vector *k* is used to indicate the identity of the corresponding knowledge graph node, facilitating the retrieval of this node via a query vector. Before storing the knowledge vectors, identity vectors, and transition matrices, corresponding low-rank and full-rank matrices need to be generated based on the knowledge graph nodes. These low-rank and full-rank matrices are then used as transition matrices for several knowledge graph nodes. Specifically, the same number of corresponding low-rank matrices and one full-rank matrix can be generated for several knowledge graph nodes, allowing for node control through the combination of the low-rank and full-rank matrices. It can be understood that the transition matrix *q_proj* is a low-rank matrix used to control the transition to the new node, and all nodes share a full-rank matrix *default_q_proj* to assist in controlling the transition to the new node. In this way, the knowledge graph can be utilized in a large model, and the knowledge of the large language model can be stored in the nodes of the knowledge graph, facilitating subsequent retrieval and reasoning.

[0047] Regarding the aforementioned knowledge graphs and large language models, it is understandable that large language models retrieve knowledge in two forms, such as... Figure 2 The example shows the retrieval of knowledge from a historical vector sequence; such as... Figure 3The method for retrieving knowledge from model parameters, as shown, can be viewed as a black box. Specifically, the input vector is mapped using a matrix to obtain the query vector: q = o_proj (input vector). Then, the knowledge contained in the model parameters is retrieved directly using the matrix mapping: Knowledge = ffn(q). Therefore, whether retrieving knowledge from historical word sequences or from model parameters, a single query vector is used. Furthermore, it's understandable that the motivation behind the self-attention mechanism in large language models is to ensure that each vector in the input sequence pays attention to the content of all other vectors (unaffected by distance), and to fuse the content of other vectors together according to the degree of attention as weights. Finally, the fused vector is used to obtain a more abstract vector representation through matrix mapping (i.e., FFN). For each vector in the sequence, matrix transformation can map to three vectors q, k, and v. The q (query vector) of the current element is multiplied by the k (identity vector) of all other elements, and the resulting scalar sequence, after being processed by Softmax, can be used as the "degree of attention" of the current element to all other vectors. This "degree of attention" is called the "self-attention relation." By using the self-attention relation to weightedly sum the v (content vectors) of other elements, the fused information can be obtained. A "multi-head self-attention mechanism" is typically used, which can be understood as repeating the self-attention mechanism multiple times (using different parameters) and concatenating the multiple fused information results. The multiple sets of self-attention relations obtained by the multi-head attention mechanism are called "multi-head self-attention relations." A knowledge graph can be understood as a database that stores the triple (knowledge a, relation b, knowledge c). The retrieval method of a knowledge graph is the process of retrieving knowledge c by using "knowledge a and relation b" as conditions.

[0048] Step S12: Obtain the input vector of the large language model, and map the query vector based on the transition matrix and the input vector.

[0049] Based on the transition matrix from the previous step, after obtaining the input vector of the large language model in this embodiment, the query vector can be mapped from the input vector using a full-rank matrix. For example, if the current input vector is s_in, the default matrix, i.e., the aforementioned full-rank matrix, can be used to map the query vector used at the knowledge graph node: q = default_q_proj(s_in).

[0050] Step S13: Determine whether the current knowledge retrieval is the first round of knowledge retrieval. If not, determine the first knowledge graph node retrieved in the previous round, and based on the first knowledge graph node and the query vector, perform node retrieval according to the preset node retrieval rules to obtain several second knowledge graph nodes.

[0051] In this embodiment, it is determined whether the current knowledge retrieval is the first round of knowledge retrieval. If it is not the first round, several first knowledge graph nodes retrieved in the previous round are identified. Based on the first knowledge graph nodes and the query vector, node recall is performed according to a preset node recall rule to obtain several second knowledge graph nodes. It is understandable that the traditional way of indexing knowledge in a knowledge graph is to directly jump to new knowledge using the current knowledge node and its relationship as conditions. For example, if the current knowledge node is "father" and the relationship is "wife," the new knowledge node to jump to is "son." This method has poor generalization ability and is not convenient for automatic learning. Therefore, this embodiment changes the retrieval method from "knowledge node to knowledge node" to "knowledge node set to knowledge node set," improving the generalization ability of knowledge retrieval.

[0052] Step S14: Generate the output vector of the large language model based on several nodes of the second knowledge graph.

[0053] In this embodiment, based on the previous step, after multiple rounds of retrieval, the knowledge in all retrieved knowledge node sets is combined, and the output vector of the large language model is generated for output.

[0054] Based on the above description, it is understandable that large language models involve a large number of parameters when retrieving knowledge. Different combinations of these parameters give the model strong generalization ability. However, the parameters in a large number of knowledge-sharing FFNs can affect each other during training, resulting in slow training and inference. Knowledge graph retrieval, on the other hand, has simple knowledge conditions, fast retrieval, and interpretability, but the number of retrieval conditions is too small, resulting in no generalization ability. In this embodiment, several knowledge graph nodes can be set based on a preset knowledge graph. Preset knowledge vectors, identity vectors, low-rank matrices, and full-rank matrices are stored in these knowledge graph nodes. The low-rank and full-rank matrices are used as transition matrices for several knowledge graph nodes. Then, the input vector to the large language model is obtained, and the query vector is mapped based on the transition matrix and the input vector. It is determined whether the current knowledge retrieval is the first round of knowledge retrieval. If not, the first knowledge graph node retrieved in the previous round is determined, and node recall is performed based on the first knowledge graph node and the query vector according to a preset node recall rule to obtain several second knowledge graph nodes. The output vector of the large language model is generated based on these second knowledge graph nodes. Through the above technical solution, this embodiment can combine knowledge graph and large language model technologies, allowing the knowledge in the large language model to be distributed among the nodes of the knowledge graph. This eliminates the need for a large amount of knowledge sharing with the same FFN parameters, combines the advantages of large language model and knowledge graph for knowledge retrieval, and avoids the problem of slow training caused by mutual interference during training due to shared FFN parameters, thus improving the efficiency of training and knowledge retrieval.

[0055] As seen in the previous embodiment, this embodiment combines knowledge graphs and large language models for knowledge retrieval. Next, this embodiment will elaborate on the specific process of applying knowledge graphs to perform knowledge retrieval within a large language model. See also... Figure 4 As shown, this embodiment of the invention discloses a specific knowledge retrieval method based on knowledge graphs, applied to a large language model, including:

[0056] Step S21: Determine whether the current knowledge retrieval is the first round of knowledge retrieval. If not, determine the first knowledge graph node retrieved in the previous round, and determine the target query vector for the current round based on the query vector and the first knowledge graph node. Perform a dot product operation on the target query vector and the identity vector of the first knowledge graph node to obtain the attention level of several third knowledge graph nodes.

[0057] In this embodiment, it is first determined whether the current round of knowledge retrieval is the first round of knowledge retrieval. If not, ... Figure 5 As shown, several first knowledge graph nodes retrieved in the previous round can be identified. Based on the query vector and the aforementioned first knowledge graph nodes, the target query vector for the current round is determined. Then, the dot product operation is performed between the target query vector and the identity vector of the first knowledge graph nodes to obtain the attention levels of several third knowledge graph nodes. This allows the previously retrieved knowledge graph nodes to explicitly influence the target query vector. Assuming that N knowledge graph nodes were retrieved in the previous round (pre_ indicates the previous ones), the current target query vector q is determined by the attention level and low-rank matrix corresponding to each first knowledge graph node:

[0058] q=pre_a[1]*pre_q_proj[1](s_in)+pre_a[2]*pre_q_proj[2](s_in)+…+pre_a[n]*pre_q_proj[n](s_in);

[0059] Then, the current query vector and the identity vector k of all knowledge graph nodes are used to perform a dot product to obtain the attention level a of a certain node, and the same number of top N nodes are recalled according to the attention level.

[0060] Step S22: Based on the attention level of the third knowledge graph node and the query vector, perform node recall according to the preset node recall rules to obtain several second knowledge graph nodes.

[0061] In this embodiment, during node recall, several third knowledge graph nodes can be sorted according to their level of attention. Then, based on the sorted results, second knowledge graph nodes are recalled according to preset node recall rules. For example, if N knowledge graph nodes were retrieved in the previous round, the N nodes with higher attention levels are recalled in this round. The retrieval method of "knowledge node jump to knowledge node" can be changed to "knowledge node set jump to knowledge node set," improving the generalization ability of knowledge retrieval.

[0062] Step S23: According to the preset calculation rules, a merged vector is obtained through several second knowledge graph nodes and the knowledge vectors corresponding to the second knowledge graph nodes, and the merged vector and the input vector are summed to obtain the output vector of the large language model.

[0063] In this embodiment, a merged vector is obtained by using the knowledge vectors corresponding to several second knowledge graph nodes. The output vector of the large language model is then obtained by summing the merged vector and the input vector. First, the knowledge from the recalled nodes is merged together:

[0064] s_v=a[1]*v[1]+a[2]*v[2]+…+a[n]*v[n];

[0065] Then, the output vector is determined using the obtained s_v and the input vector:

[0066] s_out = s_in + s_v.

[0067] In this way, by replacing the FFN in the large language model with the above method of retrieving knowledge from the knowledge graph, the set of nodes on the knowledge graph can be obtained directly through training.

[0068] In this embodiment, it is first determined whether the current knowledge retrieval is the first round of knowledge retrieval. If not, the first knowledge graph node retrieved in the previous round is identified, and the target query vector for the current round is determined based on the query vector and the first knowledge graph node. The target query vector and the identity vector of the first knowledge graph node are then multiplied by a dot product to obtain the attention levels of several third knowledge graph nodes. Then, based on the attention levels of the third knowledge graph nodes and the query vector, node recall is performed according to a preset node recall rule to obtain several second knowledge graph nodes. A merged vector is obtained using the knowledge vectors corresponding to the several second knowledge graph nodes and the second knowledge graph nodes according to a preset calculation rule. The merged vector and the input vector are then summed to obtain the output vector of the large language model. Compared to... Figure 6The traditional language model structure shown (whose block consists of a multi-head self-attention mechanism and FFN) is replaced by a large language model structure (multi-head self-attention + knowledge graph retrieval block) that integrates a knowledge graph structure in this embodiment. This combines the two technologies of knowledge graph and large language model, allowing the knowledge in the large language model to be distributed among the nodes of the knowledge graph. The set of nodes on the knowledge graph can be obtained through knowledge retrieval, which improves the efficiency of training and knowledge retrieval.

[0069] See Figure 7 As shown in the embodiments, this application also discloses a knowledge retrieval device based on a knowledge graph, including:

[0070] The node setting module 11 is used to set up a number of knowledge graph nodes based on a preset knowledge graph, and to store preset knowledge vectors, identity vectors and transition matrices in the knowledge graph nodes; the identity vector is used to represent the identity corresponding to the knowledge graph node, so as to retrieve the knowledge graph node by querying the vector;

[0071] Vector mapping module 12 is used to obtain the input vector input to the large language model, and map the query vector based on the transition matrix and the input vector;

[0072] The node recall module 13 is used to determine whether the current knowledge retrieval is the first round of knowledge retrieval. If not, it determines the first knowledge graph node retrieved in the previous round, and performs node recall based on the first knowledge graph node and the query vector according to the preset node recall rules to obtain several second knowledge graph nodes.

[0073] Vector generation module 14 is used to generate the output vector of the large language model based on several nodes of the second knowledge graph.

[0074] This embodiment can set up several knowledge graph nodes based on a preset knowledge graph, and store preset knowledge vectors, identity vectors, and transition matrices in the knowledge graph nodes. The identity vector is used to represent the identity corresponding to the knowledge graph node, so that the knowledge graph node can be retrieved through the query vector. The input vector of the large language model is obtained, and the query vector is mapped based on the transition matrix and the input vector. It is determined whether the current knowledge retrieval is the first round of knowledge retrieval. If not, the first knowledge graph node retrieved in the previous round is determined, and node retrieval is performed based on the first knowledge graph node and the query vector according to the preset node retrieval rules to obtain several second knowledge graph nodes. The output vector of the large language model is generated based on several second knowledge graph nodes. In this way, a large language model is constructed, which combines the two technologies of knowledge graph and large language model. The knowledge in the large language model can be distributed in the nodes of the knowledge graph, eliminating the need for a large number of knowledge sharing the same FFN parameters, thus improving the efficiency of training and knowledge retrieval.

[0075] In some specific embodiments, the node setting module 11 further includes:

[0076] The matrix generation submodule is used to generate corresponding low-rank and full-rank matrices based on the knowledge graph nodes, and to use the low-rank and full-rank matrices as the transition matrices of a number of the knowledge graph nodes.

[0077] Accordingly, the vector mapping module 12 specifically includes:

[0078] A vector mapping unit is used to map the query vector using the full-rank matrix and the input vector.

[0079] In some specific embodiments, the matrix generation submodule specifically includes:

[0080] The matrix generation unit is used to generate the same number of low-rank matrices and one full-rank matrix based on a plurality of knowledge graph nodes, so as to control the knowledge graph nodes by combining the low-rank matrices with the full-rank matrix.

[0081] In some specific embodiments, the node recall module 13 specifically includes:

[0082] The vector determination submodule is used to determine the target query vector for the current round based on the query vector and the first knowledge graph node, and to perform a dot product operation on the target query vector and the identity vector of the first knowledge graph node to obtain the attention level of several third knowledge graph nodes;

[0083] The first node recall unit is used to recall nodes according to the attention level of the third knowledge graph node and the query vector based on the preset node recall rules.

[0084] In some specific embodiments, the vector determination submodule specifically includes:

[0085] The vector determination unit is used to determine the target query vector for the current round by using the attention level and the low-rank matrix corresponding to each of the first knowledge graph nodes.

[0086] In some specific embodiments, the node recall module 13 specifically includes:

[0087] A node sorting unit is used to sort a plurality of third knowledge graph nodes according to the degree of attention of the third knowledge graph nodes.

[0088] The second node recall unit is used to recall the second knowledge graph node according to the preset node recall rules based on the sorting result after sorting the third knowledge graph node; the number of nodes in the second knowledge graph node is the same as the number of nodes in the first knowledge graph node.

[0089] In some specific embodiments, the vector generation module 14 specifically includes:

[0090] The vector output unit is used to obtain a merged vector by using a number of second knowledge graph nodes and the knowledge vectors corresponding to the second knowledge graph nodes according to a preset calculation rule, and to sum the merged vector and the input vector to obtain the output vector of the large language model.

[0091] Furthermore, embodiments of this application also disclose an electronic device, Figure 8 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.

[0092] Figure 8 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the knowledge graph-based knowledge retrieval method disclosed in any of the foregoing embodiments. Alternatively, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0093] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0094] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0095] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including computer programs capable of performing the knowledge graph-based knowledge retrieval method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.

[0096] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned knowledge graph-based knowledge retrieval method. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.

[0097] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0098] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0099] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0100] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0101] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A knowledge retrieval method based on a knowledge graph, characterized in that, Applied to large language models, including: Several knowledge graph nodes are set up based on a preset knowledge graph, and preset knowledge vectors, identity vectors and transition matrices are stored in the knowledge graph nodes; the identity vector is used to represent the identity corresponding to the knowledge graph node, so as to retrieve the knowledge graph node by querying the vector; Obtain the input vector input to the large language model, and map the query vector based on the transition matrix and the input vector; Determine whether the current knowledge retrieval is the first round of knowledge retrieval. If not, determine the first knowledge graph node retrieved in the previous round, and based on the first knowledge graph node and the query vector, perform node retrieval according to the preset node retrieval rules to obtain several second knowledge graph nodes. The output vector of the large language model is generated based on several nodes of the second knowledge graph. The step of recalling nodes based on the first knowledge graph node and the query vector according to a preset node recall rule includes: Based on the query vector and the first knowledge graph node, the target query vector for the current round is determined, and the target query vector and the identity vector of the first knowledge graph node are multiplied by a dot product to obtain the attention level of several third knowledge graph nodes. Based on the attention level of the third knowledge graph node and the query vector, node recall is performed according to the preset node recall rules; Accordingly, the node recall based on the first knowledge graph node and the query vector according to the preset node recall rules yields several second knowledge graph nodes, including: The third knowledge graph nodes are sorted according to their level of attention. Based on the sorting result of the third knowledge graph nodes, the second knowledge graph nodes are recalled according to the preset node recall rules; the number of nodes in the second knowledge graph nodes is the same as the number of nodes in the first knowledge graph nodes. Furthermore, the step of generating the output vector of the large language model based on several nodes of the second knowledge graph includes: According to the preset calculation rules, a merged vector is obtained through several second knowledge graph nodes and the knowledge vectors corresponding to the second knowledge graph nodes, and the merged vector and the input vector are summed to obtain the output vector of the large language model. 2.The knowledge retrieval method based on a knowledge graph according to claim 1, characterized in that, Before saving the preset knowledge vector, identity vector, and transition matrix in the knowledge graph node, the method further includes: Based on the knowledge graph nodes, generate corresponding low-rank and full-rank matrices, and use the low-rank and full-rank matrices as the transition matrices of several knowledge graph nodes; Accordingly, mapping the query vector based on the transition matrix and the input vector includes: The query vector is mapped from the full-rank matrix and the input vector. 3.The knowledge retrieval method based on a knowledge graph according to claim 2, characterized in that, The step of generating corresponding low-rank and full-rank matrices based on the knowledge graph nodes includes: The same number of low-rank matrices and one full-rank matrix are generated based on several knowledge graph nodes, so as to control the knowledge graph nodes by combining the low-rank matrices with the full-rank matrix. 4.The knowledge retrieval method based on a knowledge graph according to claim 2, characterized in that, Determining the target query vector for the current round based on the query vector and the first knowledge graph node includes: The target query vector for the current round is determined by the attention level and the low-rank matrix corresponding to each of the first knowledge graph nodes.

5. A knowledge retrieval device based on a knowledge graph, characterized in that, Applied to large language models, including: The node setting module is used to set up a number of knowledge graph nodes based on a preset knowledge graph, and to store preset knowledge vectors, identity vectors and transition matrices in the knowledge graph nodes; the identity vector is used to represent the identity corresponding to the knowledge graph node, so as to retrieve the knowledge graph node by querying the vector; The vector mapping module is used to obtain the input vector input to the large language model and map the query vector based on the transition matrix and the input vector. The node recall module is used to determine whether the current knowledge retrieval is the first round of knowledge retrieval. If not, it determines the first knowledge graph node retrieved in the previous round, and performs node recall based on the first knowledge graph node and the query vector according to the preset node recall rules to obtain several second knowledge graph nodes. A vector generation module is used to generate the output vector of the large language model based on several nodes of the second knowledge graph. The node recall module includes: The vector determination submodule is used to determine the target query vector for the current round based on the query vector and the first knowledge graph node, and to perform a dot product operation on the target query vector and the identity vector of the first knowledge graph node to obtain the attention level of several third knowledge graph nodes; The first node recall unit is used to recall nodes according to the attention level of the third knowledge graph node and the query vector according to the preset node recall rules. A node sorting unit is used to sort a plurality of third knowledge graph nodes according to the degree of attention of the third knowledge graph nodes. The second node recall unit is used to recall the second knowledge graph node according to the preset node recall rules based on the sorting result of the third knowledge graph node; the number of nodes in the second knowledge graph node is the same as the number of nodes in the first knowledge graph node. Furthermore, the vector generation module includes: The vector output unit is used to obtain a merged vector by using a number of second knowledge graph nodes and the knowledge vectors corresponding to the second knowledge graph nodes according to a preset calculation rule, and to sum the merged vector and the input vector to obtain the output vector of the large language model.

6. An electronic device, characterized in that, The electronic device includes a processor and a memory; wherein the memory is used to store a computer program, which is loaded and executed by the processor to implement the knowledge retrieval method based on a knowledge graph as described in any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that, Used to store computer programs, which, when executed by a processor, implement the knowledge retrieval method based on a knowledge graph as described in any one of claims 1 to 5.