Retrieval enhancement generation method based on business key information guidance

Through the search enhanced generation method guided by business-critical information, the problem of user problems lacking key information and poor text chunking effect in the Q&A system is solved, the search recall rate and model reasoning effect are improved, and more accurate and intelligent consultation Q&A is achieved. ability.

CN118885591APending Publication Date: 2024-11-01ZHEJIANG UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411040284.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-31
Publication Date
2024-11-01

AI Technical Summary

Technical Problem

In the question and answer system, the pre-trained model based on the Transformer architecture cannot effectively answer related questions in the vertical field, resulting in the text retrieval enhancement generation system being low and the knowledge required for user problems cannot be accurately matched, especially in complex document structures and User issues are ambiguous.

Method used

The search enhancement generation method based on business-critical information is adopted, and the matching of user problems and documents is optimized through steps such as problem transliteration, text chunking, vector representation and similar search, and the search recall and model inference effect are improved. The specific steps include: problem transcribing, positioning related pages, text chunking, vector representation and similar search, and using the big model to output the most relevant text chunks.

Benefits of technology

Improves search recall and model reasoning effects, provides more accurate and intelligent consultation and Q&A capabilities, especially when processing complex documents in vertical fields, and enhances the accuracy and practicality of the search system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118885591A_ABST
    Figure CN118885591A_ABST
Patent Text Reader

Abstract

The invention discloses a retrieval enhancement generation method based on business key information guidance. The method comprises the following steps: firstly, rewriting and reconstructing a problem of a user by utilizing a large model, and converting the problem into a new problem containing original problem semantic information and corresponding service key information; then, a new question is used for positioning a relevant document page, and a visual driving mode is adopted for carrying out text partitioning on the relevant document page; on the basis, a vector retrieval tool is utilized to retrieve the user question and the segmented text; and finally, selecting the searched first K most relevant text blocks as prompt input for the large model to generate a final answer. According to the method, the semantic structure of the original document is reserved in the text partitioning mode, and the retrieval range is narrowed in the mode that the relevant document pages are positioned through the service key information, so that the recall rate of the document is increased. According to the method, valuable reference can be provided for the retrieval enhancement generation task in a real scene.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of natural language processing (NLP), and in particular to technologies related to large language models and information retrieval. Specifically, the present invention relates to a retrieval enhancement generation method guided by business key information, which can accurately match the internal knowledge of a specific field related to the problem, and is used to improve the output of a large model. Background Art

[0002] In the question-answering system, the knowledge trained by the pre-trained model based on the Transformer architecture is not time-effective, and the model cannot answer relevant questions in vertical fields. The traditional Retrieval Augmented Generation (RAG) method uses the pre-trained model to merge additional knowledge to enhance the language model. The characteristic of this stage is to refine the pre-training technology. With the continuous development of artificial intelligence technology, the emergence of large models (Large Language Model, LLM) such as ChatGPT marks a new era in the field of NLP. LLM has shown powerful capabilities in contextual learning capabilities, which has led to RAG research shifting to provide better information for LLM in the reasoning stage to answer more complex knowledge-intensive tasks. The use of RAG technology enables LLM to have additional knowledge, thereby eliminating the fine-tuning stage and greatly saving training costs. However, due to the ambiguity, randomness and complexity of local document structure of user questions, RAG has the problem of low text retrieval accuracy in actual use, which poses a challenge to the subsequent model reasoning stage. For example, when searching for a PDF document of a bank's personal foreign exchange business, the user's customer type is divided into domestic individuals and foreign individuals. When domestic individuals and foreign individuals handle the same business, the materials required may be different. When the user enters "I am an American, what do I need to prepare for foreign exchange purchase?", the model should understand that the user is a foreign individual and wants to handle foreign exchange purchase business. However, because the traditional vector retrieval method cannot accurately represent similar texts, and the required keywords do not appear in the user's question, the original text retrieval method cannot locate the PDF page related to the page "foreign exchange purchase (foreign individuals)". Furthermore, since the large language model has contextual restrictions, the text of the located PDF page needs to be divided into blocks. PDF may contain multimodal document structures such as tables and pictures, not simple pure text forms, so a visual-driven method is needed to perform text segmentation. In addition, the word "foreign exchange purchase" may appear in different block texts, which causes great interference to subsequent text vector retrieval. Therefore, it is of significant research significance and application value to explore a method to optimize the retrieval strategy according to user questions and how to better parse complex documents to retain their semantic structure.

[0003] This paper explores the optimization method of retrieval enhancement generation in a question-answering system based on a large model in the field of natural language processing, and proposes a retrieval enhancement generation method guided by business key information. This method can effectively solve the problem that the recall rate of retrieved text is low due to the lack of key information in user questions and the poor text segmentation effect, which ultimately leads to poor model reasoning effect, and has a good effect. Summary of the invention

[0004] The purpose of the present invention is to solve the problem that the recall rate of retrieved text is low and the model reasoning effect is poor due to the lack of key information in user questions and the poor text segmentation effect in the retrieval enhancement generation system. After solving this problem, the model can provide users with more accurate and intelligent replies. In actual application scenarios, it is often necessary to transcribe the user's questions first so that they have more abundant key information for the document. Then, the complex documents are more reasonably segmented, and then the transcribed questions are used for retrieval, thereby improving the retrieval recall rate. Therefore, the present invention provides a retrieval enhancement generation method guided by business key information to transcribe user questions and reasonably segment complex documents.

[0005] To achieve the above object, the present invention provides a retrieval enhancement generation method based on business key information guidance, comprising the following steps:

[0006] S1: Question transcription: Design prompt templates based on the business keywords appearing in the document directory, and transcribe the questions by combining the designed prompt templates with the original user questions and inputting them into the big model;

[0007] S2: Locate relevant pages: read the document, extract the page range corresponding to each title according to the titles appearing in the document, and then match the relevant pages according to the transcribed questions prepared in step S1;

[0008] S3: Text segmentation: reading the corresponding document page through the relevant page number range prepared in step S2, and then segmenting the text into blocks using a document segmentation tool;

[0009] S4: vector representation: the text and the user's original question divided in step S3 are encoded using a text embedding model;

[0010] S5: Similarity search: input the text blocks encoded in step S3 and step S4 and the encoded original user questions into the large model, use the vector database to create an index, and then use the text search tool to search;

[0011] S6: Large model output: Combine the user's original question and the most relevant text block obtained in step S5 to design a prompt template, and finally use the large model for final output.

[0012] Furthermore, in step S1, the prompt template design for question transcription includes:

[0013] Preserve the semantics of the original question: The question transcribed by the large model retains the semantic information of the original question;

[0014] Business keyword replacement: Use business keywords to replace the key information that appears in the original question.

[0015] Furthermore, in step S2, locating the relevant page includes:

[0016] Traverse the document: Use the document parsing tool to traverse the entire document content and extract its title and corresponding page number;

[0017] Keyword matching: The transcribed question output in step S1 is segmented, and the corresponding title is matched using a keyword matching algorithm, and its page number range is output.

[0018] Furthermore, in step S3, text segmentation includes:

[0019] Read the relevant page content: according to the provided page range, use the document reading tool to read the page content of the corresponding range;

[0020] Segment documents by visual layout structure: Use visually driven document segmentation tools to parse the visual layout structure of a page, including page size, font type, bounding box type, and then divide the text into blocks.

[0021] Furthermore, in step S4, the model used for vector representation is a pre-trained text embedding model, which is trained on a data set of tens of millions of Chinese sentences to convert natural language into dense vectors. The text blocks and the user's original questions are vectorized through this model.

[0022] Furthermore, in step S5, similarity search includes:

[0023] Build index: Use vector database to build index of text blocks;

[0024] Cosine similarity comparison: When selecting the Top-K relevant text blocks, choose to use cosine similarity to calculate the similarity between the user question vector and the text block vector, and return the top K relevant text blocks.

[0025] Furthermore, in step S6, the output of the large model needs to include in the designed prompt template: the user question and the contents of the first K related text blocks.

[0026] The beneficial effects of the present invention are as follows: in the retrieval enhancement generation question-answering system, the present invention uses a large model to transcribe user questions that are more conducive to document retrieval for the original user questions, parses and segments complex documents, and improves the recall rate of the final relevant text, thereby providing professional consulting question-answering capabilities for local business knowledge. Compared with traditional retrieval enhancement generation systems, the present invention can better deal with complex documents in vertical fields and perform more reasonable segmentation; and better deal with problems such as low recall rate based on the original user questions, providing a more intelligent consulting question-answering experience and improving the accuracy and practicality of the retrieval enhancement generation system. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 It is a flow chart of the method designed by the present invention;

[0028] Figure 2 It is the Langchain search flow chart of the present invention;

[0029] Figure 3 It is a model framework diagram in the present invention. DETAILED DESCRIPTION

[0030] The method proposed by the present invention is further described in detail below with reference to the accompanying drawings and specific examples.

[0031] Example 1

[0032] The present invention provides a retrieval enhancement generation method based on business key information guidance, comprising the following steps:

[0033] S1: Question transcription: In this step, it is necessary to design a prompt template based on the business keywords that appear in the business document directory of the local knowledge base, and then use the designed prompt combined with the original user question to input into the large model for question transcription.

[0034] S2: Locate relevant pages. Read the document, extract the page range corresponding to each title according to the titles appearing in the document, and then match the relevant pages according to the transcribed questions prepared in step S1.

[0035] S3: Text segmentation: Read the corresponding document page through the relevant page number range prepared in step S2, and then segment the text into blocks using a document segmentation tool, such as Open-parse, ChatDoc, etc.

[0036] S4: Vector representation. The text and user's original question segmented in step S3 are encoded using the text embedding model.

[0037] S5: Similarity search. Input the text blocks encoded in step S3 and step S4 and the encoded original user questions, use the vector database to create an index, and then use text search tools to search, such as Langchain, Llamaindex, etc.

[0038] S6: Large model output. The prompt is designed based on the user's original question and the most relevant text block obtained in step S5, and the final output is finally made using the large model.

[0039] Furthermore, in step S1 of the present invention, transcribing the question through the big model is the key first step to realize the search question answering system. This step mainly designs a prompt template for the big model to transcribe the question and output it. The transcribed question has strict semantic information, which needs to include the following content:

[0040] (1) Preserve the semantics of the original question. The question transcribed by the large model should retain the semantic information of the original question, should not add too much invalid information, and should not reduce the information mentioned in the original question.

[0041] (2) Business keyword replacement. Business keywords are used to replace key information in the original question. For example, "foreign citizens" will be replaced with "foreign individuals". In the bank's personal foreign exchange business PDF document, the source of business keywords is the title of each page of the PDF, including: common valid identity documents, foreign exchange purchase, domestic individuals, foreign individuals, foreign exchange settlement, cross-border remittances, remittances by remittance companies, cross-border remittances, domestic foreign currency transfers, foreign currency cash deposits, foreign currency cash withdrawals, foreign currency cash reservations, foreign exchange exit permits, personal foreign exchange accounts, and common agency relationship materials. Based on the semantic information of the original question, the large model replaces the words in the original question with one or more business keywords as shown above, and finally forms a new user question.

[0042] Furthermore, step S2 is intended to traverse and locate the document. The purpose of this step is to locate the relevant document page range according to the problem after the transcription in step S1, so as to parse the document more conveniently later, which specifically includes:

[0043] (1) Traverse the document. Use the document parsing tool to traverse the entire document content and extract its title and corresponding page number. For example, in the bank's personal foreign exchange business PDF document, the page number corresponding to the title "Purchase of Foreign Exchange (Foreign Individuals)" is page 8.

[0044] (2) Keyword matching: The transcribed question output in step S1 is segmented, and the corresponding PDF title is matched using a keyword matching algorithm, and its page number range is output.

[0045] Furthermore, step S3 of the present invention is one of the key steps to achieve optimized retrieval. It uses a visually driven method to ensure that the content after segmentation retains the page layout information in the original document based on the content in the relevant document page number located in step S2, thereby achieving segmentation of complex documents. The main work of step S3 includes:

[0046] (1) Read the relevant page content. Use the document reading tool to read the page content of the corresponding range according to the provided page range.

[0047] (2) Segment the document by visual layout structure. Use complex document parsing tools to parse the document, including parsing page size, font type, bounding box type, chapters, and lists. Then, according to some heuristic rules, merge the title with the following content, merge the bullet list content, etc., to segment the complex document content. Compared with the traditional plain text segmentation method, the segmented result retains the semantic structure of the original document.

[0048] Furthermore, step S4 and step S5 are key steps to achieve text retrieval recall and retrieval enhancement, specifically including:

[0049] (1) Text embedding. Use an open source text embedding model trained on a dataset of tens of millions of Chinese sentences to encode the original user question and the text block obtained in step S3. Convert natural language into a dense vector.

[0050] (2) Build an index. Use the vector database to build an index of the text block to facilitate subsequent retrieval.

[0051] (3) Cosine similarity comparison. When selecting the top-K relevant text blocks, choose to use cosine similarity to calculate the similarity between the user question vector and the text block vector, and return the top K relevant text blocks.

[0052] Furthermore, step S6 of the present invention is the last key step of the retrieval enhancement generation method guided by business key information. Its input is the relevant text block obtained in S5 and the user's original question, and then a prompt template is designed, and finally it is handed over to the large model for reasoning output.

[0053] Example 2

[0054] The present invention proposes a retrieval enhancement generation method guided by business key information. In the specific implementation scenario, the bank's personal foreign exchange business PDF is taken as an example: based on the excellent semantic understanding ability of the large language model, the original question is transcribed using business keywords. The transcribed question contains the key information required for text retrieval. The transcribed question is then used to locate the relevant PDF page range, and then the relevant PDF page content is divided into blocks based on Open Parse's ability to process complex documents. The AI ​​development framework Langchain is then used to vectorize the text blocks and user questions, calculate the similarity between the two, select the top K most relevant text blocks, and return their content. Finally, the content of the text block and the user question are input into the large model, and a prompt template is designed for output. It is divided into 4 steps in total, and the specific process is as follows: Figure 1 As shown, it includes the following stages:

[0055] Step 1: Question transcription

[0056] In the implementation of the present invention, the question needs to be transcribed first, and the text in the original question is replaced with business keywords without changing the semantics, so as to facilitate the subsequent retrieval of PDF. The following are specific steps and examples, taking the bank's personal foreign exchange business intelligent customer service as an example:

[0057] Step 1.1: Define business keywords

[0058] In this document, the text of the PDF directory is parsed and extracted as business keywords.

[0059] Step 1.2: Tip Template Design

[0060] In order to guide the big model to better use business keywords to transcribe the original user questions, a prompt template for question transcription is designed in a Few shot manner to better utilize the capabilities of the big model. In the scenario of personal foreign exchange business in banks, the prompt template for the question transcription big model (taking Baidu Wenxin Yiyan as an example) can be:

[0061]

[0062] The business keywords in CONSTRAINTS are written according to the directory of the PDF document, because in this business scenario, the contents in the directory are different specific businesses in personal foreign exchange. Then examples are provided to implement context learning and help the large model to be easier to understand. The following is an implementation case of the prompt template designed based on the present invention in the bank's personal foreign exchange smart customer service.

[0063]

[0064] It can be seen that the paraphrased question contains the business keyword of personal foreign exchange account, which facilitates the positioning of PDF and retrieval in subsequent steps.

[0065] Step 2: Data Preprocessing

[0066] In the implementation mode of the present invention, step 2 is to process the document data, including how to locate the relevant document pages and how to divide the document into blocks. The following are the specific data processing steps, taking the bank's personal foreign exchange business PDF as an example:

[0067] Step 2.1: Traverse the document

[0068] First, use the PDF file layout analysis tool - PDFPlumber to operate the PDF third-party library, read the entire PDF file, and then extract the title corresponding to each business and its page number in the PDF document. After reading, save it into a json file so that you can directly load the data later. The data in the json file is as follows: {'Common valid identity documents': 3, 'Purchase of foreign exchange (domestic individuals)': 4, 'Settlement of foreign exchange (domestic individuals)': 5, 'Purchase of foreign exchange (foreign individuals)': 6}.

[0069] Step 2.2: Keyword matching

[0070] The question transcribed in step 1 is segmented, and then the keyword matching algorithm is used to match the title extracted from the json file in step 2.1, and its PDF page number is returned. The following is an example:

[0071] Paraphrase: I am a foreign individual and I want to purchase foreign exchange. What should I prepare?

[0072] The matched content is {'Purchase of foreign exchange (foreign individuals)':6}. That is, the answer related to the user's question is on page 6, and its title content is "Purchase of foreign exchange (foreign individuals)".

[0073] Step 2.3: Read the relevant page content

[0074] Based on the page range provided, the pypdf library in Open Parse is used to read the PDF page content of the corresponding range. This content saves the information in the original file for subsequent text segmentation.

[0075] Step 2.4: Segment the document into a visual layout structure

[0076] The document content information provided in step 2.3 is segmented into text blocks using Open Parse (a third-party library). The working principle of this implementation is to first use pdfminer.six (a third-party library) to extract the page layout information, including the position and size of elements such as text blocks and pictures. Then extract the text content and put it into a node. Furthermore, this Node also includes information such as the size of the text block, the length of the boundary, the number of words in the text, etc. Unlike other tools, it uses a visual approach to drive document analysis, rather than simply converting the document into plain text and then segmenting it, so it can better preserve the semantic structure of the original document, such as titles, chapters, and lists. Traditional text segmentation will lose this valuable information.

[0077] Step 3: Text search tools

[0078] In the embodiment of the present invention, step 3 is to perform similarity search on the divided text, with the purpose of extracting the most relevant text block information from the located relevant document page content. The text search tool selected by the present invention is Langchain. The specific Langchian search flow chart is as follows: Figure 2 The following are the specific vector search steps, taking the search for bank personal foreign exchange business intelligent customer service as an example:

[0079] Step 3.1: Vector Representation

[0080] The vector representation of this step is divided into user vector representation and text block vector representation. In order to facilitate subsequent model retrieval, the present invention needs to represent the text as a high-dimensional vector, so as to calculate the distance between vectors to represent the similarity between the two. First, the preprocessed text block in step 2 is loaded into Langchain, and then the text embedding model M3E, which is trained on a dataset of tens of millions of Chinese sentences, is used to encode the original user question and the text block obtained in step 2. Convert natural language into dense vectors.

[0081] Step 3.2: Similarity search

[0082] In this sub-step, we need to put the text vector obtained in step 3.1 into the Faiss vector database to create an index, and then use cosine similarity to represent the distance between two vectors. The Faiss vector database uses the inverted product quantization algorithm to build an index.

[0083] Specifically, there are two ideas: Inverted File (IVF) and Product Quantization (PQ). Simply put, PQ is to first define an M, which means how many segments the specified vector is divided into. Then cluster each segment, and get 256 cluster centers for each segment. Finally, get 256*M cluster centers based on all vectors. Then assign all vectors. Taking a 128-dimensional vector as an example, first cut the vector into M segments, and then each segment of the vector can find the nearest cluster center ID, so that a 128-dimensional vector becomes an M-dimensional vector, completing the compression of the vector. The idea of ​​IVF is to lock the global traversal into a subspace traversal, thereby discarding unnecessary global calculations and sorting. The specific approach is to first perform K-Means clustering on all vectors, divide them into K clusters, and then reference PQ to calculate the distance.

[0084] Generally speaking, when constructing indexes and queries, the Faiss vector database greatly improves the speed of vector retrieval. Taking the bank's personal foreign exchange business PDF as an example, the text retrieved based on the user's question is expressed as follows:

[0085]

[0086]

[0087] In the specific implementation of the present invention, K is selected to be 3, that is, the top three text blocks with the highest similarity are selected and the contents thereof are returned. Each relevant document is a text block returned by the search, and it can be seen that the most relevant Document 1 contains the answer required for the question.

[0088] Step 4: Answer reply

[0089] In the implementation of the present invention, step 4 is the final answer output. Using the semantic understanding and generation capabilities of the large model, a prompt template is designed based on the user's original question and the relevant text block obtained in step 3, and input into the large model to obtain the final output. The prompt template designed by the present invention is as follows.

[0090]

[0091]

[0092] After the above four steps, the retrieval enhancement generation method guided by business key information can be realized.

[0093] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

[0094] The above embodiments are only used to illustrate the design ideas and features of the present invention, and their purpose is to enable those skilled in the art to understand the content of the present invention and implement it accordingly. The protection scope of the present invention is not limited to the above embodiments. Therefore, any equivalent changes or modifications made based on the principles and design ideas disclosed by the present invention are within the protection scope of the present invention.

Claims

1. A search enhancement generation method based on business key information guidance, characterized in that: The following steps are involved: S1: Question transcription: Design prompt templates based on the business keywords appearing in the document directory, and transcribe the questions by combining the designed prompt templates with the original user questions and inputting them into the big model; S2: Locate relevant pages: read the document, extract the page range corresponding to each title according to the titles appearing in the document, and then match the relevant pages according to the transcribed questions prepared in step S1; S3: Text segmentation: reading the corresponding document page through the relevant page number range prepared in step S2, and then segmenting the text into blocks using a document segmentation tool; S4: vector representation: the text and the user's original question divided in step S3 are encoded using a text embedding model; S5: Similarity search: input the text blocks encoded in step S3 and step S4 and the encoded original user questions into the large model, use the vector database to create an index, and then use the text search tool to search; S6: Large model output: Combine the user's original question and the most relevant text block obtained in step S5 to design a prompt template, and finally use the large model for final output.

2. The retrieval enhancement generation method based on business key information guidance according to claim 1 is characterized in that: In step S1, the prompt template design for question transcription includes: Preserve the semantics of the original question: The question transcribed by the large model retains the semantic information of the original question; Business keyword replacement: Use business keywords to replace the key information that appears in the original question.

3. The retrieval enhancement generation method based on business key information guidance according to claim 1 is characterized in that: In step S2, locating the relevant page includes: Traverse the document: Use the document parsing tool to traverse the entire document content and extract its title and corresponding page number; Keyword matching: The transcribed question output in step S1 is segmented, and the corresponding title is matched using a keyword matching algorithm, and its page number range is output.

4. The retrieval enhancement generation method based on business key information guidance according to claim 1 is characterized in that: In step S3, text segmentation includes: Read the relevant page content: according to the provided page range, use the document reading tool to read the page content of the corresponding range; Segment documents by visual layout structure: Use visually driven document segmentation tools to parse the visual layout structure of a page, including page size, font type, bounding box type, and then divide the text into blocks.

5. The retrieval enhancement generation method based on business key information guidance according to claim 1 is characterized in that: In step S4, the model used for vector representation is a pre-trained text embedding model, which is trained on a dataset of tens of millions of Chinese sentences to convert natural language into dense vectors. The model is used to vectorize text blocks and original questions of users.

6. The method for enhancing retrieval based on business key information guidance according to claim 1, characterized in that: In step S5, similarity search includes: Build index: Use vector database to build index of text blocks; Cosine similarity comparison: When selecting the Top-K relevant text blocks, choose to use cosine similarity to calculate the similarity between the user question vector and the text block vector, and return the top K relevant text blocks.

7. The retrieval enhancement generation method based on business key information guidance according to claim 1 is characterized in that: In step S6, the output of the large model needs to include in the designed prompt template: the user question and the contents of the first K relevant text blocks.