RAG method, system and device based on intention enhancement and medium
By using the intent-enhanced RAG method, which aligns user intent with LLM and named entity models and combines the ReRanker algorithm and Prompt Template, the problems of insufficient recall and high noise in the RAG method are solved, achieving high relevance and diversity recall of information and improving the overall performance of the model.
Patent Information
- Application Number
- CN202410824312.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-25
- Publication Date
- 2024-11-01
AI Technical Summary
Existing RAG methods lack semantic information during the recall phase, resulting in insufficient and noisy recalled texts. It is difficult to align user intent with the knowledge graph, which increases the inference cost and time of large-scale language models. Furthermore, it is difficult to balance diversity and relevance during the reordering phase.
By employing the intent-enhanced RAG method, LLM is used for user intent alignment. Combined with named entity model and ReRanker algorithm, knowledge graph retrieval and reranking are performed. Prompt Template is used to obtain the answer. The large model is controlled to perform intent analysis before recall and the GTE word embedding algorithm is used for semantic vector representation and cosine similarity calculation.
It improves the completeness and relevance of the recalled information, reduces noise, enhances the alignment between the knowledge graph and user queries, and improves the overall performance and efficiency of the model.
Smart Images

Figure CN118885576A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology. Specifically, the present invention is applied to the RAG field, and in particular to a RAG method, system, device and medium based on intent enhancement. Background Art
[0002] In recent years, with the rapid development of natural language processing (NLP) technology, large-scale language models (LLMs) have become a new productivity and are widely used to solve various problems. It is generally believed that as the model scale increases, the amount of data increases, and the computing power improves, the performance of the model will also improve accordingly, which is the so-called Scaling Law. However, although LLM has performed well in many fields, it still has some problems, such as hallucinations, catastrophic forgetting, high training costs, outdated knowledge, and lack of professional problem-solving capabilities. To solve these problems, application methods such as RAG (Relation-augmented Abstractive Graph-based Retrieval) and AGENT have emerged. Among them, RAG is regarded as an effective method to solve the hallucination problem and the unexplainability problem.
[0003] Knowledge graph (KG) is considered to provide higher quality context information because it stores a large amount of clean knowledge that has been extracted, fused, cleaned, etc., which helps RAG work more efficiently compared to traditional document-level databases such as Elasticsearch (ES) or web search. In addition, KG's advanced path query capabilities and knowledge path reasoning capabilities enable it to handle more complex reasoning tasks. However, RAG currently faces three major challenges: 1. Traditional RAG uses embedding vectors to recall text in the database, but queries are often not clearly expressed and lack semantic information, resulting in insufficient and noisy recalled text. This not only wastes token resources, but also causes a rapid decrease in the inference speed of large-scale language models.
[0004] 2. In the recall phase, how to align user intention with high-quality structured knowledge? The current approach is to reflect and plan by calling LLM, which leads to frequent calls to LLM, reduces the overall system performance, and increases costs.
[0005] 3. In the re-ranking phase, traditional methods often get into trouble in balancing diversity and relevance. Since user queries usually contain monotonous attributes and sparse keywords, and keyword attributes are crucial in the structured knowledge of KG, it is difficult to align user intent with KG knowledge. Summary of the invention
[0006] The object of the present invention is to provide a RAG method, system, device and medium based on intent enhancement, so as to solve all or one of the above problems existing in the prior art.
[0007] In order to solve the above technical problems, the specific technical solutions of the present invention are as follows: On the one hand, the present invention provides a RAG method based on intent enhancement, comprising the following steps: User Intent Alignment: LLM is used to explore the answers to user queries, and named entity model is used to extract entity information from the query and LLM output; Knowledge graph retrieval: Use the extracted entity information as anchor to search the knowledge base knowledge; Rerank sorting: Rerank the search data in combination with the query using the ReRanker algorithm; Get the answer: Get the answer using the sorted results of the Prompt Template collection.
[0008] As an improved solution, the user intention alignment further includes: Based on LLM, the control large model performs intent analysis before recall, and the control large model expands and infers the user's query.
[0009] As an improved solution, the user intention alignment further includes: The NER command entity model is used to extract entity information of answers and queries.
[0010] As an improved solution, the NER model is the CASREL algorithm.
[0011] As an improved solution, the method of extracting entity information of answers and queries by using the NER command entity model further includes: The NER command entity model is used to non-extract SPO triples and perform entity extraction.
[0012] As an improved solution, the knowledge graph retrieval further includes: Use entity data to recall data in the knowledge graph; Use GTE word embedding algorithm to represent text as semantic vector; Let the query vector and the entity vector in the knowledge graph perform cosine similarity calculation.
[0013] As an improved solution, the rerank sorting further includes: Use query to sort the inference chain data; Combine intent parsing data and query splitting chunk data; Chunk data and inference chain data are used to perform bge model inference to obtain the sorting results.
[0014] On the other hand, the present invention also provides a RAG system based on intent enhancement, comprising: User intention alignment module, which is used to: use LLM to explore the answer to the user query and use the named entity model to extract entity information from the query and LLM output; The knowledge graph retrieval module is used to: use the extracted entity information as an anchor to search the knowledge base knowledge; The rerank sorting module is used to rerank the search data in combination with the query using the ReRanker algorithm; The answer acquisition module is used to obtain the answer using the results after sorting the Prompt Template set.
[0015] On the other hand, the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the RAG method based on intent enhancement are implemented.
[0016] On the other hand, the present invention further provides a computer device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein: The memory is used to store computer programs; The processor is used to execute the steps of the RAG method based on intent enhancement by running the program stored in the memory.
[0017] The beneficial effects of the technical solution of the present invention are: 1. The RAG method based on intent enhancement described in the present invention can utilize the reasoning ability of LLM to add an intent analysis function to the large model before recall, so that the large model can expand and reason about the user's query, so that the information that can be recalled in subsequent recalls is high in completeness and relevance, alleviating the problem of information misalignment between the user query and the KG knowledge base; at the same time, in order to further align the knowledge base and the user's query, in the later stage of the retrieval stage, a rerank module is added to process the data from the KG query, and the final data is organized into contextual data that is both diverse and has the highest relevance to the query and intent analysis output, ultimately improving the comprehensive performance of the model.
[0018] 2. The RAG system based on intent enhancement described in the present invention can realize the RAG method based on intent enhancement described in the present invention through the mutual cooperation of system modules.
[0019] 3. The computer-readable storage medium described in the present invention can realize the cooperation of the guiding system module, thereby realizing the RAG method based on intent enhancement described in the present invention, and the computer-readable storage medium described in the present invention also effectively improves the operability of the RAG method based on intent enhancement.
[0020] 4. The computer device described in the present invention can store and execute the computer-readable storage medium, thereby realizing the RAG method based on intent enhancement described in the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0022] Figure 1 is a flowchart of the RAG method based on intent enhancement described in Example 1 of the present invention; Figure 2 is a detailed flowchart of the RAG method based on intent enhancement described in Example 1 of the present invention; Figure 3 2 is a schematic diagram of the architecture of the RAG system based on intent enhancement according to Embodiment 2 of the present invention; Figure 4 is a schematic diagram of the structure of the computer device described in Example 4 of the present invention; The symbols in the accompanying drawings are explained as follows: 1501, processor; 1502, communication interface; 1503, memory; 1504, communication bus. DETAILED DESCRIPTION
[0023] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings so that the advantages and features of the present invention can be more easily understood by those skilled in the art, thereby making a clearer and more definite definition of the protection scope of the present invention.
[0024] In the description of the present invention, it should be noted that the embodiments described in the present invention are only part of the embodiments of the present invention, rather than all of the embodiments; based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present invention.
[0025] The terms "first", "second", etc. in the specification and claims of this article and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of this article described here can be implemented in an order other than those illustrated or described here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, device, product or equipment that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0026] In the description of the present invention, it should be noted that LLM is a large language model; NLP is natural language processing; RAG is a retrieval enhancement technology; Prompt is a prompt word technology; Finetuning is a large model fine-tuning technology; and KG is a knowledge graph technology. Example 1
[0027] This embodiment provides a RAG method based on intent enhancement, such as Figure 1 and Figure 2 As shown, the following steps are included: S100, User Intent Alignment: In this step, LLM is used to explore possible answers to the user's query, and then the named entity model is used to extract entity information from the query and the output of LLM; Specifically, by leveraging the reasoning capability of LLM, the big model adds an intent analysis function before recalling, allowing the big model to expand and reason about the user's query, so that the information that can be recalled in subsequent recalls is highly complete and relevant, alleviating the problem of information misalignment between the user's query and the KG knowledge base; Specifically, for example, a user says, "I want to know the country's tax policy. Where can I get it?" The traditional method extracts the tax policy entity, and then all the node information related to the entity is recalled. If the user's query is processed using the big model, the location information of the tax policy we are asking about can be accurately found. At the same time, the flexibility of the big model prompt design can be used to restrict the output of LLM, so that LLM can provide more comprehensive information. Reduce the large number of LLM calls generated by using LLM's reflection and planning capabilities.
[0028] Specifically, the large model LLM is used to analyze the user's input query intent in order to better analyze the user's intent; the corresponding LLM prompt template is: "###Task description: \nYou are an expert in a certain field. Please write an article to answer the user's question according to the requirements\n\n###Answer requirements: \n(1) Please think carefully, understand the user's question and answer it step by step, and do not skip key steps. \n(2) Completely analyze the problem through thinking and exploratory analysis. \n\n###User input: {query}." Specifically, the NER command entity model is used to extract the entity information of the answer + query. The NER model used is the CASREL algorithm, which does not extract SPO triples but entities, so that more knowledge graph data can be recalled in the initial stage; It should be noted that the above examples are only for explaining the present invention and cannot limit the protection scope of the present invention.
[0029] S200, Knowledge Graph Retrieval: In this step, the extracted entity information is used as an anchor to search for knowledge in the knowledge base; Specifically, entity data is used to recall data in the knowledge graph; Specifically, in order to find the corresponding entity ID in the knowledge graph (i.e., entity alignment and linking), the GTE word embedding algorithm is used, through which the text is represented by a semantic vector; Specifically, the query vector and the entity vector in the knowledge graph are subjected to cosine similarity calculation. When the cosine similarity exceeds the preset threshold of 0.75, it indicates similarity / match; Specifically, for the matched entities, we obtain the corresponding reasoning chain data within 3 hops (we found that the user's query usually does not exceed 3 hops); Specifically, in order to better capture analogical reasoning information and information about joint effects, the tail-to-tail and head-to-head reasoning chain data is saved, which not only retains the entity and relationship link information, but also retains the metadata and description data of the head and tail entities in the reasoning chain; It should be noted that the above examples are only for explaining the present invention and cannot limit the protection scope of the present invention.
[0030] S300, rerank sorting: In this step, the retrieved data is re-ranked in combination with the query using the ReRanker algorithm; this further aligns the knowledge base and the user's query, and organizes the data into contextual data that is both diverse and relevant to the query; Specifically, the inference chain data retrieved through the second stage still contains a lot of noise and data redundancy; therefore, a re-ranking model is used to reduce redundant knowledge data; Specifically, the bge sorting model is used; query is used to sort the inference chain data, and the intent parsing data generated in the first stage is combined with the query, and they are divided into chunks to form a data set C; the chunk data and each inference chain data are used to perform bge model reasoning to obtain a sorting result; It should be noted that the above examples are only for explaining the present invention and cannot limit the protection scope of the present invention.
[0031] S400, answer acquisition: In this step, the final answer is obtained using the sorted results of the Prompt Template collection; Specifically, the sorted data is used as context information, and the user's query is used as the question. Through the prompt template, the input of the LLM is formed, and then the final answer is obtained. Specifically, the prompt template is: "###Task description\nYou are an expert on something. Based on contextual knowledge and your internal knowledge, provide a more professional suggestion to the user's question, and the suggestion should meet the corresponding answer requirements.\n\n###: Answer requirements\n(1) Please think carefully, understand the user's question and answer the question step by step, and do not skip key steps.\n(2) Provide clear key information in the answer and directly provide the corresponding answer based on the user's question.\n\n###Context information: The knowledge context obtained from the knowledge base is: {context}\n\n###User input: {query}"; It should be noted that the above examples are only for explaining the present invention and cannot limit the protection scope of the present invention. Example 2
[0032] This embodiment is based on the same inventive concept as the RAG method based on intent enhancement described in Embodiment 1, and provides a RAG system based on intent enhancement, such as Figure 3 As shown, including: User intention alignment module, which is used to: use LLM to explore the answer to the user query and use the named entity model to extract entity information from the query and LLM output; The knowledge graph retrieval module is used to: use the extracted entity information as an anchor to search the knowledge base knowledge; The rerank sorting module is used to rerank the search data in combination with the query using the ReRanker algorithm; The answer acquisition module is used to obtain the answer using the results after sorting the Prompt Template set. Example 3
[0033] This embodiment provides a computer-readable storage medium, including: The storage medium is used to store computer software instructions used to implement the intent-enhanced RAG method described in the above-mentioned Example 1, which includes a program for executing the above-mentioned program set for the intent-enhanced RAG method; specifically, the executable program can be built into the intent-enhanced RAG system described in Example 2, so that the intent-enhanced RAG system can implement the intent-enhanced RAG method described in Example 1 by executing the built-in executable program.
[0034] In addition, the computer-readable storage medium of this embodiment may adopt any combination of one or more computer-readable storage media, wherein the computer-readable storage medium includes electrical, optical, electromagnetic, infrared or semiconductor systems, devices or components, or any combination thereof. Example 4
[0035] This embodiment provides an electronic device, such as Figure 4 As shown, the electronic device may include: a processor 1501 , a communication interface 1502 , a memory 1503 and a communication bus 1504 , wherein the processor 1501 , the communication interface 1502 , and the memory 1503 communicate with each other via the communication bus 1504 .
[0036] Memory 1503, used for storing computer programs; The processor 1501 is configured to implement the steps of the RAG method based on intent enhancement described in the above-mentioned embodiment 1 when executing the computer program stored in the memory 1503.
[0037] As an embodiment of the present invention, the communication bus mentioned in the above terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0038] As an implementation mode of the present invention, the communication interface is used for communication between the above-mentioned terminal and other devices.
[0039] As an embodiment of the present invention, the memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0040] As an embodiment of the present invention, the above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
[0041] Different from the prior art, the RAG method, system, device and medium based on intent enhancement of the present application can utilize the reasoning ability of LLM to add an intent analysis function to the large model before recall, so that the large model can expand and reason about the user's query, so that the information that can be recalled in subsequent recalls is high in completeness and relevance, alleviating the problem of information misalignment between the user query and the KG knowledge base; at the same time, in order to further align the knowledge base and the user's query, in the later stage of the retrieval stage, a rerank module is added to process the data from the KG query, and the final data is organized into contextual data that is both diverse and has the highest relevance to the query and intent analysis output, thereby ultimately improving the overall performance of the model.
[0042] It should be understood that in the various embodiments of this document, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this document.
[0043] It should also be understood that in the embodiments of this article, the term "and / or" is only a description of the association relationship of the associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0044] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this article.
[0045] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0046] In the several embodiments provided herein, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, or can be electrical, mechanical or other forms of connection.
[0047] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of this article.
[0048] In addition, each functional unit in each embodiment of this invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of software functional unit.
[0049] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this article is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of this article. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0050] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A RAG method based on intent enhancement, It is characterized in that The following steps are involved: User Intent Alignment: LLM is used to explore the answers to user queries, and named entity model is used to extract entity information from the query and LLM output; Knowledge graph retrieval: Use the extracted entity information as anchor to search the knowledge base knowledge; Rerank sorting: Rerank the search data in combination with the query using the ReRanker algorithm; Get the answer: Get the answer using the sorted results of the Prompt Template collection.
2. The RAG method based on intent enhancement according to claim 1, Features: The user intention alignment further comprises: Based on LLM, the control large model performs intent analysis before recall, and the control large model expands and infers the user's query.
3. The RAG method based on intent enhancement according to claim 1, Features: The user intention alignment further comprises: The NER command entity model is used to extract entity information of answers and queries.
4. The RAG method based on intent enhancement according to claim 3, Features: The NER model is the CASREL algorithm.
5. The RAG method based on intent enhancement according to claim 3, Features: The extracting entity information of the answer and the query using the NER command entity model further includes: The NER command entity model is used to non-extract SPO triples and perform entity extraction.
6. The RAG method based on intent enhancement according to claim 1, Features: The knowledge graph retrieval further includes: Use entity data to recall data in the knowledge graph; Use the GTE word embedding algorithm to represent the text as a semantic vector; Let the query vector and the entity vector in the knowledge graph perform cosine similarity calculation.
7. The RAG method based on intent enhancement according to claim 1, Features: The rerank sorting further comprises: Use query to sort the inference chain data; Combine intent parsing data and query splitting chunk data; Chunk data and inference chain data are used to perform bge model inference to obtain the sorting results.
8. An intent-enhanced RAG system, It is characterized in that include: User intention alignment module, which is used to: use LLM to explore the answer to the user query and use the named entity model to extract entity information from the query and LLM output; The knowledge graph retrieval module is used to: use the extracted entity information as an anchor to search the knowledge base knowledge; The rerank sorting module is used to rerank the search data in combination with the query using the ReRanker algorithm; The answer acquisition module is used to obtain the answer using the results after sorting the Prompt Template set.
9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the RAG method based on intention enhancement in any one of claims 1 to 7 are implemented.
10. A computer device, It is characterized in that It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; wherein: The memory is used to store computer programs; The processor is used to execute the steps of the RAG method based on intention enhancement in any one of claims 1 to 7 by running the program stored in the memory.
Citation Information
Cited By
Retrieval enhancement generation method based on theme enhancement and related products
CN121166749A
