RAG tuning method and device, storage medium and processor
By automatically tuning the RAG model, the problem of insufficient adaptability of traditional models in different domains is solved, the efficiency and accuracy of knowledge base retrieval are improved, and the optimal parameters and strategies are automatically selected and combined in different knowledge domains.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-10
- Publication Date
- 2026-04-10
AI Technical Summary
Traditional RAG models lack adaptability to the differences in knowledge characteristics across different domains, resulting in time-consuming, labor-intensive, and inefficient parameter tuning.
By acquiring the target source file, parsing the file, slicing the data, setting vector parameters, constructing a multi-dimensional vector, setting a retrieval and recall strategy, performing retrieval and recall, configuring reordering and LLM synthesis, and automatically adjusting slicing rules and retrieval and recall strategies based on evaluation results, automated optimization is achieved.
It improves the efficiency and accuracy of knowledge base retrieval, adapts to the differences in different knowledge domains, and reduces the time and cost of manual adjustments.
Smart Images

Figure CN121833771A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence and knowledge graph, in particular to a RAG optimization method and device, a storage medium and a processor. BACKGROUND
[0002] With the rapid development of artificial intelligence technology, knowledge graph as an important knowledge representation and management means has been widely applied in various fields. RAG model as a new knowledge enhancement technology has shown significant advantages in natural language processing, machine translation, intelligent question answering and other tasks. RAG model can significantly improve the reasoning ability and generation quality of the model by combining the retrieved knowledge with the generation model. Traditional RAG model usually relies on manual design and parameter adjustment, which is not only time-consuming and laborious, but also difficult to adapt to the differences in knowledge characteristics of different fields. SUMMARY
[0003] The purpose of the embodiments of the present application is to provide a RAG optimization method, device, storage medium and processor. The method improves the efficiency and accuracy of knowledge base retrieval.
[0004] To achieve the above purpose, the first aspect of the present application provides a RAG optimization method, which comprises: Obtaining a target material file, and performing file analysis on the target material file to obtain a test text; According to the slicing rule, the test text is sliced to obtain slicing data, and the slicing rule includes character slicing and mark slicing; Setting a vector parameter for the slicing data, configuring an index parameter according to the vector parameter, and constructing a multi-dimensional vector according to the slicing data and the index parameter; Setting a retrieval recall strategy for retrieving and recalling the multi-dimensional vector to obtain recall data, and configuring and rearranging the recall data and synthesizing the LLM to obtain result data; Evaluating the result data to obtain an evaluation result, and adjusting the slicing rule and / or retrieval recall strategy of RAG according to the evaluation result.
[0005] Optionally, the slicing includes length slicing, semantic slicing and paragraph slicing of the text; The slicing data includes body, abstract and title; The index configuration metric includes context relevance and context recall.
[0006] Optionally, the configuration, rearrangement and LLM synthesis of the recall data to obtain result data comprises: Feature extraction is performed on the recall data to obtain document features, context features and document quality features; The document features, context features, and document quality features are configured and rearranged, and then fed into the LLM model to obtain the result data, which includes the quality and relevance of the recalled data.
[0007] Optionally, the evaluation of the result data to obtain the evaluation result includes: An evaluation standard is set to assess the content quality and relevance of the result data to obtain the evaluation result.
[0008] Optionally, adjusting the slicing rules and / or retrieval recall strategy based on the evaluation results includes: When the evaluation result does not meet the threshold range, the slice step size of the test text is adjusted, and / or the index of the slice start position and the index of the slice end position are adjusted, and / or the retrieval recall strategy is adjusted, the recall strategy includes content matching-based recall and system filtering-based recall. By setting a context scroll window between slices, you can adjust the index of the start position and the index of the end position of the slice.
[0009] Optionally, adjusting the slicing step size of the test text when the evaluation result does not meet the threshold range includes: When the evaluation result exceeds the maximum value of the threshold range, the slice step size of the test text is reduced based on the difference between the evaluation result and the maximum value of the threshold range. When the evaluation result is less than the minimum value of the threshold range, the slice step size of the test text is increased based on the difference between the evaluation result and the minimum value of the threshold range.
[0010] Optionally, the method further includes: Cleaned data is obtained by performing data cleaning on the test text according to its type. The data cleaning includes: handling missing values, removing duplicate data, correcting data errors, standardizing data format, removing noisy data, and proofreading labels.
[0011] A second aspect of this application provides a tuning apparatus for RAG, the apparatus comprising: The acquisition module is used to acquire the target material file and parse the target material file to obtain the test text; The first processing module is used to slice the test text according to slicing rules to obtain slice data, wherein the slicing rules include character slicing and marker slicing. The second processing module is used to set vector parameters for the slice data, perform index configuration based on the vector parameters to obtain index parameters, and construct a multidimensional vector based on the slice data and the index parameters. The third processing module is used to set the retrieval and recall strategy, to retrieve and recall the multidimensional vector to obtain recall data, and to perform configuration rearrangement and LLM synthesis on the recall data to obtain result data. The fourth processing module is used to evaluate the result data to obtain an evaluation result, and adjust the RAG slicing rules and / or retrieval recall strategy according to the evaluation result.
[0012] A third aspect of this application provides a processor configured to perform the tuning method of RAG as described above.
[0013] A fourth aspect of this application provides a machine-readable storage medium storing instructions that, when executed by a processor, configure the processor to perform the tuning method of RAG as described above.
[0014] The fifth aspect of this application provides a computer program product, including a computer program that, when executed by a processor, implements the tuning method of RAG as described above.
[0015] The RAG optimization method of the present invention includes: acquiring a target material file; parsing the target material file to obtain test text; slicing the test text according to slicing rules to obtain slice data, wherein the slicing rules include character slicing and tag slicing; setting vector parameters for the slice data; configuring index parameters according to the vector parameters to obtain index parameters; constructing a multi-dimensional vector based on the slice data and index parameters; setting a retrieval and recall strategy for retrieving and recalling the multi-dimensional vector to obtain recall data; performing configuration rearrangement and LLM synthesis on the recall data to obtain result data; evaluating the result data to obtain an evaluation result; and adjusting the RAG slicing rules and / or retrieval and recall strategy according to the evaluation result. This application, by constructing a multi-stage processing mechanism and combining evaluation results for automated optimization, realizes the function of automatically selecting and combining the best parameters or strategies in different knowledge domains. This method improves the efficiency and accuracy of knowledge base retrieval.
[0016] Other features and advantages of the embodiments of this application will be described in detail in the following detailed description section. Attached Figure Description
[0017] The accompanying drawings are provided to further illustrate the embodiments of this application and form part of the specification. They are used together with the following detailed description to explain the embodiments of this application, but do not constitute a limitation on the embodiments of this application. In the drawings: Figure 1 The schematic diagram illustrates a flowchart of a RAG tuning method according to an embodiment of this application; Figure 2A schematic diagram illustrating one embodiment according to this application is shown. Figure 3 A schematic diagram of a RAG tuning apparatus according to an embodiment of this application is shown. Figure 4 The diagram illustrates the internal structure of a computer device according to an embodiment of this application.
[0018] Explanation of reference numerals in the attached figures 100-RAG tuning device; 200 - Acquisition Module; 300 - First Processing Module; 400 - Second Processing Module; 500 - Third Processing Module; 600 - Fourth processing module. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for illustration and explanation of the embodiments of this application and are not intended to limit the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0020] It should be noted that if the embodiments of this application involve directional indicators (such as up, down, left, right, front, back, etc.), the directional indicators are only used to explain the relative positional relationship and movement of each component in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indicators will also change accordingly.
[0021] Furthermore, if the embodiments of this application involve descriptions such as "first" or "second," these descriptions are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first" or "second" may explicitly or implicitly include at least one of those features. Additionally, the technical solutions of various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.
[0022] The acquisition, transmission, storage, use, and processing of data in this application comply with relevant national laws and regulations. Furthermore, it should be noted that existing industry solutions such as software, components, and models may be mentioned in the embodiments of this application. These should be considered exemplary, intended only to illustrate the feasibility of implementing the technical solution of this application, and do not imply that the applicant has already used or necessarily used such solutions.
[0023] Figure 1 A schematic flowchart illustrating a RAG tuning method according to an embodiment of this application is shown. Figure 1 As shown, in one embodiment of this application, a method for optimizing RAG is provided, including the following steps: Step S101 is to obtain a target material file and perform file parsing on the target material file to obtain test text.
[0024] The RAG (Retrieval Augmented Generation) combines information retrieval with system prompts, anchoring the LLM (Large Language Model) to accurate, up-to-date, and relevant information retrieved from external knowledge stores.
[0025] The target material file refers to the original data file that has not been deeply processed, retains its initial form, and may contain basic annotation information, including text files and structured data such as PDF, Word, Excel, PPT, images, audio and video, etc.
[0026] In one specific implementation method, the target material file is parsed to extract text. The appropriate tool or solution is selected based on the structured / unstructured attributes of the file format to ensure the accuracy (e.g., preserving layout logic and avoiding garbled characters) and completeness (e.g., not omitting tables / annotations) of the extracted text. For example, text files store content in text encoding, requiring no complex format conversion; the encoding is read and extracted directly. Layout-type files (such as PDFs and PPTs) prioritize preserving layout logic (e.g., multi-column layouts, formulas, and embedded images); text extraction must differentiate between native text PDFs (copyable) and scanned PDFs (image formats). Multimedia files (images, audio, and video) do not inherently contain text and require OCR (image-to-text) or ASR (speech-to-text) extraction.
[0027] The method further includes: cleaning the test text according to its type to obtain cleaned data; the data cleaning includes: handling missing values, removing duplicate data, correcting data errors, unifying data format, removing noisy data, and proofreading annotations.
[0028] Specifically, missing values refer to some fields in the dataset being empty (such as N / A in Excel, NULL in a database); duplicate data refers to entries in the dataset that are completely identical (such as duplicate orders) or have the same key information (such as multiple duplicate registration records for the same user); data errors include entry errors (such as entering an extra digit in a code), logical errors (such as age = 200 years old, income being negative), and format errors (such as writing the date as 2024 / 13 / 01), which need to be located through rule validation or visualization; errors in labeled data (such as text classification labels, image detection boxes, NLP named entity annotations) will directly affect the model's performance and need to be corrected through manual and automated methods.
[0029] Step S102 involves slicing the test text according to slicing rules to obtain sliced data. The slicing rules include character slicing and tag slicing. The slicing includes length slicing, semantic slicing, and paragraph slicing of the text; the sliced data includes the main text, summary, and title; the index configuration metrics include context relevance and context recall.
[0030] In one specific implementation, when the complete dataset is too large or has too many dimensions, slicing to extract task-relevant parts can reduce computational costs, decrease interference information, and make analysis and modeling more efficient. Slicing image data extracts specified pixel regions (such as cropping faces or capturing local scenes), essentially cutting off the spatial range of the pixel matrix. Slicing time-series data extracts data according to a time range (such as hourly temperature for a given day or voltage per second for a given hour).
[0031] Step S103 involves setting vector parameters for the slice data, configuring index parameters based on the vector parameters, and constructing a multidimensional vector based on the slice data and the index parameters.
[0032] In one specific implementation, index parameters are obtained by configuring the index based on vector parameters. This involves matching the features of the vector data (such as dimension, distance metric, and data size) with the functional requirements of the index (such as query speed and memory usage). Through parameterized configuration of tools or frameworks, index parameters that can be directly used for vector retrieval are generated.
[0033] Vector data (such as image feature vectors and text) typically has high dimensionality (tens to tens of thousands of dimensions) and large data volume (millions or hundreds of millions), making distance calculation by traversing all vectors extremely inefficient. Therefore, the vector index in this application preprocesses the vectors using specific data structures (such as inverted indexes, clustering trees, and hash tables). The final generated index parameters exist in a tool-specific form and can be directly used for subsequent vector retrieval tasks.
[0034] Step S104 involves setting a retrieval and recall strategy to retrieve and recall the multidimensional vector to obtain recall data, and then performing configuration rearrangement and LLM synthesis on the recall data to obtain result data.
[0035] According to one specific implementation, the step of configuring and rearranging the recalled data and synthesizing it using an LLM model to obtain the result data includes: extracting features from the recalled data to obtain document features, context features, and document quality features; configuring and rearranging the document features, context features, and document quality features and then inputting them into an LLM model to obtain the result data, wherein the result data includes the quality and relevance of the recalled data.
[0036] Feature extraction is the process of mining, filtering, or constructing representative information from raw data. It transforms high-dimensional, complex raw data into low-dimensional, interpretable feature vectors that can support subsequent tasks (such as classification, clustering, and prediction). Depending on the type of raw data (structured or unstructured) and the task objective, feature extraction methods can be categorized into structured data feature extraction, unstructured data feature extraction, and general feature extraction strategies.
[0037] The process of configuring and rearranging the document features, context features, and document quality features before inputting them into the LLM model to obtain the final data includes rearranging at least one of the same and / or similar document features, context features, and document quality features before inputting them into the LLM model to obtain the final data. Alternatively, the weights of the document features, context features, and document quality features can be determined separately, and the features can be rearranged according to their weights. For example, they can be sorted by weighted scores (numerical arrangement). The weights can be determined through expert experience or model training (such as logistic regression, neural networks).
[0038] Step S105 involves evaluating the result data to obtain an evaluation result, and adjusting the RAG slicing rules and / or retrieval recall strategy based on the evaluation result.
[0039] According to one specific implementation, the step of evaluating the result data to obtain an evaluation result includes: setting evaluation criteria to evaluate the content quality and content relevance of the result data to obtain an evaluation result.
[0040] Specifically, the evaluation may include classification task evaluation, regression task evaluation, clustering task evaluation, and generation task evaluation. The result data includes the quality and relevance of the recalled data. Data quality measures whether the data is reliable, complete, and accurate, while data relevance measures whether the data matches business objectives and analytical needs, determining whether the data can provide value for a specific task.
[0041] The assessment of data quality includes: completeness assessment (whether data fields or records are complete and without missing key information); assessment of whether data values conform to reality, logical rules, or business standards, and whether there is any false or erroneous information; and assessment of whether the data update frequency matches the business's need for freshness. The assessment of data relevance includes: quantifying the degree of correlation between data fields and business objectives through statistical indicators; and determining relevance in conjunction with business logic.
[0042] The step of adjusting the slicing rules and / or retrieval recall strategy based on the evaluation results includes: when the evaluation results do not meet the threshold range, adjusting the slicing step size of the test text, and / or adjusting the index of the start position and the end position of the slice, and / or adjusting the retrieval recall strategy, wherein the recall strategy includes content-matching-based recall and system-filtering-based recall; and adjusting the index of the start position and the end position of the slice by setting a context scrolling window between the slices.
[0043] The step of adjusting the slice step size of the test text when the evaluation result does not meet the threshold range includes: when the evaluation result exceeds the maximum value of the threshold range, reducing the slice step size of the test text according to the difference between the evaluation result and the maximum value of the threshold range; and when the evaluation result is less than the minimum value of the threshold range, increasing the slice step size of the test text according to the difference between the evaluation result and the minimum value of the threshold range.
[0044] Figure 2 A schematic diagram illustrating one embodiment according to this application is shown. Figure 2 As shown, this application mainly consists of the following modules: document parsing module, cleaning module, slicing module, summarizing module, vector module, storage module, recall module, rearrangement module, LLM synthesis module, evaluation module, and parameter module. These modules cooperate with each other to complete the process from raw materials to knowledge retrieval.
[0045] Specifically, the file parsing module, cleaning module, slicing module, summarizing module, vector module, storage module, recall module, rearrangement module, and LLM synthesis module are all configurable. The file parsing module supports multiple file formats, including but not limited to Word, TXT, Excel, and PPT; the cleaning module supports various ETL strategies based on an expression engine; the slicing module provides strategies such as length slicing, semantic slicing, and paragraph slicing; the summarizing module generates summaries from the sliced content; the vector module generates multi-dimensional vectors from the summary content, body text, and titles; the storage module includes full-text search and vector indexing, and the index type can be dynamically configured according to performance and accuracy; the recall module can dynamically configure recall strategies; the rearrangement module can dynamically configure rearrangement strategies; and the LLM generation module can dynamically modify generation parameters.
[0046] The evaluation module uses the ragas framework to comprehensively evaluate all nodes by processing sliced data, vector data, recalled data, and rearranged data. It evaluates whether the RAG performance meets the requirements using multiple metrics such as Faithfulness, Answer Relevance, Context Precision, Context Recall, and Context Entity Recall.
[0047] The parameter module dynamically adjusts the strategies or parameters of corresponding nodes based on the results of the evaluation module. It then compares these adjustments with previous evaluation results in real time. By using a controlled variable method, it continuously optimizes the strategies or parameters of each node before the termination condition, ensuring that the parameters or strategies of each node meet the experimental results. Through continuous dynamic parameter tuning, RAG achieves the experimental effects, significantly improving the efficiency and accuracy of RAG retrieval generation, and providing positive support for knowledge base construction and knowledge retrieval.
[0048] In one embodiment, such as Figure 3 As shown, a RAG tuning device 100 is provided, including an acquisition module 200, a first processing module 300, a second processing module 400, a third processing module 500, and a fourth processing module 600, wherein: The acquisition module 200 is used to acquire the target material file and perform file parsing on the target material file to obtain the test text; The first processing module 300 is used to slice the test text according to slicing rules to obtain slice data, wherein the slicing rules include character slicing and marker slicing. The second processing module 400 is used to set vector parameters for the slice data, perform index configuration based on the vector parameters to obtain index parameters, and construct a multidimensional vector based on the slice data and the index parameters. The third processing module 500 is used to set a retrieval and recall strategy, to retrieve and recall the multidimensional vector to obtain recall data, and to perform configuration rearrangement and LLM synthesis on the recall data to obtain result data. The fourth processing module 600 is used to evaluate the result data to obtain an evaluation result, and adjust the RAG slicing rules and / or retrieval recall strategy according to the evaluation result.
[0049] The RAG optimization method of the present invention includes: acquiring a target material file; parsing the target material file to obtain test text; slicing the test text according to slicing rules to obtain slice data, wherein the slicing rules include character slicing and tag slicing; setting vector parameters for the slice data; configuring index parameters according to the vector parameters to obtain index parameters; constructing a multi-dimensional vector based on the slice data and index parameters; setting a retrieval and recall strategy for retrieving and recalling the multi-dimensional vector to obtain recall data; performing configuration rearrangement and LLM synthesis on the recall data to obtain result data; evaluating the result data to obtain an evaluation result; and adjusting the RAG slicing rules and / or retrieval and recall strategy according to the evaluation result. This application, by constructing a multi-stage processing mechanism and combining evaluation results for automated optimization, realizes the function of automatically selecting and combining the best parameters or strategies in different knowledge domains. This method improves the efficiency and accuracy of knowledge base retrieval.
[0050] The RAG tuning device includes a processor and a memory. The aforementioned acquisition module 200, first processing module 300, second processing module 400, third processing module 500, and fourth processing module 600 are all stored in the memory as program units. The processor executes the aforementioned program modules stored in the memory to implement the corresponding functions.
[0051] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and RAG tuning methods can be implemented by adjusting kernel parameters.
[0052] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0053] This application provides a storage medium storing a program that, when executed by a processor, implements the aforementioned RAG tuning method.
[0054] This application provides a processor for running a program, wherein the program executes the above-described RAG tuning method during runtime.
[0055] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 4 As shown. The computer device includes a processor A01, a network interface A02, a display screen A04, an input device A05, and a memory (not shown) connected via a system bus. The processor A01 provides computing and control capabilities. The memory includes internal memory A03 and a non-volatile storage medium A06. The non-volatile storage medium A06 stores an operating system B01 and a computer program B02. The internal memory A03 provides an environment for the operation of the operating system B01 and the computer program B02 stored in the non-volatile storage medium A06. The network interface A02 is used for communication with external terminals via a network connection. When the computer program is executed by the processor A01, it implements a RAG tuning method. The display screen A04 can be a liquid crystal display (LCD) or an e-ink display. The input device A05 can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.
[0056] Those skilled in the art will understand that Figure 4 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0057] In one embodiment, the RAG tuning apparatus provided in this application can be implemented as a computer program, which can be implemented in the form of, for example... Figure 4 The computer program, comprised of various program modules, runs on the computer device shown. It causes the processor to execute the steps in the RAG tuning methods of the various embodiments of this application described in this specification.
[0058] This application provides an apparatus, including a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps: acquiring a target material file; parsing the target material file to obtain test text; slicing the test text according to slicing rules to obtain slice data, the slicing rules including character slicing and tag slicing; setting vector parameters for the slice data; configuring an index based on the vector parameters to obtain index parameters; constructing a multidimensional vector based on the slice data and index parameters; setting a retrieval and recall strategy to retrieve and recall data from the multidimensional vector; performing configuration rearrangement and LLM synthesis on the recalled data to obtain result data; evaluating the result data to obtain an evaluation result; and adjusting the RAG slicing rules and / or retrieval and recall strategy based on the evaluation result.
[0059] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program with the following method steps: obtaining a target material file; parsing the target material file to obtain test text; slicing the test text according to slicing rules to obtain slice data, the slicing rules including character slicing and tag slicing; setting vector parameters for the slice data; configuring indexes according to the vector parameters to obtain index parameters; constructing a multidimensional vector according to the slice data and index parameters; setting a retrieval and recall strategy for retrieving and recalling the multidimensional vector to obtain recall data; performing configuration rearrangement and LLM synthesis on the recall data to obtain result data; evaluating the result data to obtain an evaluation result; and adjusting the RAG slicing rules and / or retrieval and recall strategy according to the evaluation result.
[0060] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0061] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0062] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0063] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0064] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0065] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0066] Computer-readable media include both permanent and non-permanent, removable and non-removable media, which can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0067] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0068] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for optimizing RAG, characterized in that, The method includes: Obtain the target material file, and parse the target material file to obtain the test text; The test text is sliced according to slicing rules to obtain sliced data, wherein the slicing rules include character slicing and marker slicing; Set vector parameters for the slice data, configure index parameters according to the vector parameters, and construct a multidimensional vector based on the slice data and index parameters. A retrieval and recall strategy is set up to retrieve and recall the multidimensional vector to obtain recall data, and the recall data is configured, rearranged, and synthesized using LLM to obtain result data. The resulting data is evaluated to obtain evaluation results, and the RAG slicing rules and / or retrieval recall strategies are adjusted based on the evaluation results.
2. The method according to claim 1, characterized in that, The slicing includes length slicing, semantic slicing, and paragraph slicing of the text; The sliced data includes the main text, abstract, and title; The metrics for the index configuration include contextual relevance and contextual recall.
3. The method according to claim 1, characterized in that, The result data obtained by configuring and rearranging the recalled data and synthesizing it using LLM includes: Feature extraction is performed on the recalled data to obtain document features, context features, and document quality features; The document features, context features, and document quality features are configured and rearranged, and then fed into the LLM model to obtain the result data, which includes the quality and relevance of the recalled data.
4. The method according to claim 1, characterized in that, The evaluation of the result data to obtain the evaluation result includes: An evaluation standard is set to assess the content quality and relevance of the result data to obtain the evaluation result.
5. The method according to claim 1, characterized in that, The adjustment of RAG slicing rules and / or retrieval recall strategies based on the evaluation results includes: When the evaluation result does not meet the threshold range, the slice step size of the test text is adjusted, and / or the index of the slice start position and the index of the slice end position are adjusted, and / or the retrieval recall strategy is adjusted, the recall strategy includes content matching-based recall and system filtering-based recall. By setting a context scroll window between slices, you can adjust the index of the start position and the index of the end position of the slice.
6. The method according to claim 5, characterized in that, When the evaluation result does not meet the threshold range, the step size of the test text slice is adjusted, including: When the evaluation result exceeds the maximum value of the threshold range, the slice step size of the test text is reduced based on the difference between the evaluation result and the maximum value of the threshold range. When the evaluation result is less than the minimum value of the threshold range, the slice step size of the test text is increased based on the difference between the evaluation result and the minimum value of the threshold range.
7. The method according to claim 1, characterized in that, The method also includes: Cleaned data is obtained by performing data cleaning on the test text according to its type. The data cleaning includes: handling missing values, removing duplicate data, correcting data errors, standardizing data format, removing noisy data, and proofreading labels.
8. A tuning device for RAG, characterized in that, The device includes: The acquisition module is used to acquire the target material file and parse the target material file to obtain the test text; The first processing module is used to slice the test text according to slicing rules to obtain slice data, wherein the slicing rules include character slicing and marker slicing. The second processing module is used to set vector parameters for the slice data, perform index configuration based on the vector parameters to obtain index parameters, and construct a multidimensional vector based on the slice data and the index parameters. The third processing module is used to set the retrieval and recall strategy, to retrieve and recall the multidimensional vector to obtain recall data, and to perform configuration rearrangement and LLM synthesis on the recall data to obtain result data. The fourth processing module is used to evaluate the result data to obtain an evaluation result, and adjust the RAG slicing rules and / or retrieval recall strategy according to the evaluation result.
9. A processor, characterized in that, It is configured to perform the RAG tuning method according to any one of claims 1 to 7.
10. A machine-readable storage medium storing instructions thereon, characterized in that, When executed by the processor, this instruction causes the processor to be configured to perform the tuning method of RAG according to any one of claims 1 to 7.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the RAG tuning method according to any one of claims 1 to 7.