A retrieval method and device, electronic equipment, and storage medium
By constructing a two-dimensional lookup table with both term frequency and document length as indexes, the problem of high computational cost and low efficiency in existing retrieval methods is solved, achieving efficient similarity calculation and improving retrieval efficiency.
Patent Information
- Application Number
- CN202611430363.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-15
- Publication Date
- 2026-11-20
AI Technical Summary
Current retrieval methods suffer from high computational costs and low efficiency, mainly due to the large overhead of floating-point division operations, which is particularly pronounced when there are many candidate documents.
A two-dimensional lookup table with word frequency and document length as dual indexes is constructed. The similarity value is obtained directly through memory addressing, avoiding real-time floating-point division calculation. Only the word frequency and length of the document need to be extracted.
It significantly reduces the arithmetic load of the retrieval process, improves retrieval efficiency, and significantly reduces the overall retrieval time, while ensuring the accuracy of similarity.
Smart Images

Figure CN123138359A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of retrieval technology, specifically relating to a retrieval method and apparatus, electronic equipment, and storage medium. Background Technology
[0002] With the explosive growth of internet information, search engines have become the core infrastructure for big data retrieval, knowledge management, and online search services. Current mainstream retrieval methods are based on the similarity between documents and the keywords to be searched. Generally, the similarity between each document in the database and the keywords to be searched is calculated, then the documents are sorted based on similarity, and the documents with the highest similarity are returned to the user.
[0003] While this method achieves good retrieval results, most similarity calculations involve floating-point division, which is computationally expensive, especially when there are many candidate documents. Therefore, current retrieval methods suffer from high computational cost and low efficiency. Summary of the Invention
[0004] This application provides a retrieval method, apparatus, electronic device, and storage medium, which can solve the problems of high computational cost and low efficiency in current retrieval methods.
[0005] In a first aspect, embodiments of this application provide a retrieval method, the method comprising: Obtain at least one keyword to be searched; For each keyword to be searched, a two-dimensional lookup table is generated, wherein the two-dimensional lookup table uses word frequency and document length as index dimensions, and the elements in the two-dimensional lookup table are used to represent the similarity between the keyword to be searched and the corresponding document under different preset word frequencies and preset document lengths; The initial filtering threshold is determined based on the two-dimensional lookup table. Based on the initial screening threshold and the two-dimensional lookup table, multiple documents with high similarity are selected from the database as search results, wherein the search results include at least N1 documents, and N1 is the preset target return quantity.
[0006] In one possible implementation of the first aspect, generating a two-dimensional lookup table for each keyword to be searched includes: Given the document length, for each preset word frequency, based on the similarity calculation formula, the similarity between the keyword to be searched and the corresponding document under all different preset document lengths is calculated to obtain the similarity array corresponding to the preset word frequency; after calculating the similarity array corresponding to all preset word frequencies, the two-dimensional lookup table is obtained; wherein, the value range of the preset word frequency is within [1, M], and M is the pre-calculated threshold of the preset word frequency; If the document length cannot be obtained, only the one-dimensional terms with a preset constant norm corresponding to the document length are filled, and the benchmark terms with the preset minimum word frequency are pre-calculated.
[0007] In one possible implementation of the first aspect, the step of selecting multiple documents with high similarity from the database as search results based on the initial screening threshold and the two-dimensional lookup table includes: From the database, the first document block with a maximum score greater than or equal to the initial filtering threshold is selected, wherein each document block includes multiple documents, the maximum score of the block is estimated based on the maximum word frequency within the block recorded in the skip index information of the document block, and the comprehensive similarity is determined based on the similarity between the document and each keyword to be searched; For each first document block, based on the two-dimensional lookup table, determine the comprehensive similarity between each document in the first document block and the keyword to be searched; The N2 documents with the highest overall similarity in the first document block are used as the search results.
[0008] In one possible implementation of the first aspect, determining the similarity between a document and the keyword to be searched, based on the two-dimensional lookup table, includes: Compare the word frequency of the keyword to be retrieved in the documents whose similarity is to be determined with the size of M; If the word frequency is less than or equal to M, then the similarity is searched from the two-dimensional lookup table based on the word frequency and the document length of the document; If the word frequency is greater than M, then the similarity is calculated based on the similarity calculation formula, according to the word frequency and the document length of the document.
[0009] In one possible implementation of the first aspect, when N2 is less than N1, the method further includes: Based on the two-dimensional lookup table, the comprehensive similarity between each document in the second document block and the keyword to be searched is determined, wherein the second document block is the document block in the database other than the first document block; The documents in the second document block are sorted with the filtered documents according to their overall similarity, and the N1 documents with the highest overall similarity are retained as the search results. The number of documents supplemented from the second document block is N3 = N1 - N2.
[0010] In one possible implementation of the first aspect, the method further includes: The document block with the abnormal maximum score is also included as the first document block.
[0011] In one possible implementation of the first aspect, determining the initial filtering threshold based on the two-dimensional lookup table includes: For each keyword to be searched, the similarity value with the minimum preset word frequency and the shortest preset document length is determined from the two-dimensional lookup table to obtain the maximum possible similarity corresponding to the keyword to be searched, wherein the maximum possible similarity is the maximum similarity that the document and the keyword to be searched can achieve; The initial screening threshold is determined based on the maximum possible similarity corresponding to each of the keywords to be searched, wherein the initial screening threshold is a query-level constant threshold that is calculated once before the search begins.
[0012] Secondly, embodiments of this application provide a retrieval device, including an acquisition unit, a pre-calculation unit, and a filtering unit: The acquisition unit is used to acquire at least one keyword to be searched; The pre-computation unit is used to generate a two-dimensional lookup table for each keyword to be retrieved. The two-dimensional lookup table uses word frequency and document length as index dimensions. The elements in the two-dimensional lookup table are used to represent the similarity between the keyword to be retrieved and the corresponding document under different preset word frequencies and preset document lengths. The filtering unit is used to determine an initial filtering threshold based on the two-dimensional lookup table, and based on the initial filtering threshold and the two-dimensional lookup table, to filter multiple documents with high similarity from the database as search results, wherein the search results include at least N1 documents, where N1 is a preset target return quantity.
[0013] Thirdly, embodiments of this application provide an electronic device, including a processor and a memory, wherein the memory is used to store a computer program; the processor is used to execute the computer program stored in the memory to implement the method described in the first aspect.
[0014] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed, can implement the method described in the first aspect above.
[0015] The beneficial effects of this application's embodiments compared to existing technologies are as follows: This application constructs a two-dimensional lookup table with word frequency and document length as dual indexes. Each element of this table directly corresponds to a similarity value under a specific combination. This allows for retrieval by extracting only the word frequency and length parameters of the document, and the corresponding similarity can be read through memory addressing. For documents with word frequencies within the pre-calculated threshold, there is no need to perform real-time similarity calculations involving floating-point division. The latency of floating-point division operations is typically tens of clock cycles, far exceeding that of memory access operations, and a large number of division instructions can cause processor pipeline blockage. In contrast, table lookup only requires one address calculation and memory read, thus significantly reducing the processing time per document. As the database size increases, this cumulative effect of saving computation per document becomes even more significant, and the overall retrieval time decreases significantly. Therefore, while ensuring similarity accuracy, high-cost floating-point operations are transformed into low-cost memory access operations, fundamentally reducing the arithmetic load of the retrieval process and significantly improving retrieval efficiency. Attached Figure Description
[0016] Figure 1 A flowchart illustrating the implementation of a retrieval method provided in this application; Figure 2 A flowchart illustrating the implementation of a similar document filtering method provided in this application embodiment; Figure 3 This is a schematic diagram of the structure of a retrieval device provided in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0017] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0018] It should be understood that, when used in this application specification, the term "comprising" indicates the presence of the described feature, integral, step, operation, element, and / or component, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components, and / or collections thereof.
[0019] It should also be understood that the term “and / or” as used in this application specification means any combination of one or more of the associated listed items, as well as all possible combinations, and includes such combinations.
[0020] As used in this application specification, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if [the described condition or event] is detected" may be interpreted, depending on the context, as "once determined," "in response to determination," "once [the described condition or event] is detected," or "in response to detection of [the described condition or event]."
[0021] Furthermore, in the description of this application, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0022] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0023] The present application will be described in further detail below with reference to specific embodiments, but the implementation of the present application is not limited thereto.
[0024] The method provided in this application can be applied to electronic devices such as mobile terminals, personal laptops, and supercomputers. This application does not impose any restrictions on the specific type of electronic device.
[0025] Example 1 Figure 1 The flowchart illustrates the implementation of a retrieval method provided in this application. As an example and not a limitation, the method may include steps S101-S104, which are described below.
[0026] S101, Obtain at least one keyword to be searched.
[0027] For example, a user can enter at least one keyword in the search box and then signal the electronic device to begin searching by clicking on the page. In response to this click, the electronic device receives the at least one keyword entered by the user.
[0028] For example, users can enter "features" or "risks" in the search box, separating different keywords with commas. Alternatively, users can enter multiple keywords consecutively, which will be processed by the electronic device through word segmentation.
[0029] Optionally, for databases with relatively fixed keywords, frequently used keywords can be displayed on the page, and users can send these keywords to electronic devices by clicking on them.
[0030] S102, Generate a two-dimensional lookup table for each keyword to be searched.
[0031] For example, in the similarity calculation formula used in this application, the similarity between the keyword to be retrieved and the document is mainly determined by the word frequency of the keyword in the document and the document length. Furthermore, the similarity calculation involves computationally expensive operations such as floating-point division. Therefore, referring to Table 1 and Code 1 below, the two-dimensional lookup table can use word frequency and document length as index dimensions. The elements in the table can represent the similarity between the keyword to be retrieved and the corresponding document under different preset word frequencies and preset document lengths.
[0032] Specifically, see Table 1 below. The preset word frequency range can be within [1, M], where M is the pre-calculated threshold of the preset word frequency. The document length range can be within [0, 255], covering the entire value space of the document length.
[0033] Here, document length refers to the encoded length of the document, not its actual length. The corresponding document refers to a document in which the frequency of the keyword to be searched is the preset frequency and the document length is the preset document length.
[0034] Table 1
[0035] For example, taking the keyword "apple" as an example, see Table 1 above, where the element value is 0.75. This indicates that if the frequency of "apple" in a document in the database is 1, and the document length is also 1, then the similarity between this document and "apple" should be 0.75.
[0036] Code 1
[0037] For example, referring to Code 1 above, the element type in the two-dimensional lookup table can be a single-precision floating-point number. A two-dimensional lookup table can occupy approximately 11KB of storage space, using stack allocation. The flag `use_score_lut` is used to control whether the two-dimensional lookup table is enabled.
[0038] In one example, the pre-calculated threshold for the preset word frequency can be set in advance by the search engine maintainers, for example, M is set to 10.
[0039] In one example, see Code 2 below, you can first fill the two-dimensional lookup table from the word frequency dimension, and then from the document length dimension.
[0040] For example, for each preset word frequency, the similarity between the keyword to be searched and the corresponding document can be calculated based on the similarity formula, given the preset word frequency and all preset document lengths, to obtain the similarity array corresponding to the preset word frequency. After calculating the similarity arrays corresponding to all preset word frequencies, a two-dimensional lookup table is obtained.
[0041] Code 2
[0042] For example, the similarity calculation formula can be the similarity calculation formula in algorithms such as BM25 and BM25F.
[0043] Specifically, the similarity can be calculated using the BM25 scoring algorithm with the following formula:
[0044] in, Indicates similarity. For weight normalization factor, Indicate word frequency, This indicates the document length. This term in the formula... This involves floating-point division.
[0045] S103, Determine the initial screening threshold based on the two-dimensional lookup table.
[0046] In one example, the similarity value for each keyword to be searched can be determined from the two-dimensional lookup table corresponding to the keyword, where the word frequency is at a preset minimum (i.e., word frequency is 1) and the document length is the shortest (i.e., the norm corresponding to the document length is the smallest). This yields the maximum possible similarity for that keyword—the upper bound of the similarity that a document with a word frequency of 1 can achieve. Then, based on the maximum possible similarity for all keywords to be searched, an initial filtering threshold is determined.
[0047] For example, the initial screening threshold can be a weighted sum of the maximum possible similarities of each keyword to be searched.
[0048] Optionally, when calculating the overall similarity, a higher weight value can be set for scarce keywords to be searched.
[0049] S104: Based on the initial screening threshold and a two-dimensional lookup table, select multiple documents with high similarity from the database as search results.
[0050] For example, the returned search results include at least N1 documents, where N1 is the target number of returned documents.
[0051] In some embodiments, a two-dimensional lookup table can be used to filter documents from the database that have a high overall similarity and are greater than the filtering threshold as search results.
[0052] For example, when there is only one keyword to be searched, the overall similarity refers to the similarity between that keyword and documents in the database. When there are multiple keywords to be searched, the overall similarity is similar to the filtering threshold, and can be a weighted sum of the similarities between each keyword and documents in the database.
[0053] In one possible implementation, document blocks with a maximum score greater than or equal to an initial filtering threshold can be selected from the database to obtain multiple first document blocks. Then, for each first document block, a two-dimensional lookup table is used to determine the overall similarity between each document within it and the keyword to be searched. Finally, the N² documents with the highest overall similarity from the first document blocks are selected as the search results.
[0054] For example, the maximum block score is the upper bound of the overall similarity of documents in a document block, estimated based on the maximum word frequency within the block recorded in the skip index information of the document block.
[0055] Optionally, referring to Code 3 below, a reliability gate can be applied to the maximum block score: when the maximum term frequency within a block exceeds the single-byte range, the block-max term_freq field in the skip entry may overflow or be marked as an invalid value (such as a sentinel value), or the maximum term frequency within the block may be zero (indicating that skip entry data is missing). In this case, the maximum block score of the document block is unreliable, and skipping of the document block is abandoned. The document block is directly treated as the first document block for which the comprehensive similarity needs to be calculated.
[0056] Code 3
[0057] In one example, see Code 4 below. When calculating similarity, if the frequency of the keyword to be searched in the document is within the two-dimensional lookup table, that is, less than or equal to M, then the similarity between the keyword to be searched and the document can be found from the two-dimensional lookup table; otherwise, the similarity can be calculated directly according to the similarity calculation formula.
[0058] Code 4
[0059] In one possible implementation, if the number of documents N2 in the search results obtained based on the first document block is less than N1, then based on the two-dimensional lookup table, the comprehensive similarity between each document in the remaining document block of the database, i.e. the second document block, and the keyword to be searched can be determined. The N3 documents with the highest comprehensive similarity are added to the candidate set and sorted uniformly with the determined documents according to the comprehensive similarity. The N1 documents with the highest comprehensive similarity are retained as the search results.
[0060] For example, N3 = N1 - N2.
[0061] This application constructs a two-dimensional lookup table with term frequency and document length as dual indexes. Each element of this table directly corresponds to a similarity value under a specific combination. This allows for retrieval by extracting only the term frequency and length parameters of the document, and then retrieving the corresponding similarity value through memory addressing. For documents with term frequencies within a pre-calculated threshold, there is no need to perform real-time similarity calculations involving floating-point division. The latency of floating-point division operations is typically tens of clock cycles, far exceeding that of memory access operations, and a large number of division instructions can cause processor pipeline blockage. In contrast, table lookup only requires one address calculation and memory read, thus significantly reducing the processing time per document. As the database size increases, this cumulative effect of saving computation per document becomes even more significant, resulting in a significant decrease in overall retrieval time. Therefore, while ensuring similarity accuracy, high-cost floating-point operations are transformed into low-cost memory access operations, fundamentally reducing the arithmetic load of the retrieval process and significantly improving retrieval efficiency.
[0062] Furthermore, compared to the cold-start retrieval method that directly uses 0 as the initial screening threshold, this application uses the maximum possible similarity when the word frequency in the lookup table is 1 and the document is the shortest as the initial screening threshold. This threshold is calculated once before the retrieval begins and is not updated with the status of the candidate set. This avoids the operation of decoding all documents in the low-scoring document block and determining the comprehensive similarity when the retrieval begins, significantly reducing the number of similarity determinations and the amount of computation.
[0063] Furthermore, by forcing the document block to be treated as the first document block for similarity calculation when the maximum score of the block is unreliable, it is possible to avoid documents being missed and improve the credibility of the search results.
[0064] Example 2 Figure 2 The diagram illustrates a flowchart of a similar document filtering method provided in an embodiment of this application. As an example and not a limitation, this method can be a specific possible implementation of step S104 described above. The method may include steps S201-S210, which are described below.
[0065] S201, determine whether the maximum score of the i-th document block in the database is greater than the current filtering threshold.
[0066] For example, i is a positive integer.
[0067] For example, to avoid the large computational overhead of calculating the similarity between the keyword to be searched and each document in the database, the documents in the database can be divided into blocks, and multiple documents can be assembled into a document block.
[0068] In one example, during retrieval, the document block can be directly compared with the maximum score of the target keyword and the current filtering threshold. If the maximum score of the block is greater than or equal to the current filtering threshold, the document block is determined to be a first document block, and the following step S202 can be performed.
[0069] For example, the maximum block score refers to the upper bound of the overall similarity of documents in a document block, estimated based on the maximum term frequency of the document block. Taking the BM25 score as an example, the maximum block score can be determined based on the maximum term frequency and minimum document length of the document block; the maximum term frequency of the document block is recorded in the skip entry information pre-stored for the document block in the inverted index, and reading this information does not require decoding the documents within the document block.
[0070] For example, the initial value of the filtering threshold can be the initial filtering threshold mentioned above. That is, at the beginning of the search, the initial filtering threshold can be compared with the maximum score of the document block.
[0071] For example, during the process of filtering document blocks with the initial filtering threshold, the filtering threshold remains unchanged as a constant at the query level and is not updated with the filling status of the candidate set, so that the block-level skipping behavior in the cold start phase (when the candidate set is not full) is consistent with that in the normal phase; the threshold update in the following steps S208a-S209a is an optional enhancement method used when it is necessary to enhance the pruning force.
[0072] In another example, if the maximum score of the i-th document block is less than the current filtering threshold, the document block can be determined to be a second document block, and no further steps are taken.
[0073] S202, determine whether the number of documents in the candidate set is less than N1.
[0074] For example, the candidate set stores documents with a high overall similarity.
[0075] In one example, when the search begins, there are few documents in the candidate set, so step S203b can be performed. As the search progresses, the candidate set is gradually filled. Once the number of documents in the candidate set is detected to be equal to N1, step S203a can be performed.
[0076] S203a, based on a two-dimensional lookup table, determine the similarity between the j-th document in the first document block and the keyword to be searched, and obtain the comprehensive similarity.
[0077] For example, j is a positive integer.
[0078] In one example, the frequency of each keyword to be searched can be determined first, and then compared with a pre-calculated threshold. If the frequency of a keyword is greater than the pre-calculated threshold, the similarity between the j-th document and the keyword is calculated in real time according to the similarity calculation formula. If the frequency of a keyword is less than or equal to the pre-calculated threshold, the similarity between the j-th document and the keyword is found in the two-dimensional lookup table of the keyword. Finally, the overall similarity of the j-th document is calculated based on the similarity between the j-th document and all the keywords to be searched.
[0079] Specifically, if the specialized encoding bit of the word frequency indicates that the word frequency is 1 (e.g., the encoding bit is zero), then the similarity can be directly read from the corresponding row in the two-dimensional lookup table with the word frequency index of 1, skipping the comparison between the word frequency and the pre-calculated threshold, thus reducing branch judgments.
[0080] For example, the overall similarity can be a weighted sum of the similarities between a document and all search keywords.
[0081] S204a, compare the overall similarity of the j-th document with the current minimum competition score.
[0082] For example, the current minimum competition score refers to the minimum overall similarity of all documents in the candidate set.
[0083] In one example, if the overall similarity is less than or equal to the current minimum competition score, the candidate set is not updated, and the following step S206a is performed directly.
[0084] In another example, if the overall similarity of the j-th document is greater than the current minimum competition score, then step S205a needs to be performed first to update the candidate set, and then step S206a needs to be performed.
[0085] S205a, based on the j-th document, update the candidate set.
[0086] For example, the document with the lowest overall similarity in the current candidate set can be removed, and the j-th document can be added to the candidate set. At the same time, the current minimum competition score of the candidate set can be updated, and then step S206a can be performed.
[0087] S206a, determine whether the j-th document is the last document in the i-th document block.
[0088] In one example, if the j-th document is the last document in the i-th document block, step S207a can be performed.
[0089] In another example, if the j-th document is not the last document in the i-th document block, then we can let j = j + 1 to determine the overall similarity of the next document starting from step S203a.
[0090] S207a, determine whether the i-th document block is the last document block in the database.
[0091] In one example, if the i-th document block is not the last document block in the database, step S208a can be performed.
[0092] In another example, if the i-th document block is the last document block in the database, then step S210 can be performed to output the documents in the candidate set as the retrieval results.
[0093] S208a, determine whether the current minimum competition score is greater than the current screening threshold.
[0094] In one example, if the current minimum competition score is greater than the current screening threshold, step S209a can be performed to update the current screening threshold.
[0095] In another example, if the current minimum competition score is less than or equal to the current filtering threshold, then i = i + 1, and starting from step S201, filter the next document block.
[0096] S209a, Update the filtering threshold.
[0097] For example, the current minimum competition score can be used as the updated filtering threshold, and then let i = i + 1, starting from step S201, to filter the next document block.
[0098] S203b, add the j-th document to the candidate set.
[0099] For example, when there are few documents in the candidate set, the j-th document can be added directly to the candidate set, and then S204b can be performed.
[0100] S204b, determine whether the j-th document is the last document in the i-th document block.
[0101] In one example, if the j-th document is not the last document in the i-th document block, then j = j + 1, and start filtering the next document from step S202.
[0102] In another example, if the j-th document is the last document in the i-th document block, the following step S205b can be performed.
[0103] S205b, determine whether the i-th document block is the last document block in the database.
[0104] In one example, if the i-th document block is the last document block in the database, step S206b can be performed to determine whether the number of documents in the candidate set after adding the j-th document is less than N1.
[0105] In another example, if the i-th document block is not the last document block in the database, we can let i = i + 1 and start filtering the next document block from step S201.
[0106] S206b, determine whether the number of documents in the candidate set is less than N1.
[0107] In one example, if the number of documents N2 in the candidate set is not less than N1, step S210 can be performed; otherwise, step S207b can be performed.
[0108] S207b, reset the filtering threshold, and select N3 documents with high overall similarity from the second document block to add to the candidate set. After adding, sort them uniformly according to overall similarity, and retain the N1 documents with the highest overall similarity.
[0109] For example, N3 = N1 - N2.
[0110] In one example, referring to code 5 below, when there are few documents in the candidate set, the filtering threshold can be reset to 0. The second document block with the lowest overall similarity is then filtered to find N3 documents with higher overall similarity, which are added to the candidate set. These N3 documents are then sorted according to their overall similarity with the existing documents in the candidate set, and the N1 documents with the highest overall similarity are retained. Then, step S210 is performed.
[0111] Code 5
[0112] For example, based on steps similar to S202-S209a, with the target number of documents N3 that need to be supplemented in the candidate set as the objective, the initial value of the filtering threshold is set to 0, and documents with high overall similarity are filtered from the second document block and sorted uniformly with the original documents in the candidate set.
[0113] S210, output the documents in the current candidate set as the search results.
[0114] This application prioritizes filtering document blocks with high overall similarity and searches for documents in the remaining document blocks when the number of documents in the search results is small, which can reduce the amount of computation while ensuring the search effect.
[0115] Example 3 Figure 3 This is a schematic diagram of a retrieval device provided in an embodiment of this application. As an example and not a limitation, the device may include an acquisition unit 310, a pre-calculation unit 320, and a filtering unit 330.
[0116] In some embodiments, the acquisition unit 310 is used to acquire at least one keyword to be retrieved; the pre-calculation unit 320 is used to generate a two-dimensional lookup table for each keyword to be retrieved; and the filtering unit 330 is used to determine an initial filtering threshold based on the two-dimensional lookup table, and to filter multiple documents with high similarity from the database as search results based on the initial filtering threshold and the two-dimensional lookup table.
[0117] For example, the two-dimensional lookup table uses word frequency and document length as index dimensions. The elements in the two-dimensional lookup table are used to represent the similarity between the keyword to be searched and the corresponding document under different preset word frequencies and preset document lengths.
[0118] For example, the search results include at least N1 documents, where N1 is the preset target number of results.
[0119] In one possible implementation, the pre-computation unit 320 is specifically used to calculate the similarity between the keyword to be retrieved and the corresponding document under all different preset document lengths for each preset word frequency, based on the similarity calculation formula, to obtain a similarity array corresponding to the preset word frequency; after calculating the similarity array corresponding to all preset word frequencies, a two-dimensional lookup table is obtained; wherein, in the case that the database does not store data on document length, the two-dimensional lookup table is downgraded to filling only one-dimensional items with a preset constant norm corresponding to the document length, and pre-computing the benchmark item when the word frequency takes a preset minimum value.
[0120] For example, the preset word frequency ranges from [1, M], where M is the pre-calculated threshold of the preset word frequency.
[0121] In one possible implementation, the filtering unit 330 is specifically used to filter first document blocks from the database whose maximum score is greater than or equal to the initial filtering threshold; for each first document block, based on a two-dimensional lookup table, to determine the comprehensive similarity between each document in the first document block and the keyword to be retrieved.
[0122] For example, each document block includes multiple documents. The maximum score of the block is the upper bound of the comprehensive similarity of the documents in the document block, which is estimated based on the maximum word frequency recorded in the skip index information of the document block. There is no need to calculate the comprehensive similarity of each document in the document block individually. The comprehensive similarity is determined based on the similarity between the document and each keyword to be searched.
[0123] In one example, the filtering unit 330 is specifically used in the similarity calculation process to: compare the word frequency of the keyword to be retrieved in the document whose similarity needs to be determined with the value of M; if the word frequency is less than or equal to M, then based on the word frequency and the document length of the document, the similarity is searched from the two-dimensional lookup table, wherein if the word frequency is a preset minimum value of 1, then the similarity is directly read from the corresponding row in the two-dimensional lookup table with the preset minimum value index; if the word frequency is greater than M, then based on the similarity calculation formula, the similarity is calculated according to the word frequency and the document length of the document.
[0124] In one example, when N2 is less than N1, the filtering unit 330 is specifically used to determine the comprehensive similarity between each document in the second document block and the keyword to be searched based on a two-dimensional lookup table. The second document block is a document block in the database other than the first document block. The documents in the second document block are sorted in a unified manner with the determined documents according to their comprehensive similarity, and the N1 documents with the highest comprehensive similarity are retained as the search results. The number of documents supplemented from the second document block is N3 = N1 - N2.
[0125] For example, N3 = N1 - N2.
[0126] In one possible implementation, the pre-computation unit 320 is specifically used to determine, for each keyword to be retrieved, the similarity value when the word frequency takes the preset minimum value and the document length is the shortest document from the two-dimensional lookup table, and obtain the maximum possible similarity corresponding to the keyword to be retrieved, wherein the shortest document is the document with the smallest norm corresponding to the document length; and determine the initial screening threshold based on the maximum possible similarity corresponding to each keyword to be retrieved. The initial screening threshold is a query-level constant threshold calculated once before the retrieval begins, and is independent of each document block.
[0127] In one example, the filtering unit 330 is also used to perform credibility gating on each document block: if the maximum word frequency within the block corresponding to any keyword to be retrieved that participates in the block maximum score estimation is a sentinel value indicating data anomaly or is zero, then the maximum block score of the document block is determined to be unreliable, skipping of the document block is disabled, and the document block is used as the first document block for comprehensive similarity calculation to avoid documents being missed.
[0128] This application constructs a two-dimensional lookup table with term frequency and document length as dual indexes. Each element of this table directly corresponds to a similarity value under a specific combination. This allows for retrieval by extracting only the term frequency and length parameters of the document, and then retrieving the corresponding similarity value through memory addressing. For documents with term frequencies within a pre-calculated threshold, there is no need to perform real-time similarity calculations involving floating-point division. The latency of floating-point division operations is typically tens of clock cycles, far exceeding that of memory access operations, and a large number of division instructions can cause processor pipeline blockage. In contrast, table lookup only requires one address calculation and memory read, thus significantly reducing the processing time per document. As the database size increases, this cumulative effect of saving computation per document becomes even more significant, resulting in a significant decrease in overall retrieval time. Therefore, while ensuring similarity accuracy, high-cost floating-point operations are transformed into low-cost memory access operations, fundamentally reducing the arithmetic load of the retrieval process and significantly improving retrieval efficiency.
[0129] Example 4 Figure 4 The diagram shown is a structural schematic of an electronic device provided in an embodiment of this application. For example... Figure 4 The illustrated electronic device 400 may include: at least one processor 410 ( Figure 4 The diagram shows only one processor, a memory 420, and a computer program 430 stored in the memory 420 and executable on the at least one processor 410, which, when executing the computer program 430, implements the steps in any of the above method embodiments.
[0130] The electronic device 400 may be a robot or other processing device capable of implementing the above methods. This application embodiment does not impose any restrictions on the specific type of electronic device.
[0131] Those skilled in the art will understand that Figure 4 This is merely an example of electronic device 400 and does not constitute a limitation on the electronic device. It may include more or fewer components than shown, or combine certain components, or use different components. For example, the electronic device 400 may also include input / output interfaces.
[0132] The processor 410 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0133] In some embodiments, the memory 420 may be an internal storage unit, such as a hard disk or RAM. In other embodiments, the memory 420 may be an external storage device, such as a plug-in hard disk, a smart memory card (SMC), a secure digital card (SD), or a flash card. Furthermore, the memory 420 may include both internal and external storage units. The memory 420 is used to store the operating system, applications, boot loader, data, and other programs, such as the program code of the computer program. The memory 420 can also be used to temporarily store data that has been output or will be output.
[0134] It should be understood that the sequence number of each step in the above embodiments does not imply 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 embodiments of this application.
[0135] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0136] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps in the above-described method embodiments.
[0137] This application provides a computer program product that, when run on an electronic device, causes the electronic device to execute the steps described in the various method embodiments above.
[0138] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying computer program code to a photographing device / terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.
[0139] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0140] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
Claims
1. A retrieval method, characterized in that, include: Obtain at least one keyword to be searched; For each keyword to be searched, a two-dimensional lookup table is generated, wherein the two-dimensional lookup table uses word frequency and document length as index dimensions, and the elements in the two-dimensional lookup table are used to represent the similarity between the keyword to be searched and the corresponding document under different preset word frequencies and preset document lengths; The initial filtering threshold is determined based on the two-dimensional lookup table. Based on the initial screening threshold and the two-dimensional lookup table, multiple documents with high similarity are selected from the database as search results, wherein the search results include at least N1 documents, and N1 is the preset target return quantity.
2. The method according to claim 1, characterized in that, For each keyword to be searched, a two-dimensional lookup table is generated, including: Given the document length, for each preset word frequency, based on the similarity calculation formula, the similarity between the keyword to be searched and the corresponding document under all different preset document lengths is calculated to obtain the similarity array corresponding to the preset word frequency; after calculating the similarity array corresponding to all preset word frequencies, the two-dimensional lookup table is obtained; wherein, the value range of the preset word frequency is within [1, M], and M is the pre-calculated threshold of the preset word frequency; If the document length cannot be obtained, only the one-dimensional terms with the norm corresponding to the document length are filled, and the benchmark terms with the word frequency taking the preset minimum value are pre-calculated.
3. The method according to claim 2, characterized in that, The step of selecting multiple documents with high similarity from the database as search results based on the initial screening threshold and the two-dimensional lookup table includes: From the database, the first document block with a maximum score greater than or equal to the initial filtering threshold is selected, wherein each document block includes multiple documents, the maximum score of the block is estimated based on the maximum word frequency within the block recorded in the skip index information of the document block, and the comprehensive similarity is determined based on the similarity between the document and each keyword to be searched; For each first document block, based on the two-dimensional lookup table, determine the comprehensive similarity between each document in the first document block and the keyword to be searched; The N2 documents with the highest overall similarity in the first document block are used as the search results.
4. The method according to claim 3, characterized in that, Based on the two-dimensional lookup table, the similarity between the document and the keyword to be searched is determined, including: Compare the word frequency of the keyword to be retrieved in the documents whose similarity is to be determined with the size of M; If the word frequency is less than or equal to M, then the similarity is searched from the two-dimensional lookup table based on the word frequency and the document length of the document; If the word frequency is greater than M, then the similarity is calculated based on the similarity calculation formula, according to the word frequency and the document length of the document.
5. The method according to claim 4, characterized in that, When N2 is less than N1, the method further includes: Based on the two-dimensional lookup table, the comprehensive similarity between each document in the second document block and the keyword to be searched is determined, wherein the second document block is the document block in the database other than the first document block; The documents in the second document block are sorted with the filtered documents according to their overall similarity, and the N1 documents with the highest overall similarity are retained as the search results. The number of documents supplemented from the second document block is N3 = N1 - N2.
6. The method according to claim 3, characterized in that, The method further includes: The document block with the abnormal maximum score is also included as the first document block.
7. The method according to any one of claims 1-6, characterized in that, The step of determining the initial filtering threshold based on the two-dimensional lookup table includes: For each keyword to be searched, the similarity value with the minimum preset word frequency and the shortest preset document length is determined from the two-dimensional lookup table to obtain the maximum possible similarity corresponding to the keyword to be searched, wherein the maximum possible similarity is the maximum similarity that the document and the keyword to be searched can achieve; The initial screening threshold is determined based on the maximum possible similarity corresponding to each of the keywords to be searched, wherein the initial screening threshold is a query-level constant threshold that is calculated once before the search begins.
8. A retrieval device, characterized in that, Includes acquisition unit, pre-calculation unit, and filtering unit; The acquisition unit is used to acquire at least one keyword to be searched; The pre-computation unit is used to generate a two-dimensional lookup table for each keyword to be retrieved. The two-dimensional lookup table uses word frequency and document length as index dimensions. The elements in the two-dimensional lookup table are used to represent the similarity between the keyword to be retrieved and the corresponding document under different preset word frequencies and preset document lengths. The filtering unit is used to determine an initial filtering threshold based on the two-dimensional lookup table, and based on the initial filtering threshold and the two-dimensional lookup table, to filter multiple documents with high similarity from the database as search results, wherein the search results include at least N1 documents, where N1 is a preset target return quantity.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, When the processor executes the computer program, it implements the method as described in any one of claims 1-7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by an electronic device, it implements the method as described in any one of claims 1-7.
