Retrieval method and system based on semantic partitioning, electronic equipment and storage medium
Through the search method based on semantic chunking, the problems of inaccurate search, incompleteness, mismatch of block settings and excessive noise in the prior art are solved, and more accurate and comprehensive search results and more complete answer generation are achieved.
Patent Information
- Application Number
- CN202411740918.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-04-08
AI Technical Summary
Existing search-based Q&A techniques have challenges in search accuracy, comprehensiveness, matching block settings and excessive noise, resulting in incomplete answers or deviations from the topic.
Using a search method based on semantic chunking, by segmenting text materials into sentences and encoding them into vectors, cosine similarity between adjacent sentences is calculated, block boundaries are determined, and block vectors are stored in the vector database. Use the LLM model to rewrite user queries, search related blocks, generate correlation scores, remove low-rating blocks, and use the BM25 searcher to search and reorder keywords to finally generate answers.
It improves the relevance and accuracy of search results, optimizes the organization and search efficiency of information, reduces the impact of noisy information, and ensures the integrity of answers and the consistency of topics.
Smart Images

Figure CN119782460A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of artificial intelligence technology, and specifically relates to a retrieval method, system, electronic device and storage medium based on semantic segmentation. Background Art
[0002] In the field of natural language processing, Retrieval-Augmented Generation (RAG) technology, as an important branch of information retrieval and text understanding, has received increasing attention from academia and industry in recent years. RAG technology cleverly integrates the two functions of retrieval and generation, aiming to accurately assist the generation of answers by efficiently retrieving relevant documents.
[0003] Although RAG technology has shown great potential and application prospects, the current implementation version still faces many challenges. The first problem is the accuracy and comprehensiveness of retrieval. Due to the massiveness and complexity of the information world, how to quickly and accurately retrieve documents that are highly relevant to the question from a huge knowledge base is still a difficult problem that needs to be solved. In addition, the mismatch between the block setting of the retrieval results and the user's query requirements often leads to incomplete or off-topic answers.
[0004] At the same time, too much noise is also a major problem of current RAG technology. In the process of information retrieval, there are often a large number of documents that are irrelevant to the question or have weak relevance. This noise information not only increases the complexity of answer generation, but also may mislead the judgment of the model, thus affecting the accuracy and reliability of the final answer. Summary of the invention
[0005] The purpose of the embodiments of the present invention is to provide a retrieval method, system, electronic device and storage medium based on semantic segmentation, which is used to fully or at least partially solve the technical problems of inaccurate retrieval, incomplete retrieval, mismatched segmentation settings and excessive noise in the above-mentioned prior art.
[0006] In a first aspect, an embodiment of the present application provides a retrieval method based on semantic segmentation, comprising: Split the text material into sentences and encode each sentence into a vector; Calculate the cosine similarity between adjacent sentences, determine the block boundary according to the cosine similarity threshold, merge multiple sentences belonging to the same block boundary into blocks, and encode each block into a vector and store it in the vector database; The LLM model is used to rewrite the user input query and retrieve relevant blocks from the vector database. The LLM model generates an initial relevance score for each block and removes blocks below the score threshold to obtain the target block. The BM25 searcher is used to search for keywords in the target block, the results of the keyword search are reordered and combined with the target block into a context, and the user input query and context are sent to the LLM model to generate an answer.
[0007] Optionally, the cosine similarity between adjacent sentences is calculated according to the following formula: ; In the formula, A and B represent adjacent sentences, A∙B represents the dot product between A and B vectors, and |A||B| represents the product of the modules of A and B vectors.
[0008] Optionally, determining the block boundary based on a cosine similarity threshold includes: A cosine similarity threshold is set in advance. When the cosine similarity between adjacent sentences is lower than the cosine similarity threshold, it represents the beginning of a new topic, thereby determining the boundary of the block.
[0009] Optionally, the user input query is rewritten using the LLM model, and relevant blocks are retrieved from the vector database. The LLM model generates an initial relevance score for each block, and blocks below a score threshold are removed to obtain a target block, including: Using the LLM model, the original query input by the user is rewritten according to the prompts, and the relevant blocks are retrieved from the vector database; Using the cosine similarity metric, duplicate or highly similar blocks are identified and removed, and the remaining blocks are sorted according to their similarity to the query to prioritize blocks with high similarity; Using the LLM model to assign an initial relevance score to each block based on the prompt, and give a reflective score based on subsequent user feedback, and using an independent critic LLM model to assign a critic score to each block, and obtain the target relevance score by averaging the initial score, reflective score, and critic score; The LLM model is used to analyze the distribution of target relevance scores and recommend an optimal scoring threshold. Blocks with scores higher than the scoring threshold are retained to obtain the target blocks.
[0010] Optionally, the bge-reranker-large model is used to rerank the results of keyword retrieval and the target block into context.
[0011] Optionally, the bge-reranker-large model is based on the RetroMAE pre-trained model and uses an asymmetric encoder-decoder structure. The encoder part consists of 12 layers of Transformer and the decoder part has one layer of Transformer. During the pre-training stage, the encoder masks the input text by 15%~30%, and the decoder masks the input text by 50%~70% to increase the complexity of the task.
[0012] Optionally, after calculating the cosine similarity between adjacent sentences, determining the block boundary according to the cosine similarity threshold, merging multiple sentences belonging to the same block boundary into blocks, and encoding each block into a vector and storing it in the vector database, the semantic block-based retrieval method further includes: Initialize a retriever, wherein the retriever is used to retrieve the block with the highest relevance by comparing the vector of the user input query with the block vectors stored in the vector database.
[0013] In a second aspect, the embodiment of the present application further provides a retrieval system based on semantic segmentation, comprising: A segmentation unit for segmenting the text material into multiple sentences and encoding each sentence into a vector; A calculation unit, used for calculating the cosine similarity between adjacent sentences, determining the block boundary according to the cosine similarity threshold, merging multiple sentences belonging to the same block boundary into blocks, and encoding each block into a vector and storing it in a vector database; The deduplication unit is used to rewrite the user input query using the LLM model and retrieve the relevant blocks in the vector database. The LLM model generates an initial relevance score for each block and removes the blocks below the score threshold to obtain the target block. The re-ranking unit is used to use the BM25 searcher to retrieve keywords in the target block, re-rank the results of the keyword search and the target block to form a context, and send the user input query and context to the LLM model to generate an answer.
[0014] In a third aspect, an embodiment of the present application further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned semantic block-based retrieval method when executing the program.
[0015] In a fourth aspect, an embodiment of the present application further provides a storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above-mentioned semantic segmentation-based retrieval method are implemented.
[0016] It can be seen from the above technical solutions that the present invention has the following advantages: In the semantic block-based retrieval method, system, electronic device and storage medium provided by the present application, by performing sentence segmentation to generate a numerical vector representation of a sentence and calculating the cosine similarity between consecutive sentence vectors, the beginning of a new topic can be more accurately identified, thereby determining the boundary of the block, and by setting the maximum length of the block, the organization of information and the retrieval efficiency are optimized, thereby ensuring the relevance and accuracy of the retrieval results. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solution of the present invention, the accompanying drawings required for use in the description will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0018] Figure 1 A flowchart of a retrieval method based on semantic segmentation provided by an embodiment of the present invention; Figure 2 A flowchart of obtaining a target block by using an LLM model provided by an embodiment of the present invention; Figure 3 A detailed flow chart of a retrieval method based on semantic segmentation provided by an embodiment of the present invention; Figure 4 A schematic diagram of the structure of a retrieval system based on semantic segmentation provided by an embodiment of the present invention; Figure 5 A schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0019] In the detailed description below, various embodiments of the present disclosure will be described more fully. The present disclosure may have various embodiments, and adjustments and changes may be made therein. However, it should be understood that there is no intention to limit the various embodiments of the present disclosure to the specific embodiments disclosed herein, but rather the present disclosure should be understood to cover all adjustments, equivalents and / or alternatives that fall within the spirit and scope of the various embodiments of the present disclosure.
[0020] Hereinafter, the terms "include" or "may include" that may be used in various embodiments of the present disclosure indicate the presence of the disclosed functions or operations, and do not limit the addition of one or more functions or operations. In addition, as used in various embodiments of the present disclosure, the terms "include", "have" and their cognates are intended only to indicate specific features, numbers, steps, operations, or combinations of the foregoing items, and should not be understood as first excluding the presence of one or more other features, numbers, steps, operations, or combinations of the foregoing items or the possibility of adding one or more features, numbers, steps, operations, or combinations of the foregoing items.
[0021] In various embodiments of the present disclosure, the expression "or" or "at least one of A or / and B" includes any combination or all combinations of the words listed at the same time. For example, the expression "A or B" or "at least one of A or / and B" may include A, may include B, or may include both A and B.
[0022] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0023] See also Figure 1 FIG. 1 is a flowchart of a retrieval method based on semantic segmentation in a specific embodiment, comprising the following execution steps: Step 100: Segment the text material into multiple sentences and encode each sentence into a vector.
[0024] Specifically, we first perform sentence segmentation: use the NLTK library in natural language processing to segment all the materials into sentences. Then we perform sentence embedding generation: use an open source embedding model such as BGE-M3 to generate a numerical vector representation of each sentence.
[0025] It should be noted that BGE-M3 is based on the XLM-RoBERTa model and is improved by the RetroMAE method. It can support more than 100 working languages, and realize multilingual retrieval and cross-language retrieval by learning the common semantic space of different languages. The model can simultaneously complete three common retrieval functions: dense retrieval, multi-vector retrieval, and sparse retrieval, and can handle inputs of different granularities, from short sentences to long documents of up to 8,192 tokens.
[0026] Step 101: Calculate the cosine similarity between adjacent sentences, determine the block boundary according to the cosine similarity threshold, merge multiple sentences belonging to the same block boundary into blocks, and encode each block into a vector and store it in the vector database.
[0027] Specifically, for each created block, the BGE-M3 model is used again to generate a vector representation of the block, and the vectors of these blocks are stored in the Milvus vector database for subsequent efficient similarity search.
[0028] Exemplarily, the cosine similarity between adjacent sentences is calculated according to the following formula: ; In the formula, A and B represent adjacent sentences, A∙B represents the dot product between A and B vectors, and |A||B| represents the product of the modules of A and B vectors.
[0029] The semantic coherence of adjacent sentences can be determined by calculating the cosine similarity between them.
[0030] Step 102: The user input query is rewritten using the LLM model, and related blocks are retrieved from the vector database. The LLM model generates an initial relevance score for each block, and blocks below a score threshold are removed to obtain a target block.
[0031] In a specific embodiment, LLM query rewriting: uses a pre-trained large language model (such as Qwen series Qwen27B) to rewrite the user's original query according to the provided prompts to enhance the retrieval effect. Redundancy removal: uses the cosine similarity measure to identify and remove duplicate or highly similar blocks. Semantic similarity sorting: sorts the remaining blocks according to their similarity to the query, and prioritizes more relevant blocks. Initial LLM scoring: LLM assigns an initial relevance score to each block according to the predefined prompts. Self-reflection: LLM will give reflections based on subsequent user feedback and rewrite the reflection score. If the user does not propose a reflection at the beginning, the default reflection score is used. Critics LLM scoring: An independent critic LLM assigns its own score to each block to verify the initial score. Final score calculation: The final relevance score is obtained by averaging the initial score, reflection score, and critic score. LLM threshold analysis: LLM analyzes the distribution of the final score and recommends an optimal threshold for determining which blocks are relevant. Threshold application: retains blocks with scores higher than the dynamic threshold for use in generating answers.
[0032] Step 103: Use the BM25 searcher to search for keywords in the target block, reorder the results of the keyword search and the target block to form a context, and send the user input query and context to the LLM model to generate an answer.
[0033] Specifically, the bge-reranker-large model is used to rerank the results obtained by keyword retrieval and the target block into context.
[0034] In this embodiment, the bge-reranker-large model is based on the RetroMAE pre-training model, adopts an asymmetric encoder-decoder structure, the encoder part consists of 12 layers of Transformer, and the decoder part is set with one layer of Transformer; wherein, in the pre-training stage, the encoder masks the input text by 15% to 30%, and the decoder masks the input text by 50% to 70% to increase the complexity of the task. The model is fine-tuned on multiple tasks through instruction fine-tuning, which enhances the versatility and adaptability of the model. Negative sampling and difficult negative example mining: Through negative sampling and difficult negative example mining, the discriminative power of semantic vectors is enhanced, and the performance of the model in retrieval tasks is improved. The core function of this model is to re-rank the Top-K documents initially retrieved to improve the relevance and accuracy of the retrieval results.
[0035] Context compilation and answer generation: The filtered chunks are used as context for LLM. LLM answer generation: Use LLM to generate the correct answer based on the context and the user’s original question. Evaluation: Users can evaluate the quality of RAG application, including the relevance, fidelity of the answer, and the relevance of the retrieved context. Feedback loop: Based on the evaluation results and user feedback, the RAG process and model performance are continuously optimized.
[0036] In an embodiment of the present invention, based on step 101, a possible embodiment is given below to non-limitingly illustrate the specific implementation scheme of determining the block boundary according to the cosine similarity threshold in the step.
[0037] A cosine similarity threshold is set in advance. When the cosine similarity between adjacent sentences is lower than the cosine similarity threshold, it represents the beginning of a new topic, thereby determining the boundary of the block.
[0038] In some implementations, sentences are grouped into blocks according to the determined block boundaries, and it is ensured that the length of each block does not exceed a preset maximum length.
[0039] It should be understood that the preset maximum length can be set according to the specific application scenario, such as 500 characters, and is not limited here.
[0040] In one embodiment of the present invention, refer to Figure 2 As shown, based on step 102, a possible embodiment will be given below to illustrate its specific implementation scheme in a non-limiting manner.
[0041] S1020: Using the LLM model, rewrite the original query input by the user according to the prompt, and retrieve relevant blocks from the vector database.
[0042] S1021: Using the cosine similarity metric to identify and remove duplicate or highly similar blocks, and sorting the remaining blocks according to their similarity to the query, so as to give priority to processing blocks with high similarity.
[0043] S1022: Using the LLM model to assign an initial relevance score to each block based on the prompt, and giving a reflective score based on subsequent user feedback, and using an independent critic LLM model to assign a critic score to each block, and obtaining a target relevance score by averaging the initial score, reflective score, and critic score.
[0044] S1023: Analyze the distribution of target relevance scores using the LLM model, and recommend an optimal score threshold, retain blocks with scores higher than the score threshold, and obtain target blocks.
[0045] In some implementations, after executing step 101, a step is further executed: initializing a retriever, wherein the retriever is used to retrieve the block with the highest relevance by comparing the vector of the user input query with the block vectors stored in the vector database.
[0046] In one embodiment, Figure 3 This is a detailed flow chart of a retrieval method based on semantic segmentation provided according to an embodiment of the present invention. This embodiment is further optimized and expanded on the basis of the above embodiments.
[0047] First, use NLTK to segment the text to be retrieved, use bge-m3 to generate sentence embedding vectors, calculate the similarity between adjacent sentences, determine the boundaries of the blocks according to the threshold similarity, group the sentences into blocks according to the length limit of each block, generate vectors for the blocks through bge-m3, and store them in the database. For user input queries, use LLM to rewrite the queries, retrieve from the library according to the rewritten queries, remove highly repeated blocks, and generate an initial score for each block by LLM. Set prompt to reflect on the score and give a reflection score. Use an independent critic LLM to score each block, average the initial score, reflection score and critic score. According to the score, LLM sets a threshold and removes blocks below the threshold. BM25 retriever performs keyword retrieval, and uses the beg-reranker-large model to reorder all the above blocks. The filtered blocks are converted into contexts, and the original questions and contexts are sent to the large model to generate questions and answers. Based on user feedback, if the requirements are not met, the process is re-executed. Set prompt to reflect on the score and give the reflection score.
[0048] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
[0049] This application uses the NLTK library for sentence segmentation, combines the bge-m3 model to generate a numerical vector representation of the sentence, and calculates the cosine similarity between consecutive sentence vectors. This patent can more accurately identify the beginning of a new topic, thereby determining the boundaries of the block. This method not only improves the recognition accuracy of semantic coherence, but also optimizes the organization and retrieval efficiency of information by setting the maximum length of the block. By adopting an innovative scoring mechanism, including LLM self-reflection and critic LLM scoring, the final relevance score is obtained. At the same time, the user's feedback results act on the reflective score. This method improves the accuracy and reliability of the score, meets the user's intention, and ensures the relevance of the retrieval results.
[0050] like Figure 4 As shown, the following is an embodiment of the semantic segmentation-based retrieval system provided by the embodiment of the present disclosure, which belongs to the same inventive concept as the semantic segmentation-based retrieval method of the above-mentioned embodiments. For details not described in detail in the embodiment of the semantic segmentation-based retrieval system, please refer to the above-mentioned embodiment of the semantic segmentation-based retrieval method.
[0051] A segmentation unit 40, for segmenting the text material into a plurality of sentences and encoding each sentence into a vector; A calculation unit 41 is used to calculate the cosine similarity between adjacent sentences, determine the block boundary according to the cosine similarity threshold, merge multiple sentences belonging to the same block boundary into blocks, and encode each block into a vector and store it in the vector database; A deduplication unit 42 is used to rewrite the user input query using the LLM model and retrieve relevant blocks from the vector database. The LLM model generates an initial relevance score for each block and removes blocks below a score threshold to obtain a target block. The reordering unit 43 is used to use the BM25 searcher to search for keywords in the target block, reorder the results of the keyword search and the target block to form a context, and send the user input query and the context to the LLM model to generate an answer.
[0052] Figure 5 It is a schematic diagram of the hardware structure of an electronic device for implementing various embodiments of the present invention.
[0053] The retrieval method based on semantic segmentation provided in the embodiment of the present application can be applied to electronic devices. It will be appreciated by those skilled in the art that the electronic device structure involved in the embodiment of the present invention does not constitute a limitation on the electronic device, and the electronic device may include more or less components than shown, or combine certain components, or arrange different components. In an embodiment of the present invention, the electronic device includes but is not limited to a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples, and are not intended to limit the implementation of the embodiments of the present application described and / or required herein.
[0054] The electronic device may include a processor, an external memory interface, an internal memory, a universal serial bus (USB) interface, a charging management module, a power management module, a battery, a wireless communication module, an audio module, a speaker, a microphone, a sensor module, buttons, a camera, a display, and a SIM card interface, etc.
[0055] It is to be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0056] The processor may include one or more processing units, for example, the processor may include a central processing unit (CPU), an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units may be independent devices or integrated into one or more processors.
[0057] The processor can be the nerve center and command center of the electronic device. The controller can generate an operation control signal according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.
[0058] A memory may also be provided in the processor for storing instructions and data. In some embodiments, the memory in the processor is a cache memory. The memory may store instructions or data that the processor has just used or is cyclically used. If the processor needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor, and thus improves system efficiency.
[0059] The external memory interface can be used to connect an external memory card, such as a MicroSD card, to expand the storage capacity of the electronic device. The external memory card communicates with the processor through the external memory interface to implement data storage functions. For example, files such as music and videos can be saved in the external memory card.
[0060] The internal memory can be used to store computer executable program codes, which include instructions. The processor executes various functional applications and data processing of the electronic device by running the instructions stored in the internal memory. The internal memory may include a program storage area and a data storage area. The internal memory may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0061] The wireless communication function of an electronic device can be realized through an antenna, a wireless communication module, a modem processor, and a baseband processor.
[0062] The wireless communication module can provide wireless communication solutions for electronic devices, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared technology (IR), etc.
[0063] Electronic devices can implement audio functions, etc. through audio modules, speakers, receivers, microphones, headphone jacks, and application processors.
[0064] Electronic devices can achieve shooting functions through ISP, camera, video codec, GPU, display and application processor.
[0065] Electronic devices can achieve display functions through GPU, display screen and application processor.
[0066] The GPU is a microprocessor for image processing that connects the display screen and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor may include one or more GPUs that execute program instructions to generate or change display information.
[0067] The display screen is used to display images, videos, etc. The display screen includes a display panel.
[0068] The electronic device described above implements the technical solution of the subject name of the retrieval method based on semantic segmentation of the present application, achieving the beneficial effect of more accurate retrieval results.
[0069] The storage medium provided in the present application stores a program product capable of implementing a retrieval method based on semantic segmentation.
[0070] The retrieval method based on semantic segmentation includes: dividing the text material into multiple sentences and encoding each sentence into a vector; calculating the cosine similarity between adjacent sentences, and determining the block boundary according to the cosine similarity threshold, merging multiple sentences belonging to the same block boundary into blocks, and encoding each block into a vector and storing it in a vector database; using the LLM model to rewrite the user input query, and retrieve related blocks from the vector database, the LLM model generates an initial relevance score for each block, and removes blocks below the score threshold to obtain a target block; using the BM25 retriever to retrieve keywords in the target block, reordering the results obtained by the keyword retrieval and the target block into a context, and sending the user input query and the context to the LLM model to generate an answer.
[0071] In some possible implementations, the method and system for retrieving the subject name based on semantic segmentation of the present disclosure may be implemented in the form of a program product, which includes a program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps described in the above “Exemplary Method” section of this specification according to various exemplary implementations of the present disclosure.
[0072] The storage medium of the present disclosure can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0073] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A retrieval method based on semantic segmentation, characterized in that: include: Split the text material into sentences and encode each sentence into a vector; Calculate the cosine similarity between adjacent sentences, determine the block boundary according to the cosine similarity threshold, merge multiple sentences belonging to the same block boundary into blocks, and encode each block into a vector and store it in the vector database; The LLM model is used to rewrite the user input query and retrieve relevant blocks from the vector database. The LLM model generates an initial relevance score for each block and removes blocks below the score threshold to obtain the target block. The BM25 searcher is used to search for keywords in the target block, the results of the keyword search are reordered and combined with the target block into a context, and the user input query and context are sent to the LLM model to generate an answer.
2. The retrieval method based on semantic segmentation according to claim 1, characterized in that: The cosine similarity between adjacent sentences is calculated according to the following formula: ; In the formula, A and B represent adjacent sentences, A∙B represents the dot product between A and B vectors, and |A||B| represents the product of the modules of A and B vectors.
3. The retrieval method based on semantic segmentation according to claim 1, characterized in that: Determine block boundaries based on cosine similarity thresholds, including: A cosine similarity threshold is set in advance. When the cosine similarity between adjacent sentences is lower than the cosine similarity threshold, it represents the beginning of a new topic, thereby determining the boundary of the block.
4. The retrieval method based on semantic segmentation according to claim 1, characterized in that: The LLM model is used to rewrite the user input query and retrieve relevant blocks from the vector database. The LLM model generates an initial relevance score for each block and removes blocks below the score threshold to obtain the target block, including: Using the LLM model, the original query input by the user is rewritten according to the prompts, and the relevant blocks are retrieved from the vector database; Using the cosine similarity metric, duplicate or highly similar blocks are identified and removed, and the remaining blocks are sorted according to their similarity to the query to prioritize blocks with high similarity; Using the LLM model to assign an initial relevance score to each block based on the prompt, and give a reflective score based on subsequent user feedback, and using an independent critic LLM model to assign a critic score to each block, and obtain the target relevance score by averaging the initial score, reflective score, and critic score; The LLM model is used to analyze the distribution of target relevance scores and recommend an optimal scoring threshold. Blocks with scores higher than the scoring threshold are retained to obtain the target blocks.
5. The retrieval method based on semantic segmentation according to claim 1, characterized in that: The bge-reranker-large model is used to rerank the results obtained from keyword retrieval and the target block into context.
6. The retrieval method based on semantic segmentation according to claim 5, characterized in that: The bge-reranker-large model is based on the RetroMAE pre-trained model and adopts an asymmetric encoder-decoder structure. The encoder part consists of 12 layers of Transformer, and the decoder part has one layer of Transformer. During the pre-training stage, the encoder masks the input text by 15%~30%, and the decoder masks the input text by 50%~70% to increase the complexity of the task.
7. The retrieval method based on semantic segmentation according to claim 1, characterized in that: After calculating the cosine similarity between adjacent sentences, determining the block boundary according to the cosine similarity threshold, merging multiple sentences belonging to the same block boundary into blocks, and encoding each block into a vector and storing it in a vector database, the semantic block-based retrieval method further includes: Initialize a retriever, wherein the retriever is used to retrieve the block with the highest relevance by comparing the vector of the user input query with the block vectors stored in the vector database.
8. A retrieval system based on semantic segmentation, characterized in that: include: A segmentation unit for segmenting the text material into multiple sentences and encoding each sentence into a vector; A calculation unit, used for calculating the cosine similarity between adjacent sentences, determining the block boundary according to the cosine similarity threshold, merging multiple sentences belonging to the same block boundary into blocks, and encoding each block into a vector and storing it in a vector database; The deduplication unit is used to rewrite the user input query using the LLM model and retrieve the relevant blocks in the vector database. The LLM model generates an initial relevance score for each block and removes the blocks below the score threshold to obtain the target block. The re-ranking unit is used to use the BM25 searcher to retrieve keywords in the target block, re-rank the results of the keyword search and the target block to form a context, and send the user input query and context to the LLM model to generate an answer.
9. An electronic device comprising 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 of the semantic segmentation-based retrieval method as described in any one of claims 1 to 7 are implemented.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the semantic segmentation-based retrieval method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
RAG retrieval generation system oriented to intensive data scene
CN120296138A
Intelligent question and answer processing method and device, electronic equipment and storage medium
CN120873151A