RAG enhanced retrieval method, system, device and program
By building a large-scale corpus and pre-trained RAG model, the problems of low retrieval accuracy and weak generalization capabilities in the existing technology are solved, and more efficient and accurate information retrieval is achieved, improving user experience.
Patent Information
- Application Number
- CN202510093565.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-21
- Publication Date
- 2025-05-09
AI Technical Summary
When the existing RAG-based enhanced search methods deal with complex semantics and cross-domain information, there are problems such as low retrieval accuracy and poor generalization ability.
By building a large-scale corpus containing multiple types of data, pre-processing it, pre-training the RAG model, using the pre-training model to encode the query statement, generate a query vector, and calculate the similarity score with the text vector in the corpus, and return the text with the highest score as the search result.
It improves the search accuracy and generalization capabilities, achieves more accurate user intention understanding and more efficient information retrieval, and improves the usability and user experience of search results.
Smart Images

Figure CN119961434A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of retrieval technology, and in particular to a RAG enhanced retrieval method, system, device and program. Background Art
[0002] With the advent of the big data era, information retrieval has become an important means for people to obtain information. However, traditional information retrieval methods often have problems such as slow retrieval speed and low accuracy when facing massive data. In recent years, with the development of deep learning technology, information retrieval methods based on deep learning have gradually emerged. Among them, the enhanced retrieval method based on the large model RAG (Retrieval Augmented Generation) has become a hot topic of current research due to its powerful feature extraction and semantic understanding capabilities.
[0003] The RAG model is a Transformer-based pre-training model that combines generative pre-training tasks with retrieval pre-training tasks, enabling the model to both generate text and retrieve relevant information from large amounts of text.
[0004] Existing RAG-based enhanced retrieval methods still have certain limitations when dealing with complex semantics and cross-domain information, such as low retrieval accuracy and weak generalization ability.
[0005] It can be seen from this that how to create a new RAG enhanced retrieval method has become a goal that the industry urgently needs to improve. Summary of the invention
[0006] In view of this, an embodiment of the present disclosure provides a RAG enhanced retrieval method, which at least partially solves the problems existing in the prior art.
[0007] In a first aspect, an embodiment of the present disclosure provides a RAG enhanced retrieval method, the method comprising the following steps: Constructing a large-scale corpus containing multiple types of data, and preprocessing the large-scale corpus; Pre-train the RAG model; Encode the query sentence based on the pre-trained RAG model to obtain the query vector; A similarity score is calculated based on the query vector and the text vectors in the large-scale corpus, and the text with the highest score is used as the retrieval result.
[0008] According to a specific implementation method of the embodiment of the present disclosure, it includes: text, image and video.
[0009] According to a specific implementation of the embodiment of the present disclosure, the preprocessing of the large-scale corpus includes the following steps: Performing word segmentation processing on the original corpus of the large-scale corpus, dividing the text into subword units, and obtaining word segmentation results; Based on the word segmentation result, performing a stop word removal operation; the stop word removal operation includes screening and deleting words that do not carry semantic information to generate a simplified text; Based on a named entity recognition model, the words in the simplified text are annotated, and key entities are extracted and classified to generate a corpus with entity information; The corpus with entity information is formatted and the annotation format is unified.
[0010] According to a specific implementation of the embodiment of the present disclosure, the pre-training of the RAG model includes: The RAG model is trained based on generation tasks and retrieval tasks; The contrastive learning method based on negative sampling enables the model to better understand semantic information by constructing positive and negative examples.
[0011] According to a specific implementation of the embodiment of the present disclosure, the method further includes: The pre-trained RAG model is used as the teacher model, and the intermediate feature representation generated by the input sample and the final output result are used as the supervision signal; Constructing a lightweight student model; wherein the number of network layers, parameter scale and / or number of attention heads of the student model are less than those of the teacher model, and optimizing the structure of the student model based on parameter sharing or low-rank decomposition technology; Train the student model based on the intermediate feature representation of the teacher model, the supervision signal, the preset distillation loss function and the supervised learning loss function, and optimize the student model based on the optimization algorithm; The performance of the student model is compared with that of the teacher model. When the result meets the preset threshold, the training ends.
[0012] According to a specific implementation of the embodiment of the present disclosure, encoding the query sentence based on the pre-trained RAG model to obtain the query vector includes: Perform preliminary processing on the query statement to generate formatted query text; Perform word segmentation on the formatted query text and break it into word sequences; Input the word segmentation results into the encoder part of the RAG model to generate the corresponding word vectors and add position information to each word vector; Through the multi-head attention mechanism within the RAG model, the semantic relationship between each part of the word vector is comprehensively analyzed to generate a semantic representation that integrates context information; Aggregating the semantic representations through a pooling operation to generate a vector representation of a fixed length; Normalize the fixed-length vector representation.
[0013] According to a specific implementation of the embodiment of the present disclosure, the similarity score calculation based on the query vector and the text vector in the large-scale corpus includes: Normalize the query vector and the text vectors in the corpus; Compare the similarity scores between the query vector and the text vector based on cosine similarity; All text vectors are sorted by relevance based on the similarity scores.
[0014] In a second aspect, an embodiment of the present disclosure provides a RAG enhanced retrieval system, the system comprising: A corpus module is configured to construct a large-scale corpus containing multiple types of data and preprocess the large-scale corpus; RAG module, configured to pre-train the RAG model; A retrieval module is configured to encode the query sentence based on the pre-trained RAG model to obtain a query vector; Furthermore, similarity scores are calculated based on the query vector and the text vectors in the large-scale corpus, and the text with the highest score is used as the retrieval result.
[0015] In a third aspect, an embodiment of the present disclosure further provides an electronic device, the electronic device comprising: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor performs the RAG enhanced retrieval method as described in any one of the first aspect or any one of the implementations of the first aspect.
[0016] In a fourth aspect, an embodiment of the present disclosure further provides a computer program product, comprising a computer program stored on a non-transitory computer-readable storage medium, wherein the computer program comprises program instructions, and when the program instructions are executed by a computer, the computer executes the RAG enhanced retrieval method in the aforementioned first aspect or any implementation of the first aspect.
[0017] The RAG enhanced retrieval method in the disclosed embodiment, by utilizing the deep semantic understanding ability of the RAG model, can more accurately understand the user's intention and return more accurate retrieval results; by searching in the semantic vector space, it has higher search speed and efficiency than the traditional keyword matching method; by optimizing the sorting and display of retrieval results, the present invention improves the usability of retrieval results and user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The above is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0019] Figure 1 A schematic diagram of a RAG enhanced retrieval method flow chart provided in an embodiment of the present disclosure; Figure 2 A schematic diagram of the structure of a RAG enhanced retrieval system provided by an embodiment of the present disclosure; Figure 3 A schematic diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0020] The embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
[0021] The following describes the embodiments of the present disclosure through specific examples, and those skilled in the art can easily understand other advantages and effects of the present disclosure from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all of the embodiments. The present disclosure can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present disclosure. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present disclosure.
[0022] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein may be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on the present disclosure, it should be understood by those skilled in the art that an aspect described herein may be implemented independently of any other aspect, and two or more of these aspects may be combined in various ways. For example, any number of aspects described herein may be used to implement a device and / or practice a method. In addition, other structures and / or functionalities other than one or more of the aspects described herein may be used to implement this device and / or practice this method.
[0023] Additionally, in the following description, specific details are provided to facilitate a thorough understanding of the examples. However, it will be understood by those skilled in the art that the aspects described may be practiced without these specific details.
[0024] The embodiment of the present invention provides a RAG enhanced retrieval method, which utilizes the deep semantic understanding ability of the RAG model: the RAG model is trained with a large amount of text data, and can capture the deep semantics and contextual relationships of the text, providing a more accurate semantic representation for information retrieval; designing an efficient retrieval algorithm: the retrieval algorithm designed by the present invention combines the semantic representation ability of the RAG model, and can quickly search for texts similar to the query vector in a high-dimensional vector space, thereby improving the retrieval speed; optimizing the sorting and display of retrieval results: the present invention not only focuses on the accuracy of the retrieval, but also pays attention to the user experience. By optimizing the sorting and display of retrieval results, user satisfaction is improved.
[0025] Figure 1 A schematic diagram of the RAG enhanced retrieval method process provided in an embodiment of the present disclosure.
[0026] like Figure 1 As shown, at step S110, a large-scale corpus containing multiple types of data is constructed, and the large-scale corpus is preprocessed.
[0027] In the embodiment of the present invention, the multiple types of data include: text, image and video.
[0028] In the embodiments of the present invention, the preprocessing of the large-scale corpus includes the following steps: performing word segmentation on the original corpus of the large-scale corpus, splitting the text into sub-word units to obtain a word segmentation result; based on the word segmentation result, performing a stop word removal operation; the stop word removal operation includes screening and deleting words that do not carry semantic information to generate a refined text; based on a named entity recognition model, performing entity annotation on the words in the refined text, extracting and classifying key entities to generate a corpus with entity information; formatting the corpus with entity information to unify the annotation format.
[0029] More specifically, a large-scale corpus containing various types of data (such as text, images, videos, etc.) is constructed, and the corpus is preprocessed, including operations such as word segmentation, stop word removal, and entity annotation.
[0030] Specifically, it includes the following steps: 1. Perform word segmentation on the original corpus. By using a rule-based method or a deep learning model (such as the BERT tokenizer), split the text into individual words or sub-word units to generate a word segmentation result; 2. Based on the word segmentation result, perform a stop word removal operation. Use a standard stop word list or a custom stop word set to screen and delete words that do not carry semantic information (such as "of", "is", "in") to generate a refined text containing only important words; 3. For the refined text, adopt a named entity recognition (NER) model (such as BERT-NER or a CRF-based model) to perform entity annotation on the words in it, extract and classify key entities (such as person names, place names, organization names, etc.) to generate a corpus with entity information; 4. The corpus processed through the above steps is further formatted to unify the annotation format (such as the BIO or BIOES format) to generate a standardized dataset suitable for subsequent retrieval models.
[0031] More specifically, next, go to step S120.
[0032] At step S120, pre-train the RAG model.
[0033] In the embodiments of the present invention, the pre-training of the RAG model includes: training the RAG model based on generative tasks and retrieval tasks; based on the contrastive learning method of negative sampling, by constructing positive examples and negative examples, enabling the model to better understand semantic information.
[0034] More specifically, the RAG model is pre-trained, and the pre-training tasks include generative tasks and retrieval tasks. Generative tasks are used to train the model's ability to generate text, and retrieval tasks are used to train the model's ability to retrieve relevant information from a large amount of text. During the pre-training process, the present invention adopts a contrastive learning method based on negative sampling, which enables the model to better understand semantic information by constructing positive and negative examples.
[0035] In an embodiment of the present invention, the method also includes: using a pre-trained RAG model as a teacher model, and using the intermediate feature representation generated by the RAG model for the input sample and the final output result as a supervisory signal; constructing a lightweight student model; wherein the number of network layers, parameter scale and / or number of attention heads of the student model are less than those of the teacher model, and the student model structure is optimized based on parameter sharing or low-rank decomposition technology; training the student model based on the intermediate feature representation of the teacher model, the supervisory signal, the preset distillation loss function and the supervised learning loss function, and optimizing the student model based on the optimization algorithm; comparing the performance of the student model with that of the teacher model, and when the result meets the preset threshold, the training ends.
[0036] More specifically, the following steps are included: 1. Teacher model output preparation: Use the pre-trained RAG model as the teacher model, and use its intermediate feature representations (such as attention weights, hidden layer representations) generated for the input samples and the final output results (such as retrieved document scores or generated text) as supervision signals; 2. Student model structure design: Design a lightweight student model to reduce the number of network layers, parameter size, or the number of attention heads, and use techniques such as parameter sharing or low-rank decomposition to further optimize the structure; 3. Distillation loss calculation: During the training process, the distillation loss function is defined, including the following parts: 1) Soft target loss: Let the student model imitate the probability distribution of the teacher model (such as the distribution output by Softmax) to maintain the reasoning ability of the teacher model; 2) Hard target loss: By comparing with the ground truth, we ensure that the output of the student model still meets the task requirements; 3) Intermediate layer alignment loss: align the intermediate features of the student model with the teacher model, for example, using Euclidean distance or KL divergence to minimize the difference; 4. Optimization and training: Combine distillation loss and traditional supervised learning loss, use optimization algorithms (such as Adam or SGD) to train the student model, and gradually approach the performance of the teacher model; 5. Model verification and deployment: Compare the performance of the student model and the teacher model on the validation set to ensure that the student model significantly reduces the inference time and resource consumption when the performance is close, and then deploy the student model to actual applications.
[0037] The principle of reducing computational complexity and increasing retrieval speed: Parameter size reduction: The student model effectively reduces the computational complexity of the model by reducing the number of parameters (such as reducing layers and trimming attention heads), thus reducing the amount of computation required during reasoning. Weight sharing and low-rank decomposition: Through technical means such as matrix low-rank decomposition and weight sharing, the memory usage required for loading and calculation is reduced; Improved reasoning efficiency: Since the structure of the student model is more lightweight, the number of calculation steps and time in the reasoning process are significantly reduced, thereby improving the retrieval speed; Soft target guidance: By imitating the output distribution of the teacher model, the student model can quickly learn key knowledge without requiring too much computing resources, thus achieving a balance between performance and efficiency.
[0038] More specifically, in order to improve the generalization ability of retrieval, the present invention also introduces a method based on knowledge distillation. Specifically, the pre-trained RAG model is used as the teacher model to train a lightweight student model. During the training process, by allowing the student model to imitate the output of the teacher model, the student model can reduce the computational complexity and improve the retrieval speed while maintaining good performance.
[0039] Next, go to step S130.
[0040] In step S130 , the query sentence is encoded based on the pre-trained RAG model to obtain a query vector.
[0041] In an embodiment of the present invention, the query statement is encoded based on the pre-trained RAG model to obtain a query vector, including: performing preliminary processing on the query statement to generate a formatted query text; performing word segmentation on the formatted query text to decompose it into a word sequence; inputting the word segmentation result into the encoder part of the RAG model to generate a corresponding word vector, and adding position information to each word vector; through the multi-head attention mechanism inside the RAG model, the semantic relationship of each part in the word vector is comprehensively analyzed to generate a semantic representation that integrates context information; the semantic representation is aggregated through a pooling operation to generate a vector representation of a fixed length; and the fixed-length vector representation is normalized.
[0042] More specifically, the following steps are included: 1. Text standardization: Perform preliminary processing on the query statement, including converting the text to lowercase, removing extra spaces, standardizing punctuation, etc., to generate formatted query text.
[0043] 2. Participle and subword decomposition: Use natural language processing tools to segment the query text and break it down into word sequences. For complex or rare words, use subword decomposition to further break them down into smaller units to ensure the integrity of semantic information.
[0044] 3. Embedding vector generation: The word segmentation results are input into the encoder part of the RAG model to generate corresponding word vectors. These word vectors are the semantic representation of each word or subword by the model.
[0045] 4. Position code addition: Position information is added to each word vector to ensure that the model can capture the importance of word order in the sentence, thereby strengthening the representation of contextual semantics.
[0046] 5. Contextual relationship modeling: Through the multi-head attention mechanism within the model, the semantic relationship between each part of the query statement is comprehensively analyzed to generate a semantic representation that integrates contextual information.
[0047] 6. Aggregation and pooling: The context-processed semantic representations are aggregated through pooling operations (such as average pooling or selecting vector representations of specific identifiers) to generate a fixed-length vector representation.
[0048] 7. Vector normalization: The generated semantic vectors are normalized to make them conform to the specifications required in vector retrieval, which is convenient for subsequent similarity calculation.
[0049] More specifically, in the retrieval stage, the present invention proposes a retrieval strategy based on semantic similarity calculation. Specifically, for a given query statement, the RAG model is first used to encode the query statement to obtain a query vector. Then, the query vector is similarly calculated with the text vector in the corpus to obtain a similarity score. Finally, the texts in the corpus are sorted according to the similarity score, and the text with the highest score is returned as the retrieval result.
[0050] Next, go to step S140.
[0051] In step S140, similarity scores are calculated based on the query vector and the text vectors in the large-scale corpus, and the text with the highest score is used as the retrieval result.
[0052] In an embodiment of the present invention, the similarity score calculation based on the query vector and the text vectors in the large-scale corpus includes: normalizing the query vector and the text vectors in the corpus; comparing the similarity scores between the query vector and the text vector based on cosine similarity; and sorting all text vectors according to relevance based on the similarity scores.
[0053] More specifically, the following steps are included: 1. Vector Normalization Before similarity calculation, the query vector and the text vector in the corpus need to be normalized. The purpose of this process is to adjust all vectors to the same scale range so that the similarity calculation is not affected by the length of the vector. This ensures that the comparison results are more fair and consistent.
[0054] 2. Similarity score calculation The cosine similarity method is used to compare the similarity between the query vector and the text vector. This method determines the degree of match between two vectors by judging the directional similarity between them. The higher the similarity score, the closer the content corresponding to the two vectors is. This calculation method is particularly suitable for processing the comparison of high-dimensional semantic vectors.
[0055] 3. Filter and sort Based on the calculated similarity scores, all text vectors are sorted by relevance. Usually, a portion of text that is closest to the query vector is selected as the result output. Certain conditions can be set when filtering, such as only retaining texts with similarity scores that meet a certain standard, or selecting the top several results with the highest scores. At the same time, other factors (such as the importance of the text or the semantic diversity) can be combined to further optimize the results.
[0056] In an embodiment of the present invention, the present invention also includes the following optimization method: 1. Sorting optimization In the process of sorting the search results, the embodiment of the present disclosure introduces a multi-dimensional optimization strategy to make the sorting more in line with the user's intention and actual needs. Specifically, it includes:
[0057] (1) Semantic relevance sorting: The search results are sorted based on the semantic similarity score between the search results and the user's query, ensuring that the content that best meets the user's needs is ranked first.
[0058] (2) Content weight sorting: Combine the weight factors of the results (such as the authority, timeliness, popularity, etc. of the text) to increase the priority of important content. For example, for news searches, the latest or most authoritative reports are displayed first.
[0059] (3) User behavior sorting: By analyzing the user's historical behavior and preferences (such as previous clicks, dwell time, and other data), the sorting is personalized to provide users with results that are more in line with their habits.
[0060] 2. Display optimization At the display level, the present invention improves the user's interactive experience and information acquisition efficiency by improving the presentation of search results: (1) Hierarchical display: The search results are divided into different content categories or topic blocks to help users quickly find the content they are interested in. For example, when users search for knowledge in a certain field, they can first display authoritative literature, then related cases or popular questions and answers.
[0061] (2) Summary generation: Combined with the generation capabilities of the RAG model, a concise semantic summary is generated for each search result, allowing users to quickly understand the content summary without clicking.
[0062] (3) Highlight keywords: Highlight keywords or phrases related to user queries in the result text to help users quickly locate useful information.
[0063] (4) Multimodal support: Supports the integration of multiple information forms such as text, pictures, and videos into the result display, making the content more intuitive and richer.
[0064] 3. Dynamic Adjustment The present invention also introduces a dynamic adjustment mechanism to optimize the sorting and display methods based on real-time feedback from users. For example:
[0065] Real-time sorting adjustment: When a user clicks on a certain type of result multiple times, the system will dynamically adjust the sorting logic to prioritize the content types that the user is interested in.
[0066] Personalized recommendations: Based on the user's search history, regional characteristics or language habits, the display method and language adaptation of results are dynamically adjusted to provide personalized content recommendations.
[0067] The present invention is described in detail below by way of examples.
[0068] Data collection and processing: Collect a large amount of text data and perform preprocessing, including word segmentation, stop word removal, text cleaning and other steps.
[0069] Model training: Use the collected text data to train the RAG model and generate a semantic vector representation of the text.
[0070] Build index: Store the trained semantic vectors as indexes for subsequent retrieval operations.
[0071] User Query Processing: Preprocess and perform semantic analysis on the user's query statement to generate a query vector.
[0072] Retrieval Operation: Search for texts similar to the query vector in the index and sort them according to the similarity scores.
[0073] Result Presentation: Present the retrieval results to the user in an intuitive and easy-to-use manner, such as lists, summaries, etc.
[0074] Feedback and Optimization: Continuously optimize the model and retrieval algorithm based on the user's feedback and behavioral data to improve the performance of the retrieval system.
[0075] Suppose a user enters a query statement on a medical and health knowledge retrieval platform: "How to improve the lifestyle of hypertension?" Taking the user's expectation to obtain authoritative and detailed advice as an example: 1. Data Collection and Processing Data Sources: The platform has collected a large amount of text data from medical journals, health encyclopedias, and doctor's advice, covering the pathological knowledge, treatment methods, and lifestyle advice of hypertension.
[0076] Data Preprocessing: Perform the following operations on the collected text data: Word Segmentation: Split the sentences into basic units (such as "improve", "hypertension", "lifestyle").
[0077] Stop Word Removal: Remove common words that contribute little to semantics (such as "of", "is", "and").
[0078] Text Cleaning: Remove redundant information (such as HTML tags, duplicate paragraphs) to ensure data quality.
[0079] 2. Model Training Use the preprocessed text data above to train the RAG (Retrieval-Augmented Generation) model: Generate Semantic Vectors: The model represents each piece of text as a high-dimensional semantic vector through deep semantic understanding.
[0080] Model Optimization: Through contrastive learning, make the texts of similar topics closer and the irrelevant content farther away to ensure accurate semantic representation.
[0081] 3. Index Construction Store the generated text semantic vectors as a retrieval index and construct an efficient retrieval structure (such as HNSW index) for fast similarity calculation.
[0082] Each index entry retains meta information (such as source, summary, publication time) for subsequent sorting and presentation.
[0083] 4. User query processing The user enters "How to improve the lifestyle of high blood pressure?" The system processes the query: Word segmentation and semantic analysis: The system segments the query and extracts core semantic features (such as "improvement", "hypertension", "lifestyle").
[0084] Generate query vector: Use the trained RAG model to convert user queries into semantic vector representations to facilitate subsequent similarity calculations.
[0085] 5. Retrieval operation Vector matching: The system searches the semantic index for text that is most similar to the query vector and calculates a similarity score (such as cosine similarity).
[0086] Search results may include: A health magazine article, "Guidelines for Lifestyle Adjustments for Patients with Hypertension."
[0087] An authoritative medical report "Latest Recommendations for the Management of Hypertension".
[0088] A doctor's popular science article "How can diet and exercise help control high blood pressure?"
[0089] Sorting optimization: The search results are weighted and sorted based on multiple factors such as similarity score, content authority (such as whether it is from a medical journal), and publication time.
[0090] 6. Results display The system presents the results to the user in an intuitive way: List format: Title, summary, source and publication date are clearly visible.
[0091] Summary generation: The RAG model is used to generate summaries that are highly relevant to the query, providing users with concise preview information.
[0092] Interactive function: Users can click to view the full text, save the content of interest, or ask questions directly to the platform.
[0093] 7. Feedback and Optimization User behavior collection: The system analyzes user clicks, dwell time, likes and other behaviors to determine the relevance of search results.
[0094] Feedback optimization: Continuously adjust the model’s retrieval strategy based on user behavior data: Optimize training data and enhance the model's semantic understanding of high-frequency queries.
[0095] Adjust the sorting algorithm to increase the weight of content with higher user satisfaction.
[0096] The RAG enhanced retrieval method proposed in the present invention improves the retrieval accuracy and generalization ability by improving the pre-training tasks of the RAG model and optimizing the retrieval strategy; in terms of multi-level preprocessing of large-scale corpora, by improving the quality of the corpus, the model can understand complex semantics more accurately and improve retrieval accuracy, while laying a high-quality data foundation for cross-domain retrieval; in terms of the enhancement mechanism of the dynamic knowledge base, the generalization ability of the model in multi-domain scenarios is enhanced, solving the limitation of inaccurate cross-domain information.
[0097] Compared with the traditional method, the present invention has the following significant advantages: Higher accuracy: By leveraging the deep semantic understanding capabilities of the RAG model, the present invention can more accurately understand user intent and return more accurate retrieval results.
[0098] Higher efficiency: Searching in the semantic vector space has higher search speed and efficiency than traditional keyword matching methods.
[0099] Better user experience: By optimizing the sorting and display of search results, the present invention improves the usability and user experience of search results.
[0100] Figure 2 The RAG enhanced retrieval system 200 provided by the present invention is shown, including a corpus module 210 , a RAG module 220 and a retrieval module 230 .
[0101] The corpus module 210 is used to construct a large-scale corpus containing multiple types of data and preprocess the large-scale corpus; The RAG module 220 is used to pre-train the RAG model; The retrieval module 230 is used to encode the query statement based on the pre-trained RAG model to obtain a query vector; and calculate the similarity score based on the query vector and the text vector in the large-scale corpus, and take the text with the highest score as the retrieval result.
[0102] See also Figure 3 The embodiment of the present disclosure further provides an electronic device 30, the electronic device comprising: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the RAG enhanced retrieval method in the aforementioned method embodiment.
[0103] The embodiment of the present disclosure also provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the RAG enhanced retrieval method in the aforementioned method embodiment.
[0104] The embodiments of the present disclosure also provide a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, which, when executed by a computer, enable the computer to execute the RAG enhanced retrieval method in the aforementioned method embodiment.
[0105] Reference below Figure 3 , which shows a schematic diagram of the structure of an electronic device 30 suitable for implementing the embodiment of the present disclosure. The electronic device in the embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 3 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0106] like Figure 3 As shown, the electronic device 30 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 302 or a program loaded from a storage device 308 to a random access memory (RAM) 303. In the RAM 303, various programs and data required for the operation of the electronic device 30 are also stored. The processing device 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0107] Typically, the following devices may be connected to the I / O interface 305: input devices 306 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 308 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 309. The communication device 309 may allow the electronic device 30 to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows an electronic device 30 with various devices, it should be understood that it is not required to implement or have all the devices shown. More or fewer devices may be implemented or have alternatively.
[0108] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 309, or installed from the storage device 308, or installed from the ROM 302. When the computer program is executed by the processing device 301, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0109] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0110] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0111] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: obtains at least two Internet Protocol addresses; sends a node evaluation request including the at least two Internet Protocol addresses to a node evaluation device, wherein the node evaluation device selects an Internet Protocol address from the at least two Internet Protocol addresses and returns it; receives the Internet Protocol address returned by the node evaluation device; wherein the obtained Internet Protocol address indicates an edge node in a content distribution network.
[0112] Alternatively, the computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device: receives a node evaluation request including at least two Internet Protocol addresses; selects an Internet Protocol address from the at least two Internet Protocol addresses; and returns the selected Internet Protocol address; wherein the received Internet Protocol address indicates an edge node in a content distribution network.
[0113] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0114] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0115] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a unit does not limit the unit itself in some cases. For example, the first acquisition unit may also be described as a "unit for acquiring at least two Internet Protocol addresses".
[0116] It should be understood that various parts of the present disclosure may be implemented in hardware, software, firmware, or a combination thereof.
[0117] The above is only a specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present disclosure should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A RAG enhanced retrieval method, characterized in that: The method comprises the following steps: Constructing a large-scale corpus containing multiple types of data, and preprocessing the large-scale corpus; Pre-train the RAG model; Encode the query sentence based on the pre-trained RAG model to obtain the query vector; A similarity score is calculated based on the query vector and the text vectors in the large-scale corpus, and the text with the highest score is used as the retrieval result.
2. The RAG enhanced retrieval method according to claim 1, characterized in that: The multiple types of data include: text, images and videos.
3. The RAG enhanced retrieval method according to claim 1, characterized in that: The preprocessing of the large-scale corpus comprises the following steps: Performing word segmentation processing on the original corpus of the large-scale corpus, dividing the text into subword units, and obtaining word segmentation results; Based on the word segmentation result, performing a stop word removal operation; the stop word removal operation includes screening and deleting words that do not carry semantic information to generate a simplified text; Based on a named entity recognition model, the words in the simplified text are annotated, and key entities are extracted and classified to generate a corpus with entity information; The corpus with entity information is formatted and the annotation format is unified.
4. The RAG enhanced retrieval method according to claim 1, characterized in that: The pre-training of the RAG model includes: The RAG model is trained based on generation tasks and retrieval tasks; The contrastive learning method based on negative sampling enables the model to better understand semantic information by constructing positive and negative examples.
5. The RAG enhanced retrieval method according to claim 4, characterized in that: The method further comprises: The pre-trained RAG model is used as the teacher model, and the intermediate feature representation generated by the input sample and the final output result are used as the supervision signal; Constructing a lightweight student model; wherein the number of network layers, parameter scale and / or number of attention heads of the student model are less than those of the teacher model, and the structure of the student model is optimized based on parameter sharing or low-rank decomposition technology; Train the student model based on the intermediate feature representation of the teacher model, the supervision signal, the preset distillation loss function and the supervised learning loss function, and optimize the student model based on the optimization algorithm; The performance of the student model is compared with that of the teacher model. When the result meets the preset threshold, the training ends.
6. The RAG enhanced retrieval method according to claim 1, characterized in that: The query sentence is encoded based on the pre-trained RAG model to obtain a query vector, including: Perform preliminary processing on the query statement to generate formatted query text; Perform word segmentation on the formatted query text and break it into word sequences; Input the word segmentation results into the encoder part of the RAG model to generate the corresponding word vectors and add position information to each word vector; Through the multi-head attention mechanism within the RAG model, the semantic relationship between each part of the word vector is comprehensively analyzed to generate a semantic representation that integrates context information; Aggregating the semantic representations through a pooling operation to generate a vector representation of a fixed length; Normalize the fixed-length vector representation.
7. The RAG enhanced retrieval method according to claim 1, characterized in that: The calculating of similarity scores based on the query vector and the text vectors in the large-scale corpus includes: Normalize the query vector and the text vectors in the corpus; Compare the similarity scores between the query vector and the text vector based on cosine similarity; All text vectors are sorted by relevance based on the similarity scores.
8. A RAG enhanced retrieval system, characterized in that: The system comprises: A corpus module is configured to construct a large-scale corpus containing multiple types of data and preprocess the large-scale corpus; RAG module, configured to pre-train the RAG model; A retrieval module is configured to encode the query sentence based on the pre-trained RAG model to obtain a query vector; Furthermore, similarity scores are calculated based on the query vector and the text vectors in the large-scale corpus, and the text with the highest score is used as the retrieval result.
9. An electronic device, characterized in that: The electronic device includes: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor executes the RAG enhanced retrieval method according to any one of claims 1 to 7.
10. A computer program product, characterized in that The computer program product comprises a computer program stored on a non-transitory computer-readable storage medium, wherein the computer program comprises program instructions, and when the program instructions are executed by a computer, the computer is caused to execute the RAG enhanced retrieval method as claimed in any one of claims 1 to 7.
Citation Information
Cited By
Service recommendation decision-making method based on large model retrieval enhancement generation and related equipment
CN120804394A
Service recommendation decision method and related device based on large model retrieval enhanced generation
CN120804394B
Data reasoning method, device and equipment and calculation medium
CN121328749A
Retrieval enhancement generation vertical domain optimization method and device based on BGE big language model, equipment and storage medium
CN121786210A