A RAG text processing method, device and medium based on multi-channel recall
Patent Information
- Application Number
- CN202411666863.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2044-11-21
AI Technical Summary
RAG technology has problems such as inability to recall text storage and recall, insufficient recall relevance, and limited context tokens, etc., etc., etc.
The RAG text processing method based on multiple recall is adopted. By processing the corpus used by RAG, the RAG embedding model and LLM model are called to generate hypothetical problems, and the user's prompt words are semantic enhanced. The RAG embedding model, ElasticSearch and hypothetical problems are combined to perform multiple recalls, filtering and cutting document blocks, and generating the final context output result.
Improve recall and result diversity, enhance the accuracy and robustness of search results, reduce bias in a single recall source, and ensure that the result set contains diverse content.
Smart Images

Figure CN119167921B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a RAG text processing method, device and medium based on multi-channel recall. Background Art
[0002] With the development of neural network technology, such as the development of recurrent neural network (RNN), long short-term memory network (LSTM), convolutional neural network (CNN), Transformer and other models, model parameters have rapidly expanded from millions to billions, and as the number of model parameters increases, the model's capabilities are becoming stronger and stronger. Although the model has achieved very significant results in text generation, the model's knowledge is limited by training data and cannot solve the problem of timeliness.
[0003] In order to solve the problem of knowledge updating and timeliness of the model, the Facebook AI Research (FAIR) team proposed the Retrieval-Augmented Generation (RAG) technology. This technology aims to improve the relevance, accuracy and diversity of model-generated text by combining the two processes of retrieval and generation. For example, RAG alleviates the model's hallucination problem by retrieving a large amount of relevant information before generating text output, and then inputting the retrieved information into the model as context.
[0004] Although RAG technology has been used in many fields to solve the limitations of the model, there are still some technical difficulties in the storage and recall of texts, such as the inability to recall, insufficient recall relevance, and limited context tokens resulting in the truncation of answers. Summary of the invention
[0005] The embodiment of the present application provides a RAG text processing method, device and medium based on multi-channel recall to solve the problems existing in the related art. The technical solution is as follows:
[0006] In a first aspect, an embodiment of the present application provides a RAG text processing method based on multi-channel recall, including:
[0007] Process the corpus used by RAG to obtain multiple document blocks;
[0008] Calling the RAG embedding model to perform vectorization processing on each of the document blocks, and saving the vector results of each of the document blocks;
[0009] Using ElasticSearch to index the keywords in each of the document blocks, and saving the keyword index results of each of the document blocks;
[0010] Calling an LLM model to generate a plurality of hypothetical questions for each of the document blocks, and saving the plurality of hypothetical questions, wherein the LLM model refers to a large language model;
[0011] Perform semantic enhancement processing on the user's prompt words to obtain new prompt words;
[0012] Based on the new prompt word, perform multi-way recall on the RAG embedding model, the ElasticSearch and the multiple hypothetical questions to obtain a set of document blocks summarized by ranking;
[0013] Calling the LLM model to filter out a plurality of target document blocks from the document block set, wherein the target document blocks are document blocks related to the new prompt word;
[0014] According to a preset number of document blocks, a plurality of the target document blocks are cut and processed to obtain a final context output result;
[0015] The new prompt word and the context output result are combined as the output answer of the LLM model.
[0016] In one implementation, the corpus used by RAG is processed to obtain multiple document blocks including:
[0017] Organize the corpus used by RAG to obtain different types of documents;
[0018] Each category of the documents is segmented into a plurality of document blocks using a specified segmentation rule to obtain the plurality of document blocks.
[0019] In one implementation, the RAG embedding model includes the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model; calling the RAG embedding model to vectorize each of the document blocks, and saving the vector result of each of the document blocks includes:
[0020] The maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model and the GanymedeNil / text2vec-large-chinese embedding model are respectively called to perform vectorization processing on each of the document blocks to obtain three first sub-vector results;
[0021] The three first sub-vector results are respectively saved in different indexes of Milvus to obtain the vector result.
[0022] In one embodiment, saving the plurality of hypothetical questions comprises:
[0023] Calling the RAG embedding model to perform vector processing on the plurality of hypothetical questions respectively to obtain a plurality of second sub-vector results;
[0024] The plurality of second sub-vector results are saved in corresponding indexes of Milvus.
[0025] In one implementation, semantic enhancement is performed on the user's prompt word to obtain a new prompt word including:
[0026] Get the user's chat history;
[0027] The LLM model is called to perform semantic enhancement processing on the prompt word based on the chat record to obtain the new prompt word.
[0028] In one implementation, the RAG embedding model includes the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model; based on the new prompt word, multi-way recall is performed on the RAG embedding model, the ElasticSearch, and the multiple hypothetical questions, and the document block set summarized by ranking includes:
[0029] After calling the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model to respectively vectorize the new prompt word, a plurality of first related document blocks are recalled according to the vector results;
[0030] Calling the reciprocal ranking fusion RRF algorithm to calculate the score of each of the first relevant document blocks;
[0031] After calling the maidalun1020 / bce-embedding-base_v1 embedding model to vectorize the new prompt word, index and retrieve the multiple hypothetical questions to recall a number of second related document blocks;
[0032] Calling the RRF algorithm to calculate the score of each of the second relevant document blocks;
[0033] Perform keyword search on the new prompt word using the BM25 algorithm on ElasticSearch to retrieve a number of third related document blocks;
[0034] Calling the RRF algorithm to calculate the score of each of the third relevant document blocks;
[0035] Adding the scores of at least two identical related document blocks among the plurality of the first related document blocks, the plurality of the second related document blocks, and the plurality of the third related document blocks to obtain a total score, retaining one related document block among the at least two related document blocks, and using the total score as the score of the one related document block;
[0036] The remaining relevant document blocks among the plurality of the first relevant document blocks, the plurality of the second relevant document blocks and the plurality of the third relevant document blocks are sorted and aggregated according to the scores to obtain the document block set.
[0037] In one implementation, calling the LLM model to filter out a plurality of target document blocks from the document block set includes:
[0038] The document block set and the new prompt word are submitted to the LLM model, and the LLM model performs relevance judgment on the document block set, and selects document blocks related to the new prompt word from the document block set to obtain a plurality of target document blocks.
[0039] In a second aspect, the embodiment of the present application further provides a RAG text processing device based on multi-channel recall, including:
[0040] The processing unit is used to process the corpus used by RAG to obtain multiple document blocks; call the RAG embedding model to perform vectorization processing on each of the document blocks and save the vector results of each of the document blocks; use ElasticSearch to index the keywords in each of the document blocks and save the keyword index results of each of the document blocks; call the LLM model to generate multiple hypothetical questions for each of the document blocks and save the multiple hypothetical questions, wherein the LLM model refers to a large language model; perform semantic enhancement processing on the user's prompt words to obtain new prompt words;
[0041] A recall unit, configured to perform multi-way recall on the RAG embedding model, the ElasticSearch, and the plurality of hypothetical questions based on the new prompt word to obtain a document block set summarized by ranking;
[0042] A screening unit, configured to call the LLM model to screen out a plurality of target document blocks from the document block set, wherein the target document blocks are document blocks related to the new prompt word; and to perform segmentation processing on the plurality of target document blocks according to a preset number of document blocks to obtain a final context output result;
[0043] An output unit is used to combine the new prompt word and the context output result as the output answer of the LLM model.
[0044] In one implementation, when the processing unit is used to process the corpus used by the RAG to obtain a plurality of document blocks, it is specifically used to:
[0045] Organize the corpus used by RAG to obtain different types of documents;
[0046] Each category of the documents is segmented into a plurality of document blocks using a specified segmentation rule to obtain the plurality of document blocks.
[0047] In one implementation, the RAG embedding model includes a maidalun1020 / bce-embedding-base_v1 embedding model, a baai / bge-large-zh-v1.5 embedding model, and a GanymedeNil / text2vec-large-chinese embedding model; when the processing unit is used to call the RAG embedding model to perform vectorization processing on each of the document blocks and save the vector result of each of the document blocks, it is specifically used to:
[0048] The maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model and the GanymedeNil / text2vec-large-chinese embedding model are respectively called to perform vectorization processing on each of the document blocks to obtain three first sub-vector results;
[0049] The three first sub-vector results are respectively saved in different indexes of Milvus to obtain the vector result.
[0050] In one implementation, when the processing unit is used to save the plurality of hypothetical questions, it is specifically used to:
[0051] Calling the RAG embedding model to perform vector processing on the plurality of hypothetical questions respectively to obtain a plurality of second sub-vector results;
[0052] The plurality of second sub-vector results are saved in corresponding indexes of Milvus.
[0053] In one embodiment, when the processing unit is used to perform semantic enhancement processing on the user's prompt word to obtain a new prompt word, it is specifically used to:
[0054] Get the user's chat history;
[0055] The LLM model is called to perform semantic enhancement processing on the prompt word based on the chat record to obtain the new prompt word.
[0056] In one implementation, the RAG embedding model includes a maidalun1020 / bce-embedding-base_v1 embedding model, a baai / bge-large-zh-v1.5 embedding model, and a GanymedeNil / text2vec-large-chinese embedding model; when the recall unit is used to perform multi-way recall on the RAG embedding model, the ElasticSearch, and the multiple hypothetical questions based on the new prompt word to obtain a set of document blocks summarized by ranking, it is specifically used to:
[0057] After calling the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model to respectively vectorize the new prompt word, a plurality of first related document blocks are recalled according to the vector results;
[0058] Calling the reciprocal ranking fusion RRF algorithm to calculate the score of each of the first relevant document blocks;
[0059] After calling the maidalun1020 / bce-embedding-base_v1 embedding model to vectorize the new prompt word, index and retrieve the multiple hypothetical questions to recall a number of second related document blocks;
[0060] Calling the RRF algorithm to calculate the score of each of the second relevant document blocks;
[0061] Perform keyword search on the new prompt word using the BM25 algorithm on ElasticSearch to retrieve a number of third related document blocks;
[0062] Calling the RRF algorithm to calculate the score of each of the third relevant document blocks;
[0063] Adding the scores of at least two identical related document blocks among the plurality of the first related document blocks, the plurality of the second related document blocks, and the plurality of the third related document blocks to obtain a total score, retaining one related document block among the at least two related document blocks, and using the total score as the score of the one related document block;
[0064] The remaining relevant document blocks among the plurality of the first relevant document blocks, the plurality of the second relevant document blocks and the plurality of the third relevant document blocks are sorted and aggregated according to the scores to obtain the document block set.
[0065] In one implementation, when the screening unit is used to call the LLM model to screen out a plurality of target document blocks from the document block set, it is specifically used to:
[0066] The document block set and the new prompt word are submitted to the LLM model, and the LLM model performs relevance judgment on the document block set, and selects document blocks related to the new prompt word from the document block set to obtain a plurality of target document blocks.
[0067] In a third aspect, an embodiment of the present application further provides a computer device, comprising: a memory and a processor, wherein the memory stores instructions, and the instructions are loaded and executed by the processor to implement a method in any one of the above-mentioned aspects, wherein the memory and the processor communicate with each other through an internal connection path.
[0068] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program runs on a computer, the method in any one of the above-mentioned embodiments is implemented.
[0069] The advantages or beneficial effects of the above technical solution include at least:
[0070] (i) Improving recall rate: By using multiple different recall sources and strategies, we can increase the chances of retrieving relevant document blocks, thereby improving the overall recall rate.
[0071] (ii) Enhanced result diversity: Different recall paths may focus on different information and document features, thus ensuring that the result set contains diverse content.
[0072] (iii) Improved accuracy: Multi-channel recall can improve the accuracy of retrieval results by combining the advantages of different recall sources and reducing the bias that may exist in a single recall source.
[0073] (iv) Enhanced robustness: When a problem occurs in a recall path, other paths can still provide useful results. This can reduce the system's reliance on a single recall technology and enhance overall robustness.
[0074] The above summary is for illustrative purposes only and is not intended to be limiting in any way. In addition to the illustrative aspects, embodiments and features described above, further aspects, embodiments and features of the present application will be readily apparent by reference to the accompanying drawings and the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the multiple drawings represent the same or similar parts or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings only depict some embodiments disclosed in the present application and should not be regarded as limiting the scope of the present application.
[0076] Figure 1 A flowchart of a RAG text processing method based on multi-channel recall provided in an embodiment of the present application;
[0077] Figure 2 A structural block diagram of a RAG text processing device based on multi-channel recall provided in an embodiment of the present application;
[0078] Figure 3 A structural block diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0079] In the following, only some exemplary embodiments are briefly described. As those skilled in the art will appreciate, the described embodiments may be modified in various ways without departing from the spirit or scope of the present application. Therefore, the drawings and descriptions are considered to be exemplary and non-restrictive in nature.
[0080] Various technical solutions provided by the embodiments of the present application will be described in detail below with reference to the accompanying drawings.
[0081] Before introducing the embodiments of the present application, some terms in the present application are first explained to facilitate understanding by those skilled in the art.
[0082] Large Language Model (LLM): A language model consisting of an artificial neural network with a large number of parameters, which is trained on a large amount of labeled text using self-supervised learning or semi-supervised learning techniques to generate text or predict language models.
[0083] Milvus: It is a cloud-native vector database used to store and manage embedded vectors generated by machine learning models, supporting high availability, high performance, and easy scalability.
[0084] Multi-Path Retrieval: is an advanced retrieval mode that improves the retrieval effect of the model by combining multiple different retrieval methods.
[0085] BM25 (Best Matching 25): is a probability-based ranking function used in information retrieval systems.
[0086] Reciprocal Rank Fusion (RRF): is an algorithm used to evaluate the search scores of multiple sequentially ranked results to generate a unified result set.
[0087] The following will be combined Figure 1 The RAG text processing method based on multi-channel recall provided in the embodiment of the present application is specifically described. Figure 1 As shown, the method may include the following steps:
[0088] S110, processing the corpus used by RAG to obtain multiple document blocks.
[0089] In one implementation, the implementation process of step S110 may include the following steps:
[0090] S111. Arrange the corpus used by RAG to obtain different types of documents.
[0091] In specific implementation, the corpus used by RAG can be screened and sorted according to type to obtain different types of documents.
[0092] For example, for word-based corpora, the following screening and sorting can be performed: check the rationality of the content title, split the merged tables, delete the tables with blank lines, check whether the attachment content supports parsing, check whether the pictures are blurred, and add markdown tags to the code blocks.
[0093] For example, for PDF-type corpora, the following screening and sorting can be performed: scanned copies need to be clear, and non-scanned copies also need to be sorted as word-type corpora.
[0094] For example, for Excel-type corpora, the following screening and sorting can be performed: there must be no merged cells, and all columns to be imported must be filled with specific values.
[0095] For example, for audio corpus, the following screening and sorting can be performed: the audio quality is free of noise and the speech is clear.
[0096] For example, for video corpus, the following screening and sorting can be performed: the audio quality is free of noise and the speech is clear.
[0097] For example, for image corpora, the following screening and sorting can be performed: the text in the image is clear, there is no overlap, and there is no excessive color that affects the text recognition results.
[0098] That is, step S111 is a RAG corpus organization step. By executing step S111, the corpus used by RAG can be strictly screened and organized to ensure the quality and diversity of the corpus, laying a solid foundation for subsequent recall and response accuracy.
[0099] S112. Using a specified segmentation rule, each type of document is segmented into a number of document blocks to obtain a plurality of document blocks.
[0100] In specific implementation, different segmentation rules may be adopted according to the document type to segment each type of document into a number of document blocks (checks) suitable for processing, thereby obtaining a plurality of document blocks.
[0101] For example, for word-based corpora, the following segmentation processing can be performed: after converting to markdown format, segment by title to ensure the integrity of the content, extract pictures and attachments and upload them to the OSS storage server, and replace pictures with links.
[0102] For example, for PDF corpora, the following segmentation processing can be performed: after the scanned copy is subjected to OCR recognition, it is segmented by 200 words. After the non-scanned copy is converted to word, it is processed in word mode.
[0103] For example, for Excel-type corpus, the following segmentation process can be performed: each row of data and the table header are combined and matched as a piece of text.
[0104] For example, for audio corpus, the following segmentation process can be performed: after performing speech recognition on the audio, it is segmented according to 200 words.
[0105] For example, for video corpus, the following segmentation process can be performed: extract the audio in the video and save it as mp3, then perform speech recognition on the audio and segment it by 200 words.
[0106] For example, for image corpus, the following segmentation process can be performed: after using OCR to recognize and restore the text, it is segmented into 200 words.
[0107] That is, step S112 is a document block segmentation step. By executing step S112, subsequent recall processing can be facilitated.
[0108] In the embodiment of the present application, by executing step S110, the quality and diversity of the document blocks can be ensured, which is convenient for subsequent recall processing and helps to improve the recall accuracy of the contextual question large model.
[0109] S120, calling the RAG embedding model to perform vectorization processing on each document block, and saving the vector result of each document block.
[0110] In one embodiment, the RAG embedding model may include, but is not limited to, the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model.
[0111] In one implementation, the implementation process of step S120 may include the following steps:
[0112] S121. Call the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model respectively to vectorize each document block to obtain three first sub-vector results.
[0113] S122. Save the three first sub-vector results to different indexes of Milvus respectively.
[0114] In the embodiment of the present application, by executing step S120, each document block can be vectorized one by one using the RAG embedding model, providing a basis for subsequent recall.
[0115] The current mainstream technical implementations are all based on a single embedding model for document recall. However, in the embodiment of the present application, by executing the above step S120, a combination of multiple technologies can be used for document recall, which greatly improves the recall rate.
[0116] S130, using ElasticSearch to index the keywords in each document block, and save the keyword index results of each document block.
[0117] In one implementation, a Chinese word segmenter can be installed in ElasticSearch to support Chinese word segmentation. Then, each document block can be imported into ElasticSearch, and the searchContext field in ElasticSearch can be used to segment each document block and extract keywords, so as to implement indexing of keywords in each document block, obtain keyword index results for each document block, and save the keyword index results for each document block in the ElasticSearch index.
[0118] In the embodiment of the present application, by executing step S130, ElasticSearch can be used to index the keywords in each document block to optimize the recall effect of the keyword search.
[0119] S140 , calling the LLM model to generate multiple hypothetical questions for each document block, and saving the multiple hypothetical questions.
[0120] In one implementation, the LLM model may be called to generate multiple hypothetical questions for each document block, such as generating 10 hypothetical questions, and then the function_call capability of the LLM model may be used to constrain these multiple hypothetical questions (ie, the return results of the LLM model).
[0121] In one implementation, the implementation process of saving multiple hypothetical questions may include the following steps:
[0122] S141. Call the RAG embedding model to perform vector processing on multiple hypothetical questions respectively to obtain multiple second sub-vector results.
[0123] In a specific implementation, the maidalun1020 / bce-embedding-base_v1 embedding model may be called to vectorize multiple hypothetical questions respectively to obtain multiple second sub-vector results. For example, when the number of hypothetical questions is 10, the number of second sub-vector results obtained is 10.
[0124] S142. Save the multiple second sub-vector results into corresponding indexes of Milvus.
[0125] In the embodiment of the present application, by executing step S140, a series of hypothetical questions can be generated for each document block to enrich the dimension of recall.
[0126] S150: Perform semantic enhancement processing on the user's prompt word to obtain a new prompt word.
[0127] In one implementation, the implementation process of step S150 may include the following steps:
[0128] S151. Obtain the user's chat history.
[0129] In specific implementation, the user can input a prompt word for the question. Afterwards, it can be determined whether the user has a historical chat context based on the prompt word. If yes, the user's chat record (history_chat) can be queried from the cache, that is, the user's chat record can be obtained from the cache.
[0130] S152: Call the LLM model to perform semantic enhancement processing on the prompt word based on the chat record to obtain a new prompt word.
[0131] In specific implementation, the prompt word (Prompt) can be combined with the chat record, and the LLM model can be called to generate a semantically enhanced new prompt word (new_prompt) to rewrite the prompt word and clarify the user's question intention. It can be understood that the LLM model enhances the prompt word according to the user's historical conversation to obtain the new prompt word.
[0132] In the embodiment of the present application, by executing step S150, semantic enhancement and rewriting of the user's prompt words can be achieved to improve the accuracy of subsequent recall.
[0133] S160. Based on the new prompt word, perform multi-way recall on the RAG embedding model, ElasticSearch, and multiple hypothetical questions to obtain a set of document blocks summarized by ranking.
[0134] In one implementation, the implementation process of step S160 may include the following steps:
[0135] S161, calling the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model to respectively vectorize the new prompt words, and then recalling several first related document blocks according to the vector results.
[0136] In the specific implementation, after calling the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model to vectorize the new prompt word, the corresponding three third sub-vector results can be obtained. After that, the relevant document blocks can be recalled according to the three third sub-vector results to obtain several first relevant document blocks. For example, according to the vector results of the new prompt word in multiple embedding models, that is, the three third sub-vector results, the corresponding indexes in Milvus are respectively calculated for similarity, and then the relevant document blocks are recalled to obtain several first relevant document blocks.
[0137] S162: Call the RRF algorithm to calculate the score of each first relevant document block.
[0138] In specific implementation, step S162 can be performed in an existing manner, and this application does not limit this.
[0139] In an embodiment of the present application, by executing steps S161 and S162, the limitations of a single embedding model can be abandoned, and multiple embedding models can be used for parallel recall, and the recalled document blocks are reordered through the RRF algorithm, effectively solving the problem of insufficient relevance that may be caused by a single embedding model.
[0140] S163. After calling the maidalun1020 / bce-embedding-base_v1 embedding model to vectorize the new prompt word, index retrieval is performed on multiple hypothetical questions to recall several second related document blocks.
[0141] In the specific implementation, after calling the maidalun1020 / bce-embedding-base_v1 embedding model to vectorize the new prompt word, the corresponding vector result can be obtained. Afterwards, the multiple hypothetical questions generated in the above step S140 can be indexed and retrieved according to the vector result, and several second related document blocks can be recalled. It can be understood that the new prompt word is vectorized using the embedding model of the hypothetical question, and then the vector result of the new prompt word recalls the relevant document block in the hypothetical question of Milvus.
[0142] In an embodiment of the present application, by executing step S163, a series of hypothetical questions can be pre-set and the user's actual questions can be combined with these pre-set questions to recall document blocks, thereby effectively solving the recall failure problem caused by inaccurate or incomplete semantics of user questions.
[0143] S164: Call the RRF algorithm to calculate the score of each second relevant document block.
[0144] In specific implementation, step S164 can be performed in an existing manner, and this application does not limit this.
[0145] S165, performing keyword search on the new prompt word using the BM25 algorithm on ElasticSearch, and recalling a number of third related document blocks.
[0146] In an embodiment of the present application, by executing step S165, the BM25 algorithm of ElasticSearch can be used for keyword search recall to address the problem of low scores caused by different document block lengths, thereby ensuring that both long texts and short texts can get fair recall opportunities.
[0147] S166. Call the RRF algorithm to calculate the score of each third relevant document block.
[0148] In specific implementation, step S166 can be performed in an existing manner, and this application does not limit this.
[0149] S167. Add the scores of at least two identical related document blocks among the plurality of first related document blocks, the plurality of second related document blocks, and the plurality of third related document blocks to obtain a total score, retain one related document block among the at least two related document blocks, and use the total score as the score of the one related document block.
[0150] That is, in step S167, the scores of the above-mentioned recalled related document blocks are recalculated, the scores of the same document blocks are added together to calculate the total score, and then one document block in the same document block is retained, and the total score is used as the score of the document block.
[0151] S168. Sort and aggregate the remaining relevant document blocks among the plurality of first relevant document blocks, the plurality of second relevant document blocks, and the plurality of third relevant document blocks according to the sizes of the scores to obtain a document block set.
[0152] In specific implementation, by executing step S168, the final document block ranking of multi-way recall can be obtained.
[0153] In an embodiment of the present application, by executing step S160, the chance of retrieving relevant document blocks can be increased by using multiple different recall sources and strategies, thereby improving the overall recall rate, and different recall paths may focus on different information and document features, which can ensure that the result set (i.e., the document block set) contains diverse content, enhance the result diversity, and multi-path recall can reduce the possible deviation of a single recall source by combining the advantages of different recall sources, thereby improving the accuracy of the retrieval results. At the same time, when a problem occurs in a recall path, other paths can still provide useful results, which can reduce the system's dependence on a single recall technology and enhance the overall robustness.
[0154] S170 , calling the LLM model to filter out a number of target document blocks from the document block set.
[0155] In one implementation, the target document block may be a document block related to the new prompt word.
[0156] In one implementation, the document block set and the new prompt word can be submitted to the LLM model, and the LLM model performs relevance judgment on the document block set, and screens out document blocks related to the new prompt word from the document block set to obtain a number of target document blocks. For example, after receiving the document block set and the new prompt word, the LLM model determines whether any document block in the document block set can answer the question of the new prompt word, and screens out document blocks that can answer the question of the new prompt word to obtain a number of target document blocks, so as to perform secondary filtering on the document blocks and reduce document blocks with high scores but unable to answer the question of the new prompt word.
[0157] As an example, the new prompt word is: \"Gushen Low Code Platform Introduction\" Is it related to this document? Is it related to the above? You only need to reply 'yes' or 'no'. If you can't judge, reply 'no'. A document block in the document block set is as follows:
[0158] Then, the judgment result is no, that is, it can be judged that the document block is irrelevant to the new prompt word.
[0159] In the embodiment of the present application, by executing step S170, the LLM model can be called to perform relevance judgment on the aggregated document block set, and those document blocks with high scores but irrelevant to the user's question can be excluded, thereby improving the overall recall rate.
[0160] S180: According to a preset number of document blocks, a plurality of target document blocks are segmented to obtain a final context output result.
[0161] In one implementation, a number of target document blocks may be intercepted according to a preset number of document blocks, so as to segment the filtered document blocks and form a final context output result.
[0162] In a specific implementation, the preset number of document blocks can be set according to actual needs, and the embodiment of the present application does not limit this.
[0163] S190, combining the new prompt word and the context output result as the output answer of the LLM model.
[0164] In one embodiment, the new prompt word and the context output result can be combined and submitted to the LLM model to answer the user's question. It can be understood that the new prompt word and the context output result are used as a context question large model to obtain the final answer and return it.
[0165] In specific implementation, the above steps S110 to S140 are the data processing stage, and the above steps S150 to S190 are the data use stage.
[0166] In summary, the RAG text processing method based on multi-channel recall provided in the embodiment of the present application can achieve the following beneficial effects:
[0167] (i) Improving recall rate: By using multiple different recall sources and strategies, we can increase the chances of retrieving relevant document blocks, thereby improving the overall recall rate.
[0168] (ii) Enhanced result diversity: Different recall paths may focus on different information and document features, thus ensuring that the result set contains diverse content.
[0169] (iii) Improved accuracy: Multi-channel recall can improve the accuracy of retrieval results by combining the advantages of different recall sources and reducing the bias that may exist in a single recall source.
[0170] (iv) Enhanced robustness: When a problem occurs in a recall path, other paths can still provide useful results. This can reduce the system's reliance on a single recall technology and enhance overall robustness.
[0171] Figure 2 FIG. 2 shows a structural block diagram of a RAG text processing device based on multi-channel recall according to an embodiment of the present application. Figure 2 As shown, the device may include:
[0172] The processing unit 210 is used to process the corpus used by RAG to obtain multiple document blocks; call the RAG embedding model to perform vectorization processing on each document block and save the vector result of each document block; use ElasticSearch to index the keywords in each document block and save the keyword index result of each document block; call the LLM model to generate multiple hypothetical questions for each document block and save the multiple hypothetical questions, the LLM model refers to a large language model; perform semantic enhancement processing on the user's prompt words to obtain new prompt words;
[0173] A recall unit 220 is used to perform multi-way recall on the RAG embedding model, ElasticSearch and multiple hypothetical questions based on the new prompt word to obtain a document block set summarized by ranking;
[0174] The screening unit 230 is used to call the LLM model to screen out a number of target document blocks from the document block set, where the target document blocks are document blocks related to the new prompt word; according to a preset number of document blocks, the target document blocks are cut and processed to obtain a final context output result;
[0175] The output unit 240 is used to combine the new prompt word and the context output result as the output answer of the LLM model.
[0176] In one implementation, when the processing unit 210 is used to process the corpus used by the RAG to obtain multiple document blocks, it is specifically used to:
[0177] Organize the corpus used by RAG to obtain different types of documents;
[0178] Using the specified segmentation rules, each type of document is segmented into several document blocks to obtain multiple document blocks.
[0179] In one implementation, the RAG embedding model includes the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model; when the processing unit 210 is used to call the RAG embedding model to perform vectorization processing on each document block and save the vector result of each document block, it is specifically used to:
[0180] The maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model are respectively called to vectorize each document block to obtain three first sub-vector results;
[0181] The three first sub-vector results are saved to different indexes of Milvus respectively to obtain vector results.
[0182] In one implementation, when the processing unit 210 is used to save a plurality of hypothetical questions, it is specifically used to:
[0183] Call the RAG embedding model to perform vector processing on multiple hypothetical questions respectively to obtain multiple second sub-vector results;
[0184] The multiple second sub-vector results are saved to the corresponding indexes of Milvus.
[0185] In one implementation, when the processing unit 210 is used to perform semantic enhancement processing on the user's prompt word to obtain a new prompt word, it is specifically used to:
[0186] Get the user's chat history;
[0187] The LLM model is called to perform semantic enhancement processing on the prompt words based on the chat records to obtain new prompt words.
[0188] In one embodiment, the RAG embedding model includes the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model; the recall unit 220 is used to perform multi-way recall on the RAG embedding model, ElasticSearch, and multiple hypothetical questions based on the new prompt word to obtain a set of document blocks summarized by ranking, specifically for:
[0189] After calling the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model to vectorize the new prompt words, several first relevant document blocks are recalled according to the vector results;
[0190] Call the reciprocal ranking fusion RRF algorithm to calculate the score of each first relevant document block;
[0191] After calling the maidalun1020 / bce-embedding-base_v1 embedding model to vectorize the new prompt word, multiple hypothetical questions are indexed and retrieved to retrieve several second related document blocks;
[0192] Call the RRF algorithm to calculate the score of each second relevant document block;
[0193] Perform keyword search on the new prompt word using the BM25 algorithm on ElasticSearch and recall several third-related document blocks;
[0194] Call the RRF algorithm to calculate the score of each third relevant document block;
[0195] Adding scores of at least two identical related document blocks among the plurality of first related document blocks, the plurality of second related document blocks, and the plurality of third related document blocks to obtain a total score, retaining one related document block among the at least two related document blocks, and using the total score as the score of one related document block;
[0196] The remaining relevant document blocks among the plurality of first relevant document blocks, the plurality of second relevant document blocks and the plurality of third relevant document blocks are sorted and aggregated according to the scores to obtain a document block set.
[0197] In one implementation, when the screening unit 230 is used to call the LLM model to screen out a number of target document blocks from the document block set, it is specifically used to:
[0198] The document block set and the new prompt word are submitted to the LLM model, and the LLM model judges the relevance of the document block set, and selects the document blocks related to the new prompt word from the document block set to obtain several target document blocks.
[0199] The functions of each unit in the RAG text processing device based on multi-way recall in the embodiment of the present application can be found in the corresponding description in the above method, and will not be repeated here.
[0200] Figure 3 FIG. 2 shows a block diagram of a computer device according to an embodiment of the present application. Figure 3 As shown, the computer device includes: a memory 310 and a processor 320. The memory 310 stores instructions, and the instructions are loaded and executed by the processor 320 to implement the RAG text processing method based on multi-way recall in the above embodiment. The number of the memory 310 and the processor 320 can be one or more.
[0201] The computer device also includes:
[0202] The communication interface 330 is used to communicate with external devices and perform data exchange transmission.
[0203] If the memory 310, the processor 320 and the communication interface 330 are implemented independently, the memory 310, the processor 320 and the communication interface 330 can be connected to each other through a bus and communicate with each other. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 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.
[0204] Optionally, in a specific implementation, if the memory 310, the processor 320 and the communication interface 330 are integrated on a chip, the memory 310, the processor 320 and the communication interface 330 can communicate with each other through an internal interface.
[0205] An embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer program runs on a computer, the method provided in the embodiment of the present application is implemented.
[0206] An embodiment of the present application also provides a chip, which includes a processor for calling and executing instructions stored in a memory, so that a communication device equipped with the chip executes the method provided by the embodiment of the present application.
[0207] An embodiment of the present application also provides a chip, including: an input interface, an output interface, a processor and a memory, wherein the input interface, the output interface, the processor and the memory are connected via an internal connection path, and the processor is used to execute the code in the memory. When the code is executed, the processor is used to execute the method provided in the embodiment of the application.
[0208] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. It is worth noting that the processor may be a processor that supports the Advanced RISC Machines (ARM) architecture.
[0209] Further, optionally, the above-mentioned memory may include a read-only memory and a random access memory, and may also include a non-volatile random access memory. The memory may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may include a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may include a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available. For example, static RAM (SRAM), dynamic random access memory (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct rambus RAM (DR RAM).
[0210] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium.
[0211] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments or examples described in this specification and the features of different embodiments or examples, unless they are contradictory.
[0212] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0213] Any process or method description in the flow chart or otherwise described herein can be understood to represent a module, fragment or portion of a code including one or more executable instructions for implementing the steps of a specific logical function or process. And the scope of the preferred embodiment of the present application includes other implementations, in which the functions may not be performed in the order shown or discussed, including in a substantially simultaneous manner or in a reverse order according to the functions involved.
[0214] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, which can be embodied in any computer-readable medium for use by an instruction execution system, apparatus or device (such as a computer-based system, a system including a processor or other system that can fetch instructions from an instruction execution system, apparatus or device and execute instructions), or used in combination with these instruction execution systems, apparatuses or devices.
[0215] It should be understood that the various parts of the present application can be implemented with hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented with software or firmware stored in a memory and executed by a suitable instruction execution system. All or part of the steps of the above embodiment method can be completed by instructing the relevant hardware through a program, which can be stored in a computer-readable storage medium, and when the program is executed, it includes one of the steps of the method embodiment or a combination thereof.
[0216] In addition, each functional unit in each embodiment of the present application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into one module. The above-mentioned integrated module can be implemented in the form of hardware or in the form of a software functional module. If the above-mentioned integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. The storage medium can be a read-only memory, a disk or an optical disk, etc.
[0217] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A RAG text processing method based on multi-way recall, characterized in that: include: Process the corpus used by RAG to obtain multiple document blocks; Calling the RAG embedding model to perform vectorization processing on each of the document blocks, and saving the vector results of each of the document blocks; Using ElasticSearch to index the keywords in each of the document blocks, and saving the keyword index results of each of the document blocks; Calling an LLM model to generate a plurality of hypothetical questions for each of the document blocks, and saving the plurality of hypothetical questions, wherein the LLM model refers to a large language model; Perform semantic enhancement processing on the user's prompt words to obtain new prompt words; Based on the new prompt word, perform multi-way recall on the RAG embedding model, the ElasticSearch and the multiple hypothetical questions to obtain a set of document blocks summarized by ranking; Calling the LLM model to filter out a plurality of target document blocks from the document block set, wherein the target document blocks are document blocks related to the new prompt word; According to a preset number of document blocks, a plurality of the target document blocks are cut and processed to obtain a final context output result; Combining the new prompt word with the context output result as the output answer of the LLM model; The RAG embedding models include the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model; The RAG embedding model is called to perform vectorization processing on each document block, and the vector result of each document block is saved, including: The maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model and the GanymedeNil / text2vec-large-chinese embedding model are respectively called to perform vectorization processing on each of the document blocks to obtain three first sub-vector results; The three first sub-vector results are respectively saved in different indexes of Milvus to obtain the vector results; Wherein, based on the new prompt word, multi-way recall is performed on the RAG embedding model, the ElasticSearch and the multiple hypothetical questions, and the document block set summarized by ranking is obtained, including: After calling the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model to respectively vectorize the new prompt word, a plurality of first related document blocks are recalled according to the vector results; Calling the reciprocal ranking fusion RRF algorithm to calculate the score of each of the first relevant document blocks; After calling the maidalun1020 / bce-embedding-base_v1 embedding model to vectorize the new prompt word, index and retrieve the multiple hypothetical questions to recall a number of second related document blocks; Calling the RRF algorithm to calculate the score of each of the second relevant document blocks; Perform keyword search on the new prompt word using the BM25 algorithm on ElasticSearch to retrieve a number of third related document blocks; Calling the RRF algorithm to calculate the score of each of the third relevant document blocks; Adding the scores of at least two identical related document blocks among the plurality of the first related document blocks, the plurality of the second related document blocks, and the plurality of the third related document blocks to obtain a total score, retaining one related document block among the at least two related document blocks, and using the total score as the score of the one related document block; The remaining relevant document blocks among the plurality of the first relevant document blocks, the plurality of the second relevant document blocks and the plurality of the third relevant document blocks are sorted and aggregated according to the scores to obtain the document block set.
2. The method according to claim 1, characterized in that The corpus used by RAG is processed to obtain multiple document blocks including: Organize the corpus used by RAG to obtain different types of documents; Each category of the documents is segmented into a plurality of document blocks using a specified segmentation rule to obtain the plurality of document blocks.
3. The method according to claim 1, characterized in that Saving a number of these hypothetical questions includes: Calling the RAG embedding model to perform vector processing on the plurality of hypothetical questions respectively to obtain a plurality of second sub-vector results; The plurality of second sub-vector results are saved in corresponding indexes of Milvus.
4. The method according to claim 1, characterized in that: The user's prompt words are semantically enhanced to obtain new prompt words including: Get the user's chat history; The LLM model is called to perform semantic enhancement processing on the prompt word based on the chat record to obtain the new prompt word.
5. The method according to any one of claims 1 to 4, characterized in that Calling the LLM model to filter out a number of target document blocks from the document block set includes: The document block set and the new prompt word are submitted to the LLM model, and the LLM model performs relevance judgment on the document block set, and selects document blocks related to the new prompt word from the document block set to obtain a plurality of target document blocks.
6. A RAG text processing device based on multi-channel recall, characterized in that: include: A processing unit, used to process the corpus used by RAG to obtain multiple document blocks; Calling the RAG embedding model to perform vectorization processing on each of the document blocks, and saving the vector results of each of the document blocks; using ElasticSearch to index the keywords in each of the document blocks, and saving the keyword index results of each of the document blocks; Calling the LLM model to generate multiple hypothetical questions for each document block, and saving the multiple hypothetical questions, wherein the LLM model refers to a large language model; performing semantic enhancement processing on the user's prompt word to obtain a new prompt word; A recall unit, configured to perform multi-way recall on the RAG embedding model, the ElasticSearch, and the plurality of hypothetical questions based on the new prompt word to obtain a document block set summarized by ranking; A screening unit, configured to call the LLM model to screen out a plurality of target document blocks from the document block set, wherein the target document blocks are document blocks related to the new prompt word; and to perform segmentation processing on the plurality of target document blocks according to a preset number of document blocks to obtain a final context output result; An output unit, used for combining the new prompt word and the context output result as an output answer of the LLM model; The RAG embedding model includes the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model; when the processing unit is used to call the RAG embedding model to perform vectorization processing on each of the document blocks and save the vector results of each of the document blocks, it is specifically used to: respectively call the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model to perform vectorization processing on each of the document blocks to obtain three first sub-vector results; respectively save the three first sub-vector results to different indexes of Milvus to obtain the vector results; Wherein, when the recall unit is used to perform multi-way recall on the RAG embedding model, the ElasticSearch and the multiple hypothetical questions based on the new prompt word to obtain a set of document blocks summarized by ranking, it is specifically used to: call the maidalun1020 / bce-embedding-base_v1 embedding model, the baai / bge-large-zh-v1.5 embedding model, and the GanymedeNil / text2vec-large-chinese embedding model to vectorize the new prompt word respectively, and then recall several first related document blocks according to the vector results; call the reciprocal ranking fusion RRF algorithm to calculate the score of each first related document block; call the maidalun1020 / bce-embedding-base_v1 embedding model to vectorize the new prompt word After processing, the multiple hypothetical questions are indexed and retrieved to recall several second relevant document blocks; the RRF algorithm is called to calculate the score of each of the second relevant document blocks; the new prompt word is searched for keywords on ElasticSearch using the BM25 algorithm to recall several third relevant document blocks; the RRF algorithm is called to calculate the score of each of the third relevant document blocks; the scores of at least two identical relevant document blocks in several first relevant document blocks, several second relevant document blocks and several third relevant document blocks are added to obtain the total score, one relevant document block in the at least two relevant document blocks is retained, and the total score is used as the score of the one relevant document block; the remaining relevant document blocks in several first relevant document blocks, several second relevant document blocks and several third relevant document blocks are sorted and summarized according to the size of the score to obtain the document block set.
7. A computer device, characterized in that: include: A memory and a processor, wherein the memory stores instructions, and the instructions are loaded and executed by the processor to implement the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed on a computer, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
RAG knowledge question-answering method and device based on fusion vector and keyword retrieval
CN117951274A
LLM-based intelligent questioning and answering method, system and equipment in power field and medium
CN118277521A