Retrieval enhancement method based on semantic comprehension and semantic generation model

Optimizing RAG technology through semantic understanding and generation models solves the problems of semantic coherence destruction and poor matching effects in document segmentation and vectorization processing, achieves high-performance retrieval enhancement, and improves retrieval and question-answering effects.

CN118733715AInactive Publication Date: 2024-10-01HANGZHOU FUJIA TECH CO LTD

Patent Information

Application Number
CN202411225415.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-03
Publication Date
2024-10-01
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Existing RAG technology easily destroys semantic coherence during document segmentation and vectorization processing, resulting in poor matching results, and the semantic and lexical differences between user questions and document expressions lead to poor retrieval results.

Method used

Use semantic understanding and semantic generation models for document preprocessing and segmentation, merge slices through the semantic inheritance relationship model, use the summary generation model to extract key information, and build fragment and keyword vector indexes, rewrite user questions based on historical conversations, and conduct key Word recall and segment retrieval.

Benefits of technology

Effectively retain the semantic integrity of document splitting results, reduce interference information, improve matching performance, eliminate ambiguity, and enhance retrieval and question-answering effects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733715A_ABST
    Figure CN118733715A_ABST
Patent Text Reader

Abstract

The invention discloses a retrieval enhancement method based on semantic comprehension and a semantic generation model. The retrieval enhancement method comprises the following steps: 1) a document preprocessing step, 2) a document processing step, 3) a length limiting step, 4) a fragment vector index construction step, 5) a keyword vector index construction step, 6) a question retrieval step and 7) an answer generation step. According to the method, the document is segmented on the basis of the semantic level, so that the semantic integrity of a splitting result can be reserved to a great extent; key information is further extracted from overlong document fragments, so that interference information can be effectively reduced, and the matching performance is improved; original user questions are rewritten in combination with historical dialogue contents, necessary information missing in the user questions can be complemented, ambiguity is eliminated, and therefore the retrieval and question and answer effects are improved; and recall strategies of different dimensions are realized by using the keywords generated in the user question, so that recalled contents are more comprehensive.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of information extraction, and more specifically, to a retrieval enhancement method based on semantic understanding and semantic generation model. Background Art

[0002] As the most widely used LLM implementation scenario, RAG (Retrieval-Augmented Generation) can effectively make up for the defect that LLM cannot update its own knowledge base in real time. It can also reduce the illusion during its generation to a certain extent and improve the interpretability. The existing RAG implementation scheme is generally divided into several parts: document preprocessing and segmentation, text vectorization, index construction, question retrieval, recall rearrangement, etc. The quality of each link will affect the final performance of the system, so optimizing RAG is a systematic process. The main defects at present are: first, the current mainstream document segmentation method is mainly based on rules, such as segmentation according to the document layout format or truncation according to the length of the text. This approach can easily lead to the destruction of the semantic coherence of the text; second, the processed document slices are directly vectorized and then constructed for retrieval. On the one hand, the matching effect is often unsatisfactory due to the difference in semantic distribution between the document slices and the user questions. On the other hand, if the document slices are too long, they will contain too much information. Matching user questions often only requires part of the information, and redundant content may affect the final matching effect; thirdly, using the original question for vector retrieval may result in semantic differences, vocabulary differences, ambiguity, etc. with the text expression in the document, which greatly reduces the retrieval effect. Summary of the invention

[0003] The present invention overcomes the deficiencies of the prior art and provides a method for optimizing each module of RAG by utilizing semantic understanding and semantic generation model, so as to realize a universal, high-performance and reliable retrieval enhancement method based on semantic understanding and semantic generation model.

[0004] The technical solution of the present invention is as follows: A retrieval enhancement method based on semantic understanding and semantic generation model specifically includes the following steps: 1) Document preprocessing step: Obtain the required document data from the corresponding website and clean the document content to obtain text data; 2) Document processing step: Segment the document according to its layout structure or punctuation marks to obtain a first processing result; predict the first processing result in order through a semantic continuation relationship model, merge the slices with a continuation relationship, and obtain a second processing result; 3) Length restriction step: the maximum document slice length is limited for the content of the second processing result. If the maximum length is exceeded, key information is extracted from the slice content to obtain the third processing result; 4) Step of constructing a fragment vector index: vectorizing the third processing result to construct an index of the fragment vector; 5) Step of constructing a keyword vector index: extract keywords from the third processing result and use a keyword generation model to generate core keywords in the input text, then use a vector model to vectorize the keywords to construct an index of the keyword vector; 6) Question retrieval step: A question rewriting generation model is used for the questions raised by the user. The model rewrites the original question based on the context content, extracts keywords from the rewritten original question, vectorizes the keywords and the rewritten question, and uses the keyword index and the fragment vector index to retrieve related fragments. The top few related knowledge fragments are retrieved and the duplicates are removed as the final retrieval results. 7) Answer generation step: The retrieved content and the rewritten original question are combined into a prompt word and input into the large language model LLM for answer generation.

[0005] Furthermore, in the document preprocessing step, the document content is cleaned including removing HTML format, special symbols, and garbled characters.

[0006] Furthermore, a summary generation model will be used in the length restriction step to extract the key information from the input text.

[0007] Furthermore, the recall adopts direct recall of fragments and recall of keywords, and the recall results of the two are combined; Direct fragment recall: The rewritten user question is converted into a sentence vector using a semantic representation model. The most relevant document fragments are directly retrieved using the fragment index based on cosine similarity. The top k fragment contents are retrieved in reverse order according to similarity as the recall result. Keyword recall: The keywords extracted from user questions are converted into word vectors using a semantic representation model. The most similar keywords and their corresponding document fragments are retrieved using keyword indexes based on cosine similarity. The top k document fragments are selected based on similarity and keyword coverage. Merge recall results: remove duplicates from the two parts of the recall results and merge them into the final recall result of the retrieval part.

[0008] Compared with the prior art, the present invention has the following advantages: The present invention segments documents based on the semantic level, which can retain the semantic integrity of the segmentation results to a great extent. This segmentation method is more reasonable than the existing methods. Further extracting key information from overly long document fragments can effectively reduce interference information, thereby improving matching performance. Rewriting the original user questions in combination with historical conversation content can complete the necessary information missing in the user questions and eliminate ambiguity, thereby improving the retrieval and question-answering effects. Using the keywords generated in the user questions to implement recall strategies of different dimensions, the recalled content is more comprehensive. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] Figure 1 This is a structural diagram of the pre-trained language model of the present invention; Figure 2 It is a flowchart of document data processing of the present invention; Figure 3 It is a flowchart of user question processing of the present invention. DETAILED DESCRIPTION

[0010] The embodiments of the present invention are described in detail below, wherein the same or similar reference numerals throughout represent the same or similar elements or elements with similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention and cannot be used as a limitation of the present invention.

[0011] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meaning as generally understood by those skilled in the art in the field to which the present invention belongs. It should also be understood that terms such as those defined in common dictionaries should be understood to have meanings consistent with the meanings in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless defined as herein.

[0012] The numbers of the steps mentioned in each embodiment are only for the convenience of description and have no substantial sequence relationship. Different steps in each specific embodiment can be combined in different sequences to achieve the purpose of the invention.

[0013] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments.

[0014] like Figures 1 to 3 As shown, a retrieval enhancement method based on semantic understanding and semantic generation model specifically includes the following steps: 1) Document preprocessing step: Obtain the required policy-related document data from the corresponding website (such as the government portal website), and clean the document content to obtain text data; document content cleaning includes removing HTML format, special symbols, garbled characters, etc.

[0015] Take a tax policy as an example: 1. From January 1, 2024 to December 31, 2025, taxpayers who sell their own houses and repurchase houses in the market within one year after the sale of their current houses will be given a tax refund for the individual income tax paid on the sale of their current houses. If the amount of the newly purchased house is greater than or equal to the transfer amount of the current house, the individual income tax paid will be fully refunded; if the amount of the newly purchased house is less than the transfer amount of the current house, the individual income tax paid on the sale of the current house will be refunded in proportion to the amount of the newly purchased house to the transfer amount of the current house.

[0016] 2. The transfer amount of the current house referred to in this announcement is the market transaction price of the house. If the newly purchased house is a new house, the purchase amount is the transaction price indicated in the purchase contract signed and filed online by the taxpayer with the housing and urban-rural development department; if the newly purchased house is a second-hand house, the purchase amount is the transaction price of the house.

[0017] 3. Taxpayers who enjoy the preferential policies stipulated in this announcement must meet the following conditions at the same time: 1. The housing sold and repurchased by the taxpayer should be within the same city. The same city refers to the entire administrative area of ​​the same municipality, sub-provincial city, prefecture-level city (region, state, league).

[0018] 2. The taxpayer who sells his own house must be directly related to the newly purchased house and should be the owner of the newly purchased house or one of the owners.

[0019] 2) Document processing steps: Segment the document according to its layout structure or punctuation marks to obtain the first processing result with the smallest granularity. The tax policy is processed as shown in Table 1:

[0020] Table 1 The first processing result is predicted in order through the semantic continuation relationship model, and the slices with continuation relationship are merged to obtain the second processing result. In order to merge the semantically related parts in the first processing result, it is necessary to first construct a batch of sentence training data for judging the semantic continuation relationship. The training data example is shown in Table 2:

[0021] Table 2 Next, we fine-tune the model based on the open source pre-trained language model bert-base-uncased using the training data constructed above. Unlike the conventional approach to sentence relationship judgment, we use a prompt learning method here. We use prompt words to let the language model fill in the blanks, converting the task from calculating scores to judging classifications, which allows the model to better fit the training data and thus improve the performance of the model. Figure 1 As shown, [SEP] represents a separator, which is used to mark the interval between sentences. The prompt word is: "Do the two sentences have a semantic continuation relationship:", [MASK] represents the position marker that needs to be predicted. After merging all the content, it is input into the pre-trained language model bert-base-uncased, and then the output of the [MASK] position is dimensionally mapped through the fully connected layer. The final model output is: "Yes" or "No", which is used to judge the relationship between sentences; finally, the fine-tuned model is used to predict the adjacent sentences in the first processing result to determine whether they have a continuation relationship. If there is a continuation relationship, the two are merged, otherwise, the two are still regarded as different slices, thereby obtaining the second processing result. The specific processed results are shown in Table 3:

[0022] Table 3 Therefore, the adjusted second processing results are as shown in Table 4:

[0023] Table 4 3) Length limitation step: The maximum document slice length is limited for the content of the second processing result. If it exceeds the maximum length, key information is extracted from the slice content to obtain the third processing result; a summary generation model is used to extract key information from the input text.

[0024] Specifically, the maximum text length n is set to 128. If the length of the segmented fragment does not exceed 128, it is kept as it is; if the length of the segmented fragment exceeds 128, key information is extracted in stages. The stage here refers to the length between n and 2n, then two key information in the text are extracted, and the length between 2n and 3n, then three key information in the text are extracted, and so on, to obtain the third processing result. The extraction model used here is Qwen2-0.5B-Instruct (or gemma-2B, bloom-1B, Qwen1.5-0.5B-Chat). The specific results are shown in Table 5:

[0025] Table 5 4) Step of constructing the fragment vector index: vectorize the third processing result and construct the fragment vector index. Specifically, by building the milvus vector database: milvus is an open source vector database specially designed for processing the storage and retrieval of large-scale vector data. In order to improve the vector retrieval performance, this project has deployed the milvus vector database locally.

[0026] Then, the fragment index is constructed, and the bge-m3 (or m3e, roberta, text2vec, sbert) model is used to vectorize the semantic representation of the third processing result, and the metadata (such as fragment extraction text, original fragment text, original fragment sequence number, original document name, original document sequence number, etc.) is stored together with the vector in the milvus vector database to establish the fragment index.

[0027] 5) Step of constructing keyword vector index: extract keywords from the third processing result to obtain the fourth processing result. That is, process the third processing result and use Qwen2-0.5B-Instruct (or gemma-2B, bloom-1B, Qwen1.5-0.5B-Chat) to extract the domain keywords involved in the text to obtain the fourth processing result of keyword content. The details are as follows in Table 6:

[0028] Table 6 Use the keyword generation model to generate the core keywords in the input text, then use the vector model to vectorize the keywords and construct an index of the keyword vectors; The specific keyword index is constructed by using the bge-m3 (or m3e, roberta, text2vec, sbert) model to vectorize the semantic representation of the fourth processing result, and store the metadata (such as keyword text, fragment text corresponding to the keyword, document name corresponding to the keyword, etc.) together with the vector into the milvus vector database to establish a keyword index.

[0029] 6) Question retrieval step: Get the previous conversation content of the current user stored in the redis database based on the conversation id.

[0030] The question rewriting generation model is used to rewrite and complete the questions raised by the user and extract keywords. That is, the original question is rewritten based on the context content, and the keywords of the rewritten original question are extracted. The keywords and rewritten questions are vectorized respectively, and the keyword index and fragment vector index are used to retrieve related fragments. The top few related knowledge fragments are recalled respectively, and the final search results are obtained after deduplication.

[0031] Specifically, based on the above dialogue content, based on LLM and combined with prompt engineering, the current user question is rewritten to eliminate ambiguity, add background information, clarify the focus of the question, etc. At the same time, the keywords of the completed question are extracted for subsequent original text recall. The question rewriting model used here is Qwen2-7B-Instruct (or glm4-9B, llama3.1-8B, baichuan2-7B), and an example is shown in Table 7 below:

[0032] Table 7 The recall adopts direct fragment recall and keyword recall, and the recall results of the two are merged.

[0033] Direct fragment recall: The rewritten user question is converted into a sentence vector using the semantic representation model bge-m3 (or m3e, roberta, text2vec, sbert), and the most relevant document fragments are directly retrieved using the fragment index based on cosine similarity. The top k fragment contents are then sorted in reverse order according to the similarity and taken as the recall result.

[0034] Keyword recall: The keywords extracted from user questions are converted into word vectors using the semantic representation model bge-m3 (or m3e, roberta, text2vec, sbert). The most similar keywords and their corresponding document fragments are retrieved using the keyword index based on cosine similarity. The top k document fragments are selected based on similarity and keyword coverage. Generally, two are sufficient, and the specific settings can be changed according to actual conditions.

[0035] Merge recall results: remove duplicates from the two recall results and merge them into the final recall result of the search part. The specific example is shown in Table 8:

[0036] Table 8 7) Answer generation step: The retrieved content and the rewritten original question are combined into a prompt word and input into the large language model LLM (such as llama3.1-70b, qwen2-72b, gemma2-27b, deepseek-67B) for answer generation as the user's answer.

[0037] Specific user question: How to calculate the refund ratio of personal income tax for the sale of a house? Answer: Between 2024 and 2025, taxpayers who sell their own homes and repurchase a new home within one year can enjoy individual tax refunds, with the amount of the refund determined based on the ratio of the transfer amount of the new home to the current home. The transfer amount of the current home is the market transaction price, and the amount of the new home is determined based on the contract filing or transaction price.

[0038] In summary, this solution can segment documents based on the semantic level, which can retain the semantic integrity of the segmentation results to a great extent and further extract key information from long document fragments. Rewriting the original user questions based on historical conversation content can complete the missing necessary information in the user questions and eliminate ambiguity, thereby improving the retrieval and question-answering effects.

[0039] The information (including but not limited to user device information, user personal information, public service information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0040] The above is only a preferred embodiment of the present invention. It should be pointed out that ordinary technicians in this technical field can make several improvements and modifications without departing from the concept of the present invention. These improvements and modifications should also be regarded as within the scope of protection of the present invention.

Claims

1. A retrieval enhancement method based on semantic understanding and semantic generation model, Features: The specific steps include: 1) Document preprocessing step: crawl the required document data from the website and clean the document content to obtain text data; 2) Document processing step: Segment the document according to its layout structure or punctuation marks to obtain a first processing result; predict the first processing result in order through a semantic continuation relationship model, merge the slices with a continuation relationship, and obtain a second processing result; 3) Length restriction step: the maximum document slice length is limited for the content of the second processing result. If the maximum length is exceeded, key information is extracted from the slice content to obtain the third processing result; 4) Step of constructing a fragment vector index: vectorizing the third processing result to construct an index of the fragment vector; 5) Step of constructing a keyword vector index: extract keywords from the third processing result and use a keyword generation model to generate core keywords in the input text, then use a vector model to vectorize the keywords to construct an index of the keyword vector; 6) Question retrieval step: A question rewriting generation model is used for the questions raised by the user. The model rewrites the original question based on the context content, extracts keywords from the rewritten original question, vectorizes the keywords and the rewritten question, and uses the keyword index and the fragment vector index to retrieve related fragments. The top few related knowledge fragments are retrieved and the duplicates are removed as the final retrieval results. 7) Answer generation step: The retrieved content and the rewritten original question are combined into a prompt word and input into the large language model LLM for answer generation.

2. A retrieval enhancement method based on semantic understanding and semantic generation model according to claim 1, Features: The document content is cleaned in the document preprocessing step, including removing HTML format, special symbols, and garbled characters.

3. A retrieval enhancement method based on semantic understanding and semantic generation model according to claim 1, Features: A summary generation model will be used in the length restriction step to extract the key information from the input text.

4. The retrieval enhancement method based on semantic understanding and semantic generation model according to claim 1, Features: The recall adopts direct recall of fragments and recall of keywords, and the recall results of the two are combined; Direct fragment recall: The rewritten user question is converted into a sentence vector using a semantic representation model. The most relevant document fragments are directly retrieved using the fragment index based on cosine similarity. The top k fragment contents are retrieved in reverse order according to similarity as the recall result. Keyword recall: The keywords extracted from user questions are converted into word vectors using a semantic representation model. The most similar keywords and their corresponding document fragments are retrieved using keyword indexes based on cosine similarity. The top k document fragments are selected based on similarity and keyword coverage. Merge recall results: remove duplicates from the two parts of the recall results and merge them into the final recall result of the retrieval part.

Citation Information

Patent Citations

  • Universal document question and answer implementation method, system and equipment and storage medium

    CN116881425A

  • Document segmentation method, device and equipment and readable storage medium

    CN117520549A

  • Question answering method, apparatus and device, and medium

    CN117591639A

  • LLM-based intelligent questioning and answering method, system and equipment in power field and medium

    CN118277521A

  • Information retrieval method and device, electronic equipment and storage medium

    CN118394916A

Cited By

  • Semantic network-based large language model collaborative patch incorporation evaluation method

    CN119512560A

  • Information retrieval method and system based on RAG and large language model

    CN119597870A

  • Enhanced document generation and retrieval method based on knowledge graph

    CN119646178A

  • Method for improving recall accuracy of article document by using RAG technology

    CN120216708A

  • Multi-dimensional efficient recall method for complex timeliness document

    CN120849684A