Retrieval enhancement generation method and device

通过构建知识图谱并结合语言模型处理提示词,解决了现有检索增强生成方法中答案不准确和不完整的问题,实现了更高效和准确的答案生成。

CN120277193APending Publication Date: 2025-07-08HENAN QINWEI DIGITAL TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510429081.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-07
Publication Date
2025-07-08

AI Technical Summary

Technical Problem

When existing search enhancement generation methods deal with queries that require global knowledge and complex reasoning, they can easily lead to the loss of context information and the answer is not accurate and complete.

Method used

By constructing a knowledge graph, retrieving the knowledge graph content based on user query information, and processing prompt words with similar document blocks and language models, we can determine accurate and complete answers.

Benefits of technology

Improve the accuracy and completeness of the search and enhance the generation method, reduce the time-consuming and hardware resource consumption, and improve the search efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120277193A_ABST
    Figure CN120277193A_ABST
Patent Text Reader

Abstract

The invention provides a retrieval enhancement generation method and device. The method comprises the steps of obtaining user query information; retrieving the knowledge graph based on the user query information, and determining corresponding knowledge graph content; performing similarity recall on the document vector library based on user query information to obtain similar document blocks; determining cue words based on the knowledge graph content, the similar document blocks and the user query information; and processing the cue word based on the language model to obtain an answer. According to the technical scheme, the knowledge graph content including the context information and the global knowledge is added in the cue word, so that the cue word is processed based on the large language model, an accurate and complete answer can be obtained, and the accuracy and integrity of the retrieval enhancement generation method are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the technical field of natural language processing, and in particular, to a retrieval augmented generation method and device. Background Art

[0002] With the rapid development of large language models (LLMs), the retrieve-and-generate (RAG) method based on LLMs has attracted much attention in the field of natural language processing. This RAG method first retrieves document chunks related to the user query information from a document vector library, and then uses a large language model to process the retrieved relevant document chunks and the user query information to generate an answer.

[0003] However, when this RAG method processes queries that require global knowledge and complex reasoning, it will lose the information between contexts due to the lack of understanding of the relationships between text contexts; it will also reduce the quality of the answer due to the lack of global knowledge understanding. Moreover, due to the independence of document chunks, the answer will lack coherence or important information will be omitted. Therefore, there is an urgent need for a RAG method to solve the above problems and improve the accuracy and integrity of the answer. Summary of the Invention

[0004] The embodiments of the present application provide a retrieval augmented generation method, which can solve the problems that the answers obtained by the existing RAG methods are not accurate enough and not complete enough.

[0005] To achieve the above object, the embodiments of the present application adopt the following technical solutions:

[0006] In a first aspect, the embodiments of the present application provide a retrieval augmented generation method, the method includes: obtaining user query information; retrieving a knowledge graph based on the user query information to determine the corresponding knowledge graph content; wherein, the knowledge graph is constructed based on a document library; performing similarity recall on a document vector library based on the user query information to obtain similar document chunks; wherein, the document vector library is constructed based on the document library; determining a prompt word based on the knowledge graph content, the similar document chunks and the user query information; and processing the prompt word based on a language model to obtain an answer.

[0007] Based on this solution, since the knowledge graph can display all entities and the complete relationships between entities, retrieving the knowledge graph through the user query information can obtain knowledge graph content including context information and global knowledge. Furthermore, based on the knowledge graph content, the similar document chunks and the user query information, a prompt word including context information and global knowledge can be determined. In this way, processing the prompt word based on the language model can obtain a relatively accurate and complete answer, improving the accuracy and integrity of the retrieval augmented generation method.

[0008] In a possible implementation, the retrieval augmented generation method further includes: extracting entities from a document library based on a first entity extraction algorithm to obtain a plurality of document entities; wherein, the first entity extraction algorithm is an algorithm corresponding to traditional natural language processing; identifying the relationships between the document entities; and constructing a knowledge graph based on the document entities and the relationships between the document entities.

[0009] Based on this solution, since traditional natural language processing has higher accuracy and lower complexity compared with large models, the entities obtained by extracting entities based on the first entity extraction algorithm corresponding to traditional natural language processing are more accurate and the speed is also faster. Therefore, based on the entities and the identified relationships between the entities, a knowledge graph can be constructed quickly and accurately.

[0010] In another possible implementation, constructing a knowledge graph based on the document entities and the relationships between the document entities includes: constructing a concept graph based on the document entities and the relationships between the document entities; extracting the hierarchical community structure of the concept graph; and constructing a knowledge graph based on the concept graph and the hierarchical community structure.

[0011] Based on this solution, since the hierarchical community structure can organize knowledge hierarchically, the knowledge graph constructed based on the concept graph and the hierarchical community structure of the concept graph can achieve hierarchical organization and modular management of knowledge. When retrieving the knowledge graph, it can reduce the retrieval time consumption and the consumption of hardware resources, shorten the retrieval time, and improve the retrieval efficiency.

[0012] In yet another possible implementation, retrieving a knowledge graph based on user query information and determining the corresponding knowledge graph content includes: extracting an entity from the user query information to obtain a query entity; parsing the knowledge graph to obtain a knowledge text library corresponding to the knowledge graph; and retrieving the knowledge graph content from the knowledge text library based on the query entity.

[0013] Based on this solution, by extracting the entity of the user query information and retrieving the texturized knowledge graph based on the obtained query entity, in this way, the retrieval of the knowledge graph can be realized, and the knowledge graph content that is contextually related and comprehensive can be obtained.

[0014] In yet another possible implementation, extracting an entity from the user query information to obtain a query entity includes: obtaining a second entity extraction algorithm, wherein the second entity extraction algorithm is an algorithm corresponding to traditional natural language processing; and processing the user query information based on the second entity extraction algorithm to obtain a query entity.

[0015] Based on this solution, since traditional natural language processing has higher accuracy and lower complexity compared to large models, processing the user's query information through the second entity extraction algorithm corresponding to traditional natural language processing can quickly and accurately obtain the query entity, reducing the retrieval time and consumption of hardware resources.

[0016] In another possible implementation, retrieve the knowledge text library based on the query entity to obtain the knowledge graph content, including: retrieving knowledge texts based on the query entity to obtain multiple knowledge outputs; re-ranking the multiple knowledge outputs using a re-ranker to obtain the re-ranked multiple knowledge outputs; determining the knowledge graph content based on the re-ranked multiple knowledge outputs.

[0017] Based on this solution, by re-ranking the retrieved knowledge outputs, filtering and optimizing the knowledge outputs are achieved, and the knowledge graph content is determined based on the re-ranked multiple knowledge outputs; in this way, the problem that the knowledge graph does not highlight the key points can be solved.

[0018] In another possible implementation, the retrieval enhanced generation method further includes: splitting each document in the document library into blocks to obtain multiple document blocks; converting each document block into a vector using a vector tool to obtain multiple document vectors; building an index between each document vector and the corresponding document block to obtain a document vector library.

[0019] Based on this solution, by splitting each document in the document library into blocks and vectorizing each document block, multiple document vectors are obtained. In this way, by building an index between each document vector and the corresponding document block, the preservation of the document vectors and document blocks can be realized, and a document vector library is obtained.

[0020] In another possible implementation, perform similarity recall on the document vector library based on the user's query information to obtain similar document blocks, including: converting the user's query information into a vector using a vector tool to obtain a query vector; performing similarity recall on the document vector library based on the query vector to obtain similar document blocks.

[0021] Based on this solution, by vectorizing the user's query information into a query vector, in this way, the most similar document block with the highest similarity can be recalled from the document vector library based on the query vector.

[0022] In another possible implementation, determine the prompt word based on the knowledge graph content, similar document blocks, and the user's query information, including: concatenating the knowledge graph content, similar document blocks, and the user's query information to obtain a concatenated text; determining the prompt word based on the concatenated text.

[0023] Based on this solution, by splicing the content of the knowledge graph, similar document chunks, and user query information, a prompt word including knowledge topology content can be obtained, that is, a prompt word for the content of the knowledge graph including context information and global knowledge can be determined. Thus, based on this prompt word, answers with high accuracy and integrity can be obtained.

[0024] In a second aspect, an embodiment of the present application provides a computing device, which includes: a processor, and a memory for storing processor-executable instructions; the processor is configured to execute the retrieval enhancement generation method in the first aspect above.

[0025] In a third aspect, an embodiment of the present application provides a retrieval enhancement generation device, which includes: a first acquisition module for acquiring user query information; a retrieval module for retrieving the knowledge graph based on the user query information to determine the corresponding knowledge graph content; wherein, the knowledge graph is constructed based on a document library; a recall module for performing similarity recall on the document vector library based on the user query information to obtain similar document chunks; wherein, the document vector library is constructed based on the document library; a determination module for determining a prompt word based on the knowledge graph content, the similar document chunks, and the user query information; a processing module for processing the prompt word based on a language model to obtain an answer.

[0026] In a fourth aspect, an embodiment of the present application provides a storage medium, which stores a computer program for executing the retrieval enhancement generation method provided in the first aspect above.

[0027] In a fifth aspect, an embodiment of the present application provides a computer program product, when the instructions in the computer program product are executed by a processor, the retrieval enhancement generation method provided in the first aspect above is executed. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1 It is a schematic flowchart of a retrieval enhancement generation method provided by an embodiment of the present application.

[0029] Figure 2 It is a schematic flowchart of another retrieval enhancement generation method provided by an embodiment of the present application.

[0030] Figure 3 It is a schematic flowchart of yet another retrieval enhancement generation method provided by an embodiment of the present application.

[0031] Figure 4 It is a schematic flowchart of yet another retrieval enhancement generation method provided by an embodiment of the present application.

[0032] Figure 5 It is a schematic flowchart of yet another retrieval enhancement generation method provided by an embodiment of the present application.

[0033] Figure 6 It is a schematic flowchart of another retrieval enhanced generation method provided by an embodiment of the present application.

[0034] Figure 7 It is a schematic flowchart of another retrieval enhanced generation method provided by an embodiment of the present application.

[0035] Figure 8 It is a schematic flowchart of another retrieval enhanced generation method provided by an embodiment of the present application.

[0036] Figure 9 It is a schematic structural diagram of a retrieval enhanced generation device provided by an embodiment of the present application.

[0037] Figure 10 It is a schematic structural diagram of a computing device provided by an embodiment of the present application.

[0038] Figure 11 It is a schematic structural diagram of another computing device provided by an embodiment of the present application. Detailed implementation manners

[0039] Next, the technical solutions in the embodiments of the present application will be described in conjunction with the accompanying drawings in the embodiments of the present application. For the convenience of clearly describing the technical solutions in the embodiments of the present application, the descriptions such as first and second that appear in the embodiments of the present application are only for schematic and distinguishing the description objects, without any order, and do not represent the special limitation on the number of devices in the embodiments of the present application, and cannot constitute any limitation to the embodiments of the present application.

[0040] Next, the relevant technical terms in the embodiments of the present application will be described:

[0041] A computing device is an electronic device used to perform computing tasks. Computing devices can include personal computers, servers, embedded computers, supercomputers, etc. In this application, a server is taken as an example of a computing device for illustrative purposes. The server in this application can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, cloud communications, middleware services, domain name services, security services, Content Delivery Network (CDN), as well as big databases and artificial intelligence platforms. When the above server is a server cluster or a distributed system composed of multiple physical servers, the multiple physical servers can form a blockchain, and each physical server is a node on the blockchain. The physical types of servers can include cabinet servers, rack servers, high-density servers, Graphic Processing Unit (GPU) servers, tower servers, and can also be blade servers, Artificial Intelligence (AI) servers, etc. The embodiments of this application do not limit the types of servers.

[0042] Natural Language Processing (NLP): NLP is an important research direction in the field of artificial intelligence, integrating knowledge from multiple disciplinary fields such as linguistics, computer science, machine learning, mathematics, and cognitive psychology. It is an interdisciplinary subject integrating computer science, artificial intelligence, and linguistics. It includes two main aspects: natural language understanding and natural language generation. The research content includes various levels such as characters, words, phrases, sentences, paragraphs, and chapters. It is a bridge of communication between machine language and human language. Its purpose is to enable machines to understand, interpret, and generate human language, achieve effective communication between humans and machines, and enable computers to perform tasks such as language translation, sentiment analysis, and text summarization.

[0043] Knowledge Graph: A knowledge graph is a modern theory that combines the theories and methods of disciplines such as applied mathematics, graphics, information visualization technology, and information science with methods such as bibliometric citation analysis and co-occurrence analysis, and uses a visualized graph to vividly display the core structure, development history, frontier fields, and overall knowledge architecture of a discipline to achieve the purpose of multi-disciplinary integration.

[0044] Re-ranking: The re-ranker is a key component in an information retrieval system used to further rank the initial retrieval results. It optimizes the initial results through more complex models such as machine learning, deep learning, or rule-based models to ensure that users get more accurate results. Re-rankers are widely used in search engines, question-and-answer systems, recommendation systems, and advertising systems, and can effectively improve the relevance of the system and user satisfaction.

[0045] Retrieval-Augmented Generation (RAG): RAG is a model that combines retrieval and generation techniques. It generates answers or content by referring to information from an external knowledge base, has strong interpretability and customization capabilities, and is applicable to multiple natural language processing tasks such as question-and-answer systems, document generation, and intelligent assistants. The advantages of the RAG model lie in its strong versatility, the ability to achieve instant knowledge updates, and the provision of more efficient and accurate information services through end-to-end evaluation methods.

[0046] LLM: LLM refers to an artificial intelligence model trained with large-scale data and having powerful natural language processing capabilities. Such models can understand and generate human language and are widely used in tasks such as text generation, translation, and question-and-answer.

[0047] An embodiment of this application provides a retrieval-augmented generation method. This method constructs a knowledge graph and determines the knowledge graph content corresponding to the user's query information based on the knowledge graph, so that the knowledge graph content can reflect context information and global knowledge. Therefore, when the knowledge graph content is included in the prompt, processing the prompt based on the large language model can obtain a relatively accurate and complete answer, improving the accuracy and completeness of the retrieval-augmented generation method.

[0048] Figure 1 It is a schematic flowchart of a retrieval-augmented generation method provided by an embodiment of this application. This retrieval-augmented generation method can be applied to a computing device and can be implemented through a script file of the computing device. As Figure 1 shown, this retrieval-augmented generation method includes the following steps S101 - step S105.

[0049] Step S101, obtain the user's query information.

[0050] Exemplarily, the user's query information can also be referred to as the input query information or the user's question. In some examples, the user's query information may include the question input by the user.

[0051] Step S102, retrieve the knowledge graph based on the user's query information and determine the corresponding knowledge graph content.

[0052] Among them, the knowledge graph can be constructed based on a document library.

[0053] The document library may include multiple historical documents. The embodiments of the present application do not limit the number of documents in the document library. The embodiments of the present application take the example that the document library includes at least 10 historical documents for illustrative purposes.

[0054] Before step S102, a knowledge graph can be constructed based on the document library. In some examples, the computing device can obtain multiple historical documents, then construct a document library based on the multiple historical documents, and then process the document library through a first processing algorithm to obtain a knowledge graph.

[0055] The computing device can obtain multiple historical documents by means of web crawling or directly obtain internal documents. The embodiments of the present application do not limit the way of obtaining the document library. The embodiments of the present application take the example of directly obtaining internal documents for illustrative purposes.

[0056] The first processing algorithm can be an algorithm for constructing a knowledge graph based on multiple documents. In some examples, the first processing algorithm includes entity recognition, relationship extraction, etc. The embodiments of the present application do not limit the type of the first processing algorithm.

[0057] Exemplarily, the knowledge graph content, also known as community content, is the content in a specific data format corresponding to the user's query information in the knowledge graph. In some examples, the specific data format can be the first text format of [Person] [Action] [Event], or the second text format of [Person] [Location] [Event]. The embodiments of the present application do not limit the type of the specific data format. The embodiments of the present application take the specific data format of [Person] [Action] [Event] as an example for illustrative purposes. Taking the user's query information as "Did Person 1 publish?" as an example. The knowledge graph content may include at least one of the following:

[0058] Content 1: (Person 1)-[:Published]->(Theory 1)

[0059] Content 2: (Theory 1: Theory {Publication Year: "Year 1", Type: "Type 1"})

[0060] Content 3: (Theory 1)-[:Contains]->(Formula 2)

[0061] Content 4: (Formula 2: Formula {Formula: "Formula 1", Belonging Theory: "Theory 1"})

[0062] Content 5: (Person 1: Person {Occupation: "Physicist", Birth Year: "Year 2", Death Year: "Year 3", Nationality: "Country A"}).

[0063] Exemplarily, the computing device may extract query entities from the user query information, and retrieve the knowledge graph based on the query entities in a regular rule or small model manner to obtain corresponding knowledge graph content. The embodiments of the present application do not limit the implementation manner of retrieving the knowledge graph based on the query entities. The embodiments of the present application take retrieving the knowledge graph based on the query entities by regular rules as an example for exemplary illustration.

[0064] Step S103: Perform similarity recall on the document vector library based on the user query information to obtain similar document chunks.

[0065] Among them, the document vector library is constructed based on the document library.

[0066] Before step S103, the document vector library may be constructed based on the document library first. In some examples, the computing device may obtain multiple historical documents, then construct a document library based on the multiple historical documents, and then process the document library through a second processing algorithm to obtain the document vector library.

[0067] The embodiments of the present application will not elaborate on the acquisition methods of multiple document libraries here.

[0068] The first processing algorithm for acquisition may be an algorithm for constructing a document vector library based on multiple documents. In some examples, the second processing algorithm includes document chunking, vectorization processing, etc. The embodiments of the present application do not limit the type of the second processing algorithm.

[0069] Exemplarily, the similar document chunk may be the document chunk corresponding to the text vector most similar to the user query information in the document vector library.

[0070] The similar document chunk may include one document chunk or multiple document chunks. The present application does not limit the number of document chunks in the similar document chunk. The embodiments of the present application take the similar document chunk including one document chunk as an example for exemplary illustration.

[0071] Exemplarily, the computing device may first determine the query vector corresponding to the user query information, then calculate the similarity between the query vector and each document vector in the document vector library, and determine the similar document chunk based on the magnitude of the similarity.

[0072] In some examples, taking the similar document chunk including one document chunk as an example. If the user's query is "Did Person Name 1 publish?", then the similar document chunk may be "Person Name 1 was born in Year 2 and is a great physical scientist".

[0073] Step S104: Determine the prompt word based on the knowledge graph content, the similar document chunk, and the user query information.

[0074] Exemplarily, the computing device may splice the knowledge graph content, similar document blocks, and user query information to obtain a spliced text, and determine a prompt word based on the spliced text.

[0075] In some examples, the computing device may splice the knowledge graph content, similar document blocks, and user query information in a preset splicing manner, and use the obtained spliced text as the prompt word.

[0076] The preset splicing manner may include any one of the following splicing manners: directly splicing the knowledge graph content, similar document blocks, and user query information; using a predefined template to combine the knowledge graph content, similar document blocks, and user query information; splicing the knowledge graph content, similar document blocks, and user query information in a structured format; and other splicing manners. The embodiments of the present application do not limit the type of the preset splicing manner. The embodiments of the present application take the preset splicing manner as directly splicing the knowledge graph content, similar document blocks, and user query information as an example for exemplary illustration.

[0077] Taking the preset splicing manner as directly splicing the knowledge graph content, similar document blocks, and user query information as an example. In some examples, the electronic device may directly splice in the order of the knowledge graph content, similar document blocks, and user query information, or directly splice in the order of similar document blocks, knowledge graph content, and user query information, or directly splice in the order of user query information, knowledge graph content, and similar document blocks. The embodiments of the present application do not limit the order of the direct knowledge graph content, similar document blocks, and user query information. The embodiments of the present application take directly splicing in the order of the knowledge graph content, similar document blocks, and user query information as an example for exemplary illustration.

[0078] Taking directly splicing in the order of the knowledge graph content, similar document blocks, and user query information as an example. If the knowledge graph content includes Content 1: "(Person Name 1)-[:published]->(Theory 1)" and Content 2: "(Theory 1: Theory{publication year: "Year 1", type: "Type 1"})", the similar document block includes: "Person Name 1 was born in Year 2 and is a great physical scientist", and the user query information includes: "What did Person Name 1 publish?", then the prompt word is "What did Person Name 1 publish? (Person Name 1)-[:published]->(Theory 1) Theory{publication year: "Year 1", type: "Type 1"}) Person Name 1 was born in Year 2 and is a great physical scientist".

[0079] Step S105: Process the prompt word based on the language model to obtain an answer.

[0080] Exemplarily, the language model can be a general large language model that has been trained and can be used to answer the input user inquiries or questions. The embodiments of this application do not limit the structure of the large language model. Taking the large language model as an example that may include an input layer, an encoder, a decoder, an output layer, etc., the embodiments of this application are exemplarily described.

[0081] Exemplarily, the computing device can input the prompt into the large language model, and the large language model can encode and decode the prompt through the self-attention mechanism to generate an answer. In some examples, the large language model can perform preprocessing (including word segmentation and tagging), vectorized representation (including word embedding and position encoding), Transformer core processing (including self-attention mechanism, feed-forward network, and multi-head attention), and output generation and other processing on the prompt in response to the prompt, and obtain an answer with a natural language expression that conforms to semantics and context logic. For example, if the prompt is "Who published? (Person 1)-[:published]->(Theory 1) Theory {publication year: "Year 1", type: "Type 1"}) Person 1 was born in Year 2 and is a great physical scientist", the answer output by the large language model can be "Person 1 invented XXX".

[0082] For the retrieval-augmented generation method provided by the embodiments of this application, since the knowledge graph can display all entities and the complete relationships between each entity, therefore, by retrieving the knowledge graph through the user query information, the knowledge graph content including context information and global knowledge can be obtained. Furthermore, based on the knowledge graph content, similar document chunks, and user query information, the prompt for the knowledge graph content including context information and global knowledge can be determined. In this way, based on the large language model to process the prompt, a more accurate and complete answer can be obtained, improving the accuracy and integrity of the retrieval-augmented generation method.

[0083] In some embodiments of this application, in order to be able to retrieve based on the knowledge graph at any time, the computing device can, before obtaining the user query information, perform entity extraction on the obtained document library through the knowledge graph large model, and construct a knowledge graph based on the extracted document entities and the relationships between each document entity. However, the knowledge graph large model is not only very complex but also has relatively weak industry background knowledge. Thus, when performing entity extraction through the knowledge graph large model, the output document entities are not stable enough, the accuracy is not high enough, and at the same time, it will occupy a large amount of computing resources, seriously affecting the efficiency and speed of retrieval-augmented generation.

[0084] Based on the above technical problems, an embodiment of the present application provides a method for constructing a knowledge graph based on a document library. This method uses traditional natural language processing algorithms instead of a knowledge graph large model to extract document entities from the document library, and then identifies the relationships between the document entities. Based on the document entities and the relationships between the document entities, a knowledge graph is constructed. As Figure 2 shown, on the basis of the above Figure 1 shown embodiment, before executing step S101 to obtain user query information, this retrieval augmented generation method may further include the following steps S106 to S108.

[0085] Step S106: Extract entities from the document library based on the first entity extraction algorithm to obtain a plurality of document entities.

[0086] Among them, the first entity extraction algorithm is an algorithm corresponding to traditional natural language processing.

[0087] Exemplarily, the document entity can be a named entity, and the document entity can include a person's name, a place name, an organization name, etc. The embodiment of the present application does not limit the type of the document entity.

[0088] The first entity extraction algorithm may include at least one of algorithms such as a small model, an entity extraction algorithm, a noun extraction algorithm, a phrase extraction algorithm, and a similar word matching algorithm. The embodiment of the present application does not limit the algorithms included in the first entity extraction algorithm.

[0089] In some examples, the computing device can use the lightweight NLTK (Natural Language Toolkit) library for entity extraction. For example, each document in the document library can be tokenized first, then part-of-speech tagged, and named entity recognition can be performed on the part-of-speech tagged sentences through the ne_chunk function provided by NLTK to obtain a plurality of sample entities.

[0090] Step S107: Identify the relationships between the document entities.

[0091] Exemplarily, the relationships between the document entities can be semantic connections between the document entities. In some examples, the relationships between the document entities can include "located in", "works in", "belongs to", etc.

[0092] The computing device can identify the relationships between entities through the dependency syntax analysis tool of NLTK. In some examples, the computing device can identify the relationships between the document entities through three key steps: text preprocessing, dependency syntax analysis, and entity relationship extraction.

[0093] In some examples, after identifying document entities and the relationships between the document entities, the computing device may integrate the identified document entities and the relationships between the document entities into structured data (data in a fixed data format) to facilitate the storage and query of the document entities and the relationships between the document entities.

[0094] Step S108: Construct a knowledge graph based on the document entities and the relationships between the document entities.

[0095] Exemplarily, the computing device may directly construct a knowledge graph according to the document entities and the relationships between the document entities, or may first perform knowledge representation and / or classification on the relationships between the document entities and each document entity, and then construct a knowledge graph based on the knowledge representation and / or classification results. The embodiments of the present application do not limit the implementation manner of constructing a knowledge graph based on the document entities and the relationships between the document entities.

[0096] For the retrieval enhanced generation method provided by the embodiments of the present application, compared with traditional natural language processing and large models, the accuracy is higher and the complexity is lower. Therefore, the entities obtained by extracting entities based on the first entity extraction algorithm corresponding to traditional natural language processing are more accurate, and the extraction speed is also faster. Therefore, based on the document entities and the relationships between the identified document entities, a knowledge graph can be constructed quickly and accurately.

[0097] In some embodiments of the present application, to construct a hierarchical and modular knowledge graph, a concept graph may be first constructed based on the document entities and the relationships between the document entities, and a knowledge graph may be constructed based on the concept graph and the hierarchical community structure of the concept graph. As Figure 3 shown, based on the above Figure 2 shown embodiments, step S108 of constructing a knowledge graph based on the document entities and the relationships between the document entities may include the following steps S1081 to S1083.

[0098] Step S1081: Construct a concept graph based on the document entities and the relationships between the document entities.

[0099] Exemplarily, a concept graph is a graphical knowledge representation tool used to display the relationships and structures between concepts. The concept graph can visualize abstract concepts and their associations through nodes and connections, helping to understand complex topics, organize information, or design solutions. Among them, the nodes represent concepts, ideas, or entities, and the connections represent the relationships between concepts.

[0100] In some examples, a computing device may define nodes and edges based on document entities and the relationships between the document entities, represent a graph through a graph data structure or a graph database, populate the nodes and edges in the graph data structure or the graph database to obtain a concept graph, and store the concept graph. In some examples, the graph may be constructed by using the NetworkX library of Python and nodes and edges may be added to obtain a concept graph.

[0101] Step S1082: Extract the hierarchical community structure of the concept graph.

[0102] Exemplarily, the hierarchical community structure refers to a relationship where communities (or modules) are nested or layered in a complex network (such as a graph, a knowledge graph, a social network, etc.). In some examples, the hierarchical community structure may include a strip structure and a composite structure. Extracting the hierarchical community structure of the concept graph may be to divide the nodes (entities) in the concept graph into nested communities (modules), thereby revealing the multi-level organizational structure of the concept graph.

[0103] The computing device may use a community detection algorithm to extract the hierarchical community structure from the concept graph to achieve efficient extraction of the hierarchical community structure. The community detection algorithm may be one of the Louvain algorithm, the Girvan - Newman algorithm, the hierarchical clustering algorithm, etc. In the embodiments of this application, the community detection algorithm is taken as an example of the hierarchical clustering algorithm for exemplary illustration. In some examples, the community detection algorithm is agglomerative hierarchical clustering. Here, agglomerative hierarchical clustering is a bottom - up method. Each data point is initially regarded as a separate cluster, and then the most similar clusters are gradually merged until all data points are merged into one cluster or a certain termination condition is reached. In other examples, the community detection algorithm is divisive hierarchical clustering. In the embodiments of this application, the hierarchical clustering algorithm is taken as an example of agglomerative hierarchical clustering for exemplary illustration.

[0104] Step S1083: Construct a knowledge graph based on the concept graph and the hierarchical community structure.

[0105] Exemplarily, the computing device may first define the hierarchical structure of the knowledge graph, then add the nodes and edges in the concept graph to the knowledge graph, and add the hierarchical relationships between communities based on the hierarchical community structure. Finally, the knowledge graph is saved. In some examples, the mainstream graph database Neo4j or open - source tools such as ConceptNet, DBpedia, and DeepKE that support extracting knowledge from unstructured text and constructing a knowledge graph may be used to construct the knowledge graph.

[0106] The retrieval enhancement generation method provided by the embodiments of the present application. Since the hierarchical community structure can organize knowledge hierarchically, the knowledge graph constructed based on the concept graph and the hierarchical community structure of the concept graph can achieve hierarchical organization and modular management of knowledge. Furthermore, when retrieving the knowledge graph, it can reduce the retrieval time consumption and the consumption of hardware resources, shorten the retrieval time, and improve the retrieval efficiency.

[0107] As Figure 4 shown, based on the above Figure 1 embodiment, step S102 for retrieving the knowledge graph based on the user query information and determining the corresponding knowledge graph content may include the following steps S1021 to S1023.

[0108] Step S1021: Extract entities from the user query information to obtain query entities.

[0109] Exemplarily, since traditional natural language processing has higher accuracy and lower complexity compared with large models, in order to quickly and accurately obtain query entities and reduce the retrieval time consumption and the consumption of hardware resources, the user query information can be processed by the second entity extraction algorithm corresponding to traditional natural language processing to obtain query entities.

[0110] In some embodiments, extracting entities from the user query information to obtain query entities may include: obtaining a second entity extraction algorithm, where the second entity extraction algorithm is an algorithm corresponding to traditional natural language processing; processing the user query information based on the second entity extraction algorithm to obtain query entities.

[0111] Exemplarily, the second entity extraction algorithm may be the same as or different from the first entity extraction algorithm. The embodiments of the present application do not limit the type of the second entity extraction algorithm. The embodiments of the present application take the second entity algorithm being the same as the first entity algorithm as an example for exemplary illustration.

[0112] Similar to extracting entities from the document library based on the first entity extraction algorithm to obtain multiple document entities, the computing device can use the lightweight NLTK library to extract entities from the user query information to obtain query entities. For example, the user query information can be first part-of-speech tagged, and the named entity recognition can be performed on the sentence with part-of-speech tagged through the ne_chunk function provided by NLTK to obtain at least one query entity.

[0113] Step S1022: Parse the knowledge graph to obtain the knowledge text library corresponding to the knowledge graph.

[0114] Exemplarily, the computing device may convert each piece of structured data in the knowledge graph into natural language text to obtain a knowledge text library. In some examples, the computing device may first determine a predefined text template, then extract document entities and the relationships between the document entities from the knowledge graph, and generate corresponding knowledge texts based on the extracted document entities, the relationships between the document entities, and the predefined text template to construct the knowledge text library.

[0115] In some examples, the knowledge texts in the knowledge text library may include a first text format of [Person] [Action] [Event] and / or a second text format of [Person] [Location] [Event].

[0116] Step S1023, retrieve the knowledge text library based on the query entity to obtain the knowledge graph content.

[0117] Taking the text in the first text format of [Person] [Action] [Event] included in the knowledge text library as an example. The computing device may retrieve the [Person] in each knowledge text in the knowledge text library based on regular rules or a small model, obtain multiple knowledge texts related to the text knowledge, and determine the knowledge graph content based on the multiple knowledge texts.

[0118] Taking the retrieved entity as "Person Name 1" as an example. In some examples, the computing device may query the [Person] in each knowledge text in the knowledge text library, and use all the knowledge texts with [Person] being [Person Name 1] as the knowledge graph content. For example, if the knowledge text library includes [Person Name 1] [Action 1] [Event 1], [Person Name 1] [Action 2] [Event 2], [Person Name 1] [Action 3] [Event 3], [Person Name 1] [Action 4] [Event 4], [Person Name 1] [Action 5] [Event 5], [Person Name 2] [Action 6] [Event 6], and other knowledge texts, then [Person Name 1] [Action 1] [Event 1], [Person Name 1] [Action 2] [Event 2], [Person Name 1] [Action 3] [Event 3], [Person Name 1] [Action 4] [Event 4], and [Person Name 1] [Action 5] [Event 5] may be used as the knowledge graph content.

[0119] The retrieval enhanced generation method provided by the embodiments of the present application extracts the entity of the user query information and retrieves the texturized knowledge graph based on the obtained query entity. In this way, the retrieval of the knowledge graph can be realized, and the knowledge graph content associated with the context and comprehensive can be obtained.

[0120] In some examples, when retrieving the knowledge text library based on the query entity, multiple knowledge outputs may be obtained. Since the multiple knowledge outputs are not optimized and sorted, there is a problem that the key points are not highlighted in the knowledge graph constructed based on the multiple knowledge outputs.

[0121] Based on the above technical problems, as Figure 5 shown, in the aboveFigure 4 Based on the illustrated embodiments, step S1023 retrieves the knowledge text library based on the query entity, and obtaining the content of the knowledge graph may include the following steps S501 to S503.

[0122] Step S501: Retrieve the knowledge text library based on the query entity to obtain multiple knowledge outputs.

[0123] Exemplarily, the multiple knowledge outputs may be multiple knowledge texts in the knowledge text library related to the query entity. The number of knowledge texts in the multiple knowledge outputs may be greater than or equal to 1. In some examples, 100 knowledge outputs may be obtained based on retrieving the knowledge text library by the retrieval entity. The embodiments of the present application do not limit the number of knowledge texts in the multiple knowledge outputs. The embodiments of the present application take the multiple knowledge outputs including 100 knowledge texts as an example for exemplary illustration.

[0124] Exemplarily, the multiple knowledge outputs may be multiple knowledge outputs in a random order, and the multiple knowledge outputs in this random order cannot reflect the relevance between each knowledge output and the query entity. In some examples, taking the user's query as "What did Person 1 publish?", the multiple knowledge outputs may include:

[0125] Content 4: (Formula 2: Formula{Formula: "Formula 1", Belonging theory: "Theory 1"});

[0126] Content 5: (Person 1: Person{Occupation: "Physicist", Birth year: "Year 2", Death year: "Year 3", Nationality: "Country A"});

[0127] Content 1: (Person 1)-[:Published]->(Theory 1);

[0128] Content 3: (Theory 1)-[:Contains]->(Formula 2);

[0129] Content 2: (Theory 1: Theory{Publication year: "Year 1", Type: "Type 1"})... and so on, a total of 100 knowledge outputs.

[0130] Step S502: Reorder the multiple knowledge outputs based on a re-ranker to obtain the re-ordered multiple knowledge outputs.

[0131] Exemplarily, the re-ordered multiple knowledge outputs may be multiple knowledge outputs arranged in the order of the magnitude of relevance. Taking the multiple knowledge outputs including:

[0132] Content 4: (Formula 2: Formula{Formula: "Formula 1", Belonging theory: "Theory 1"});

[0133] Content 5: (Person 1: Person {Occupation: "Physicist", Birth Year: "Year 2", Death Year: "Year 3", Nationality: "Country A"});

[0134] Content 1: (Person 1)-[:Published]->(Theory 1);

[0135] Content 3: (Theory 1)-[:Contains]->(Formula 2);

[0136] Content 2: (Theory 1: Theory {Publication Year: "Year 1", Type: "Type 1"})... and so on, taking 100 pieces of knowledge output as an example. In some examples, the multiple pieces of knowledge output after reordering may include:

[0137] Content 1: (Person 1)-[:Published]->(Theory 1);

[0138] Content 2: (Theory 1: Theory {Publication Year: "Year 1", Type: "Type 1"});

[0139] Content 3: (Theory 1)-[:Contains]->(Formula 2);

[0140] Content 4: (Formula 2: Formula {Formula: "Formula 1", Belonging Theory: "Theory 1"});

[0141] Content 5: (Person 1: Person {Occupation: "Physicist", Birth Year: "Year 2", Death Year: "Year 3", Nationality: "Country A"})... and so on, 100 pieces of knowledge output.

[0142] Exemplarily, the computing device can optimize multiple pieces of knowledge output based on information such as context and semantics through a reorderer to obtain the multiple pieces of knowledge output after reordering.

[0143] Step S503: Determine the knowledge graph content based on the multiple pieces of knowledge output after reordering.

[0144] Exemplarily, the computing device can select a preset number of knowledge outputs from the multiple pieces of knowledge output after reordering as the knowledge graph content. This preset number can be any integer greater than 1. In some examples, the preset number can be any integer greater than or equal to 5 and less than or equal to 10. The embodiments of the present application do not limit the size of the preset number. The embodiments of the present application take the preset number as 5 for exemplary illustration.

[0145] Taking the multiple pieces of knowledge output after reordering including:

[0146] Content 1: (Person 1)-[:Published]->(Theory 1);

[0147] Content 2: (Theory 1: Theory{Publication Year: "Year 1", Type: "Type 1"});

[0148] Content 3: (Theory 1)-[:Contains]->(Formula 2);

[0149] Content 4: (Formula 2: Formula{Formula: "Formula 1", Belonging Theory: "Theory 1"});

[0150] Content 5: (Person 1: Person{Occupation: "Physicist", Birth Year: "Year 2", Death Year: "Year 3", Nationality: "Country A"})... and so on, with a total of 100 knowledge outputs. Taking the preset quantity of 5 as an example. In some exemplary cases, the knowledge graph content may include:

[0151] Content 1: (Person 1)-[:Published]->(Theory 1);

[0152] Content 2: (Theory 1: Theory{Publication Year: "Year 1", Type: "Type 1"});

[0153] Content 3: (Theory 1)-[:Contains]->(Formula 2);

[0154] Content 4: (Formula 2: Formula{Formula: "Formula 1", Belonging Theory: "Theory 1"});

[0155] Content 5: (Person 1: Person{Occupation: "Physicist", Birth Year: "Year 2", Death Year: "Year 3", Nationality: "Country A"}).

[0156] The retrieval enhanced generation method provided by the embodiments of the present application re - ranks the retrieved knowledge outputs, realizes the filtering and optimization of the knowledge outputs, and determines the knowledge graph content based on multiple re - ranked knowledge outputs; in this way, the problem that the knowledge graph does not highlight the key points can be solved.

[0157] In some embodiments of the present application, in order to be able to retrieve based on the document vector library at any time, the computing device may build a document vector library based on the obtained document library before obtaining the user query information. The embodiments of the present application provide a method for building a document vector library based on a document library. As Figure 6 shown, on the basis of the above - mentioned Figure 1 shown embodiments, before executing step S101 to obtain the user query information, the retrieval enhanced generation method may further include the following steps S109 to step S111.

[0158] Step S109: Divide each document in the document library into blocks to obtain a plurality of document blocks.

[0159] Exemplarily, the computing device can chunk the text based on LangChain to obtain multiple document chunks. In some examples, the computing device can select and invoke a suitable text splitter, configure the chunking parameters, and then perform chunking to obtain multiple document chunks.

[0160] Step S110: Convert each document chunk into a vector based on a vector tool to obtain multiple document vectors.

[0161] Exemplarily, the vector tool can include any one of Chroma, sklearn, gensim, FAISS, and other tools capable of vectorizing document chunks. The embodiments of the present application do not limit the type of the vector tool. The embodiments of the present application take the vector tool as FAISS as an example for exemplary illustration.

[0162] In some examples, the vector tool can include a text embedding model. Therefore, the computing device can input each document chunk into the vector tool, and process each document chunk through the text embedding model in the vector tool to obtain multiple document vectors.

[0163] Step S111: Build an index between each document vector and the corresponding document chunk to obtain a document vector library.

[0164] Exemplarily, the computing device can build an index between each document vector and the corresponding document chunk based on the vector tool, and save multiple document vectors and the corresponding document chunks based on the index to build a document vector library.

[0165] In some examples, the vector tool for building an index between each document vector and the corresponding document chunk and the vector tool for converting each document chunk into a vector can be the same tool. For example, the vector tool for building an index between each document vector and the corresponding document chunk and the vector tool for converting each document chunk into a vector can both be FAISS.

[0166] The retrieval enhanced generation method provided by the embodiments of the present application chunks each document in the document library and vectorizes each document chunk to obtain multiple document vectors. In this way, building an index between each document vector and the corresponding document chunk can realize the preservation of the document vectors and document chunks, and obtain a document vector library.

[0167] As Figure 7 shown, based on the above Figure 1 shown embodiments, step S103 for similarity recall of the document vector library based on the user query information to obtain similar document chunks can include the following steps S1031 and S1032.

[0168] Step S1031: Convert the user query information into a vector based on a vector tool to obtain a query vector.

[0169] Exemplarily, the computing device can vectorize the user query information based on the same vector tool to obtain a query vector. In some examples, the computing device can continue to use FAISS to convert the user query information into a vector to obtain a query vector.

[0170] Step S1032: Perform similarity recall on the document vector library based on the query vector to obtain similar document blocks.

[0171] Exemplarily, the computing device can calculate the cosine distance between the query vector and each document vector in the document vector library to obtain the similarity between the query vector and each document vector, and determine the similar document block based on the document vector with the highest similarity. In some examples, determining the similar document block based on the document vector with the highest similarity may include: mapping the document vector with the highest similarity based on the mapping relationship between the vector and the text to obtain the document block corresponding to the document vector with the highest similarity, and determining this document block as the similar document block.

[0172] In some examples, the computing device can input the user query information and the document vector library into the service interface of FAISS. In this way, FAISS can output the most similar document block, and use this most similar document block as the similar document block.

[0173] The retrieval enhanced generation method provided by the embodiments of the present application vectorizes the user query information into a query vector. In this way, based on the query vector, the most similar similar document block can be recalled from the document vector library.

[0174] Figure 8 It is a schematic flowchart of another retrieval enhanced generation method provided by the embodiments of the present application. As Figure 8 shown, this retrieval enhanced generation method includes the following steps S801 to step S810.

[0175] Step S801: Obtain historical documents.

[0176] Exemplarily, for the implementation manner of step S801, refer to step S101 of the embodiment as Figure 1 shown. The embodiments of the present application will not elaborate here.

[0177] Step S802: Perform word segmentation, part-of-speech tagging, and entity recognition on the historical documents through NLTK to obtain multiple document entities.

[0178] Exemplarily, for the implementation manner of step S802, refer to step S1021 of the embodiment as Figure 2 shown. The embodiments of the present application will not elaborate here.

[0179] Step S803: Identify the relationships between the document entities through the dependency syntax analysis tool of NLTK.

[0180] For example, the implementation of step S803 can be seen in Figure 2 The step S1022 of the illustrated embodiment will not be described in detail in the embodiment of the present application.

[0181] Step S804: Based on multiple document entities and the relationships between the document entities, use Python's NetworkX library to build a graph, and add nodes and edges to obtain a concept graph.

[0182] For example, the implementation of step S804 can be seen in Figure 3 The step S301 of the illustrated embodiment will not be described in detail in the embodiment of the present application.

[0183] Step S805: extracting the hierarchical community structure of the concept graph using a hierarchical clustering algorithm.

[0184] For example, the implementation of step S805 can be seen in Figure 3 The step S302 of the illustrated embodiment will not be described in detail in the embodiment of the present application.

[0185] Step S806: Based on the concept graph and the hierarchical community structure, the mainstream graph database Neo4j is used to construct and save the knowledge graph.

[0186] For example, the implementation of step S806 can be seen in Figure 3 The step S303 of the illustrated embodiment will not be described in detail in the embodiment of the present application.

[0187] Step S807: Obtain user query information.

[0188] For example, the implementation of step S807 can be seen in Figure 1 The step S103 of the illustrated embodiment will not be described in detail in the embodiment of the present application.

[0189] Step S808: retrieve the knowledge graph according to the user query information, and reorder the search results to obtain the most relevant knowledge graph contents.

[0190] For example, the implementation of step S808 can be seen in Figure 5 The step S502 of the illustrated embodiment will not be described in detail in the embodiment of the present application.

[0191] Step S809: Divide the text into blocks through LangChain to obtain multiple document blocks.

[0192] For example, the implementation of step S809 can be seen in Figure 6 The step S1024 of the illustrated embodiment will not be described in detail in the embodiment of the present application.

[0193] Step S810: Vectorize each document block using the vector tool FAISS to obtain multiple document vectors.

[0194] Exemplarily, for the implementation of step S810, reference can be made to step S1025 of the embodiment as shown in Figure 6 the embodiment, which will not be elaborated herein in the embodiments of the present application.

[0195] Step S811: Build an index between each document vector and the corresponding document block to obtain a document vector library.

[0196] Step S812: Perform similarity recall on the document vector library based on the user query information to obtain text fragments.

[0197] Exemplarily, for the implementation of step S812, reference can be made to step S105 of the embodiment as shown in Figure 1 the embodiment and step S1501 and step S1502 of the embodiment as shown in Figure 7 the embodiment, which will not be elaborated herein in the embodiments of the present application.

[0198] Step S813: Build a prompt based on multiple knowledge graph contents, document fragments, and user query information, and input it into the LLM.

[0199] Exemplarily, for the implementation of step S813, reference can be made to step S106 of the embodiment as shown in Figure 1 the embodiment, which will not be elaborated herein in the embodiments of the present application.

[0200] Step S814: The LLM extracts and generates answers.

[0201] Exemplarily, for the implementation of step S814, reference can be made to step S107 of the embodiment as shown in Figure 1 the embodiment, which will not be elaborated herein in the embodiments of the present application.

[0202] Step S815: Return the user result.

[0203] Exemplarily, the computing device can return and output the answer as the user result of the user query information. In some examples, the returned user result can be displayed on the computing device. For example, "Person Name 1 invented XXX" can be displayed on the display interface of the computing device.

[0204] Corresponding to the foregoing embodiments of the retrieval augmented generation method, the present application also provides an embodiment of a retrieval augmented generation device. As Figure 9 shown, the retrieval augmented generation device 90 may include a first acquisition module 901, a retrieval module 902, a recall module 903, a determination module 904, and a processing module 905.

[0205] Among them, the first acquisition module 901 is used to acquire user query information;

[0206] A retrieval module 902, configured to retrieve a knowledge graph based on user query information and determine corresponding knowledge graph content;

[0207] A recall module 903, configured to perform similarity recall on a document vector library based on user query information to obtain similar document blocks;

[0208] A determination module 904, configured to determine a prompt word based on the knowledge graph content, the similar document blocks, and the user query information;

[0209] A processing module 905, configured to process the prompt word based on a language model to obtain an answer.

[0210] In some embodiments of the present application, the retrieval enhanced generation device 90 further includes: a first construction module, configured to extract entities from a document library based on a first entity extraction algorithm to obtain a plurality of document entities; wherein, the first entity extraction algorithm is an algorithm corresponding to traditional natural language processing; identify the relationships between the document entities; and construct a knowledge graph based on the document entities and the relationships between the document entities.

[0211] In some embodiments of the present application, the construction module is specifically configured to construct a concept graph based on the document entities and the relationships between the document entities; extract a hierarchical community structure of the concept graph; and construct a knowledge graph based on the concept graph and the hierarchical community structure.

[0212] In some embodiments of the present application, the retrieval module 902 is specifically configured to extract an entity from the user query information to obtain a query entity; parse the knowledge graph to obtain a knowledge text library corresponding to the knowledge graph; and retrieve the knowledge text library based on the query entity to obtain the knowledge graph content.

[0213] In some embodiments of the present application, the retrieval module 902 is specifically configured to obtain a second entity extraction algorithm, wherein the second entity extraction algorithm is an algorithm corresponding to traditional natural language processing; and process the user query information based on the second entity extraction algorithm to obtain a query entity.

[0214] In some embodiments of the present application, the retrieval module 902 is specifically configured to retrieve knowledge texts based on the query entity to obtain multiple knowledge outputs; reorder the multiple knowledge outputs based on a re-ranker to obtain re-ordered multiple knowledge outputs; and determine the knowledge graph content based on the re-ordered multiple knowledge outputs.

[0215] In some embodiments of the present application, the retrieval enhanced generation device 90 further includes: a second construction module, configured to divide each document in the document library into chunks to obtain a plurality of document chunks; convert each document chunk into a vector based on a vector tool to obtain a plurality of document vectors; build an index between each document vector and the corresponding document chunk to obtain a document vector library.

[0216] In some embodiments of the present application, the recall module 903 is specifically configured to convert the user query information into a vector based on a vector tool to obtain a query vector; perform similarity recall on the document vector library based on the query vector to obtain similar document chunks.

[0217] In some embodiments of the present application, the determination module 904 is specifically configured to splice the knowledge graph content, the similar document chunks, and the user query information to obtain a spliced text; determine a prompt word based on the spliced text.

[0218] For the beneficial technical effects corresponding to the exemplary embodiments of the above-mentioned retrieval enhanced generation device 90, reference may be made to the corresponding beneficial technical effects in the method embodiment part above, which will not be elaborated here.

[0219] Corresponding to the embodiments of the foregoing retrieval enhanced generation method, the present application further provides an embodiment of a computing device. Figure 10 The following is a schematic structural diagram of a computing device provided by an embodiment of the present application. As Figure 10 shown, the computing device 100 may include a processor 1001 and a memory 1002 for storing executable instructions of the processor 1001.

[0220] Among them, the processor 1002 is configured to execute the retrieval enhanced generation method provided in the above embodiment.

[0221] It should be noted that for the beneficial technical effects corresponding to the exemplary embodiments of the above-mentioned computing device, reference may be made to the corresponding beneficial technical effects in the method embodiment part above, which will not be elaborated here.

[0222] As Figure 11 shown, on the basis of the above Figure 10 shown embodiment, the computing device 100 may further include a communication interface 1003.

[0223] The communication interface 1003 may enable the computing device 100 to communicate with other electronic devices or servers through a network.

[0224] In some embodiments, the memory 1002 may also cache data to be processed or already processed by the processor 1001 and each module in the computing device 100, and may be implemented by FLASH (flash memory) or RAM (Random Access Memory).

[0225] In addition to the above methods and devices, embodiments of the present application may also provide a computer program product, including computer program instructions, which, when run by a processor, cause the processor to execute the steps in the virtual machine migration methods of various embodiments of the present application described in the method embodiment section above.

[0226] The computer program product may be written in any combination of one or more programming languages for programming code to perform the operations of the embodiments of the present application. The programming languages include object-oriented programming languages such as Java, C++, etc., and also include conventional procedural programming languages such as the "C" language or similar programming languages. The programming code may be executed entirely on the user computing device, partially on the user device, executed as an independent software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0227] Furthermore, embodiments of the present application may also be a computer-readable storage medium, on which computer program instructions are stored, which, when run by a processor, cause the processor to execute the steps in the virtual machine migration methods of various embodiments of the present application described in the method embodiment section above.

[0228] The computer-readable storage medium may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium, for example but not limited to, includes systems, devices or components of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of the readable storage medium include: electrical connections with one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above.

[0229] The basic principles of the present application have been described above in conjunction with specific embodiments. However, the advantages, benefits, effects, etc. mentioned in the present application are only examples and not limitations, and it cannot be considered that they are essential for each embodiment of the present application. In addition, the specific details of the above embodiments are only for the purpose of illustration and facilitation of understanding, rather than limitations. The above details do not limit the present application to necessarily adopt the above specific details for implementation.

[0230] Those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalent technologies, the present application also intends to include these changes and modifications.

[0231] Moreover, the above-described embodiments are only specific embodiments of the present application and are not used to limit the protection scope of the present application. Any modifications, equivalent replacements, improvements, etc. made on the basis of the technical solutions of the present application shall be included within the protection scope of the present application.

Claims

1. A retrieval-augmented generation method, characterized in that, The method includes: Obtaining user query information; Retrieving a knowledge graph based on the user query information to determine corresponding knowledge graph content; wherein, the knowledge graph is constructed based on a document library; Performing similarity recall on a document vector library based on the user query information to obtain similar document chunks; wherein, the document vector library is constructed based on the document library; Determining a prompt word based on the knowledge graph content, the similar document chunks, and the user query information; Processing the prompt word based on a language model to obtain an answer.

2. The method according to claim 1, wherein The method further includes: Extracting entities from the document library based on a first entity extraction algorithm to obtain multiple document entities; wherein, the first entity extraction algorithm is an algorithm corresponding to traditional natural language processing; Identifying the relationships between the document entities; Constructing the knowledge graph based on the document entities and the relationships between the document entities.

3. The method according to claim 2, wherein The constructing the knowledge graph based on the document entities and the relationships between the document entities includes: Constructing a concept graph based on the document entities and the relationships between the document entities; Extracting a hierarchical community structure of the concept graph; Constructing the knowledge graph based on the concept graph and the hierarchical community structure.

4. The method according to claim 1, wherein The retrieving the knowledge graph based on the user query information to determine corresponding knowledge graph content includes: Extracting entities from the user query information to obtain query entities; Parsing the knowledge graph to obtain a knowledge text library corresponding to the knowledge graph; Retrieving the knowledge text library based on the query entities to obtain the knowledge graph content.

5. The method according to claim 4, characterized in that, The extracting entities from the user query information to obtain query entities includes: Obtaining a second entity extraction algorithm, wherein, the second entity extraction algorithm is an algorithm corresponding to traditional natural language processing; Processing the user query information based on the second entity extraction algorithm to obtain the query entities.

6. The method according to claim 4, wherein The retrieving the knowledge text library based on the query entities to obtain the knowledge graph content includes: Retrieving the knowledge text based on the query entities to obtain multiple knowledge outputs; Re-ranking the multiple knowledge outputs based on a re-ranker to obtain the re-ranked multiple knowledge outputs; Determining the knowledge graph content based on the re-ranked multiple knowledge outputs.

7. The method according to any one of claims 1-6, characterized in that, The method further includes: Chunking each document in the document library to obtain multiple document chunks; Converting each document chunk into a vector based on a vector tool to obtain multiple document vectors; Constructing an index between each document vector and the corresponding document chunk to obtain the document vector library.

8. The method according to any one of claims 1 to 6, characterized in that, The performing similarity recall on the document vector library based on the user query information to obtain similar document chunks includes: Converting the user query information into a vector based on a vector tool to obtain a query vector; Performing similarity recall on the document vector library based on the query vector to obtain the similar document chunks.

9. The method according to any one of claims 1 to 6, characterized in that The determining a prompt word based on the knowledge graph content, the similar document chunks, and the user query information includes: Concatenate the knowledge graph content, the similar document blocks, and the user query information to obtain a concatenated text; Determine the prompt word based on the concatenated text.

10. A computing device, characterized in that, The computing device includes: a processor and a memory for storing instructions executable by the processor; The processor is configured to execute the retrieval enhanced generation method according to any one of claims 1-9 above.