A text retrieval method and device based on knowledge graph
By converting documents into knowledge graphs and combining large language models and cosine similarity, the problems of result completeness and matching accuracy in text retrieval are solved, and more efficient text matching and the accuracy of search results are achieved.
Patent Information
- Application Number
- CN202411160429.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-22
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2044-08-22
AI Technical Summary
The prior art is difficult to improve the completeness of the results and the accuracy of the matching process in text retrieval, and it is easy to miss relevant information and is greatly affected by the length of the vector.
By converting documents into knowledge graphs, introducing mesh features, combining large language models and cosine similarity, filtering the most similar knowledge graphs to obtain knowledge information, and improving the accuracy of text matching through graph embedding models.
It improves the completeness of text retrieval results and the accuracy of matching process, avoids the impact of vector length on similarity evaluation, and effectively preserves the correlation between documents and keywords.
Smart Images

Figure CN119149669B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of text retrieval, and in particular to a text retrieval method and device based on a knowledge graph. Background Art
[0002] With the popularization of electronic text materials within enterprises, the number of electronic documents is increasing over time. Even if the electronic documents are reasonably classified, it is impossible for internal personnel to quickly locate the required documents, let alone directly obtain the required key information in the documents.
[0003] In the prior art, a preliminary search of the document name is often performed through keywords to obtain the required documents, and then the chapters of the key information required are manually found from the directory of the obtained documents, and further searches are performed, which is not only time-consuming and laborious, but may also miss other relevant information content. In order to avoid a large amount of manual operation, some companies use a large language model to segment documents, obtain small segments, and convert the segments into vectors through text embedding. The similarity is calculated with the keywords entered by the user to obtain the segments that match the search keywords. The above method easily causes key information in related documents to be omitted. In addition, if the size of the segment segmentation is unreasonable, the search information finally obtained will be too scattered, resulting in the large language model being unable to answer the key information that meets the requirements based on the matching segments.
[0004] Therefore, how to improve the completeness of text retrieval results and the accuracy of text matching is a technical problem that needs to be solved at present. Summary of the invention
[0005] The present application provides a text retrieval method and device based on a knowledge graph to solve the technical problem of how to improve the completeness of text retrieval results and the accuracy of the text matching process.
[0006] In order to solve the above technical problems, in the first aspect, the embodiment of the present application provides a text retrieval method based on a knowledge graph, comprising:
[0007] Acquire first text information input by a user, and vectorize the first text information using a preset large language model to acquire a first vector;
[0008] By using the cosine similarity and combining the first vector, the most similar knowledge graph is selected from the preset knowledge base as the first knowledge graph, and knowledge information is obtained according to the first knowledge graph; the knowledge graph is obtained by extracting keywords from the preset knowledge document and combining them with the preset node association rules;
[0009] The knowledge information is input into the large language model so that the large language model outputs a text retrieval result according to the knowledge information.
[0010] Compared with the prior art, the embodiments of the present application have the following beneficial effects: by converting documents into knowledge graphs, the network features of the knowledge graphs are introduced into the retrieval and matching process, and the network features can effectively retain the correlation between different documents and the correlation between different keywords. After converting the documents into knowledge graphs, the correlation between fields and fields and the correlation between documents can be better judged based on the correlation between nodes and knowledge graphs, so that a more complete text retrieval result can be obtained based on a knowledge graph obtained by matching. In addition, when the segmented documents are too large or too many keywords are input, resulting in a vector that is too long, the cosine similarity is used to judge the similarity between the two vectors, avoiding the influence of the vector length on the similarity evaluation and improving the accuracy of the text matching process.
[0011] In some embodiments of the first aspect of the present application, the knowledge graph is obtained by extracting keywords from preset knowledge documents and combining them with preset node association rules, including:
[0012] Slice the knowledge document to obtain a number of slice documents, and count the frequency of each term in the knowledge document appearing in each of the slice documents;
[0013] According to a first preset threshold value, and in combination with the word frequencies of the words appearing in each of the slice documents, all first keywords of each of the slice documents are determined;
[0014] The first keyword is used as a node and combined with the node association rule to obtain a knowledge graph corresponding to each of the slice documents.
[0015] Compared with the prior art, the above embodiment has the following beneficial effects: by determining whether the term is a keyword in the slice document through the frequency of occurrence of the term in the slice document, and taking all the keywords in the slice document as nodes of the knowledge graph, and combining the degree of association between the keywords, the knowledge graph of the corresponding slice document is established. When the keywords of other slice documents are the same as a keyword in the current slice document, the two slice documents are associated through the shared nodes of the knowledge graph, and the nodes of the knowledge graph are constructed through the keywords, so that the knowledge graph contains the key text information in each slice document, which improves the completeness of the subsequent text retrieval results.
[0016] In some embodiments of the first aspect of the present application, the determining of all first keywords of each of the slice documents according to the first preset threshold and in combination with the word frequencies of the entries appearing in each of the slice documents in sequence includes:
[0017] Counting the document frequencies of each of the terms being included in each of the slice documents;
[0018] According to the word frequency and document frequency corresponding to the first terms in the current slice document, obtain the weight of each first term in the corresponding slice document;
[0019] According to the weight of each first term and in combination with the first preset threshold, all the first keywords are screened out from all the first terms in the current slice document.
[0020] Compared with the prior art, the above embodiment has the following beneficial effects: in addition to considering the frequency of occurrence of a single term in a single slice document, the number of slice documents containing the term, that is, the document frequency, is also counted. This process not only considers the importance of the term in a single slice document, but also considers its importance in the entire document, so that the first keyword selected contains more semantic features of the document, thereby improving the accuracy of subsequent text matching.
[0021] In some embodiments of the first aspect of the present application, acquiring knowledge information according to the first knowledge graph includes:
[0022] Acquire a plurality of second knowledge graphs associated with the first knowledge graph; wherein the second knowledge graph includes: a knowledge graph that shares the same node as the first knowledge graph;
[0023] Merge the first knowledge graph and all slice documents corresponding to the second knowledge graph to obtain the knowledge information.
[0024] Compared with the prior art, the above embodiment has the following beneficial effects: after obtaining the first knowledge graph that best matches the first text information input by the user, the slice document that best matches the first text information can be determined. At this time, through the network structure characteristics of the knowledge graph, the second knowledge graph connected to the first knowledge graph can be easily found, and the corresponding slice document can be obtained according to the second knowledge graph, thereby obtaining all slice documents related to the first text information, thereby improving the completeness of the acquired knowledge information.
[0025] In some embodiments of the first aspect of the present application, the method of selecting the most similar knowledge graph from a preset knowledge base as the first knowledge graph by combining the first vector with the cosine similarity includes:
[0026] Traversing each knowledge graph in the knowledge base in turn, and obtaining a second vector corresponding to the current knowledge graph through a preset graph embedding model;
[0027] Calculate the cosine similarity between each of the second vectors and the first vector, and determine that the knowledge graph corresponding to the second vector with the largest cosine similarity is the first knowledge graph.
[0028] Compared with the prior art, the above embodiment has the following beneficial effects: During the document segmentation process, the segmented document may be too large or too many keywords may be input, resulting in a vector that is too long. Therefore, the similarity between two vectors is judged by cosine similarity, which avoids the influence of vector length on similarity evaluation and improves the accuracy of the text matching process; in addition, the matching problem of text information and graph information is solved by combining the knowledge graph and the graph embedding model, so that the node association features of the knowledge graph can be used to improve the accuracy of the subsequent text matching process.
[0029] In some embodiments of the first aspect of the present application, the large language model outputs a text retrieval result according to the knowledge information, including:
[0030] By using the large language model, the knowledge information is sorted to obtain third text information;
[0031] The third text information is templated by a preset template to obtain the text search result.
[0032] Compared with the prior art, the above embodiment has the following beneficial effects: after the complete knowledge information is obtained, the knowledge information cannot be directly used to reply to the user. Through the large language model, the knowledge information is further integrated and understood, and the third text information after integration is templated, which is equivalent to integrating the discrete key information fragments into a complete and coherent text search result, thereby improving the accuracy of the text search result in expression and improving the efficiency of the user's search information acquisition.
[0033] In a second aspect, the embodiment of the present application further provides a text retrieval device based on a knowledge graph, comprising: a text vector acquisition module, a knowledge information acquisition module, and a text retrieval result acquisition module;
[0034] The text vector acquisition module is used to acquire first text information input by a user, and vectorize the first text information through a preset large language model to acquire a first vector;
[0035] The knowledge information acquisition module is used to select the most similar knowledge graph from a preset knowledge base as a first knowledge graph by combining the cosine similarity and the first vector, and acquire knowledge information according to the first knowledge graph; the knowledge graph is acquired by extracting keywords from a preset knowledge document and combining them with a preset node association rule;
[0036] The text search result acquisition module is used to input the knowledge information into the large language model so that the large language model outputs a text search result according to the knowledge information.
[0037] In some embodiments of the second aspect of the present application, the knowledge graph is obtained by extracting keywords from preset knowledge documents and combining them with preset node association rules, including:
[0038] Slice the knowledge document to obtain a number of slice documents, and count the frequency of each term in the knowledge document appearing in each of the slice documents;
[0039] According to a first preset threshold value, and in combination with the word frequencies of the words appearing in each of the slice documents, all first keywords of each of the slice documents are determined;
[0040] The first keyword is used as a node and combined with the node association rule to obtain a knowledge graph corresponding to each of the slice documents.
[0041] In some embodiments of the second aspect of the present application, the knowledge information acquisition module is used to acquire knowledge information according to the first knowledge graph, including:
[0042] Acquire a plurality of second knowledge graphs associated with the first knowledge graph; wherein the second knowledge graph includes: a knowledge graph that shares the same node as the first knowledge graph;
[0043] Merge the first knowledge graph and all slice documents corresponding to the second knowledge graph to obtain the knowledge information.
[0044] In some embodiments of the second aspect of the present application, the knowledge information acquisition module is used to select the most similar knowledge graph from a preset knowledge base as the first knowledge graph by combining the first vector through cosine similarity, including:
[0045] Traversing each knowledge graph in the knowledge base in turn, and obtaining a second vector corresponding to the current knowledge graph through a preset graph embedding model;
[0046] Calculate the cosine similarity between each of the second vectors and the first vector, and determine that the knowledge graph corresponding to the second vector with the largest cosine similarity is the first knowledge graph. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 A schematic diagram of a flow chart of a text retrieval method based on a knowledge graph provided in some embodiments of the present application;
[0048] Figure 2A schematic diagram of the structure of a knowledge graph-based text retrieval device provided in some embodiments of the present application. DETAILED DESCRIPTION
[0049] When performing text information retrieval, some companies use a large language model to segment documents, obtain small segments, and convert the segments into vectors through text embedding, and perform similarity calculations with the keywords entered by the user to obtain segments that match the search keywords. The above method easily causes key information in related documents to be omitted. In addition, if the size of the segment segment is unreasonable, the search information obtained in the end will be too scattered, resulting in the large language model being unable to answer the key information that meets the requirements based on the matching segments.
[0050] In order to solve the above technical problems, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0051] Embodiment 1
[0052] Please refer to Figure 1 , a text retrieval method based on a knowledge graph provided in an embodiment of the present application, including S10 to S30, specifically:
[0053] S10: Obtain first text information input by a user, and vectorize the first text information using a preset large language model to obtain a first vector.
[0054] Preferably, in some embodiments of the present application, the first vector may be obtained by the following preferred implementation:
[0055] S11: First, select a suitable large language model according to the requirements. Here, we take the BERT model as an example.
[0056] S12: tokenizing the first text information input by the user to split the text into tokens, and obtaining a corresponding token ID;
[0057] S13: Input the data obtained in S12 into the BERT model, extract the hidden state of the token as the first vector of the first text information, and normalize or reduce the dimension of the first vector as required.
[0058] S20: Using cosine similarity and combining with the first vector, select the most similar knowledge graph from the preset knowledge base as the first knowledge graph, and obtain knowledge information based on the first knowledge graph; wherein the knowledge graph is obtained by extracting keywords from preset knowledge documents and combining with preset node association rules.
[0059] In some embodiments of the present application, the knowledge graph is obtained by extracting keywords from preset knowledge documents and combining them with preset node association rules, including:
[0060] Slice the knowledge document to obtain a number of slice documents, and count the frequency of each term in the knowledge document appearing in each of the slice documents;
[0061] According to a first preset threshold value, and in combination with the word frequencies of the words appearing in each of the slice documents, all first keywords of each of the slice documents are determined;
[0062] The first keyword is used as a node and combined with the node association rule to obtain a knowledge graph corresponding to each of the slice documents.
[0063] By the frequency of the entry in the slice document, it is determined whether the entry is a keyword in the slice document, and all the keywords in the slice document are used as nodes of the knowledge graph. In combination with the degree of association between the keywords, the knowledge graph of the corresponding slice document is established. When the keywords of other slice documents are the same as a keyword in the current slice document, the two slice documents are associated through the shared nodes of the knowledge graph, and the nodes of the knowledge graph are constructed through keywords, so that the knowledge graph contains the key text information in each slice document, which improves the completeness of subsequent text retrieval results.
[0064] Preferably, in some embodiments of the present application, the document can be sliced by the following preferred implementation method: first, define a set of delimiters for segmenting the document, and prioritize these delimiters according to the importance of the document structure; for example, chapter titles can be used as the highest priority delimiters, and paragraph marks and periods can be used as secondary delimiters; starting from the top-level delimiter, the document is preliminarily segmented to generate larger sliced documents, and the size and structure of these sliced documents are checked. When the sliced document is too large or the structure does not meet the requirements, continue to use secondary delimiters or more granular delimiters to further refine the segmentation of these sliced documents until all sliced documents meet the target size and structure, and the segmentation process ends.
[0065] Preferably, in some embodiments of the present application, the node association rules can be manually set by determining whether keywords in the same slice document are associated with each other, or by setting corresponding association rules according to specific needs.
[0066] Preferably, in some embodiments of the present application, after determining whether there is an association between the keywords in each slice document, a number of triplets (keyword-association-keyword) will be obtained, and all the obtained triplets will be further stored in the knowledge base through Neo4j, and a corresponding knowledge graph will be generated. At this time, there will be shared nodes corresponding to the same key nodes between different knowledge graphs, and corresponding association relationships can be set for the nodes in different knowledge graphs through manual operation, that is, association relationships can be added to the keywords between different slice documents.
[0067] In some embodiments of the present application, determining all first keywords of each of the slice documents according to the first preset threshold and sequentially combining the word frequencies of the entries appearing in each of the slice documents includes:
[0068] Counting the document frequencies of each of the terms being included in each of the slice documents;
[0069] According to the word frequency and document frequency corresponding to the first terms in the current slice document, obtain the weight of each first term in the corresponding slice document;
[0070] According to the weight of each first term and in combination with the first preset threshold, all the first keywords are screened out from all the first terms in the current slice document.
[0071] In addition to considering the frequency of occurrence of a single term in a single slice document, the number of slice documents containing the term, that is, the document frequency, is also counted. This process not only considers the importance of the term in a single slice document, but also considers its importance in the entire document, so that the first keyword selected contains more semantic features of the document, thereby improving the accuracy of subsequent text matching.
[0072] Preferably, in some embodiments of the present application, the first keyword can be determined by the following preferred implementations:
[0073] S21: Determine the frequency of the term in the current slice document using the following formula:
[0074]
[0075] Among them, p t,d is the frequency of term t in slice document d; η t,d is the number of times term t appears in slice document d; N d is the total number of terms in slice document d;
[0076] S22: Determine the frequency of documents containing the term using the following formula:
[0077]
[0078] Among them, p t ′ is the document frequency corresponding to term t; D is the total number of sliced documents; D t is the number of slice documents containing term t;
[0079] S23: Determine the criticality of each term in the sliced document according to the term frequency and document frequency using the following formula:
[0080]
[0081] S24: According to S21 to S23, evaluate in turn whether the criticality of each term in the current slice document is greater than a first preset threshold; if so, select the corresponding term as the first keyword; otherwise, discard the term.
[0082] In some embodiments of the present application, acquiring knowledge information according to the first knowledge graph includes:
[0083] Acquire a plurality of second knowledge graphs associated with the first knowledge graph; wherein the second knowledge graph includes: a knowledge graph that shares the same node as the first knowledge graph;
[0084] Merge the first knowledge graph and all slice documents corresponding to the second knowledge graph to obtain the knowledge information.
[0085] After obtaining the first knowledge graph that best matches the first text information input by the user, the slice document that best matches the first text information can be determined. At this time, through the network structure characteristics of the knowledge graph, the second knowledge graph connected to the first knowledge graph can be easily found, and the corresponding slice document can be obtained based on the second knowledge graph, thereby obtaining all slice documents related to the first text information and improving the completeness of the acquired knowledge information.
[0086] In some embodiments of the present application, the method of selecting the most similar knowledge graph from a preset knowledge base as the first knowledge graph by combining the first vector with the cosine similarity includes:
[0087] Traversing each knowledge graph in the knowledge base in turn, and obtaining a second vector corresponding to the current knowledge graph through a preset graph embedding model;
[0088] Calculate the cosine similarity between each of the second vectors and the first vector, and determine that the knowledge graph corresponding to the second vector with the largest cosine similarity is the first knowledge graph.
[0089] During the document segmentation process, the segmented document may be too large or there may be too many input keywords, resulting in a vector that is too long. Therefore, the cosine similarity is used to determine the similarity between two vectors, avoiding the influence of vector length on similarity evaluation and improving the accuracy of the text matching process. In addition, the combination of knowledge graph and graph embedding model solves the matching problem of text information and graph information, making it possible to use the node association features of the knowledge graph to improve the accuracy of the subsequent text matching process.
[0090] Preferably, in some embodiments of the present application, the cosine similarity of the first vector and the second vector can be evaluated by the following preferred implementation:
[0091]
[0092] Wherein, CS is the cosine similarity; A and B are the first vector and the second vector respectively; A·B is the dot product of the two vectors; ||A|| and ||B|| are the Euclidean norms of the two vectors respectively.
[0093] Preferably, in some embodiments of the present application, a second preset threshold may be set. When the cosine similarity between the first vector and the second vector is greater than the second preset threshold, the knowledge graph corresponding to the second vector is directly used as the first knowledge graph.
[0094] S30: Inputting the knowledge information into the large language model, so that the large language model outputs a text retrieval result according to the knowledge information.
[0095] In some embodiments of the present application, the large language model outputs text retrieval results based on the knowledge information, including:
[0096] By using the large language model, the knowledge information is sorted to obtain third text information;
[0097] The third text information is templated by a preset template to obtain the text search result.
[0098] After obtaining complete knowledge information, it cannot be used directly to reply to users. Through the large language model, the knowledge information is further integrated and understood, and the third text information after integration is templated. This is equivalent to integrating discrete key information fragments into complete and coherent text retrieval results, which improves the accuracy of text retrieval results in expression and improves the efficiency of users in obtaining retrieval information.
[0099] Preferably, in some embodiments of the present application, when a knowledge graph matching the first text information input by the user cannot be found, a corresponding reply message is output to the user to prompt the user that the document data he or she wishes to retrieve cannot be found.
[0100] In summary, the text retrieval method of a knowledge graph provided by the embodiment of the present application has the following beneficial effects: by converting the document into a knowledge graph, the network feature of the knowledge graph is introduced into the retrieval and matching process, and the network feature can effectively retain the correlation between different documents and the correlation between different keywords. After the document is converted into a knowledge graph, the correlation between fields and fields and the correlation between documents can be better judged according to the correlation between nodes and knowledge graphs, so that a more complete text retrieval result can be obtained based on a knowledge graph obtained by matching. In addition, when the segmented document is too large or too many keywords are input, resulting in a vector that is too long, the similarity between the two vectors is judged by cosine similarity, which avoids the influence of vector length on similarity evaluation and improves the accuracy of the text matching process.
[0101] Embodiment 2
[0102] refer to Figure 2 , a text retrieval device based on knowledge graph provided in an embodiment of the present application, includes: a text vector acquisition module 11, a knowledge information acquisition module 12 and a text retrieval result acquisition module 13.
[0103] In some embodiments of the present application, the text vector acquisition module 11 is used to acquire first text information input by a user, and vectorize the first text information through a preset large language model to acquire a first vector; the knowledge information acquisition module 12 is used to select the most similar knowledge graph from a preset knowledge base as a first knowledge graph through cosine similarity in combination with the first vector, and acquire knowledge information based on the first knowledge graph; the knowledge graph is acquired by extracting keywords from a preset knowledge document and combining them with preset node association rules; the text retrieval result acquisition module 13 is used to input the knowledge information into the large language model so that the large language model outputs a text retrieval result based on the knowledge information.
[0104] In some embodiments of the present application, the knowledge graph is obtained by extracting keywords from preset knowledge documents and combining them with preset node association rules, including: slicing the knowledge document to obtain several slice documents, and counting the word frequency of each term in the knowledge document in each slice document; determining all first keywords of each slice document according to a first preset threshold and combining the word frequency of the terms appearing in each slice document in turn; taking the first keyword as a node and combining it with the node association rule to obtain a knowledge graph corresponding to each slice document.
[0105] In some embodiments of the present application, all the first keywords of each of the slice documents are determined based on the first preset threshold and in combination with the word frequencies of the terms appearing in each of the slice documents, including: counting the document frequencies of each of the terms contained in each of the slice documents; obtaining the weight of each first term in the corresponding slice document based on the word frequencies and document frequencies corresponding to the first terms in the current slice document; and filtering out all the first keywords from all the first terms in the current slice document based on the weights of each first term and in combination with the first preset threshold.
[0106] In some embodiments of the present application, the knowledge information acquisition module 12 is used to acquire knowledge information based on the first knowledge graph, including: acquiring several second knowledge graphs associated with the first knowledge graph; wherein the second knowledge graph includes: a knowledge graph that shares the same node with the first knowledge graph; merging the first knowledge graph and all slice documents corresponding to the second knowledge graphs to acquire the knowledge information.
[0107] In some embodiments of the present application, the knowledge information acquisition module 12 is used to select the most similar knowledge graph as the first knowledge graph from a preset knowledge base through cosine similarity in combination with the first vector, including: traversing each knowledge graph in the knowledge base in turn, and obtaining the second vector corresponding to the current knowledge graph through a preset graph embedding model; calculating the cosine similarity between each of the second vectors and the first vector, and determining that the knowledge graph corresponding to the second vector with the largest cosine similarity is the first knowledge graph.
[0108] In some embodiments of the present application, the large language model outputs a text retrieval result based on the knowledge information, including: organizing the knowledge information through the large language model to obtain third text information; formatting the third text information through a preset template to obtain the text retrieval result.
[0109] In summary, the text retrieval device based on the knowledge graph provided by the embodiment of the present application has the following beneficial effects: by converting the document into the knowledge graph, the network feature of the knowledge graph is introduced into the retrieval and matching process, and the network feature can effectively retain the correlation between different documents and the correlation between different keywords. After the document is converted into the knowledge graph, the correlation between fields and fields and the correlation between documents can be better judged according to the correlation between nodes and the knowledge graph, so that a more complete text retrieval result can be obtained based on a knowledge graph obtained by matching. In addition, when the segmented document is too large or too many keywords are input, resulting in a vector that is too long, the cosine similarity is used to judge the similarity between the two vectors, avoiding the influence of the vector length on the similarity evaluation and improving the accuracy of the text matching process.
[0110] Embodiment 3
[0111] Based on the above-mentioned embodiment of the text retrieval method based on knowledge graph, another embodiment of the present application provides a text retrieval terminal device based on knowledge graph, and the text retrieval terminal device based on knowledge graph includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the text retrieval method based on knowledge graph of any embodiment of the present application is implemented.
[0112] Exemplarily, in this embodiment, the computer program may be divided into one or more modules, which are stored in the memory and executed by the processor to complete the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program in the text retrieval device based on the knowledge graph.
[0113] The text retrieval device based on the knowledge graph may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The text retrieval terminal device based on the knowledge graph may include, but is not limited to, a processor and a memory.
[0114] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the text retrieval device based on the knowledge graph, and uses various interfaces and lines to connect the various parts of the entire text retrieval device based on the knowledge graph. The memory may be used to store the computer program and / or module, and the processor implements various functions of the text retrieval device based on the knowledge graph by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function, etc.; the data storage area may store data created according to the use of the mobile phone, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (SmartMed i aCard, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0115] Embodiment 4
[0116] Based on the above-mentioned embodiment of the text retrieval method based on knowledge graph, another embodiment of the present application provides a storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the storage medium is located is controlled to execute the text retrieval method based on knowledge graph of any embodiment of the present application.
[0117] In this embodiment, the storage medium is a computer-readable storage medium, and the computer program includes computer program code, which may be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0118] The specific embodiments described above further describe the purpose, technical solutions and beneficial effects of the present application in detail. It should be understood that the above description is only a specific embodiment of the present application and is not intended to limit the scope of protection of the present application. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of protection of the present application.
Claims
1. A text retrieval method based on knowledge graph, characterized in that: include: Acquire first text information input by a user, and vectorize the first text information using a preset large language model to acquire a first vector; By using the cosine similarity and combining the first vector, the most similar knowledge graph is selected from the preset knowledge base as the first knowledge graph, and knowledge information is obtained according to the first knowledge graph; wherein the knowledge graph is obtained by extracting keywords from the preset knowledge document and combining them with the preset node association rules; Inputting the knowledge information into the large language model so that the large language model outputs a text retrieval result according to the knowledge information; The knowledge graph is obtained by extracting keywords from preset knowledge documents and combining them with preset node association rules, including: Slice the knowledge document to obtain a number of slice documents, and count the frequency of each term in the knowledge document appearing in each of the slice documents; According to a first preset threshold value, and in combination with the word frequencies of the words appearing in each of the slice documents, all first keywords of each of the slice documents are determined; Taking the first keyword as a node and combining the node association rule, obtaining a knowledge graph corresponding to each of the slice documents; The acquiring of knowledge information according to the first knowledge graph includes: Acquire a plurality of second knowledge graphs associated with the first knowledge graph; wherein the second knowledge graph includes: a knowledge graph that shares the same node as the first knowledge graph; Merge the first knowledge graph and all slice documents corresponding to the second knowledge graph to obtain the knowledge information.
2. A text retrieval method based on knowledge graph as claimed in claim 1, characterized in that: The determining of all first keywords of each of the slice documents according to the first preset threshold and in combination with the word frequencies of the entries appearing in each of the slice documents in sequence includes: Counting the document frequencies of each of the terms being included in each of the slice documents; According to the word frequency and document frequency corresponding to the first terms in the current slice document, obtain the weight of each first term in the corresponding slice document; According to the weight of each first term and in combination with the first preset threshold, all the first keywords are screened out from all the first terms in the current slice document.
3. A text retrieval method based on knowledge graph as claimed in claim 1, characterized in that: The method of selecting the most similar knowledge graph from a preset knowledge base as the first knowledge graph by combining the first vector with the cosine similarity includes: Traversing each knowledge graph in the knowledge base in turn, and obtaining a second vector corresponding to the current knowledge graph through a preset graph embedding model; Calculate the cosine similarity between each of the second vectors and the first vector, and determine that the knowledge graph corresponding to the second vector with the largest cosine similarity is the first knowledge graph.
4. A text retrieval method based on knowledge graph as claimed in claim 1, characterized in that: The large language model outputs text retrieval results according to the knowledge information, including: By using the large language model, the knowledge information is sorted to obtain third text information; The third text information is templated by a preset template to obtain the text search result.
5. A text retrieval device based on knowledge graph, characterized in that: include: Text vector acquisition module, knowledge information acquisition module and text retrieval result acquisition module; The text vector acquisition module is used to acquire first text information input by a user, and vectorize the first text information through a preset large language model to acquire a first vector; The knowledge information acquisition module is used to select the most similar knowledge graph from a preset knowledge base as a first knowledge graph by combining the cosine similarity and the first vector, and acquire knowledge information according to the first knowledge graph; the knowledge graph is acquired by extracting keywords from a preset knowledge document and combining them with a preset node association rule; The text search result acquisition module is used to input the knowledge information into the large language model so that the large language model outputs a text search result according to the knowledge information; The knowledge graph is obtained by extracting keywords from preset knowledge documents and combining them with preset node association rules, including: Slice the knowledge document to obtain a number of slice documents, and count the frequency of each term in the knowledge document appearing in each of the slice documents; According to a first preset threshold value, and in combination with the word frequencies of the words appearing in each of the slice documents, all first keywords of each of the slice documents are determined; Taking the first keyword as a node and combining the node association rule, obtaining a knowledge graph corresponding to each of the slice documents; The knowledge information acquisition module is used to acquire knowledge information according to the first knowledge graph, including: Acquire a plurality of second knowledge graphs associated with the first knowledge graph; wherein the second knowledge graph includes: a knowledge graph that shares the same node as the first knowledge graph; Merge the first knowledge graph and all slice documents corresponding to the second knowledge graph to obtain the knowledge information.
6. A text retrieval device based on knowledge graph according to claim 5, characterized in that: The knowledge information acquisition module is used to select the most similar knowledge graph from a preset knowledge base as the first knowledge graph by combining the first vector with the cosine similarity, including: Traversing each knowledge graph in the knowledge base in turn, and obtaining a second vector corresponding to the current knowledge graph through a preset graph embedding model; Calculate the cosine similarity between each of the second vectors and the first vector, and determine that the knowledge graph corresponding to the second vector with the largest cosine similarity is the first knowledge graph.
Citation Information
Patent Citations
Intelligent question and answer system based on knowledge graph subgraph retrieval
CN113297369A
Enterprise knowledge base construction query system and method based on large language model
CN117852633A