A RAG system optimization method, system, electronic device and storage medium

Through structured processing of PDF documents and hierarchical semantic enhancement of large-scale semantics, the shortcomings of existing RAG systems in dealing with large-scale similar documents and complex contexts are solved, and more accurate and comprehensive document retrieval and answer are achieved.

CN118917305BActive Publication Date: 2025-03-04HANGZHOU HARMONYCLOUD TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411411617.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-11
Publication Date
2025-03-04
Estimated Expiration
2044-10-11

AI Technical Summary

Technical Problem

Existing RAG systems are difficult to distinguish document differences when processing large-scale and similar-structured documents, resulting in inaccurate search results and lack of understanding of the global semantic structure of documents in complex contexts, making them unable to provide comprehensive and coherent answers.

Method used

By converting PDF documents into images, identifying the document structure using the object detection model, the OCR model extracts text, and generates documents with structured marks. Then, the large language model is used to generate the title of the hierarchical relationship, replace the original title, and generate summary information for each level, and finally convert the document into a high-dimensional vector for vector search and keyword search.

Benefits of technology

Effectively distinguishing similar documents, enhancing the understanding of the global semantics of documents, providing more accurate and comprehensive answers, and alleviating the limitations of traditional methods in complex document scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118917305B_ABST
    Figure CN118917305B_ABST
Patent Text Reader

Abstract

The present invention discloses a RAG system optimization method, system, electronic device and storage medium, including converting a document into an image; analyzing the image to identify the four coordinates of the anchor box and the target category; extracting the text content in the image to generate a document with structured tags; extracting titles from the document with structured tags in an orderly manner, inputting the titles into a large language model to generate hierarchical titles; replacing the original titles with hierarchical titles to generate summary information; generating multiple document blocks with titles of each level as segmentation points; converting each document block into a high-dimensional vector; and determining the final result of the retrieval based on vector search and keyword search. The present invention significantly improves the performance of the RAG system in complex question-answering tasks, can effectively distinguish similar documents and better understand the global semantics of the document, and ultimately provides more accurate and comprehensive answers, effectively alleviating the limitations of traditional methods in dealing with complex document scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of large-scale language model optimization, and in particular to a RAG system optimization method, system, electronic device and storage medium. Background Art

[0002] With the rapid development of artificial intelligence and natural language processing technologies, large language models (LLMs) have been widely used in various fields, especially in question answering (QA). With its powerful language generation capabilities, LLMs can provide high-quality answers in a variety of scenarios. However, relying solely on LLMs for question answering still faces several technical challenges, including hallucination problems, timeliness problems, and data security problems. To solve these problems, researchers have proposed a method to improve the performance of large models by fine-tuning them. However, fine-tuning large language models usually consumes a lot of computing resources and time, which limits their application in resource-constrained environments.

[0003] To this end, the industry has proposed a variety of efficient fine-tuning techniques, such as LoRA (low-rank adaptation) and QLoRA (quantized low-rank adaptation). These methods effectively reduce the computing resource consumption and time cost in the fine-tuning process by reducing the complexity of adjusting model parameters. In addition, data parallelism and tensor parallelism in distributed training have also been used to accelerate the fine-tuning process. However, even with the use of these technologies, the timeliness problem cannot be completely solved. With the increase in the frequency of document updates and the rapid change of knowledge, relying on frequent fine-tuning to maintain the accuracy and timeliness of the model still faces huge challenges in practical applications, especially in scenarios where it is necessary to quickly adapt to the latest information. The limitations of this method are particularly prominent.

[0004] As an effective way to solve the above problems, the retrieval-augmented generation (RAG) method came into being. By combining the advantages of information retrieval and generative models, the RAG system not only relies on the generation ability of LLM in question-answering tasks, but also obtains text fragments related to the query from the external retrieval corpus and inputs them into the generative model as context, thereby generating more accurate and real-time answers. Compared with traditional methods that rely solely on generative models, the RAG system significantly reduces the phenomenon of hallucinations, improves the accuracy of answers, and solves the timeliness problem to a certain extent. At the same time, it avoids the need for frequent fine-tuning and significantly reduces resource consumption.

[0005] Although RAG-based methods have made significant progress in improving the performance of large-scale language model question answering, existing RAG systems still have obvious limitations. First, standard RAG systems usually represent documents as unstructured text blocks, which shows obvious shortcomings when dealing with large-scale, structurally similar documents. When faced with documents with highly similar content and structure, such as product manuals of various models of mobile phones, corporate financial reports, and medical diagnosis and treatment manuals, existing systems have difficulty effectively distinguishing the differences between documents. When the system cannot accurately distinguish these similar documents, it often leads to inaccurate retrieval results, which affects the accuracy and relevance of the generated answers. This limitation is particularly prominent in multi-document question answering scenarios, because multi-document question answering not only needs to process a single document, but also must consider the relationships and differences between documents. Second, the limitations of existing RAG methods in dealing with complex contexts cannot be ignored. Most existing RAG systems only retrieve a small number of continuous text blocks from the corpus, which limits the understanding of the global semantic structure of the document. This approach may be able to meet the needs when dealing with simple questions and answers, but it performs poorly on complex problems that require integrating partial knowledge from multiple documents. Due to the lack of in-depth understanding of the global structure and content of the document, RAG systems find it difficult to provide comprehensive and coherent answers. This is especially evident when dealing with questions that span chapters or involve complex semantic levels. The retrieved text blocks cannot provide sufficient contextual support, resulting in the lack of depth and breadth of the generated answers, which cannot meet the needs of practical applications. Summary of the invention

[0006] In view of the shortcomings existing in the above problems, the present invention provides a RAG system optimization method, system, electronic device and storage medium.

[0007] To achieve the above object, the present invention provides a RAG system optimization method, comprising:

[0008] Convert each page of a PDF document into an image;

[0009] The target detection model is used to analyze the image and identify the four coordinates of the anchor box and the target category, which includes the article title, chapter title and text.

[0010] Sort the target categories based on their page number information and their coordinate positions on the page;

[0011] Use the OCR model to extract the text content in the image, and merge the extracted text according to the sorting results to generate a document with structured tags;

[0012] Extract titles from documents with structured tags in order, embed the titles into prompt words and input them into a large language model to generate hierarchical titles.

[0013] Replace the original title in the document with structured markup with the title of the hierarchical relationship and generate summary information for each level;

[0014] Documents with structured tags are divided into multiple document blocks using the titles of each level as the segmentation points. The document blocks include the level title, level summary and body text.

[0015] Use the vector model to convert each document block into a high-dimensional vector for supporting vector search;

[0016] Based on vector search of high-dimensional vectors and keyword search of keywords, the final result of the retrieval is determined.

[0017] Preferably, the four coordinates of the anchor box and target category , which is expressed as follows:

[0018] ;

[0019] in, and are the coordinates of the upper left and lower right corners of the anchor box, respectively. is the target category.

[0020] Preferably, sorting based on the page number information of the target category and the coordinate position of the target category on the page includes:

[0021] The page number information of the target category is sorted. The key to sorting is the page number of the target category. and its upper left corner coordinates , sorting score The calculation formula is as follows:

[0022] ;

[0023] in, is the coefficient used to adjust the weights of different dimensions, Indicates the page number where the target category is located. and Respectively represent the horizontal and vertical positions of the target category in the page.

[0024] Preferably, for a root title , which is passed through a large language model Process and inject the title after the hierarchical relationship It is expressed as:

[0025] ;

[0026] For a non-root title , its level title The parent level title and the current title Connected, expressed as:

[0027] ;

[0028] in, Indicates the current title The parent title of the function It is used to connect the parent level title with the current title based on the set delimiter string to generate a complete level title.

[0029] Preferably, replacing the original title in the document with the structured markup with the title of the hierarchical relationship, and generating summary information for each level includes:

[0030] For leaf nodes, summary information Large language model According to the text content corresponding to the node Generate, which can be expressed as:

[0031] ;

[0032] After generating the summaries of all leaf nodes, the summary information of each parent node is summarized layer by layer through topological sorting; for non-leaf nodes, their summaries It not only relies on its own main text content, but also needs to integrate the summary information of all its child nodes to form a more comprehensive overview. The specific formula is as follows:

[0033] ;

[0034] in, Represents the summary of each child node of this non-leaf node, Indicates the text content of the non-leaf node.

[0035] Preferably, based on the vector search of the high-dimensional vector and the keyword search of the keyword, determining the final result of the search includes:

[0036] Cosine similarity score for vector search And the BM25 score of keyword search Normalize them and linearly map them to the range of 0 to 1. Then, combine the normalized scores by weighted average to generate the final comprehensive score. , expressed as:

[0037] ;

[0038] in, and They are the weight coefficients for vector search and keyword search respectively.

[0039] The present application also provides a RAG system optimization system, including:

[0040] The conversion module is used to convert each page of the PDF document into an image;

[0041] A recognition module, used to analyze the image using a target detection model to identify four coordinates of the anchor box and target categories, wherein the target categories include article titles, chapter titles, and text;

[0042] A sorting module, used for sorting based on the page number information of the target category and the coordinate position of the target category on the page;

[0043] An extraction module, used to extract text content from the image using an OCR model, and merge the extracted text according to the sorting result to generate a document with structured tags;

[0044] A large language model module is used to sequentially extract titles from the document with structured tags, embed the titles into prompt words and input them into the large language model to generate hierarchical titles;

[0045] A replacement module, used to replace the original title in the document with the structured markup with the title of the hierarchical relationship, and generate summary information for each level;

[0046] A segmentation module, used for generating a plurality of document blocks with each level title as a segmentation point for the document with structured tags, wherein the document blocks include a level title, a level summary and a body text;

[0047] A conversion module, used for converting each of the document blocks into a high-dimensional vector for supporting vector search using a vector model;

[0048] The retrieval module is used to determine the final result of the retrieval based on the vector search of the high-dimensional vector and the keyword search of the keyword.

[0049] The present invention also provides an electronic device, comprising at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program, and when the program is executed by the processing unit, the processing unit executes the above method.

[0050] The present invention also provides a storage medium storing a computer program executable by an electronic device. When the program runs on the electronic device, the electronic device executes the above method.

[0051] Compared with the prior art, the present invention has the following beneficial effects:

[0052] The present invention significantly improves the performance of the RAG system in complex question-answering tasks, can effectively distinguish similar documents and better understand the global semantics of documents, and ultimately provide more accurate and comprehensive answers, effectively alleviating the limitations of traditional methods in dealing with complex document scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] Figure 1 It is a flow chart of the RAG system optimization method of the present invention. DETAILED DESCRIPTION

[0054] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0055] Reference Figure 1 The present invention provides a RAG system optimization method, comprising:

[0056] Convert each page of a PDF document into an image;

[0057] Specifically, the PDF structure parser is responsible for converting the original format of the PDF document into a structured text format for subsequent processing, and identifying various structural elements in the document for further hierarchical semantic enhancement operations.

[0058] Analyzing the image using a target detection model to identify four coordinates of an anchor box and target categories, wherein the target categories include article titles, chapter titles, and text;

[0059] Specifically, we use a pre-trained object detection model (YOLOv8) to analyze these images and identify and extract key structural elements in the document, including article titles, chapter titles, and text areas. The output data format of each detected object includes the four coordinates of the anchor box and target category , which is expressed as follows:

[0060] ;

[0061] in, and are the coordinates of the upper left and lower right corners of the anchor box, respectively. Indicates the category of the target, such as "article title", "section title", or "body text".

[0062] Sorting based on the page number information of the target category and the coordinate position of the target category on the page;

[0063] Specifically, after detecting and obtaining the structural elements of the document, these detected objects need to be sorted to ensure that the reconstructed document can reflect the logical order and spatial layout of the original content. The sorting process first preliminarily sorts the detected objects based on the page number information where the detected objects are located, and then further sorts them based on the coordinate position of the objects in the page. Specifically, the key to sorting is the page number where the object is located. and its upper left corner coordinates . Sorting score The calculation formula is as follows:

[0064] ;

[0065] in, is the coefficient used to adjust the weights of different dimensions, Indicates the page number where the object is located. and Respectively represent the horizontal and vertical positions of the object on the page.

[0066] Typically, A larger value of ensures that the objects are sorted first in page number order. and The weights are used to further sort the objects according to their spatial positions (from left to right, top to bottom) on the same page.

[0067] Extracting text content from the image using an OCR model, and merging the extracted text according to the sorting results to generate a document with structured tags;

[0068] Specifically, after sorting the document structure elements, the OCR model (PaddleOCR) is used to extract the text content in the image. The extracted text will be merged in order according to the sorting results, and combined with the classification results of the target detection, it will be reconstructed into a document with structured tags. For example, the detected "article title" will be marked as a first-level title (#), and the "chapter title" will be marked as a second-level title (##), and the body of the text will be inserted into the document in its original order.

[0069] Orderly extracting titles from the document with structured tags, and embedding the titles into prompt words and inputting them into a large language model to generate hierarchical titles;

[0070] Specifically, after completing OCR text extraction and document structure reconstruction, the preliminary structure of the document is usually presented in the form of a cross-arrangement of titles and text. Although these titles partially reflect the structure of the document, they still lack hierarchical information between titles, making it difficult to accurately assist in distinguishing the semantic subordination between similar text contents. In order to solve this problem, the title list is first extracted from the reconstructed document in an orderly manner, and prompt words are constructed through methods such as example enumeration and thought chain to standardize the format content of LLM output. Then, the title list information is embedded in the prompt words and passed to LLM for further processing to generate a title list containing a hierarchical relationship. Since the title structure usually contains significant hierarchical numbers, identifiers and semantic progressive relationships, LLM can efficiently parse this information and generate an accurate hierarchical structure.

[0071] Specifically, the processing of a title by a large language model can be expressed by the following formula:

[0072] First, for a root title , which is passed through a large language model Process and inject the title after the hierarchical relationship It can be expressed as:

[0073] ;

[0074] For a non-root title , its level title The parent level title and the current title Connected, expressed as:

[0075] ;

[0076] in, Indicates the current title The parent title of the function It is used to connect the parent level title with the current title based on the set delimiter string to generate a complete level title.

[0077] Replacing the original title in the document with the structured markup with the title of the hierarchical relationship, and generating summary information for each level;

[0078] Specifically, the hierarchical titles generated by LLM will replace the original titles in the document. Compared with the original titles, the new titles not only accurately reflect the hierarchical relationship of the document, but also make each title more unique and distinguishable by introducing specific hierarchical information. This is especially important when dealing with similar documents, because even if there are similar contents and hierarchical structures between documents, similar RAG blocks of these different documents can be distinguished by some differences in their hierarchical titles caused by specific identifiers (such as document versions or product names), thereby effectively alleviating the inaccurate retrieval caused by RAG mixing similar blocks belonging to different documents and recalling them together during the retrieval process.

[0079] After the hierarchical title injection is completed, the module will use topological sorting to generate summary information for each level from bottom to top through LLM and prompt word engineering. This process aims to form a hierarchical document summary structure by integrating the summary information of low-level nodes layer by layer.

[0080] Specifically, the system starts with the leaf node and generates its corresponding summary. For the leaf node, its summary information Large language model According to the text content corresponding to the node Generate, which can be expressed as:

[0081] ;

[0082] After generating summaries for all leaf nodes, the system summarizes the summary information of each parent node layer by layer through topological sorting. It not only relies on its own main text content, but also needs to integrate the summary information of all its child nodes to form a more comprehensive overview. The specific formula is as follows:

[0083] ;

[0084] in, Represents the summary of each child node of this non-leaf node, Indicates the text content of the non-leaf node.

[0085] The hierarchical summaries generated by LLM will be injected into the original document layer by layer to enhance RAG's understanding of the global semantics of the document, effectively alleviating the defect of one-sided answers when RAG faces questions that need to be answered across chapters or by integrating information from multiple paragraphs.

[0086] The document with structured tags generates multiple document blocks with each level title as a segmentation point, and the document blocks include level titles, level summaries and text;

[0087] Using a vector model, each of the document blocks is converted into a high-dimensional vector for supporting vector search;

[0088] Based on the vector search of the high-dimensional vector and the keyword search of the keyword, the final result of the retrieval is determined.

[0089] Specifically, after the hierarchical summary is injected, the document will generate multiple document blocks with the hierarchical titles as the segmentation points. Each document block will include three parts: hierarchical title, hierarchical summary and text content. These blocks will then be used to create vector indexes and keyword indexes, and stored in the corresponding databases for subsequent retrieval operations. When creating a vector index, each document block is first converted into a high-dimensional vector using a vectorization model (bge-m3). The generated vectors are then stored in the vector database (Milvus) to support vector search. At the same time, the keyword index supports keyword search by constructing an inverted index, and the generated inverted index is stored in the index database (Elasticsearch).

[0090] Since vector search and keyword search have different focuses in the retrieval process: vector search is better at capturing semantically related information, while keyword search focuses more on precise matching at the character level. Therefore, in the retrieval stage, the multi-way retriever combines these two methods and adopts a hybrid search strategy to ensure that the semantics and character information of the query can be fully captured. Specifically, in the retrieval stage, the multi-way retriever will perform vector search and keyword search at the same time. First, in the vector search part, the user query is vectorized through the vectorization model, and the cosine similarity between the user query vector and the document block vector is calculated to measure the semantic match between the query and the block content. At the same time, in the keyword search part, the system performs keyword matching on the document based on the inverted index, and uses the BM25 algorithm to calculate the matching score.

[0091] In order to combine the retrieval results of these two different dimensions, the multi-way searcher adopts the relative score fusion (RSF) strategy. First, the cosine similarity score of the vector search is And the BM25 score of keyword search Normalization is performed to linearly map them to a range of 0 to 1, so that the two different types of scores can be compared on the same scale. The system then combines these normalized scores through weighted averaging to generate the final comprehensive score. , which can be expressed as:

[0092] ;

[0093] in, and They are the weight coefficients of vector search and keyword search respectively. Adjusting them can optimize the final retrieval effect.

[0094] After generating the final comprehensive score, the system selects the top K document chunks (Top K) with the highest scores as candidates, and further uses the rerank model (bge-reranker-v2-m3) to evaluate the semantic relevance between the preliminary retrieval results and the user query and re-rank the retrieval results to ensure that the most relevant document chunks are displayed first in the final results, thereby improving the accuracy of the retrieval and the matching degree of the user query.

[0095] Finally, LLM uses the re-ranked retrieval information as context to perform reasoning and generate answers.

[0096] in, and They are the weight coefficients for vector search and keyword search respectively.

[0097] The PDF document RAG optimization method based on target detection and hierarchical semantic context enhancement of the present invention can effectively distinguish documents with similar content and structure, avoiding retrieval errors caused by the inability to capture differences between documents in multi-document question-answering scenarios. The PDF document RAG optimization method based on target detection and hierarchical semantic context enhancement can automatically inject a global semantic hierarchical structure into the document, effectively alleviating the problem of lack of depth and breadth of answers caused by insufficient context support in traditional RAG methods when dealing with questions that span chapters or require the integration of partial knowledge of multiple documents to answer. Example

[0098] In a pharmaceutical-related enterprise in Hong Kong, China, when using the traditional RAG system for knowledge question and answer, the company often faces the problem of inaccurate search results when dealing with documents with highly similar content and structure, such as medical diagnosis manuals and drug instructions, which seriously affects the work efficiency of internal medical staff.

[0099] After applying the PDF document RAG optimization method based on target detection and hierarchical semantic context enhancement, the RAG system can effectively distinguish these documents with similar structures and still provide comprehensive and accurate answers in large-scale document question and answering, greatly improving the work efficiency of internal corporate personnel and the stability of core business systems.

[0100] The present application also provides a RAG system optimization system, including:

[0101] The conversion module is used to convert each page of the PDF document into an image;

[0102] The recognition module is used to analyze the image using the target detection model to identify the four coordinates of the anchor box and the target category, which includes the article title, chapter title and text;

[0103] A sorting module, used for sorting based on the page number information of the target category and the coordinate position of the target category on the page;

[0104] The extraction module is used to extract the text content in the image using the OCR model, and merge the extracted text according to the sorting results to generate a document with structured tags;

[0105] The large language model module is used to sequentially extract titles from documents with structured tags, embed the titles into prompt words and input them into the large language model to generate hierarchical titles.

[0106] A replacement module, used to replace the original title in the document with structured tags with the title of the hierarchical relationship, and generate summary information for each level;

[0107] The segmentation module is used to generate multiple document blocks for documents with structured tags using the titles of each level as segmentation points. The document blocks include the level title, level summary and body text.

[0108] A conversion module, for converting each document block into a high-dimensional vector for supporting vector search using a vector model;

[0109] The retrieval module is used for vector search based on high-dimensional vectors and keyword search based on keywords to determine the final result of the retrieval.

[0110] The present invention also provides an electronic device, comprising at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program, and when the program is executed by the processing unit, the processing unit executes the above method.

[0111] The present invention also provides a storage medium storing a computer program executable by an electronic device. When the program runs on the electronic device, the electronic device executes the above method.

[0112] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A RAG system optimization method, characterized in that: include: Convert each page of a PDF document into an image; Analyzing the image using a target detection model to identify four coordinates of an anchor box and target categories, wherein the target categories include article titles, chapter titles, and text; Sorting based on the page number information of the target category and the coordinate position of the target category on the page; Extracting text content from the image using an OCR model, and merging the extracted text according to the sorting results to generate a document with structured tags; Orderly extracting titles from the document with structured tags, and embedding the titles into prompt words and inputting them into a large language model to generate hierarchical titles; Replacing the original title in the document with the structured markup with the title of the hierarchical relationship, and generating summary information for each level; The document with structured tags generates multiple document blocks with each level title as a segmentation point, and the document blocks include level titles, level summaries and text; Using a vector model, each of the document blocks is converted into a high-dimensional vector for supporting vector search; Based on the vector search of the high-dimensional vector and the keyword search of the keyword, the final result of the retrieval is determined.

2. The RAG system optimization method according to claim 1, characterized in that: The four coordinates of the anchor box and target category , which is expressed as follows: ; in, and are the coordinates of the upper left corner and lower right corner of the anchor box, respectively. is the target category.

3. The RAG system optimization method according to claim 2, characterized in that: Sorting based on the page number information of the target category and the coordinate position of the target category on the page includes: The page number information of the target category is sorted, and the key to sorting is the page number of the target category and its upper left corner coordinates , sorting score The calculation formula is as follows: ; in, is the coefficient used to adjust the weights of different dimensions, Indicates the page number where the target category is located. and Respectively represent the horizontal and vertical positions of the target category in the page.

4. The RAG system optimization method according to claim 3, characterized in that: For a root title , which is passed through the large language model Process and inject the title after the hierarchical relationship It is expressed as: ; For a non-root title , its level title The parent level title and the current title Connected, expressed as: ; in, Indicates the current title The parent title of the function It is used to connect the parent level title with the current title based on the set delimiter string to generate a complete level title.

5. The RAG system optimization method according to claim 4, characterized in that: Replacing the original title in the document with the structured markup with the title of the hierarchical relationship, and generating summary information for each level includes: For leaf nodes, summary information By the large language model According to the text content corresponding to the node Generate, which can be expressed as: ; After generating the summaries of all leaf nodes, the summary information of each parent node is summarized layer by layer through topological sorting; for non-leaf nodes, their summaries It not only relies on its own main text content, but also needs to integrate the summary information of all its child nodes to form a more comprehensive overview. The specific formula is as follows: ; in, Represents the summary of each child node of this non-leaf node, Indicates the text content of the non-leaf node.

6. The RAG system optimization method according to claim 5, characterized in that: Based on the vector search of the high-dimensional vector and the keyword search of the keyword, determining the final result of the search includes: Cosine similarity score for vector search And the BM25 score of keyword search Normalize them and linearly map them to the range of 0 to 1. Then, combine the normalized scores by weighted average to generate the final comprehensive score. , expressed as: ; in, and They are the weight coefficients for vector search and keyword search respectively.

7. A RAG system optimization system, characterized in that: include: The conversion module is used to convert each page of the PDF document into an image; A recognition module, used to analyze the image using a target detection model to identify four coordinates of the anchor box and target categories, wherein the target categories include article titles, chapter titles, and text; A sorting module, used for sorting based on the page number information of the target category and the coordinate position of the target category on the page; An extraction module, used to extract text content from the image using an OCR model, and merge the extracted text according to the sorting result to generate a document with structured tags; A large language model module is used to sequentially extract titles from the document with structured tags, embed the titles into prompt words and input them into the large language model to generate hierarchical titles; A replacement module, used to replace the original title in the document with the structured markup with the title of the hierarchical relationship, and generate summary information for each level; A segmentation module, used for generating a plurality of document blocks with each level title as a segmentation point for the document with structured tags, wherein the document blocks include a level title, a level summary and a body text; A conversion module, used for converting each of the document blocks into a high-dimensional vector for supporting vector search using a vector model; The retrieval module is used to determine the final result of the retrieval based on the vector search of the high-dimensional vector and the keyword search of the keyword.

8. An electronic device, characterized in that: The method comprises at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program, and when the program is executed by the processing unit, the processing unit executes the method according to any one of claims 1 to 6.

9. A storage medium, characterized in that: It stores a computer program executable by an electronic device. When the program runs on the electronic device, the electronic device executes the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Dialogue method and system based on document retrieval enhanced machine language model

    CN117807199A

  • Artificial intelligence body generation method and system based on RAG technology

    CN118551026A