Chain-based retrieval enhancement generation method and device and readable storage medium
By adopting chain structure and document chain reconstruction algorithm in the search enhancement generation system, the problems of difficult content segmentation and missing key content are solved, the search accuracy and answer integrity are improved, and the answering ability of the large language model is enhanced.
Patent Information
- Application Number
- CN202411062410.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-05
- Publication Date
- 2024-11-12
AI Technical Summary
The existing search enhancement generation system has limitations in terms of difficult content segmentation, missing key content, and non-questions, resulting in insufficient search accuracy and answer integrity.
Using a chain-based search enhancement generation method, by building document blocks into a double-linked list structure, optimizing document segmentation and rearrangement models, ensuring the semantics of each document block are clear, and the context content is expanded through the document chain reconstruction algorithm to improve Search accuracy and answer integrity.
It improves the accuracy of the search and the completeness of the answers, reduces the output of misleading information, and enhances the accuracy and semantic coherence of the large language model in question answering.
Smart Images

Figure CN118939776A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a chain-based retrieval enhancement generation method, device and readable storage medium. Background Art
[0002] At present, various generative large language models (LLM) have demonstrated powerful capabilities in many scenarios, but their knowledge is fixed during training and cannot be updated in real time, resulting in challenges in accuracy, knowledge update speed, expertise, and the utilization of private domain knowledge.
[0003] Retrieval-Augmented Generation (RAG) is a technology that combines information retrieval technology with the prompting function of LLM. It allows LLM to retrieve relevant information through search algorithms and use this information as context to generate answers, enabling RAG to provide richer and more accurate answers.
[0004] When answering questions, retrieval-enhanced generation prioritizes retrieving relevant information from external knowledge bases and inputs the retrieved information into the large model as the context for answering user questions. RAG effectively improves the speed of knowledge iteration and the utilization of private domain knowledge by combining the parameterized knowledge of the large language model with the non-parametric external knowledge base, while also improving the accuracy of the large language model in answering questions.
[0005] However, the current RAG system still has some limitations, such as difficulty in content segmentation, missing key content, and irrelevant answers. Summary of the invention
[0006] The technical problem to be solved by the present application is to provide a chain-based retrieval enhancement generation method, device and readable storage medium to solve the problems existing in the prior art in view of the above-mentioned deficiencies in the prior art.
[0007] In a first aspect, the present application provides a chain-based retrieval enhancement generation method, the method comprising:
[0008] S1. Obtain content to be searched, and convert the content to be searched into an embedding vector;
[0009] S2. Searching in a vector database according to the embedded vector to obtain relevant documents, wherein the vector database is constructed based on source data;
[0010] S3, performing document chain reconstruction processing based on the relevant documents to obtain a first document chain;
[0011] S4: Input the content to be searched and the first document chain into a large language model, and generate search results corresponding to the content to be searched through the large language model.
[0012] In some embodiments, in S2, the process of constructing the vector database includes:
[0013] S01. Obtain source data;
[0014] S02, cutting the source data into chunks to obtain text chunks;
[0015] S03, constructing a second document chain according to the text chunks;
[0016] S04, performing vectorization processing on the second document chain to obtain a vector matrix;
[0017] S05. Store the vector matrix in a vector database.
[0018] In some embodiments, S03 includes:
[0019] S03a, defining node information of text chunks, wherein the node information includes a data portion, a current node index, a predecessor index, and a successor index;
[0020] S03b, traverse all text chunks, and add index and source information to each text chunk according to the order of chunking;
[0021] S03c. Add the indexes of the preceding and following blocks to each of the text chunks to form the second document chain.
[0022] In some embodiments, S3 includes:
[0023] S31, reordering the relevant documents to obtain reordered documents;
[0024] S32: Perform document block classification and document chain reconstruction processing on the rearranged documents to obtain a first document chain.
[0025] In some embodiments, S32 includes:
[0026] S32a, classifying the document blocks of the rearranged document according to the document source, and obtaining classification results of each document block in the rearranged document;
[0027] S32b: Reconstruct the document chain according to the classification result to obtain a first document chain.
[0028] In some embodiments, the classification result includes a document block classification dictionary obtained by classifying the document blocks;
[0029] S32b, including:
[0030] Determine the logical position of each document block in the document chain according to the document block classification dictionary;
[0031] The rearranged documents are locally sorted according to the logical positions of the document blocks in the document chain to obtain the first document chain.
[0032] In some embodiments, S32b further includes:
[0033] Obtaining a preset number of forward-extended document blocks and a preset number of backward-extended document blocks;
[0034] Based on the preset number of forward-extended document blocks and the preset number of backward-extended document blocks, forward and backward semantic expansion processing is performed on each document block.
[0035] In a second aspect, the present application provides a chain-based search enhancement generation device, the device comprising:
[0036] A search content acquisition module, configured to acquire content to be searched and convert the content to be searched into an embedding vector;
[0037] A data retrieval module, configured to search a vector database based on the embedded vector to obtain relevant documents, wherein the vector database is constructed based on source data;
[0038] A document chain reconstruction module, configured to perform document chain reconstruction processing based on the relevant documents to obtain a first document chain;
[0039] The retrieval result acquisition module is configured to input the content to be retrieved and the first document chain into a large language model, and generate a retrieval result corresponding to the content to be retrieved through the large language model.
[0040] In a third aspect, the present application provides a chain-based retrieval enhancement generation device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to implement the chain-based retrieval enhancement generation method described in the first aspect above.
[0041] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the chain-based retrieval enhancement generation method described in the first aspect is implemented.
[0042] The present application provides a chain-based retrieval enhancement generation method, device and readable storage medium, the method comprising: obtaining content to be retrieved, converting the content to be retrieved into an embedded vector; searching in a vector database based on the embedded vector to obtain relevant documents, the vector database being constructed based on source data; reconstructing a document chain based on the relevant documents to obtain a first document chain; inputting the content to be retrieved and the first document chain into a large language model, and generating retrieval results corresponding to the content to be retrieved through the large language model. The present application provides a chain-based retrieval enhancement generation method, which enables the RAG system to use the smallest possible block division by constructing the segmented document blocks into a double linked list structure that is convenient for forward and backward bidirectional traversal, so that the semantics in each document block is as clear as possible, thereby improving the accuracy of the retrieval. At the same time, the linked list structure can efficiently expand the context content to ensure the integrity of the semantics. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0044] Figure 1 A schematic diagram of a chain-based RAG system architecture proposed in this application;
[0045] Figure 2 A schematic diagram of text vectorization storage provided in an embodiment of the present application;
[0046] Figure 3 A flowchart of a chain-based search enhancement generation method provided in an embodiment of the present application;
[0047] Figure 4 A schematic diagram of the structure of a chain-based search enhancement generation device provided in an embodiment of the present application;
[0048] Figure 5 A schematic diagram of the structure of another chain-based retrieval enhancement generation device provided in an embodiment of the present application.
[0049] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0050] In order to enable those skilled in the art to better understand the technical solution of the present application, the implementation mode of the present application will be further described in detail below with reference to the accompanying drawings.
[0051] It should be understood that the specific embodiments and drawings described herein are only used to explain the present application, rather than to limit the present application.
[0052] It can be understood that, in the absence of conflict, the various embodiments in the present application and the various features in the embodiments can be combined with each other.
[0053] It can be understood that, for the convenience of description, the drawings of the present application only show the parts related to the present application, while the parts unrelated to the present application are not shown in the drawings.
[0054] It can be understood that each unit and module involved in the embodiments of the present application may correspond to only one physical structure, or may be composed of multiple physical structures, or multiple units and modules may be integrated into one physical structure.
[0055] It can be understood that the terms "first", "second", etc. in the embodiments of the present application are used to distinguish different objects, or to distinguish different processing of the same object, rather than to describe a specific order of objects.
[0056] It is understandable that, in the absence of conflict, the functions and steps marked in the flowcharts and block diagrams of the present application may occur in an order different from that marked in the drawings.
[0057] It is understood that the flowcharts and block diagrams of the present application illustrate the possible architectures, functions, and operations of the systems, devices, equipment, and methods according to the various embodiments of the present application. Among them, each box in the flowchart or block diagram may represent a unit, module, program segment, code, which contains executable instructions for implementing the specified functions. Moreover, each box or combination of boxes in the block diagram and flowchart may be implemented by a hardware-based system that implements the specified functions, or by a combination of hardware and computer instructions.
[0058] It can be understood that the units and modules involved in the embodiments of the present application can be implemented by software or hardware, for example, the units and modules can be located in a processor.
[0059] The mainstream implementation method of RAG is to use a vector database to vectorize text. First, it converts text data into vector form and stores it in the vector database. Then, when a question is input, it converts the question into a vector and then searches the vector database for the text vector that best matches it. After a successful match, the corresponding text content can be returned as the context for the large language model to generate the answer. This method is highly efficient and accurate when dealing with large-scale information retrieval tasks.
[0060] The RAG system aims to reduce the hallucination response problem of LLM. However, the RAG system still faces a series of challenges in its actual implementation, including but not limited to missing content of retrieved documents, mismatch between retrieval and generation stages, and when the actual answer is not in the knowledge base, the RAG system provides a seemingly reasonable but incorrect answer, which can lead to misleading information for users;
[0061] Specifically, the limitations of the existing RAG system can be summarized as follows:
[0062] (1) It is difficult to segment text content. If the blocks are too large, the semantics of the document block may be unclear, reducing the accuracy of the retrieval. If the blocks are too small, the context of the retrieval content may be seriously missing and the semantics may be incomplete.
[0063] (2) Missing key content. Due to the limitation of the LLM context window and the large amount of context content returned during the retrieval phase, the RAG system will discard document blocks with lower rankings, resulting in missing key context content, which affects the quality of the answer generated by the RAG system.
[0064] (3) The RAG system easily outputs misleading information when the retrieved content does not exist in the external knowledge base or when the content of the retrieval stage does not match that of the generation stage.
[0065] Existing research has conducted extensive explorations on the above issues, such as manually adding special characters to the text and performing semantic segmentation according to the special characters, but this method is particularly time-consuming. Alternatively, simply optimizing prompts, rearranging, and other methods have improved the effect of RAG generating answers to a certain extent, but there is still room for improvement in the completeness and accuracy of the generated answers.
[0066] To solve the above problems, the present application optimizes the logical structure of the same document after segmentation, so that each document block after segmentation is still logically a whole. Based on this, in the document segmentation process, the document can be segmented into smaller blocks (chunks) to make the semantics within the chunk clearer; in addition, the present application further optimizes the prompt, introduces a rearrangement model, and proposes a document chain reconstruction algorithm in the present application to expand the before and after context for the rearranged document block, thereby improving the accuracy of the answer generated by the RAG system while improving the completeness of the answer.
[0067] The main concepts of this application include:
[0068] (1) This application optimizes the document segmentation technology through a carefully designed algorithm to ensure that even after the document is cut into smaller blocks, these document blocks can still maintain their original integrity logically. This optimization not only makes the internal semantics of the document block clearer and more focused, but also divides the document more finely to form smaller logical units, namely "chunks". These smaller chunks can more effectively improve the accuracy of the retrieval stage because of their clearer semantics.
[0069] (2) By introducing an advanced reranker model and cooperating with the Document Chain Reconstruction (DCR) algorithm proposed in this application, the most relevant documents can be ranked at the front while expanding the context of the document. This expansion not only enhances the semantic coherence of the document block, but also greatly improves the semantic richness of the document block. In addition, this application also redesigns the prompt words to reduce the output of misleading information in the RAG system.
[0070] (2) In terms of improving the effectiveness of the RAG (Retrieval-Augmented Generation) system in generating answers, this application enables the system to more accurately capture the core points of the question and generate more precise answers by introducing an optimized logical structure and a rearrangement model. At the same time, by introducing a document chain reconstruction algorithm (DCR) to expand the context content, this application also improves the completeness of the answer.
[0071] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0072] Figure 1 A schematic diagram of a chain-based RAG system architecture proposed in this application is shown in FIG. Figure 1 As shown, the chained RAG system proposed in this application is used to improve the effect of retrieval enhancement generation. Chained RAG divides long documents into smaller chunks, and logically constructs the chunks of the same document into a bidirectional linked list structure. By introducing a rearrangement model, the system can more accurately capture the core points of the question, and carefully designs a document chain reconstruction algorithm (DCR) to expand the context content of the rearranged chunks to improve the accuracy and completeness of the answer.
[0073] Based on the above-mentioned chain RAG system, the present application provides a chain-based retrieval enhancement generation method, the working process flow of which can be implemented by electronic devices, such as computers, handheld smart terminals, etc. For the convenience of explanation, the method execution subject is described as a computer in each embodiment of the present application.
[0074] The overall process of this application is divided into two stages, namely the text vectorization storage stage and the answer retrieval generation stage. The text vectorization storage stage is to build a vector database; the answer retrieval generation stage is a chain-based retrieval enhancement generation process.
[0075] Figure 2 A schematic diagram of text vectorization storage provided in an embodiment of the present application, such as Figure 2 As shown in the figure, the specific implementation steps of the text vectorization storage stage are as follows:
[0076] S01. Obtain source data;
[0077] In this step, after obtaining the source data, for different types of text data, select the corresponding library or toolkit to load source data in various formats such as PDF files, Word documents, Markdown text, Excel tables, etc. into the memory for filtering, compression, formatting, etc. to process them into the same paradigm.
[0078] S02, cutting the source data into chunks to obtain text chunks;
[0079] In this step, the loaded source text is segmented into chunks of appropriate size and the semantic integrity of each chunk is maintained as much as possible. Common text segmentation strategies include segmenting based on punctuation marks such as line breaks, periods, question marks, exclamation marks, etc. to avoid breaking in the middle of sentences. However, the size of the chunks is usually difficult to grasp. In addition, in order to make the semantics of each chunk relatively clear as much as possible, it can also be segmented according to the appropriate chunk size.
[0080] In this application, the smallest possible chunking method is used to make the semantics of each chunk as clear as possible, so that the top few chunks (top_n) with the highest relevance can be extracted during retrieval. This method can effectively improve the efficiency and accuracy of information retrieval. For example, for a source file with a larger format, it can be chunked in units of 100-200 characters.
[0081] S03, constructing a second document chain according to the text chunks;
[0082] In this application, the smallest possible chunking method is used. Although this will improve the accuracy of information retrieval, smaller chunks will reduce the semantic integrity of each document chunk. In order to improve the accuracy of information retrieval while maintaining semantic coherence, this application constructs a document chain in the form of a linked list from the chunks of the same document.
[0083] In some embodiments, S03 includes:
[0084] S03a, defining node information of text chunks, wherein the node information includes a data portion, a current node index, a predecessor index, and a successor index;
[0085] Specifically, the node information contains four parts, namely data-data part, id-index of the current node, prev_id-predecessor index, that is, the index of the previous node, and next_id-successor index, that is, the index of the next node.
[0086] S03b, traverse all text chunks, and add index and source information to each text chunk according to the order of chunking;
[0087] S03c. Add the indexes of the preceding and following blocks to each of the text chunks to form the second document chain.
[0088] By constructing a second document chain, each document block in the chain can be regarded as a node. When a node is retrieved, the previous and next nodes can be conveniently accessed through the document chain. This form can not only improve the accuracy of information retrieval, but also efficiently access the previous and next nodes of the retrieved document block through the document chain, effectively expand the context, and maintain semantic integrity.
[0089] S04, performing vectorization processing on the second document chain to obtain a vector matrix;
[0090] This step performs document chain embedding processing. Document chain embedding, also known as vectorization, is the process of converting text data into a vector matrix. This step has a direct impact on the effect of subsequent retrieval. This step can be completed through an embedding model. Commonly used embedding models include text2vec-large-chain, sentence-transformer, OpenAI Embedding, etc. The choice of embedding model in this process is crucial. Choosing a suitable vector embedding model can effectively improve the quality of retrieval.
[0091] S05. Store the vector matrix in a vector database.
[0092] After the document chain is converted into a vector form through the embedding model, the vectorized data of the document chain is stored in the vector database, so that efficient retrieval operations can be performed based on the similarity of the vector space. The process of building an index after the text is vectorized, writing it into the vector database and saving it in the disk for persistent storage is called vectorized storage of text. Vector databases suitable for RAG scenarios include: face, Chroma, Milvus, etc.
[0093] The above is an explanation of the text vectorization storage stage. The following is a detailed explanation of the answer retrieval generation stage.
[0094] Figure 3 A schematic diagram of a chain-based search enhancement generation method provided in an embodiment of the present application, such as Figure 3 As shown, the present application provides a chain-based retrieval enhancement generation method, the method includes S1-S4, which are as follows:
[0095] S1. Obtain content to be searched, and convert the content to be searched into an embedding vector;
[0096] This step is the starting stage of the entire retrieval generation process. At this stage, the user will input the questions they are concerned about or the content to be retrieved. By clearly describing the questions, the user can help the RAG system fully understand the user's intentions and provide a clear direction for subsequent retrieval. This step is crucial as it determines the effectiveness and relevance of subsequent retrieval and generation. The system will generate corresponding retrieval queries based on the content entered by the user in order to find the most relevant information in a large data set or document library. Effective question input can significantly improve the accuracy and efficiency of information retrieval.
[0097] The method of converting the content to be retrieved into an embedding vector may be the same as the method adopted in step S04, and this application does not limit this.
[0098] S2. Searching in a vector database according to the embedded vector to obtain relevant documents, wherein the vector database is constructed based on source data;
[0099] The role of question / content embedding is to convert the user's input question or the content to be retrieved into an embedding vector. These vectors are points in a high-dimensional space that can capture the semantic features of the input text. Their main functions are: semantic understanding, through the embedding vector, the system can better understand the semantics of the user input, which helps to improve the relevance and accuracy of the retrieval results; efficient retrieval: after converting the text into an embedding vector, an efficient vector search algorithm can be used to quickly find the most semantically relevant documents or information in a large-scale data set; similarity calculation, the embedding vector allows the system to evaluate the similarity between different texts by calculating the distance or similarity between vectors, which is crucial for finding the content most relevant to the user's question.
[0100] When using the embedding vector of the content to be retrieved to perform relevant document retrieval based on the user's question, there are mainly two steps:
[0101] (1) Vector database loading: Loading the vector database enables the system to access and manage all pre-processed and stored vectorized data. This allows the system to use its built-in index structure and optimization algorithm to quickly find vectors similar to the query vector in a large amount of vector data.
[0102] (1) Similarity retrieval: Use the embedded vector of the question to perform similarity retrieval in the vector database. This process usually uses methods such as cosine similarity, Euclidean distance, Manhattan distance, and maximum marginal correlation to calculate similarity. This application appropriately increases the number of returned correlation samples in the similarity retrieval step to enhance the diversity of samples.
[0103] S3, performing document chain reconstruction processing based on the relevant documents to obtain a first document chain;
[0104] In this step, based on different sources and different numbers of related documents, the obtained first document chain can be a partial document chain or a complete document chain. In addition, the number of the first document chain can be one or more.
[0105] In some embodiments, S3 includes:
[0106] S31, reordering the relevant documents to obtain reordered documents;
[0107] Specifically, step S31 uses the re-ranking model to re-rank the relevant documents to ensure that the most relevant answers are ranked first. The re-ranking model scores and re-ranks the answers by analyzing the semantic similarity and contextual matching between the generated answers and the user's questions, and returns the most relevant answers. In addition, the re-ranking model improves the quality of the generated answers by correcting errors, personalizing adjustments, and controlling diversity.
[0108] S32: Perform document block classification and document chain reconstruction processing on the rearranged documents to obtain a first document chain.
[0109] In this step, a document chain reconstruction algorithm is designed to expand the semantics of the document chain and reorder the document blocks. This process is mainly divided into two steps, namely document block classification and document chain reconstruction.
[0110] In some embodiments, S32 includes:
[0111] S32a, classifying the document blocks of the rearranged document according to the document source, and obtaining classification results of each document block in the rearranged document;
[0112] Specifically, the document block classification algorithm is as follows:
[0113] Algorithm 1: Document Classification (Document Block Classification)
[0114] Input: The document block collection documents returned after rearrangement
[0115] Output: document block classification dictionary doc_categor i es_d i ct
[0116] The input of Algorithm 1 is the rearranged document block result set. By traversing each document block in the result set, each document block is classified according to its source and the sequence number after the source file is cut into pieces, and a document block classification dictionary is generated as the input of the document chain reconstruction algorithm.
[0117] S32b: Reconstruct the document chain according to the classification result to obtain a first document chain.
[0118] In some embodiments, the classification result includes a document block classification dictionary obtained by classifying the document blocks;
[0119] S32b, including: determining the logical position of each document block in the document chain according to the document block classification dictionary; and locally sorting the rearranged documents according to the logical position of the document block in the document chain to obtain the first document chain.
[0120] In some embodiments, S32b further includes: obtaining a preset number of forward-extended document blocks and a preset number of backward-extended document blocks; and performing forward and backward semantic expansion processing on each document block based on the preset number of forward-extended document blocks and the preset number of backward-extended document blocks.
[0121] Specifically, the document chain reconstruction algorithm is as follows:
[0122] Algorithm 2: Document Chain Reconstruction
[0123] Input: document block classification dictionary doc_categor i es_d i ct, forward shift number prev_num, backward shift number next_num
[0124] Output: Generate chained document list chain_document_list
[0125] The input of Algorithm 2 mainly consists of three parameters, namely, the document block classification dictionary doc_categories_d i ct output by Algorithm 1, the forward shift number prev_num and the backward shift number next_num, where prev_num is the number of document blocks extended forward, and next_num is the number of document blocks extended backward. Algorithm 2 sorts the document block list returned in the rearrangement phase locally according to the logical position of the document block in the document chain, and can independently extend the semantics of the document block forward and backward through the two parameters next_num and prev_num to enhance the semantic integrity.
[0126] S4: Input the content to be searched and the first document chain into a large language model, and generate search results corresponding to the content to be searched through the large language model.
[0127] This step mainly implements the Prompt injection of the large language model. As the actual input of the large model, the design of the Prompt will directly affect the quality of the generated answer. The design of the Prompt has no fixed syntax and depends more on personal experience. This application injects the document chain returned in the retrieval phase and the question entered by the user into the Prompt.
[0128] Optionally, according to the characteristics of the returned document chain result set, a related instruction injection prompt may be designed to reduce the possibility that the RAG system may output misleading information.
[0129] After the constructed prompt is input into LLM, LLM will generate answers related to the question based on the question in the prompt and the chained contextual reference content. In order to ensure that the generated answers are more accurate and relevant, some specific instructions related to the search content can be injected into the prompt. These instructions can guide LLM to better understand the question and use contextual information to provide detailed and accurate answers.
[0130] The present application provides a chain-based retrieval enhancement generation method. By constructing the segmented document blocks into a double linked list structure that is convenient for forward and backward bidirectional traversal, the RAG system can adopt the smallest possible block division method, making the semantics in each document block as clear as possible, thereby improving the accuracy of retrieval. At the same time, the linked list structure can efficiently expand the context content to ensure the integrity of the semantics.
[0131] It should be understood that, although the various steps in the flowcharts in the above-described embodiments are sequentially displayed according to the indications of the arrows, these steps are not necessarily executed sequentially in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and they can be executed in other orders. Moreover, at least a portion of the steps in the figure may include a plurality of sub-steps or a plurality of stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily to be carried out sequentially, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0132] Figure 4 A schematic diagram of a chain-based search enhancement generation device provided in an embodiment of the present application, such as Figure 4 As shown, the present application provides a chain-based search enhancement generation device, the device comprising:
[0133] A search content acquisition module 11, which is configured to acquire the content to be searched and convert the content to be searched into an embedding vector;
[0134] A data retrieval module 12, which is configured to search in a vector database according to the embedded vector to obtain relevant documents, wherein the vector database is constructed based on source data;
[0135] A document chain reconstruction module 13, which is configured to perform document chain reconstruction processing based on the relevant documents to obtain a first document chain;
[0136] The search result acquisition module 14 is configured to input the content to be searched and the first document chain into a large language model, and generate a search result corresponding to the content to be searched through the large language model.
[0137] Regarding the limitation on the chain-based search enhancement generation device, reference may be made to the limitation on the chain-based search enhancement generation method in the above-mentioned embodiments of the present application, which will not be elaborated in this embodiment.
[0138] Figure 5 Another schematic diagram of a chain-based search enhancement generation device provided in an embodiment of the present application is as follows: Figure 5As shown, in some embodiments, the present application provides a chain-based retrieval enhancement generation device, including a memory 22 and a processor 21, the memory stores a computer program, and the processor is configured to run the computer program to execute the chain-based retrieval enhancement generation method in the above-mentioned embodiments of the present application.
[0139] The memory is connected to the processor, the memory may be a flash memory or a read-only memory or other memory, and the processor may be a central processing unit or a single-chip microcomputer.
[0140] In some embodiments, the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the chain-based retrieval enhancement generation method in the above-mentioned embodiments of the present application is implemented.
[0141] The computer-readable storage medium includes volatile or non-volatile, removable or non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, computer program modules or other data). Computer-readable storage media include, but are not limited to, RAM (Random Access Memory), ROM (Read-Only Memory), EEPROM (Electrically Erasable Programmable Read-Only Memory), flash memory or other memory technology, CD-ROM (Compact Disk Read-Only Memory), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer.
[0142] It is to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present application, but the present application is not limited thereto. For those skilled in the art, various modifications and improvements can be made without departing from the spirit and substance of the present application, and these modifications and improvements are also considered to be within the scope of protection of the present application.
Claims
1. A chain-based retrieval enhancement generation method, characterized in that: The method comprises: S1. Obtain content to be searched, and convert the content to be searched into an embedding vector; S2. Searching in a vector database according to the embedded vector to obtain relevant documents, wherein the vector database is constructed based on source data; S3, performing document chain reconstruction processing based on the relevant documents to obtain a first document chain; S4: Input the content to be searched and the first document chain into a large language model, and generate search results corresponding to the content to be searched through the large language model.
2. The chain-based search enhancement generation method according to claim 1, characterized in that: In S2, the process of constructing the vector database includes: S01. Obtain source data; S02, cutting the source data into chunks to obtain text chunks; S03, constructing a second document chain according to the text chunks; S04, performing vectorization processing on the second document chain to obtain a vector matrix; S05. Store the vector matrix in a vector database.
3. The chain-based search enhancement generation method according to claim 2, characterized in that: S03, including: S03a, defining node information of text chunks, wherein the node information includes a data portion, a current node index, a predecessor index, and a successor index; S03b, traverse all text chunks, and add index and source information to each text chunk according to the order of chunking; S03c. Add the indexes of the preceding and following blocks to each of the text chunks to form the second document chain.
4. The chain-based search enhancement generation method according to claim 1, characterized in that: S3, including: S31, reordering the relevant documents to obtain reordered documents; S32: Perform document block classification and document chain reconstruction processing on the rearranged documents to obtain a first document chain.
5. The chain-based search enhancement generation method according to claim 4, characterized in that: S32, including: S32a, classifying the document blocks of the rearranged document according to the document source, and obtaining classification results of each document block in the rearranged document; S32b: Reconstruct the document chain according to the classification result to obtain a first document chain.
6. The chain-based search enhancement generation method according to claim 5, characterized in that: The classification result includes a document block classification dictionary obtained by classifying the document blocks; S32b, including: Determine the logical position of each document block in the document chain according to the document block classification dictionary; The rearranged documents are locally sorted according to the logical positions of the document blocks in the document chain to obtain the first document chain.
7. The chain-based search enhancement generation method according to claim 6, characterized in that: S32b, also includes: Obtaining a preset number of forward-extended document blocks and a preset number of backward-extended document blocks; Based on the preset number of forward-extended document blocks and the preset number of backward-extended document blocks, forward and backward semantic expansion processing is performed on each document block.
8. A chain-based search enhancement generation device, characterized in that: The device comprises: A search content acquisition module, configured to acquire content to be searched and convert the content to be searched into an embedding vector; A data retrieval module, configured to search a vector database based on the embedded vector to obtain relevant documents, wherein the vector database is constructed based on source data; A document chain reconstruction module, configured to perform document chain reconstruction processing based on the relevant documents to obtain a first document chain; The retrieval result acquisition module is configured to input the content to be retrieved and the first document chain into a large language model, and generate a retrieval result corresponding to the content to be retrieved through the large language model.
9. A chain-based search enhancement generation device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to implement the chain-based retrieval enhancement generation method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the chain-based retrieval enhancement generation method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Large language model RAG optimization method based on tree neighbor context
CN119293195A
Data processing method and device, data retrieval method and device and storage medium
CN119357312A
Dynamic document generation method and system based on LLM (Language Language Model)
CN119577127A
Evaluation review content generation method based on retrieval enhancement
CN120179783A
An evaluation review content generation method based on search enhancement
CN120179783B
