RAG retrieval optimization method and system based on title enhancement and intent recognition
Through methods based on title enhancement and intent recognition, high-frequency words and hierarchical titles are extracted, documents are segmented and stored, and intent recognition is combined to narrow the search scope. This solves the problem of difficulty in determining the length of document segmentation and the decrease in retrieval speed in RAG retrieval, and improves improve the accuracy and speed of retrieval.
Patent Information
- Application Number
- CN202410909730.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-07-09
AI Technical Summary
When existing RAG retrieval technology processes documents containing a large number of titles, the segmentation length is difficult to determine, resulting in information loss or redundancy, affecting the accuracy of the results. At the same time, as the number of documents and scene types increases, the retrieval speed and accuracy decrease.
Using methods based on title enhancement and intent recognition, we build a scene knowledge base index by extracting high-frequency words, identify and classify titles, segment documents according to title levels and perform vectorized storage, and combine intent recognition to narrow the search scope and improve the accuracy of retrieval. and speed.
It improves the flexibility and semantics of document segmentation, reduces the impact of irrelevant knowledge, improves the diversity and accuracy of large model answers, shortens retrieval time, and enhances the accuracy of retrieval results.
Smart Images

Figure CN118467681B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of retrieval optimization, and in particular relates to a RAG retrieval optimization method and system based on title enhancement and intent recognition. Background Art
[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.
[0003] In RAG intelligent question and answer, the uploaded documents need to be segmented and vectorized for storage. At present, the general practice of document segmentation is mostly fixed-length, fixed-paragraph or sentence-format segmentation methods. Since most documents contain a large number of titles, these methods will ignore the title's role in summarizing and commanding the content when segmenting. At the same time, the segmentation length is difficult to determine and has poor flexibility. If the length is too short, it will lead to information loss and semantic fragmentation. If the length is too long, it will result in too much redundant data being returned, affecting the accuracy of the results. At the same time, during the RAG retrieval process, as the number of documents and the types of scenarios uploaded by users in the knowledge base increase, the speed and accuracy of RAG retrieval also decrease. Summary of the invention
[0004] In order to solve the above problems, the present invention proposes a RAG retrieval optimization method and system based on title enhancement and intent recognition. The present invention starts from the two aspects of document segmentation and storage and question retrieval of RAG, performs more logical and semantic text block segmentation and realizes more accurate and fast text block retrieval through the segmentation of document scenarios.
[0005] According to some embodiments, a first solution of the present invention provides a RAG retrieval optimization method based on title enhancement and intent recognition, which adopts the following technical solutions:
[0006] RAG retrieval optimization method based on title enhancement and intent identification includes:
[0007] Extract high-frequency words from the document and combine them with high-frequency words in the same scene knowledge base to form a scene knowledge base index;
[0008] Identify titles in documents, determine whether titles conform to the title format, and grade titles;
[0009] Split documents according to title level and store them in vector form;
[0010] After the question is vectorized, the similarity is calculated with the scene knowledge base index to determine the scene knowledge base where the document is located, and the document is retrieved in blocks and returned to the large model to generate the answer.
[0011] Furthermore, high-frequency words in the document are extracted, and high-frequency words in the same scene knowledge base are combined to form a scene knowledge base index, specifically:
[0012] Divide the documents in the local knowledge base into scenarios according to the different contents of the documents and store them in the scenario knowledge base of the corresponding scenarios;
[0013] Segment the documents in the scenario knowledge base, filter out stop words, and sort the frequencies of occurrence of the words. Extract a set number of high-frequency words based on the sorting results to obtain a list of high-frequency words in different scenarios.
[0014] The high-frequency vocabulary lists in different scenarios are vectorized to obtain the index of the scenario knowledge base in the corresponding scenario.
[0015] Furthermore, the title in the document is identified, whether the title conforms to the title format is determined, and the title is graded, specifically:
[0016] Select sentences in the document that may become titles to form a title fuzzy set;
[0017] Based on the title fuzzy set, the titles are screened according to the length of the sentence and the ending punctuation;
[0018] Analyze the title and determine the title level.
[0019] Furthermore, the document is segmented according to the title level and vectorized and stored, specifically:
[0020] Segment the document based on line breaks and filter out paragraphs with a low character ratio to obtain segmented paragraphs;
[0021] Each segmented paragraph is judged. If the segmented paragraph is not a title, it is segmented by comparing the length of the paragraph with the threshold length set for the paragraph.
[0022] If the segmented paragraph is a title, first segment it based on the length of the paragraph and compare it with the threshold length of the paragraph, and add the content description of the title before the segmented text block;
[0023] All the segmented text blocks are vectorized to obtain text block vectors, which are stored in the corresponding scene knowledge base.
[0024] Furthermore, the question is vectorized and then similarity is calculated with the scene knowledge base index to determine the scene knowledge base where the document is located, and the document is retrieved in blocks and returned to the large model to generate an answer, specifically:
[0025] Vectorize the user's question to get the user's question vector, calculate the cosine similarity between the user's question vector and the text block vector of each scenario knowledge base, and the scenario knowledge base corresponding to the text block vector with the highest similarity is the target scenario knowledge base;
[0026] Calculate the cosine similarity between the user question vector and all text block vectors in the target scenario knowledge base, and consider the text blocks with similarity higher than the set threshold as the knowledge most relevant to the user question;
[0027] The text block corresponding to the knowledge most relevant to the user's question is returned to the large model to generate an answer.
[0028] Furthermore, the sentences in the selected document that may become titles constitute a title fuzzy set, which is specifically:
[0029] The first type of title is the one that begins with brackets and square brackets and contains numbers or Chinese characters such as one, two, and three.
[0030] The sentences that start with numbers, dots, and numbers are the second type of titles;
[0031] The sentences are short and do not end with punctuation marks, which are the third type of titles.
[0032] Furthermore, the segmentation is performed by comparing the length of the paragraph with a threshold length set for the paragraph, specifically:
[0033] If the length of a paragraph is between the specified lengths t1 and t2, the paragraph is treated as a separate text block;
[0034] If the length of a paragraph is less than t1, merge the paragraph with the following paragraph;
[0035] If the length of the paragraph is greater than t2, the paragraph is segmented again into a length between t1 and t2 according to the period.
[0036] According to some embodiments, the second solution of the present invention provides a RAG retrieval optimization system based on title enhancement and intent recognition, which adopts the following technical solutions:
[0037] RAG search optimization system based on title enhancement and intent recognition, including:
[0038] An index building module, configured to extract high-frequency words in a document, and combine high-frequency words in the same scene knowledge base to form a scene knowledge base index;
[0039] A title grading module is configured to identify the title in the document, determine whether the title conforms to the title format, and grade the title;
[0040] The document segmentation module is configured to segment documents according to the title level and perform vectorized storage;
[0041] The retrieval and return module is configured to vectorize the question and calculate the similarity with the scene knowledge base index, determine the scene knowledge base where the document is located, retrieve the document blocks and return them to the large model to generate an answer.
[0042] According to some embodiments, a third aspect of the present invention provides a computer-readable storage medium.
[0043] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps in the RAG retrieval optimization method based on title enhancement and intent recognition as described in the first aspect above.
[0044] According to some embodiments, a fourth aspect of the present invention provides a computer device.
[0045] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps in the RAG retrieval optimization method based on title enhancement and intent recognition as described in the first aspect above are implemented.
[0046] Compared with the prior art, the present invention has the following beneficial effects:
[0047] The present invention provides two RAG retrieval optimization methods, namely title enhancement and intent recognition. The segmentation method of title enhancement improves the problem of ignoring the connection between title and text in the conventional segmentation method, making the information stored in the knowledge base richer and the results of the large model answers more diverse; intent recognition narrows the scope of text retrieval through scene segmentation, reduces the time required for retrieval, and makes the retrieved text blocks more accurate, reducing the impact of irrelevant knowledge on the retrieval results, making the summary of the large model more accurate. In short, these two methods are two very valuable RAG retrieval improvement methods.
[0048] The title enhancement method proposed in the present invention extracts the title in the document to segment the document, returns the text block that meets the required length and semantics, and improves the accuracy of RAG retrieval. The intent recognition method proposed in the present invention constructs different scene knowledge bases to classify documents. When searching, the intent of the question is first recognized to obtain the scene knowledge base corresponding to the document, and the text is searched after the document scope is narrowed, thereby improving the speed and accuracy of RAG retrieval. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0050] Figure 1 is a flow chart of a RAG retrieval optimization method based on title enhancement and intent recognition in an embodiment of the present invention;
[0051] Figure 2 It is a structural diagram of a RAG retrieval optimization system based on title enhancement and intent recognition in an embodiment of the present invention. DETAILED DESCRIPTION
[0052] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0053] It should be noted that the following detailed descriptions are all illustrative and intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.
[0054] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0055] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.
[0056] Terminology explanation:
[0057] RAG: Retrieval-augmented generation,overcoming the hallucination problem of large models by retrieving local knowledge.
[0058] Langchain: An open source framework for combining large models with external data sources.
[0059] Jieba: An open source library for Chinese text segmentation.
[0060] Knowledge base: A vector database that provides local knowledge for RAG.
[0061] Scenario knowledge base: The knowledge base is divided into sub-knowledge bases for different scenarios based on the different contents of the documents stored in the knowledge base.
[0062] Embodiment 1
[0063] like Figure 1As shown, this embodiment provides a RAG retrieval optimization method based on title enhancement and intent recognition. This embodiment uses the method applied to a server as an example for illustration. It can be understood that the method can also be applied to a terminal, and can also be applied to a terminal, a server, and a system, and is implemented through the interaction between the terminal and the server. The server can be an independent physical server, or a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network servers, cloud communications, middleware services, domain name services, security services CDN, and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in this application. In this embodiment, the method includes the following steps:
[0064] Extract high-frequency words from the document and combine them with high-frequency words in the same scene knowledge base to form a scene knowledge base index;
[0065] Identify titles in documents, determine whether titles conform to the title format, and grade titles;
[0066] Split documents according to title level and store them in vector form;
[0067] After the question is vectorized, the similarity is calculated with the scene knowledge base index to determine the scene knowledge base where the document is located, and the document is retrieved in blocks and returned to the large model to generate the answer.
[0068] Extract high-frequency words from the document and combine them with high-frequency words in the same scene knowledge base to form a scene knowledge base index. Specifically:
[0069] Divide the documents in the local knowledge base into scenarios according to the different contents of the documents and store them in the scenario knowledge base of the corresponding scenarios;
[0070] Segment the documents in the scenario knowledge base, filter out stop words, and sort the frequencies of occurrence of the words. Extract a set number of high-frequency words based on the sorting results to obtain a list of high-frequency words in different scenarios.
[0071] The high-frequency vocabulary lists in different scenarios are vectorized to obtain the index of the scenario knowledge base in the corresponding scenario.
[0072] Create a scenario knowledge base. In the process of building a RAG project, a local knowledge base is first needed to store the documents needed by users as local knowledge to overcome the illusion problem of large models. An innovation of the present invention is to store documents by classifying the knowledge base into more fine-grained scenarios. By storing high-frequency words in the documents in each scenario knowledge base and combining intent recognition, the retrieval scope can be narrowed during the retrieval process to improve retrieval efficiency and accuracy. The specific implementation steps of scenario classification are as follows:
[0073] Create a scenario knowledge base and classify documents, that is, perform scenario classification. The documents stored in the local knowledge of the project are classified into different scenarios according to the content of the documents, such as financial scenarios, medical scenarios, biological scenarios, etc., and the documents are uploaded and stored in different scenario knowledge bases. For example, if the local knowledge base of project A is a, classify it according to the content of the document and divide the knowledge base a into scenario knowledge bases s1, s2, s3, ...;
[0074] Extract high-frequency words. Segment the uploaded documents, use jieba to segment the documents under the scene knowledge base, and filter out stop words such as prepositions, conjunctions, and pronouns that have a high probability of appearing in the text but have no practical meaning. Sort the frequency of occurrence of the filtered words, and add the 20 words with the highest frequency to the high-frequency vocabulary list of the scene library. For example, there are two documents c1 and c2 in the scene knowledge base s1, and the high-frequency vocabulary list of c1 is [soil; rock layer; ...], and the high-frequency vocabulary list of c2 is [geology; crust; ...], then the high-frequency vocabulary list of the scene knowledge base s1 is [soil; rock layer; geology; crust; ...];
[0075] Build a scene knowledge base index. Store high-frequency words to build an index, and use the embedding model to vectorize the high-frequency word list of the scene knowledge base obtained in the previous step as the index of the scene knowledge base. For example, the high-frequency word list of s1 [soil; rock layer; geology; crust; ...] is vectorized to obtain [-0.031262476, 0.0077232053, -0.06657475, 0.009407192, ...], which is used as the scene index i1 of s1;
[0076] The above scene classification process obtains the index of the scene knowledge base, which serves as the basis for intent recognition during subsequent retrieval.
[0077] The title in the document is identified, whether the title conforms to the title format is determined, and the title is graded, specifically:
[0078] Select sentences in the document that may become titles to form a title fuzzy set;
[0079] Based on the title fuzzy set, select the title according to the length of the sentence and the ending punctuation mark;
[0080] Analyze the title to determine the title level.
[0081] Select the sentences in the document that may become titles to form a title fuzzy set, specifically:
[0082] Sentences starting with parentheses and brackets, and containing numbers or Chinese characters such as one, two, etc. as the beginning are the first type of titles;
[0083] Sentences directly starting with numbers and dots and numbers are the second type of titles;
[0084] Sentences with short length and not ending with punctuation marks are the third type of titles.
[0085] Extract and classify the document title, that is, extract the title in the document and determine the title level. During the process of uploading and storing the document in the local knowledge base, due to the limited length of the text input into the large model, large paragraphs of text often need to be segmented into text blocks. Another innovation point of the present invention lies in the optimization of the text segmentation method, that is, by identifying the titles in the document and storing the text blocks with the help of the titles to restore the document structure. The specific steps are as follows:
[0086] First, match the sentences in the document that may be titles according to the rules. The specific rules are: Type 1: Starting with (), [], [], and containing numbers or Chinese characters such as one, two, etc. as the beginning, such as (one), (1), one, etc.; Type 2: Or sentences directly starting with numbers.digits, such as 1.1, 1.1.2, etc.; Type 3: If a sentence is too short and does not end with punctuation marks such as commas and periods, it can also be used as a title.
[0087] Screen the sentences that may be titles. Sentences ending with punctuation marks such as periods and question marks are not titles, and sentences with a length exceeding the specified character length, such as 20 characters, are not titles.
[0088] Judge the title level. If it is a type 1 title, then judge whether its structure is the same as that of the previous title mark. If it is the same, it is at the same level as the previous title; if it is different, it is a sub - title of the previous title. For example, (two) and (one) are at the same level, and (two) is a sub - title of one; If it is a type 2 title, the title level can be judged by extracting the number of digits in the title mark. For example, 1.1 is a second - level title, and 1.1.1 is a third - level title.
[0089] Segment the document according to the title level and perform vectorized storage, specifically:
[0090] Segment the document based on line breaks and filter out paragraphs with a low character ratio to obtain segmented paragraphs;
[0091] Each segmented paragraph is judged. If the segmented paragraph is not a title, it is segmented by comparing the length of the paragraph with the threshold length set for the paragraph.
[0092] If the segmented paragraph is a title, first segment it based on the length of the paragraph and compare it with the threshold length of the paragraph, and add the content description of the title before the segmented text block;
[0093] All the segmented text blocks are vectorized to obtain text block vectors, which are stored in the corresponding scene knowledge base.
[0094] Segment the document based on the paragraph sentence format and title. Segment the document based on the title. First, segment the document based on the line break ( / n), and filter out paragraphs with a low character ratio and no meaning to the document content. Then judge each segmented paragraph;
[0095] If the paragraph w is not a title: if the length of w is between the specified lengths t1 and t2, w is treated as a separate text block; if the length of w is less than t1, w is merged with the following paragraph; if the length of w is greater than t2, w is split again between t1 and t2 according to the period;
[0096] If the paragraph w1 is a title, and the title is the lowest level title, the paragraph after it will be segmented in the same way as in the previous step, and the description of the title will be added before the segmented text block. For example, if the content of w1 is {1.1.1, soil types}, which is the lowest level 3 title, and the content of w2 after w1 is {soil types are divided into: black soil, loess...}, which is not a title, then the final generated text block result w3 is {this part is about soil types: soil types are divided into: black soil, loess...};
[0097] Use the same embedding model to vectorize all the segmented text blocks and store them in the corresponding scene knowledge base. For example, the vectorization result e of w3 is [-0.036425743, 0.011724075, -0.044000726, 0.037245207, …], which is stored in the scene knowledge base s1.
[0098] The question is vectorized and then similarity is calculated with the scene knowledge base index to determine the scene knowledge base where the document is located, and the document is retrieved in blocks and returned to the large model to generate an answer, specifically:
[0099] Vectorize the user's question to get the user's question vector, calculate the cosine similarity between the user's question vector and the text block vector of each scenario knowledge base, and the scenario knowledge base corresponding to the text block vector with the highest similarity is the target scenario knowledge base;
[0100] Calculate the cosine similarity between the user question vector and all text block vectors in the target scenario knowledge base, and consider the text blocks with similarity higher than the set threshold as the knowledge most relevant to the user question;
[0101] The text block corresponding to the knowledge most relevant to the user's question is returned to the large model to generate an answer.
[0102] Use intent recognition to retrieve documents and return them, use intent recognition to retrieve questions, and determine the scenario knowledge base. Use the same embedding model mentioned in the above steps to vectorize the user's question, and calculate the cosine similarity between the obtained vector and the vector of each scenario knowledge base. The one with the highest similarity is the intent of the user's question. For example, if the user's question q is {What types of soil are there?}, vectorize q to get q1[-0.045602992, 0.0049413736, -0.05299673,0.027971352, …], the similarity between q1 and the scenario knowledge base index i1 of s1 is 0.85, which is the maximum similarity of all scenarios, then the target scenario knowledge base of question q is s1.
[0103] Determine similar text blocks. Calculate the cosine similarity between q1 and all text block vectors in the scene knowledge base s1. The text blocks with higher similarity are the knowledge most relevant to the user's question.
[0104] The text block is returned to the large model to generate the answer. The result is {According to your question, soil types are divided into black soil, loess, etc.}.
[0105] Embodiment 2
[0106] like Figure 2 As shown, this embodiment provides a RAG retrieval optimization system based on title enhancement and intent recognition, including:
[0107] An index building module, configured to extract high-frequency words in a document, and combine high-frequency words in the same scene knowledge base to form a scene knowledge base index;
[0108] A title grading module is configured to identify the title in the document, determine whether the title conforms to the title format, and grade the title;
[0109] The document segmentation module is configured to segment documents according to the title level and perform vectorized storage;
[0110] The retrieval and return module is configured to vectorize the question and calculate the similarity with the scene knowledge base index, determine the scene knowledge base where the document is located, retrieve the document blocks and return them to the large model to generate an answer.
[0111] The examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiment 1. It should be noted that the above modules as part of the system can be executed in a computer system such as a set of computer executable instructions.
[0112] The description of each embodiment in the above embodiments has different emphases. For parts not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0113] The proposed system can be implemented in other ways. For example, the system embodiment described above is only illustrative, and the division of the modules is only a logical function division. In actual implementation, there may be other division methods, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed.
[0114] Embodiment 3
[0115] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps in the RAG retrieval optimization method based on title enhancement and intent recognition as described in the above-mentioned embodiment 1 are implemented.
[0116] Embodiment 4
[0117] This embodiment provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps in the RAG retrieval optimization method based on title enhancement and intent recognition as described in the first embodiment above are implemented.
[0118] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of hardware embodiments, software embodiments, or embodiments combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program code.
[0119] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0120] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0121] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0122] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0123] Although the above describes the specific implementation mode of the present invention in conjunction with the accompanying drawings, it is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art on the basis of the technical solution of the present invention without creative work are still within the scope of protection of the present invention.
Claims
1. A RAG retrieval optimization method based on title enhancement and intent recognition, characterized in that: include: Extract high-frequency words from the document and combine them with high-frequency words in the same scene knowledge base to form a scene knowledge base index; The high-frequency words in the extracted documents are combined with the high-frequency words in the same scene knowledge base to form a scene knowledge base index, specifically: Divide the documents in the local knowledge base into scenarios according to the different contents of the documents and store them in the scenario knowledge base of the corresponding scenarios; Segment the documents in the scenario knowledge base, filter out stop words, and sort the frequencies of occurrence of the words. Extract a set number of high-frequency words based on the sorting results to obtain a list of high-frequency words in different scenarios. Vectorize the high-frequency vocabulary lists in different scenarios to obtain the index of the scenario knowledge base in the corresponding scenario; Identify titles in documents, determine whether titles conform to the title format, and grade titles; Split documents according to title level and store them in vector form; The document is segmented according to the title level and vectorized and stored, specifically: Segment the document based on line breaks and filter out paragraphs with a low character ratio to obtain segmented paragraphs; Each segmented paragraph is judged. If the segmented paragraph is not a title, it is segmented by comparing the length of the paragraph with the threshold length set for the paragraph. If the segmented paragraph is a title, first segment it based on the length of the paragraph and compare it with the threshold length of the paragraph, and add the content description of the title before the segmented text block; All the segmented text blocks are vectorized to obtain text block vectors, which are stored in the corresponding scene knowledge base; After the question is vectorized, the similarity is calculated with the scene knowledge base index to determine the scene knowledge base where the document is located, and the document is retrieved in blocks and returned to the large model to generate the answer.
2. The RAG retrieval optimization method based on title enhancement and intent recognition as claimed in claim 1, characterized in that: The title in the document is identified, whether the title conforms to the title format is determined, and the title is graded, specifically: Select sentences in the document that may become titles to form a title fuzzy set; Based on the title fuzzy set, the titles are screened according to the length of the sentence and the ending punctuation; Analyze the title and determine the title level.
3. The RAG retrieval optimization method based on title enhancement and intent recognition as claimed in claim 1, characterized in that: The question is vectorized and then similarity is calculated with the scene knowledge base index to determine the scene knowledge base where the document is located, and the document is retrieved in blocks and returned to the large model to generate an answer, specifically: Vectorize the user's question to get the user's question vector, calculate the cosine similarity between the user's question vector and the text block vector of each scenario knowledge base, and the scenario knowledge base corresponding to the text block vector with the highest similarity is the target scenario knowledge base; Calculate the cosine similarity between the user question vector and all text block vectors in the target scenario knowledge base, and consider the text blocks with similarity higher than the set threshold as the knowledge most relevant to the user question; The text block corresponding to the knowledge most relevant to the user's question is returned to the large model to generate an answer.
4. The RAG retrieval optimization method based on title enhancement and intent recognition as claimed in claim 2, characterized in that: The sentences in the selected document that may become titles constitute a title fuzzy set, which is specifically: The first type of title is the one that begins with brackets and square brackets and contains numbers or Chinese characters such as one, two, and three. The sentences that start with numbers, dots, and numbers are the second type of titles; The sentences are short and do not end with punctuation marks, which are the third type of titles.
5. The RAG retrieval optimization method based on title enhancement and intent recognition as claimed in claim 1, characterized in that: The segmentation is performed by comparing the length of the paragraph with the threshold length set for the paragraph, specifically: If the length of a paragraph is between the specified lengths t1 and t2, the paragraph is treated as a separate text block; If the length of a paragraph is less than t1, merge the paragraph with the following paragraph; If the length of the paragraph is greater than t2, the paragraph is segmented again into a length between t1 and t2 according to the period.
6. RAG retrieval optimization system based on title enhancement and intent recognition, characterized by: include: An index building module, configured to extract high-frequency words in a document, and combine high-frequency words in the same scene knowledge base to form a scene knowledge base index; The high-frequency words in the extracted documents are combined with the high-frequency words in the same scene knowledge base to form a scene knowledge base index, specifically: Divide the documents in the local knowledge base into scenarios according to the different contents of the documents and store them in the scenario knowledge base of the corresponding scenarios; Segment the documents in the scenario knowledge base, filter out stop words, and sort the frequencies of occurrence of the words. Extract a set number of high-frequency words based on the sorting results to obtain a list of high-frequency words in different scenarios. Vectorize the high-frequency vocabulary lists in different scenarios to obtain the index of the scenario knowledge base in the corresponding scenario; A title grading module is configured to identify the title in the document, determine whether the title conforms to the title format, and grade the title; The document segmentation module is configured to segment documents according to the title level and perform vectorized storage; The document is segmented according to the title level and vectorized and stored, specifically: Segment the document based on line breaks and filter out paragraphs with a low character ratio to obtain segmented paragraphs; Each segmented paragraph is judged. If the segmented paragraph is not a title, it is segmented by comparing the length of the paragraph with the threshold length set for the paragraph. If the segmented paragraph is a title, first segment it based on the length of the paragraph and compare it with the threshold length of the paragraph, and add the content description of the title before the segmented text block; All the segmented text blocks are vectorized to obtain text block vectors, which are stored in the corresponding scene knowledge base; The retrieval and return module is configured to vectorize the question and calculate the similarity with the scene knowledge base index, determine the scene knowledge base where the document is located, retrieve the document blocks and return them to the large model to generate an answer.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps in the RAG retrieval optimization method based on title enhancement and intent recognition as described in any one of claims 1 to 5 are implemented.
8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps in the RAG retrieval optimization method based on title enhancement and intent recognition as described in any one of claims 1 to 5 are implemented.
