Retrieval enhancement method and system based on key sentence vector and question answering system
By segmenting text data into text blocks, extracting key sentences, converting them into vectors, and building an indexed database, the problem of insufficient semantic relevance in the reordering stage of the RAG framework is solved, achieving efficient and accurate text retrieval.
Patent Information
- Application Number
- CN202510881111.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-27
- Publication Date
- 2025-11-21
AI Technical Summary
Existing Retrieval Augmentation (RAG) frameworks suffer from insufficient semantic relevance accuracy during the re-ranking stage because they cannot consider the text length differences within text blocks, thus affecting the ability of large language models in knowledge question answering scenarios.
The text data is segmented into text blocks and key sentences are extracted. These are then converted into text block vectors and key sentence vectors. A database of indexed relationships is established, and target text blocks are determined through approximate nearest neighbor search and similarity calculation.
By accurately matching the length of key sentences, the efficiency and accuracy of text retrieval are improved, more relevant text blocks are filtered out, and user satisfaction is enhanced.
Smart Images

Figure CN120994765A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present specification relate to the field of retrieval, and in particular to a retrieval augmentation method and system based on key sentence vectors, and a question and answer system. BACKGROUND
[0002] At present, most retrieval augmentation generation (RAG) frameworks use cosine similarity calculation between user questions and text in text blocks in the reordering stage to obtain a reordering score, and reorder the text blocks according to the score. Due to the large difference in length between the user question and the text in the text block, and the fact that cosine similarity cannot consider the influence of the length of the text in the text block, the traditional RAG framework cannot obtain accurate semantic related results in the reordering stage, thereby affecting the ability of large language models in the knowledge question and answer scenario. SUMMARY
[0003] The embodiments of the present specification provide a retrieval augmentation method and system based on key sentence vectors, and a question and answer system.
[0004] The technical scheme is as follows: The embodiments of the present specification provide a retrieval augmentation method based on key sentence vectors, comprising: Obtaining a plurality of text data, and cutting the plurality of text data into a plurality of text blocks respectively; Respectively extracting at least one key sentence corresponding to each of the plurality of text blocks; Respectively converting the plurality of text blocks into text block vectors and the plurality of key sentences into key sentence vectors; Establishing a database including the index relationship between each text block, each text block vector, and each key sentence vector; Obtaining a retrieval text, and obtaining a text vector corresponding to the retrieval text; Performing approximate nearest neighbor search in the database based on the text vector and each text block vector in the database to determine a plurality of similar text blocks from the plurality of text blocks in the database; Respectively obtaining the text block vector and at least one key sentence vector corresponding to each of the plurality of similar text blocks from the database; Based on the text vector and the text block vector and at least one key sentence vector corresponding to each of the plurality of similar text blocks, obtaining a text block vector similarity and at least one key sentence vector similarity corresponding to each of the plurality of similar text blocks; Based on the text block vector similarity and at least one key sentence vector similarity corresponding to each of the plurality of similar text blocks, determining a plurality of target text blocks corresponding to the retrieval text from the plurality of similar text blocks.
[0005] As a preferred scheme, the step of respectively extracting at least one key sentence corresponding to each of the plurality of text blocks comprises: obtaining text block text lengths corresponding to the plurality of text blocks respectively; extracting at least one key sentence corresponding to each of the plurality of text blocks respectively based on the text block text lengths corresponding to the plurality of text blocks respectively.
[0006] As a preferred solution, before the step of determining the plurality of target text blocks from the plurality of similar text blocks based on the text block vector similarity corresponding to each of the plurality of similar text blocks respectively and the key sentence vector similarity corresponding to the at least one key sentence, the method further comprises: obtaining a text block vector similarity weight and a key sentence vector similarity weight; The step of determining the plurality of target text blocks from the plurality of similar text blocks based on the text block vector similarity corresponding to each of the plurality of similar text blocks respectively and the key sentence vector similarity corresponding to the at least one key sentence comprises: determining the plurality of target text blocks from the plurality of similar text blocks based on the text block vector similarity weight, the key sentence vector similarity weight, the text block vector similarity corresponding to each of the plurality of similar text blocks respectively, and the key sentence vector similarity corresponding to the at least one key sentence.
[0007] As a preferred solution, the text block vector similarity and the key sentence vector similarity are both cosine similarity; Before the step of determining the plurality of target text blocks from the plurality of similar text blocks based on the text block vector similarity corresponding to each of the plurality of similar text blocks respectively and the key sentence vector similarity corresponding to the at least one key sentence, the method further comprises: obtaining a text block text length corresponding to each of the plurality of similar text blocks respectively and a search text length of a search text; The step of determining the plurality of target text blocks from the plurality of similar text blocks based on the text block vector similarity corresponding to each of the plurality of similar text blocks respectively and the key sentence vector similarity corresponding to the at least one key sentence comprises: determining the plurality of target text blocks from the plurality of similar text blocks based on the search text length of the search text, the text block text length corresponding to each of the plurality of similar text blocks respectively, the text block vector similarity, and the key sentence vector similarity corresponding to the at least one key sentence.
[0008] As a preferred solution, the step of determining the plurality of target text blocks from the plurality of similar text blocks based on the search text length of the search text, the text block text length corresponding to each of the plurality of similar text blocks respectively, the text block vector similarity, and the key sentence vector similarity corresponding to the at least one key sentence comprises: obtaining a text block length penalty factor corresponding to each of the plurality of similar text blocks respectively based on the search text length of the search text and the text block text length corresponding to each of the plurality of similar text blocks respectively; obtaining an overall similarity corresponding to each of the plurality of similar text blocks respectively based on the text block length penalty factor corresponding to each of the plurality of similar text blocks respectively, the text block vector similarity, and the key sentence vector similarity corresponding to the at least one key sentence. determine the plurality of target text blocks from the plurality of similar text blocks based on the respective overall similarity of the plurality of similar text blocks.
[0009] As a preferred solution, the establishing the database comprising the index relationship between the text blocks, the text block vectors, and the key sentence vectors further comprises: obtaining the respective key sentence length of each key sentence; The establishing the database comprising the index relationship between the text blocks, the text block vectors, and the key sentence vectors specifically comprises: establishing the database comprising the index relationship between the text blocks, the text block vectors, the key sentence vectors, and the key sentence lengths; The determining the plurality of target text blocks from the plurality of similar text blocks based on the respective overall similarity of the plurality of similar text blocks further comprises: obtaining the respective at least one key sentence length of the plurality of similar text blocks; The determining the plurality of target text blocks from the plurality of similar text blocks based on the respective overall similarity of the plurality of similar text blocks comprises: determining the respective overall similarity of the plurality of similar text blocks based on the respective text length penalty factor, the text block vector similarity, the at least one key sentence vector similarity, and the at least one key sentence length of the plurality of similar text blocks.
[0010] As a preferred solution, the determining the respective overall similarity of the plurality of similar text blocks based on the respective text length penalty factor, the text block vector similarity, the at least one key sentence vector similarity, and the at least one key sentence length of the plurality of similar text blocks comprises: determining the respective at least one key sentence length penalty factor of the plurality of similar text blocks based on the respective text length of the retrieval text and the respective at least one key sentence length of the plurality of similar text blocks; determining the respective overall similarity of the plurality of similar text blocks based on the respective text length penalty factor, the text block vector similarity, the at least one key sentence vector similarity, and the at least one key sentence length penalty factor of the plurality of similar text blocks.
[0011] As a preferred solution, the determining the respective overall similarity of the plurality of similar text blocks based on the respective text length penalty factor, the text block vector similarity, the at least one key sentence vector similarity, and the at least one key sentence length penalty factor of the plurality of similar text blocks comprises: obtain the at least one penalty key sentence similarity of each of the plurality of similar text blocks based on the at least one key sentence length penalty factor and the at least one key sentence vector similarity of each of the plurality of similar text blocks; obtain the at least one penalty key sentence similarity of each of the plurality of similar text blocks based on the at least one key sentence length penalty factor and the at least one key sentence vector similarity of each of the plurality of similar text blocks; obtain the overall similarity of each of the plurality of similar text blocks based on the penalty text block similarity and the at least one penalty key sentence similarity of each of the plurality of similar text blocks.
[0012] In a second aspect, the embodiments of the present specification provide a large language question and answer system, comprising a retrieval module and an answering module; The retrieval module determines a plurality of target text blocks corresponding to the retrieval text by using the retrieval enhancement method based on the key sentence vector in the first aspect of the above embodiments. The answering module answers the text based on the retrieval text and the plurality of target text blocks corresponding to the retrieval text.
[0013] In a third aspect, the embodiments of the present specification provide a retrieval enhancement system based on a key sentence vector, comprising: The cutting module obtains a plurality of text data and cuts the plurality of text data into a plurality of text blocks, respectively; The extraction module extracts at least one key sentence corresponding to each of the plurality of text blocks, respectively; The conversion module converts the plurality of text blocks into text block vectors and converts the plurality of key sentences into key sentence vectors, respectively; The construction module establishes a database including the index relationship between each text block, each text block vector, and each key sentence vector; The acquisition module acquires a retrieval text and acquires a text vector corresponding to the retrieval text; The first determination module performs approximate nearest neighbor search in the database based on the text vector and each text block vector in the database to determine a plurality of similar text blocks from the plurality of text blocks in the database; The first acquisition module acquires the text block vector and the at least one key sentence vector corresponding to each of the plurality of similar text blocks from the database, respectively; The second acquisition module obtains the text block vector similarity and the at least one key sentence vector similarity corresponding to each of the plurality of similar text blocks based on the text vector and the text block vector and the at least one key sentence vector corresponding to each of the plurality of similar text blocks; The second determination module determines the plurality of target text blocks corresponding to the retrieval text from the plurality of similar text blocks based on the text block vector similarity and the at least one key sentence vector similarity corresponding to each of the plurality of similar text blocks.
[0014] Fourthly, embodiments of this specification provide an electronic device, including a processor and a memory; the processor is connected to the memory; the memory is used to store executable program code; the processor reads the executable program code stored in the memory to run a program corresponding to the executable program code, so as to perform the steps described in the first aspect of the above embodiments.
[0015] Fifthly, embodiments of this specification provide a computer storage medium storing a plurality of instructions adapted for loading by a processor and executing the steps described in the first aspect of the above embodiments.
[0016] The beneficial effects of the technical solutions provided in some embodiments of this specification include at least the following: First, multiple texts are segmented into text blocks and key sentences are extracted. Then, the text blocks and key sentences are converted into vectors. Next, a database is built to store text blocks, text block vectors, and key sentence vectors, and an index is established. During retrieval, the retrieved text is converted into a text vector, and an approximate nearest neighbor search is performed with the text block vectors in the database to find similar text blocks. Then, the corresponding text block vectors and key sentence vectors are obtained, and their similarity is calculated. Finally, based on the text block vector similarity and key sentence vector similarity, the target text block for the retrieved text is determined. Because the length of key sentences is closer to the length of the retrieved text, their vector similarity calculation is more accurate. Combining the similarity of text block and key sentence vectors can effectively filter out target text blocks, achieving efficient and accurate text retrieval. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is a flowchart illustrating the retrieval enhancement method based on key sentence vectors provided in the embodiments of this specification.
[0019] Figure 2 This is a flowchart illustrating the process of responding to large language models using the retrieval enhancement method based on key sentence vectors provided in the embodiments of this specification.
[0020] Figure 3 This is a schematic diagram of the retrieval enhancement system based on key sentence vectors provided in the embodiments of this specification.
[0021] Figure 4 is a structural schematic diagram of an electronic device provided by an embodiment of the present specification. DETAILED DESCRIPTION
[0022] The technical solutions in the embodiments of the present specification will be clearly and completely described below with reference to the drawings in the embodiments of the present specification.
[0023] The terms "first", "second", "third", and the like in the specification and claims of the present specification and the above drawings are used to distinguish different objects, and are not used to describe a particular order. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but can optionally include steps or units not listed, or can optionally include other steps or units inherent to the process, method, product, or device.
[0024] The following description provides examples and does not limit the scope, applicability, or examples set forth in the claims. Changes can be made to the functions and arrangements of described elements without departing from the scope of the present specification. Various examples can appropriately omit, replace, or add various processes or components. For example, the described methods can be performed in a different order from the described order, and various steps can be added, omitted, or combined. In addition, features described with respect to some examples can be combined into other examples.
[0025] Referring to Figure 1 , as shown in the figure, Figure 1 is a flowchart of a retrieval enhancement method based on key sentence vectors provided by an embodiment of the present specification, which can at least include: Step 102, obtaining a plurality of text data, and cutting the plurality of text data into a plurality of text blocks respectively; Step 104, extracting at least one key sentence corresponding to each of the plurality of text blocks respectively; Step 106, converting the plurality of text blocks into text block vectors and converting the plurality of key sentences into key sentence vectors respectively; Step 108, establishing a database including the index relationship between each text block, each text block vector, and each key sentence vector; Step 110, obtaining a retrieval text, and obtaining a text vector corresponding to the retrieval text; Step 112, performing approximate nearest neighbor search in the database based on the text vector and each text block vector in the database to determine a plurality of similar text blocks in the plurality of text blocks in the database; Step 114, respectively obtaining the text block vector corresponding to each of the plurality of similar text blocks and the key sentence vector corresponding to at least one key sentence from the database; Step 116, based on the text vector and the text block vector corresponding to each of the plurality of similar text blocks and the key sentence vector corresponding to at least one key sentence, obtaining the text block vector similarity corresponding to each of the plurality of similar text blocks and the key sentence vector similarity corresponding to at least one key sentence; Step 118, based on the text block vector similarity corresponding to each of the plurality of similar text blocks and the key sentence vector similarity corresponding to at least one key sentence, determining the plurality of target text blocks corresponding to the search text from the plurality of similar text blocks.
[0026] The search enhancement method provided by the embodiments of the present specification first cuts a plurality of texts into text blocks and extracts key sentences; then converts the text blocks and the key sentences into vectors; further establishes a database to store the text blocks, the text block vectors and the key sentence vectors, and establishes an index relationship; further, when searching, converts the search text into a text vector, performs an approximate nearest neighbor search on the text block vectors in the database, and finds similar text blocks; further, obtains the text block vectors and the key sentence vectors corresponding to these text blocks, and calculates the similarity with the text vector; finally, according to the text block vector similarity and the key sentence vector similarity, determines the target text blocks of the search text. Since the length of the key sentence is closer to the length of the search text, the vector similarity calculation is more accurate, and the combination of the text block vector similarity and the key sentence vector similarity can effectively filter out the target text blocks, realizing efficient and accurate text search.
[0027] Since the text block is relatively long, a certain degree of semantic compression is performed when converting into a vector, which causes some text content to be diluted when converting into a vector, and then if only the text block vector similarity is used to determine the target text block, the text block vector similarity may be high, but the overall content deviates from the core of the user input search text. In contrast, the key sentence is relatively short, and its content will not be excessively compressed when converting into a key sentence vector, so the system can more effectively filter out more relevant and accurate key sentences, and then more effectively filter out more relevant and accurate text blocks, improving the search effect and user satisfaction.
[0028] In some embodiments of the present specification, the method further comprises: obtaining the text length of each of the plurality of text blocks; based on the text length of each of the plurality of text blocks, extracting at least one key sentence corresponding to each of the plurality of text blocks.
[0029] The number of key sentences extracted from each document block is 1-3 sentences (which can be dynamically adjusted according to the length of the text block). The minimum length of the key sentence can be, but is not limited to, 10 characters, and the maximum length of the key sentence can be, but is not limited to, 200 characters.
[0030] In addition, when extracting key sentences, a repetition filtering threshold can be set to avoid extracting multiple key sentences with repeated semantics for the same text block.
[0031] In some embodiments of the present specification, before determining the plurality of target text blocks from the plurality of similar text blocks based on the text block vector similarity of each of the plurality of similar text blocks and the at least one key sentence vector similarity, the method further comprises: obtaining a text block vector similarity weight and a key sentence vector similarity weight; determining the plurality of target text blocks from the plurality of similar text blocks based on the text block vector similarity of each of the plurality of similar text blocks and the at least one key sentence vector similarity, comprises: determining the plurality of target text blocks from the plurality of similar text blocks based on the text block vector similarity weight, the key sentence vector similarity weight, the text block vector similarity of each of the plurality of similar text blocks, and the at least one key sentence vector similarity.
[0032] that is, the text block vector similarity and the key sentence vector similarity are given an influence weight for determining the respective corresponding target text blocks.
[0033] In some embodiments of the present specification, the text block vector similarity and the key sentence vector similarity are cosine similarity.
[0034] In some embodiments of the present specification, before determining the plurality of target text blocks from the plurality of similar text blocks based on the text block vector similarity of each of the plurality of similar text blocks and the at least one key sentence vector similarity, the method further comprises: obtaining a text block text length corresponding to each of the plurality of similar text blocks and a retrieval text length of the retrieval text; determining the plurality of target text blocks from the plurality of similar text blocks based on the text block vector similarity of each of the plurality of similar text blocks and the at least one key sentence vector similarity, comprises: determining the plurality of target text blocks from the plurality of similar text blocks based on the retrieval text length of the retrieval text, the text block text length corresponding to each of the plurality of similar text blocks, the text block vector similarity, and the at least one key sentence vector similarity.
[0035] Specifically, in some embodiments of the present disclosure, the determining the plurality of target text blocks from the plurality of similar text blocks based on the search text length of the search text and the text block length of each of the plurality of similar text blocks, the text block vector similarity, and the at least one key sentence vector similarity comprises: obtaining the text block length penalty factor corresponding to each of the plurality of similar text blocks based on the search text length of the search text and the text block length of each of the plurality of similar text blocks; obtaining the overall similarity corresponding to each of the plurality of similar text blocks based on the text block length penalty factor corresponding to each of the plurality of similar text blocks, the text block vector similarity, and the at least one key sentence vector similarity; determining the plurality of target text blocks from the plurality of similar text blocks based on the overall similarity corresponding to each of the plurality of similar text blocks.
[0036] The overall similarity calculation formula of the similar text block can be, but is not limited to, the following formula: Score n = α *(Sim_p1+ Sim_p2+……+ Sim_pm)+β*Sim_s * L n _factor; L n _factor= k / Y n ; wherein Score n n represents the overall similarity of the nth similar text block, α represents the key sentence vector similarity weight, β represents the text block vector similarity weight, Sim_pm represents the mth key sentence vector similarity, Sim_s represents the text block vector similarity, L n _factor represents the text block length penalty factor of the nth similar text block, k represents the search text length of the search text, and Y n represents the text block length corresponding to the nth similar text block.
[0037] Based on the above, the longer the text block length is, the more the content is compressed when the text block is converted into a text block vector, and therefore the value of the text block length penalty factor should be smaller.
[0038] In some embodiments, when the text block length exceeds 10 times the search text length, a quadratic penalty can be additionally introduced.
[0039] For the key sentence vector similarity, the adjustment principle is consistent with that of the text block vector similarity described above, and therefore in some embodiments of the present disclosure, before the database establishing comprising the index relationship between each text block, each text block vector, and each key sentence vector, the method further comprises: obtaining the key sentence length corresponding to each key sentence. The establishment includes the database of the index relationship among each text block, each text block vector, and each key sentence vector, specifically including: The establishment includes the database of the index relationship among each text block, each text block vector, each key sentence vector, and each key sentence length; Before the obtaining of the overall similarity corresponding to each of the plurality of similar text blocks based on the text block length penalty factor corresponding to each of the plurality of similar text blocks, the text block vector similarity, and the at least one key sentence vector similarity, the method further includes: Obtaining at least one key sentence length corresponding to each of the plurality of similar text blocks; The obtaining of the overall similarity corresponding to each of the plurality of similar text blocks based on the text block length penalty factor corresponding to each of the plurality of similar text blocks, the text block vector similarity, and the at least one key sentence vector similarity includes: The obtaining of the overall similarity corresponding to each of the plurality of similar text blocks based on the text block length penalty factor corresponding to each of the plurality of similar text blocks, the text block vector similarity, the at least one key sentence vector similarity, and the at least one key sentence length.
[0040] Further, the obtaining of the overall similarity corresponding to each of the plurality of similar text blocks based on the text block length penalty factor corresponding to each of the plurality of similar text blocks, the text block vector similarity, the at least one key sentence vector similarity, and the at least one key sentence length includes: The obtaining of the at least one key sentence length penalty factor corresponding to each of the plurality of similar text blocks based on the text block length penalty factor corresponding to each of the plurality of similar text blocks, the text block vector similarity, the at least one key sentence vector similarity, and the at least one key sentence length. The obtaining of the overall similarity corresponding to each of the plurality of similar text blocks based on the text block length penalty factor corresponding to each of the plurality of similar text blocks, the text block vector similarity, the at least one key sentence vector similarity, and the at least one key sentence length penalty factor.
[0041] Further, the obtaining of the overall similarity corresponding to each of the plurality of similar text blocks based on the text block length penalty factor corresponding to each of the plurality of similar text blocks, the text block vector similarity, the at least one key sentence vector similarity, and the at least one key sentence length penalty factor includes: The obtaining of the penalty text block similarity corresponding to each of the plurality of similar text blocks based on the text block length penalty factor corresponding to each of the plurality of similar text blocks, the text block vector similarity. The obtaining of the at least one penalty key sentence similarity corresponding to each of the plurality of similar text blocks based on the at least one key sentence vector similarity corresponding to each of the plurality of similar text blocks, and the at least one key sentence length penalty factor. Based on the respective penalty text block similarity of the plurality of similar text blocks, the at least one penalty key sentence similarity, obtain the respective overall similarity of the plurality of similar text blocks.
[0042] The specific calculation formula can be, but is not limited to, as follows: Score n = α *(Sim_p1 * X1_factor + Sim_p2* X2_factor +……+ Sim_pm* X m _factor)+ β* Sim_s * L n _factor; X m _factor= k / M m ; Wherein, X m _factor represents the mth key sentence length penalty factor, M m represents the key sentence length of the mth key sentence.
[0043] The embodiment of the present specification utilizes fine-grained semantic information key sentences, combines the user input retrieval text, and performs retrieval matching with the original chunk paragraph. The scores of the two are weighted and calculated to improve the effect of the rerank part in the RAG framework, thereby solving the problems of poor retrieval effect and inaccurate model question and answer in the current traditional RAG framework. In the embodiment of the present specification, the key sentence extraction work is performed when the index is constructed, ensuring that the subsequent weighted calculation part does not need to recode and calculate the vector, which produces a small additional time overhead in actual use.
[0044] The above describes specific embodiments of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different than the order in the embodiments and still achieve the desired result. In addition, the processes depicted in the figures do not necessarily require the particular order shown or sequential order to achieve the desired results. In certain implementations, multitasking and parallel processing can be advantageous or possible.
[0045] Further, the present specification also provides a large language question and answer system, which comprises at least a retrieval module, an answer module; The retrieval module adopts the retrieval enhancement method based on the key sentence vector as described in the above embodiment to determine a plurality of target text blocks corresponding to the retrieval text; The answer module performs text answering based on the retrieval text and the plurality of target text blocks corresponding to the retrieval text.
[0046] Reference Figure 2As shown, Figure 2 A flowchart of a large language model result response based on a key sentence vector retrieval enhancement method is shown, which mainly includes the following processes: I. Data preprocessing After the user uploads various files to the knowledge base and performs text extraction. Since the input data in the RAG system can come from various formats and sources, the system needs to extract text content from multiple file formats. This process involves processing multiple file types, such as txt, docx, pdf, xlsx, ppt, jpg, etc. For text type files such as txt, docx, pdf, etc., tools such as pdfminer and python-docx can be used for text reading. For files such as jpg and ppt that contain multi-modal data, optical character recognition (OCR) tools can be used to convert the information to text for subsequent processing. The processing steps include data cleaning, Chinese and English punctuation conversion, space deletion, and unified encoding format.
[0047] II. Data chunking and index construction Text data is submitted from the knowledge base to the chunking algorithm, which cuts continuous text into discrete text blocks. In this stage, the T5ChineseKSE key sentence extraction technology is introduced, which intelligently identifies and extracts key sentences from the text blocks. These key sentences will be stored as part of the metadata information in the corresponding text blocks, and the text blocks will be stored in the knowledge base. In all subsequent steps, the corresponding key sentences in the text blocks can be obtained by calling the method. Subsequently, the text blocks in the knowledge base are sent to the embedding model, and the text information is encoded through the global unified embedding model to convert it into semantic vectors and stored in the vector library. Since key sentences are mainly used for reordering tasks, we will use the unified embedding model in the reordering task to generate the embedding vectors of the key sentences, and the generated vectors will also be stored in the vector library as metadata.
[0048] III. Question retrieval Taking dense retrieval as an example, when the system receives the user's submitted query statement, it first converts the query statement into a vector through the unified embedding model, calls the vector library query interface for similarity calculation, and retrieves the preliminary relevant text blocks. At this time, the KS-Reranker reordering method is called to calculate the reordering score, which includes query and document matching score and query and key sentence matching score. The two parts of the score are weighted to obtain the reordering score. The text blocks are sorted according to the reordering score, and the highest ranked part of the text blocks is retained as knowledge. These will be input into the LLM together with the query statement (i.e. the retrieval statement) in the subsequent steps to obtain the result response.
[0049] Next, please refer to Figure 3 , Figure 3 The structure diagram of the retrieval enhancement system based on key sentence vectors provided by the embodiments of the present specification is shown.
[0050] As Figure 3 shown, the retrieval enhancement system can at least include: A cutting module that obtains a plurality of text data and cuts the plurality of text data into a plurality of text blocks respectively; An extraction module that extracts at least one key sentence corresponding to each of the plurality of text blocks respectively; A conversion module that converts the plurality of text blocks into text block vectors and converts the plurality of key sentences into key sentence vectors respectively; A construction module that establishes a database including index relationships between each text block, each text block vector, and each key sentence vector; An acquisition module that acquires a retrieval text and acquires a text vector corresponding to the retrieval text; A first determination module that performs approximate nearest neighbor search in the database based on the text vector and each text block vector in the database to determine a plurality of similar text blocks from the plurality of text blocks in the database; A first acquisition module that acquires the text block vector and at least one key sentence vector corresponding to each of the plurality of similar text blocks from the database respectively; A second acquisition module that acquires a text block vector similarity and at least one key sentence vector similarity corresponding to each of the plurality of similar text blocks based on the text vector and the text block vector and the at least one key sentence vector corresponding to each of the plurality of similar text blocks; A second determination module that determines a plurality of target text blocks corresponding to the retrieval text from the plurality of similar text blocks based on the text block vector similarity and the at least one key sentence vector similarity corresponding to each of the plurality of similar text blocks.
[0051] Each of the embodiments in the present specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the difference from other embodiments. In particular, for the retrieval enhancement system embodiment, since it is basically similar to the retrieval enhancement method embodiment, the description is relatively simple, and the relevant parts can be referred to the part of the retrieval enhancement method embodiment.
[0052] Please refer to Figure 4 The structure diagram of an electronic device provided by the embodiments of the present specification is shown.
[0053] As Figure 4As shown, the electronic device 400 can include at least one processor 401, at least one network interface 404, a user interface 403, a memory 405, and at least one communication bus 402.
[0054] The communication bus 402 can be used to realize the connection and communication of the above-mentioned components.
[0055] The user interface 403 can include a key, and the optional user interface can further include a standard wired interface, a wireless interface.
[0056] The network interface 404 can include, but is not limited to, a Bluetooth module, an NFC module, a Wi-Fi module, etc.
[0057] The processor 401 can include one or more processing cores. The processor 401 connects various parts in the entire electronic device 400 through various interfaces and lines, executes various functions of the electronic device 400 and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 405, and calling data stored in the memory 405. Optionally, the processor 401 can be implemented in at least one of the hardware forms of DSP, FPGA, PLA. The processor 401 can integrate one or a combination of CPU, GPU, and modem, etc. Among them, the CPU mainly processes the operating system, user interface, and application program, etc.; the GPU is responsible for rendering and drawing the content required to be displayed on the display screen; and the modem is used for processing wireless communication. It can be understood that the above-mentioned modem can also not be integrated into the processor 401, but can be realized by a separate chip.
[0058] The memory 405 can include RAM and can also include ROM. Optionally, the memory 405 includes a non-transitory computer readable medium. The memory 405 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 405 can include a program storage area and a data storage area, wherein the program storage area can store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area can store data involved in the above-mentioned various method embodiments, etc. The memory 405 can also be at least one storage device located away from the aforementioned processor 401. The memory 405 as a computer storage medium can include an operating system, a network communication module, a user interface module, and a retrieval enhancement application. The processor 401 can be used to call the retrieval enhancement application stored in the memory 405, and execute the steps of the retrieval enhancement method mentioned in the foregoing embodiments.
[0059] The embodiments of the present specification also provide a computer-readable storage medium, which stores instructions, when the instructions are executed on a computer or a processor, cause the computer or the processor to perform the steps of one or more of the above-mentioned retrieval enhancement method embodiments. The constituent modules of the above-mentioned electronic device, if realized in the form of software function units and sold or used as independent products, can be stored in the computer-readable storage medium.
[0060] In the above embodiments, all or part of the methods can be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the methods can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present specification are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in or transmitted by a computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center through a wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) manner. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that includes one or more available media sets. The available media can be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a digital versatile disc (DVD)), or a semiconductor medium (such as a solid state disk (SSD)), etc.
[0061] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned method embodiments can be implemented by a computer program to instruct related hardware, which can be stored in a computer-readable storage medium, and the program can include the processes of the above-mentioned method embodiments when executed. The storage medium includes ROM, RAM, magnetic or optical disk, and various program code storage media. In the case of no conflict, the technical features in the embodiments and the implementations can be combined arbitrarily.
[0062] The above-described embodiments are merely exemplary diagnostic description rather than limitation on the scope of the present specification, and various modifications and improvements made by those of ordinary skill in the art to the technical solutions of the present specification without departing from the design spirit of the present specification shall fall within the protection scope of the claims of the present specification.
Claims
1. A retrieval enhancement method based on key sentence vectors, characterized in that, include: Acquire multiple text data sets and then cut each set of text data into multiple text blocks; Extract at least one key sentence from each of the multiple text blocks; Convert multiple text blocks into text block vectors and multiple key sentences into key sentence vectors respectively; Establish a database that includes the index relationships between text blocks, text block vectors, and key sentence vectors; Get the search text and the corresponding text vector; Based on the text vector and the text block vectors in the database, an approximate nearest neighbor search is performed in the database to identify multiple similar text blocks among multiple text blocks in the database. Retrieve the text block vectors corresponding to each of the multiple similar text blocks from the database, as well as the vector of at least one key sentence. Based on the text vector, the text block vectors corresponding to multiple similar text blocks, and at least one key sentence vector, obtain the text block vector similarity of multiple similar text blocks and the similarity of at least one key sentence vector; Based on the text block vector similarity of each of the multiple similar text blocks and the vector similarity of at least one key sentence, multiple target text blocks corresponding to the retrieved text are determined from the multiple similar text blocks.
2. The retrieval enhancement method based on key sentence vectors according to claim 1, characterized in that, The extraction of at least one key sentence corresponding to each of the multiple text blocks includes: Get the text length of each of the multiple text blocks; Based on the text length of each of the multiple text blocks, extract at least one key sentence corresponding to each of the multiple text blocks.
3. The retrieval enhancement method based on key sentence vectors according to claim 1, characterized in that, Before determining multiple target text blocks from multiple similar text blocks based on the text block vector similarity corresponding to each of the multiple similar text blocks and at least one key sentence vector similarity, the method further includes: Obtain the similarity weights of text block vectors and key sentence vectors; The method of determining multiple target text blocks from multiple similar text blocks based on the text block vector similarity corresponding to each of the multiple similar text blocks and at least one key sentence vector similarity includes: Based on the text block vector similarity weight, the key sentence vector similarity weight, and the text block vector similarity of each of the multiple similar text blocks, and at least one key sentence vector similarity, multiple target text blocks are determined from multiple similar text blocks.
4. The retrieval enhancement method based on key sentence vectors according to claim 1, characterized in that, Both text block vector similarity and key sentence vector similarity are calculated using cosine similarity. Before determining multiple target text blocks from multiple similar text blocks based on the text block vector similarity corresponding to each of the multiple similar text blocks and at least one key sentence vector similarity, the method further includes: Get the text length of each of the multiple similar text blocks and the length of the search text; The method of determining multiple target text blocks from multiple similar text blocks based on the text block vector similarity corresponding to each of the multiple similar text blocks and at least one key sentence vector similarity includes: Based on the length of the retrieved text, the length of the text block corresponding to each of the multiple similar text blocks, the similarity of the text block vectors, and the similarity of at least one key sentence vector, multiple target text blocks are determined from multiple similar text blocks.
5. The retrieval enhancement method based on key sentence vectors according to claim 4, characterized in that, The method of determining multiple target text blocks from multiple similar text blocks based on the length of the retrieved text, the text length of each corresponding text block, the text block vector similarity, and at least one key sentence vector similarity includes: Based on the length of the retrieved text and the length of the text blocks corresponding to each of the multiple similar text blocks, obtain the text block length penalty factor corresponding to each of the multiple similar text blocks; Based on the text block length penalty factor, text block vector similarity, and at least one key sentence vector similarity of multiple similar text blocks, the overall similarity of each of the multiple similar text blocks is obtained. Based on the overall similarity of each of the multiple similar text blocks, multiple target text blocks are determined from the multiple similar text blocks.
6. The retrieval enhancement method based on key sentence vectors according to claim 5, characterized in that, Before establishing the database that includes the index relationships between text blocks, text block vectors, and key sentence vectors, the following steps are also included: Obtain the length of each key sentence; The establishment of the database, which includes the index relationships between text blocks, text block vectors, and key sentence vectors, specifically includes: Establish a database that includes the index relationships between each text block, each text block vector, each key sentence vector, and each key sentence length; Before obtaining the overall similarity of each of the multiple similar text blocks based on the text block length penalty factor, text block vector similarity, and at least one key sentence vector similarity, the method further includes: Obtain the length of at least one key sentence corresponding to each of multiple similar text blocks; The method of obtaining the overall similarity of multiple similar text blocks based on the text block length penalty factor, text block vector similarity, and at least one key sentence vector similarity includes: Based on the length of the retrieved text, the text block length penalty factor corresponding to each of the multiple similar text blocks, the text block vector similarity, the vector similarity of at least one key sentence, and the length of at least one key sentence, the overall similarity of each of the multiple similar text blocks is obtained.
7. The retrieval enhancement method based on key sentence vectors according to claim 6, characterized in that, The method of obtaining the overall similarity of multiple similar text blocks based on the length of the retrieved text, the text block length penalty factor corresponding to each of the multiple similar text blocks, the text block vector similarity, the vector similarity of at least one key sentence, and the length of at least one key sentence includes: Based on the length of the retrieved text and the length of at least one key sentence corresponding to each of the multiple similar text blocks, obtain the penalty factor for the length of at least one key sentence corresponding to each of the multiple similar text blocks; Based on the text length penalty factor, text block vector similarity, at least one key sentence vector similarity, and at least one key sentence length penalty factor corresponding to each of the multiple similar text blocks, the overall similarity of each of the multiple similar text blocks is obtained.
8. The retrieval enhancement method based on key sentence vectors according to claim 7, characterized in that, The method of obtaining the overall similarity of multiple similar text blocks based on their respective text length penalty factors, text block vector similarity, at least one key sentence vector similarity, and at least one key sentence length penalty factor includes: Based on the text length penalty factor and text block vector similarity of each of the multiple similar text blocks, the penalized text block similarity of each of the multiple similar text blocks is obtained. Based on the similarity of at least one key sentence vector and at least one key sentence length penalty factor corresponding to each of multiple similar text blocks, obtain at least one penalized key sentence similarity corresponding to each of multiple similar text blocks; Based on the penalized text block similarity of each of the multiple similar text blocks and the penalized key sentence similarity of at least one, the overall similarity of each of the multiple similar text blocks is obtained.
9. A large-scale language question-answering system, characterized in that, Includes a search module and a response module; The retrieval module uses the retrieval enhancement method based on key sentence vectors as described in any one of claims 1 to 8 to determine multiple target text blocks corresponding to the retrieval text; The answering module provides a text-based answer based on the retrieved text and multiple target text blocks corresponding to the retrieved text.
10. A retrieval enhancement system based on key sentence vectors, based on the retrieval enhancement method based on key sentence vectors according to any one of claims 1 to 8, characterized in that, include: The segmentation module acquires multiple text data sets and segments them into multiple text blocks. The extraction module extracts at least one key sentence corresponding to each of the multiple text blocks. The conversion module converts multiple text blocks into text block vectors and multiple key sentences into key sentence vectors, respectively. The module builds a database that includes the index relationships between text blocks, text block vectors, and key sentence vectors; The acquisition module retrieves the search text and the corresponding text vector. The first determining module performs an approximate nearest neighbor search in the database based on the text vector and the text block vectors in the database, so as to determine multiple similar text blocks among multiple text blocks in the database. The first acquisition module retrieves the text block vectors corresponding to multiple similar text blocks and at least one key sentence vector from the database. The second acquisition module, based on the text vector, the text block vector corresponding to each of the multiple similar text blocks, and at least one key sentence vector, acquires the text block vector similarity of the multiple similar text blocks and the similarity of at least one key sentence vector. The second determining module determines multiple target text blocks corresponding to the retrieved text from multiple similar text blocks based on the text block vector similarity corresponding to each of the multiple similar text blocks and at least one key sentence vector similarity.