Vector retrieval method and device, electronic equipment and storage medium

By determining and selecting the search scheme with the smallest cost score in vector retrieval, the problems of high consumption and low efficiency of vector retrieval resources in the prior art are solved, and the search efficiency and effect are improved.

CN119025723APending Publication Date: 2024-11-26BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410931128.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-11
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

The prior art lacks effective solutions in vector retrieval to choose reasonable search methods, resulting in high resource consumption and low search efficiency.

Method used

By obtaining vector search requests, the cost scores of multiple search schemes are determined, and the scheme with the smallest cost score is selected for search operations, using HNSW indexing and filtering conditions to support the effective selection of multiple search schemes.

Benefits of technology

The rational choice of search solutions is achieved, the search efficiency and effectiveness is improved, resource consumption is reduced, and the selected solutions are ensured that the selected solutions are applicable and at the lowest cost.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119025723A_ABST
    Figure CN119025723A_ABST
Patent Text Reader

Abstract

The invention provides a vector retrieval method and device, electronic equipment and a storage medium, and relates to the field of cloud computing and artificial intelligence such as information retrieval, databases and distributed storage. The method comprises the following steps: acquiring a vector retrieval request; cost scores corresponding to M preset retrieval schemes are determined, M is a positive integer larger than 1, the cost score corresponding to any retrieval scheme is an evaluation score of the cost needing to be consumed if the retrieval scheme is adopted to complete the vector retrieval operation, and the larger the value of the cost score is, the larger the cost needing to be consumed is; and selecting the cost score with the minimum value, taking the retrieval scheme corresponding to the selected cost score as a target scheme, and adopting the target scheme to complete the current vector retrieval operation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the fields of cloud computing and artificial intelligence technology, and in particular to vector retrieval methods, devices, electronic devices and storage media in the fields of information retrieval, database and distributed storage. Background Art

[0002] With the development of technology, information retrieval has become an important means for people to obtain information. Among them, vector retrieval is an information retrieval method based on the vector space model, which plays an important role in the retrieval of text, image and audio. Summary of the invention

[0003] The present disclosure provides a vector retrieval method, device, electronic device and storage medium.

[0004] A vector retrieval method, comprising:

[0005] Get vector retrieval request;

[0006] Determine the cost scores corresponding to the predetermined M retrieval schemes, where M is a positive integer greater than 1, and the cost scores corresponding to any retrieval scheme are: if the retrieval scheme is used to complete the current vector retrieval operation, the evaluation score of the cost required to be consumed, wherein the larger the value of the cost score is, the greater the cost required to be consumed;

[0007] The cost score with the smallest value is selected, and the search solution corresponding to the selected cost score is used as the target solution, and the target solution is used to complete the vector search operation.

[0008] A vector retrieval device comprises: an acquisition module, a determination module and a processing module;

[0009] The acquisition module is used to acquire a vector search request;

[0010] The determination module is used to determine the cost scores corresponding to the predetermined M retrieval schemes, where M is a positive integer greater than 1, and the cost scores corresponding to any retrieval scheme are: if the retrieval scheme is used to complete the current vector retrieval operation, the evaluation score of the cost required to be consumed, wherein the larger the value of the cost score is, the greater the cost required to be consumed;

[0011] The processing module is used to select the cost score with the smallest value, and use the search solution corresponding to the selected cost score as the target solution, and use the target solution to complete the current vector search operation.

[0012] An electronic device, comprising:

[0013] at least one processor; and

[0014] a memory communicatively connected to the at least one processor; wherein,

[0015] The memory stores instructions that can be executed by the at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to perform the method described above.

[0016] A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to execute the method as described above.

[0017] A computer program product comprises a computer program / instruction, wherein the computer program / instruction implements the method described above when executed by a processor.

[0018] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.

[0020] Figure 1 A flowchart of an embodiment of the vector retrieval method disclosed in the present invention;

[0021] Figure 2 Schematic diagram of the structure of the vector search device embodiment 200 of the present disclosure;

[0022] Figure 3 A schematic block diagram of an electronic device 300 that can be used to implement an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0023] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0024] In addition, it should be understood that the term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0025] Figure 1FIG. 1 is a flow chart of an embodiment of the vector retrieval method described in the present disclosure. Figure 1 As shown, the following specific implementation methods are included.

[0026] In step 101, a vector search request is obtained.

[0027] In step 102, the cost scores corresponding to the predetermined M retrieval schemes are determined, where M is a positive integer greater than 1. The cost scores corresponding to any retrieval scheme are: the evaluation score of the cost required to complete the vector retrieval operation if the retrieval scheme is used, where the larger the value of the cost score, the greater the cost required.

[0028] In step 103, the cost score with the smallest value is selected, and the search solution corresponding to the selected cost score is used as the target solution, and the target solution is used to complete the vector search operation.

[0029] In practical applications, there are many different ways to implement vector retrieval. There is currently no good solution for how to choose a suitable method.

[0030] By adopting the scheme described in the above method embodiment, for the obtained vector search request, the cost scores corresponding to the multiple available search schemes can be determined respectively, and the search scheme with the smallest cost score can be selected, and then the vector search operation can be completed according to the selected search scheme, thereby achieving a reasonable selection of the search scheme, thereby improving the search efficiency and search effect, and reducing resource consumption, etc.

[0031] In some embodiments of the present disclosure, a vector retrieval request may include: a vector to be retrieved. Accordingly, a target solution may be adopted to determine a retrieval result corresponding to the vector to be retrieved based on N candidate vectors in a vector database, and the retrieval result is returned, wherein the vector database includes N rows of vector data, and the N rows of vector data are respectively used as candidate vectors, N is a positive integer greater than 1, and the specific value depends on the actual situation.

[0032] In addition, in some embodiments of the present disclosure, each row of vector data may include: a primary key, vector field data, and scalar field data, and the vector index method corresponding to the vector database is a hierarchical navigation small world (HNSW) index that only includes the primary key and vector field data. Furthermore, the vector retrieval request may also include: a filter condition (p), and the filter condition is a filter condition for the primary key and / or scalar field data. Accordingly, based on the HNSW index and the filter condition, the retrieval result corresponding to the vector to be retrieved can be determined according to the N candidate vectors in the vector database.

[0033] That is to say, each row of vector data in the vector database can be composed of a primary key + vector field data + scalar field data respectively. In the scheme described in the present disclosure, it can be assumed that there is only one vector field. The primary key can be used to uniquely identify each row of vector data, the vector field can be used to store specific vector data, and the scalar field can be used to store scalar data, such as the author information of the text.

[0034] In addition, the vector indexing method corresponding to the vector database can be HNSW indexing, which only includes primary key and vector field data. Primary key and vector field data can be resident in memory, while scalar field data usually needs to be read from disk to obtain.

[0035] Generally speaking, the filtering conditions only involve primary key and scalar field data, and do not involve vector field data. In addition, the vector search described in the present disclosure can be a top-K vector search, that is, the K search results with the highest similarity to the vector to be searched are returned, where K is a positive integer and the specific value can be determined according to actual needs.

[0036] Based on the composition and indexing methods of the above-mentioned vector database, effective support for a variety of different retrieval schemes can be achieved, thereby improving the scope of application of the scheme described in the present disclosure.

[0037] In addition, M search schemes can be pre-set, and the specific value of M can be determined according to actual needs, such as 6. Accordingly, for the convenience of expression, the 6 search schemes are respectively called the first search scheme, the second search scheme, the third search scheme, the fourth search scheme, the fifth search scheme and the sixth search scheme.

[0038] In some embodiments of the present disclosure, for an acquired vector retrieval request, a method for determining cost scores corresponding to respective predetermined M retrieval schemes may include: for any retrieval scheme, performing the following processing respectively: in response to determining that the retrieval scheme is applicable to the current vector retrieval operation according to a filtering condition carried in the vector retrieval request, determining a cost score corresponding to the retrieval scheme according to a score determination method corresponding to the retrieval scheme; in response to determining that the retrieval scheme is not applicable to the current vector retrieval operation according to the filtering condition, setting the cost score corresponding to the retrieval scheme to infinity.

[0039] Since the retrieval scheme corresponding to the smallest cost score will be selected as the target scheme in the scheme disclosed in the present invention, after the cost score corresponding to any retrieval scheme is set to infinity, it means that the retrieval scheme will not be selected as the target scheme in the future, thereby achieving the effect of filtering out inapplicable retrieval schemes, and further ensuring that the selected target scheme must be an applicable retrieval scheme with the smallest cost, thereby reducing resource consumption and improving the accuracy of the obtained retrieval results.

[0040] As mentioned above, the scheme disclosed in the present invention may include six search schemes, namely, a first search scheme, a second search scheme, a third search scheme, a fourth search scheme, a fifth search scheme and a sixth search scheme. The specific implementation of each search scheme and the corresponding cost score acquisition method are explained below.

[0041] 1) First search scheme

[0042] The first search scheme may be referred to as a pre-filter scheme.

[0043] In some embodiments of the present disclosure, in response to determining that the target scheme is the first retrieval scheme, the candidate vectors that meet the filtering conditions can be determined by querying the scalar field data of N candidate vectors, and the filtering conditions are filtering conditions for the scalar field data. Based on the HNSW index, a K-nearest neighbor (KNN, K-NearestNeighbor) search can be performed on the candidate vectors that meet the filtering conditions to obtain a retrieval result.

[0044] The filtering condition carried in the vector search request may be a filtering condition for scalar field data. Then, the scalar field data of N candidate vectors may be queried respectively to determine the candidate vectors that meet the filtering condition. Assuming that the scalar field data includes a name, the specific name may be Zhang San, Li Si, Wang Wu, Zhang Qi, etc., and assuming that the filtering condition is to filter out the candidate vectors whose last name in the name is Zhang, then the candidate vectors corresponding to Zhang San and Zhang Qi are the candidate vectors that meet the filtering condition.

[0045] Afterwards, a bitmap of primary keys for the N candidate vectors may be generated, wherein the bitmap may include N bits, each bit may correspond to a candidate vector, and each bit may have a first value or a second value, wherein the first value is used to indicate that the corresponding candidate vector meets the filtering condition, and the second value is used to indicate that the corresponding candidate vector does not meet the filtering condition. For example, assuming that the value of N is 100, the generated bitmap will include 100 bits, each bit corresponds to a candidate vector, and each bit may have a value of 1 or 0, such as 1 indicating that the corresponding candidate vector meets the filtering condition, and 0 indicating that the corresponding candidate vector does not meet the filtering condition.

[0046] Furthermore, a KNN search may be performed on candidate vectors that meet the filtering conditions based on the HNSW index and the bitmap, thereby obtaining the desired search results. For example, the bitmap may be introduced into the HNSW index, and a KNN search may be performed in combination with the vector field data in the HNSW index.

[0047] In the solution disclosed herein, the search results returned to the user may refer to one or more candidate vectors, or may refer to vector field data in these candidate vectors, etc. The specific implementation method is not limited and will not be described in detail later.

[0048] The first search scheme uses less memory and is faster to implement when the value of N is small.

[0049] In addition, in some embodiments of the present disclosure, a method for determining a cost score corresponding to a first retrieval scheme may include: determining a cost score for querying scalar field data of N candidate vectors, obtaining a ratio of the number of candidate vectors that satisfy a filtering condition to N as a row selectivity, determining a cost score for a KNN retrieval based on N and the row selectivity, and taking the sum of the two cost scores as the cost score corresponding to the first retrieval scheme.

[0050] In the scheme described in this disclosure, the following symbols can be defined:

[0051]

[0052] Table 1 Different symbols defined

[0053] That is, the cost score corresponding to the first search scheme can be:

[0054] S1=disk_query_cost(N)+knn_cost(N, sel(p)); (1)

[0055] Among them, sel(p) refers to the ratio of the number of candidate vectors that meet the filtering conditions to N, that is, the row selection rate. After respectively obtaining the cost score disk_query_cost(N) of the scalar field data of querying N candidate vectors and the cost score knn_cost(N, sel(p)) of the KNN retrieval determined according to N and sel(p), the two cost scores can be added together, and the sum can be used as the cost score S1 corresponding to the first retrieval scheme.

[0056] In addition, there is no restriction on how to obtain knn_cost(N, sel(p)), hnsw_cost(N, sel(p)), disk_query_cost(N) and mem_query_cost(N). Taking knn_cost(N, sel(p)) as an example, the corresponding calculation formula can be set in advance, and N and sel(p) can be substituted into the calculation formula to obtain the calculation result, and then the calculation result can be used as the cost score of the KNN search determined according to N and sel(p). Other similarities will not be repeated later.

[0057] In the above processing method, the different operations involved in the first search scheme are fully considered, and the cost score corresponding to the first search scheme can be finally determined by combining the cost scores corresponding to the different operations, thereby improving the accuracy of the final determined cost score.

[0058] 2) Second search scheme

[0059] The second search scheme may also be referred to as a pre-filter scheme.

[0060] In some embodiments of the present disclosure, in response to determining that the target scheme is the second retrieval scheme, the candidate vectors that meet the filtering conditions can be determined by querying the scalar field data of N candidate vectors, and the filtering conditions are filtering conditions for the scalar field data. Based on the HNSW index, an approximate nearest neighbor (ANN, Approximate Nearest Neighbor) search can be performed on the candidate vectors that meet the filtering conditions to obtain a retrieval result.

[0061] The filtering condition carried in the vector search request may be a filtering condition for scalar field data, so the scalar field data of the N candidate vectors may be queried separately to determine the candidate vectors that meet the filtering condition. Afterwards, a bitmap of the primary key for the N candidate vectors may be generated, and the bitmap may include N bits, each bit may correspond to a candidate vector, and the value of each bit may be a first value or a second value, respectively. The first value is used to indicate that the corresponding candidate vector meets the filtering condition, and the second value is used to indicate that the corresponding candidate vector does not meet the filtering condition. Furthermore, an ANN search may be performed on the candidate vectors that meet the filtering condition based on the HNSW index and the bitmap, thereby obtaining the desired search results. For example, the bitmap may be passed into the HNSW index, and an ANN search may be performed in combination with the vector field data in the HNSW index.

[0062] It can be seen that both the first retrieval scheme and the second retrieval scheme need to query the scalar field data of all candidate vectors. The difference is that the first retrieval scheme performs KNN retrieval on the candidate vectors that meet the filtering conditions, while the second retrieval scheme performs ANN retrieval on the candidate vectors that meet the filtering conditions.

[0063] In addition, in some embodiments of the present disclosure, the method for determining the cost score corresponding to the second retrieval scheme may include: determining the cost score of querying the scalar field data of N candidate vectors, obtaining the ratio of the number of candidate vectors that meet the filtering conditions to N as the row selectivity, determining the cost score of the ANN retrieval under the HNSW index based on N and the row selectivity, and taking the sum of the two cost scores as the cost score corresponding to the second retrieval scheme.

[0064] That is, the cost score corresponding to the second search scheme can be:

[0065] S2=disk_query_cost(N)+hnsw_cost(N, sel(p)); (2)

[0066] That is, after respectively obtaining the cost score disk_query_cost(N) of the scalar field data of querying N candidate vectors and the cost score hnsw_cost(N, sel(p)) of ANN retrieval under the HNSW index determined according to N and sel(p), the two cost scores can be added, and the sum can be used as the cost score S2 corresponding to the second retrieval scheme.

[0067] In the above processing method, the different operations involved in the second search scheme are fully considered, and the cost score corresponding to the second search scheme can be finally determined by combining the cost scores corresponding to the different operations, thereby improving the accuracy of the final determined cost score.

[0068] In addition, the second search scheme is a more general implementation scheme. Like the first search scheme, it is applicable to the case where the filter condition carried in the vector search request is for scalar field data. If this is not the case, such as the filter condition is for the primary key, then it can be considered that the first search scheme and the second search scheme are not applicable to this vector search operation, and the cost scores corresponding to the first search scheme and the second search scheme can be set to infinity.

[0069] 3) The third search scheme

[0070] The third search scheme may be referred to as an intra-filter scheme.

[0071] In some embodiments of the present disclosure, in response to determining that the target solution is the third search solution, a KNN search may be performed on N candidate vectors based on the HNSW index and a filter condition to obtain a search result, where the filter condition is a filter condition for the primary key.

[0072] That is, a KNN search is required, and filtering can be performed by querying the primary key in memory during the KNN search. In other words, the filtering conditions can be passed into the HNSW index to filter out the primary keys that meet the filtering conditions, and the KNN search can be performed on the candidate vectors where the primary keys that meet the filtering conditions are located in combination with the vector data in the HNSW index.

[0073] Here, assuming that the primary key is an identifier (id), and assuming that the filtering condition is id<10, then if the primary key in a candidate vector is 9, it can be determined that the primary key meets the filtering condition, and if the primary key in a candidate vector is 15, it can be determined that the primary key does not meet the filtering condition.

[0074] Generally speaking, the third search scheme is implemented faster, thereby improving search efficiency, etc.

[0075] In addition, in some embodiments of the present disclosure, a method for determining a cost score corresponding to a third retrieval scheme may include: obtaining a ratio of the number of candidate vectors that satisfy the filtering conditions to N as a row selectivity, determining a cost score for a KNN retrieval based on N and the row selectivity, and determining a cost score for querying the primary key of the N candidate vectors, and taking the sum of the two cost scores as the cost score corresponding to the third retrieval scheme.

[0076] That is, the cost score corresponding to the third search scheme can be:

[0077] S3=knn_cost(N, sel(p))+mem_query_cost(N); (3)

[0078] That is, after respectively obtaining the cost score knn_cost(N, sel(p)) of the KNN search determined according to N and sel(p) and the cost score mem_query_cost(N) of querying the primary key of N candidate vectors, the two cost scores can be added together, and the sum can be used as the cost score S3 corresponding to the third search scheme.

[0079] In the above processing method, the different operations involved in the third search scheme are fully considered, and the cost score corresponding to the third search scheme can be finally determined by combining the cost scores corresponding to different operations, thereby improving the accuracy of the final determined cost score.

[0080] 4) The fourth search scheme

[0081] The fourth search scheme may also be called an intra-filter scheme.

[0082] In some embodiments of the present disclosure, in response to determining that the target solution is the fourth search solution, an ANN search may be performed on N candidate vectors based on the HNSW index and a filter condition to obtain a search result, where the filter condition is a filter condition for the primary key.

[0083] That is, an ANN search is required, and filtering can be performed through the memory query primary key during the ANN search process.

[0084] Generally speaking, the fourth search scheme is also implemented faster, thereby improving search efficiency, etc.

[0085] In addition, in some embodiments of the present disclosure, a method for determining a cost score corresponding to a fourth retrieval scheme may include: obtaining a ratio of the number of candidate vectors that satisfy the filtering conditions to N as a row selectivity, determining a cost score for ANN retrieval under an HNSW index based on N and the row selectivity, and determining a cost score for querying the primary key of the N candidate vectors, and taking the sum of the two cost scores as the cost score corresponding to the fourth retrieval scheme.

[0086] That is, the cost score corresponding to the fourth search scheme can be:

[0087] S4=hnsw_cost(N, sel(p))+mem_query_cost(N); (4)

[0088] That is, after obtaining the cost score hnsw_cost(N, sel(p)) of ANN retrieval under the HNSW index determined according to N and sel(p) and the cost score mem_query_cost(N) of querying the primary key of N candidate vectors, the two cost scores can be added, and the sum can be used as the cost score S4 corresponding to the fourth retrieval scheme.

[0089] In the above processing method, the different operations involved in the fourth search scheme are fully considered, and the cost score corresponding to the fourth search scheme can be finally determined by combining the cost scores corresponding to different operations, thereby improving the accuracy of the final determined cost score.

[0090] In addition, the third search scheme and the fourth search scheme are both applicable to the case where the filtering condition carried in the vector search request is a filtering condition for the primary key. If this is not the case, such as the filtering condition is a filtering condition for scalar field data, then the third search scheme and the fourth search scheme can be considered inapplicable to this vector search operation, and the cost scores corresponding to the third search scheme and the fourth search scheme can be set to infinity.

[0091] 5) Fifth search scheme

[0092] The fifth search scheme may be referred to as a post-filter scheme.

[0093] In some embodiments of the present disclosure, in response to determining that the target scheme is the fifth retrieval scheme and determining that the row selection rate is greater than the first threshold, an ANN retrieval without filtering conditions can be performed based on the HNSW index to obtain K*L intermediate retrieval results, where K is a positive integer, L is a positive integer greater than 1, and the row selection rate is the ratio of the number of candidate vectors that meet the filtering conditions to N. The K*L intermediate retrieval results can be post-filtered according to the filtering conditions to obtain the retrieval results.

[0094] L refers to the coefficient (alpha) shown in Table 1, that is, the expansion coefficient of top-K under the post-filtration scheme. The specific value can be determined according to actual needs, such as 5.

[0095] Under normal circumstances, after performing an ANN search without filtering conditions based on the HNSW index, K search results will be obtained. In the scheme described in the present invention, the candidate set (top-K) can be multiplied by a coefficient L, and an ANN search without filtering conditions can be performed in the HNSW index based on this coefficient, thereby obtaining K*L search results. To distinguish them from subsequent search results, the K*L search results are called intermediate search results.

[0096] Afterwards, the K*L intermediate search results may be post-filtered according to the filtering conditions to obtain the desired search results.

[0097] In addition, the specific value of the first threshold can be determined according to actual needs. If the row selection rate is less than or equal to the first threshold, the fifth search scheme cannot be used because the recall rate of the post-filtering method will become unacceptable. Accordingly, the fifth search scheme can be considered unsuitable for this vector search operation, and the cost score corresponding to the fifth search scheme can be set to infinity.

[0098] Generally speaking, the fifth search scheme is also implemented faster, thereby improving search efficiency, etc.

[0099] In addition, in some embodiments of the present disclosure, the method for determining the cost score corresponding to the fifth retrieval scheme may include: in response to determining that the filtering condition is a filtering condition for scalar field data, determining the cost score of the ANN retrieval under the HNSW index based on N and 1, and determining the cost score of the scalar field data for querying K*L intermediate retrieval results, and adding the two cost scores as the cost score corresponding to the fifth retrieval scheme.

[0100] That is, the cost score corresponding to the fifth search scheme can be:

[0101] S5=hnsw_cost(N,1)+disk_query_cost(top-K*L); (5)

[0102] Since an ANN search is performed without filtering conditions, the row selection rate can be considered to be 1. Accordingly, the cost score hnsw_cost(N, 1) of the ANN search under the HNSW index can be determined based on N and 1, and the cost score disk_query_cost(top-K*L) of the scalar field data of the K*L intermediate search results can be obtained. The sum of the two can be used as the cost score S5 corresponding to the fifth search scheme.

[0103] In the above processing method, the different operations involved in the fifth search scheme are fully considered, and the cost score corresponding to the fifth search scheme can be finally determined by combining the cost scores corresponding to different operations, thereby improving the accuracy of the final determined cost score.

[0104] In addition, the above formula (5) takes the filtering condition as a filtering condition for scalar field data as an example. If the filtering condition is a filtering condition for the primary key, then formula (5) can be adjusted accordingly.

[0105] 6) Sixth search scheme

[0106] The sixth retrieval scheme may be referred to as an intra-filter+post-filter scheme.

[0107] In some embodiments of the present disclosure, in response to determining that the target scheme is the sixth retrieval scheme, and determining that the ratio of the number of candidate vectors that simultaneously satisfy the first condition and the second condition to the number of candidate vectors that only satisfy the first condition (Sel(A / B)) is greater than a second threshold, an ANN search can be performed on the N candidate vectors based on the HNSW index and the first condition to obtain K*L intermediate retrieval results, where K is a positive integer, and L is a positive integer greater than 1. The first condition and the second condition constitute a filtering condition, and the K*L intermediate retrieval results can be post-filtered according to the second condition to obtain a retrieval result.

[0108] For example, if A represents the first condition and B represents the second condition, then the filtering condition = A + B. Generally speaking, A is the filtering condition for the primary key, and B has no restrictions.

[0109] The candidate set (top-K) can be multiplied by the coefficient L, and ANN search can be performed in the HNSW index based on this coefficient. The filtering condition is A, so that K*L intermediate search results can be obtained. Then, the K*L intermediate search results can be post-filtered according to B to obtain the required search results.

[0110] In addition, the specific value of the second threshold can be determined according to actual needs. If Sel(A / B) is less than or equal to the second threshold, the sixth search scheme cannot be used, and accordingly, the sixth search scheme can be considered inappropriate for this vector search operation, and the cost score corresponding to the sixth search scheme can be set to infinity.

[0111] The sixth retrieval scheme combines the advantages of the intra-filter scheme and the post-filter scheme, with a faster speed and a higher recall rate.

[0112] In addition, in some embodiments of the present disclosure, the method for determining the cost score corresponding to the sixth retrieval scheme may include: in response to determining that the first condition is a filtering condition for the primary key and the second condition is a filtering condition for scalar field data, determining the cost score for ANN retrieval under the HNSW index based on the ratio of the number of candidate vectors that satisfy the first condition to N and N, and determining the cost score for querying the primary key of N candidate vectors, and determining the cost score for querying the scalar field data of K*L intermediate retrieval results, and taking the sum of the three cost scores as the cost score corresponding to the sixth retrieval scheme.

[0113] That is, the cost score corresponding to the sixth search scheme can be:

[0114] hnsw_cost(N, sel(A))+mem_query_cost(N)+dist_query_cost(top-K*L); (6)

[0116] Among them, sel(A) represents the ratio of the number of candidate vectors that meet the first condition to N. The cost score hnsw_cost(N, sel(A)) of ANN retrieval under the HNSW index can be determined based on N and sel(A), and the cost score mem_query_cost(N) for querying the primary key of N candidate vectors and the cost score disk_query_cost(top-K*L) for querying the scalar field data of K*L intermediate retrieval results can be obtained respectively. Then, the sum of the three cost scores can be used as the cost score S6 corresponding to the sixth retrieval scheme.

[0117] In the above processing method, the different operations involved in the sixth search scheme are fully considered, and the cost score corresponding to the sixth search scheme can be finally determined by combining the cost scores corresponding to the different operations, thereby improving the accuracy of the final determined cost score.

[0118] For the obtained vector search request, after determining the cost scores corresponding to the six search schemes respectively, the cost score with the smallest value can be selected, and the search scheme corresponding to the selected cost score can be used as the target scheme, and then the target scheme can be used to complete this vector search operation.

[0119] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are expressed as a series of action combinations, but those skilled in the art should be aware that the present disclosure is not limited by the order of the actions described, because according to the present disclosure, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present disclosure.

[0120] The above is an introduction to the method embodiment. The following is a further explanation of the scheme disclosed in the present invention through an apparatus embodiment.

[0121] Figure 2 FIG. 2 is a schematic diagram of the structure of the vector search device embodiment 200 of the present disclosure. Figure 2 As shown, it includes: an acquisition module 201, a determination module 202 and a processing module 203.

[0122] The acquisition module 201 is used to acquire a vector search request.

[0123] Determination module 202 is used to determine the cost scores corresponding to the predetermined M retrieval schemes, where M is a positive integer greater than 1. The cost scores corresponding to any retrieval scheme are: if the retrieval scheme is used to complete the current vector retrieval operation, the evaluation score of the cost required is consumed, wherein the larger the value of the cost score is, the greater the cost required is.

[0124] The processing module 203 is used to select the cost score with the minimum value, and use the search solution corresponding to the selected cost score as the target solution to complete the current vector search operation.

[0125] By adopting the scheme described in the above-mentioned device embodiment, for the obtained vector search request, the cost scores corresponding to the multiple available search schemes can be determined respectively, and the search scheme with the smallest cost score can be selected, and then the vector search operation can be completed according to the selected search scheme, thereby achieving a reasonable selection of the search scheme, thereby improving the search efficiency and search effect, and reducing resource consumption, etc.

[0126] In some embodiments of the present disclosure, a vector retrieval request may include: a vector to be retrieved. Accordingly, the processing module 203 may adopt a target solution to determine a retrieval result corresponding to the vector to be retrieved based on N candidate vectors in a vector database, and return the retrieval result, wherein the vector database includes N rows of vector data, and the N rows of vector data are respectively used as candidate vectors, and N is a positive integer greater than 1.

[0127] In addition, in some embodiments of the present disclosure, each row of vector data may include: a primary key, vector field data, and scalar field data, and the vector index method corresponding to the vector database is an HNSW index that only includes the primary key and vector field data. Furthermore, the vector retrieval request may also include: a filtering condition, which is a filtering condition for the primary key and / or scalar field data. Accordingly, the processing module 203 can determine the retrieval result corresponding to the vector to be retrieved based on the HNSW index and the filtering condition according to the N candidate vectors in the vector database.

[0128] In addition, in some embodiments of the present disclosure, the determination module 202 may determine the cost scores corresponding to the predetermined M search schemes for the acquired vector search request, which may include: for any search scheme, performing the following processing respectively: in response to determining that the search scheme is applicable to the current vector search operation according to the filtering condition carried in the vector search request, determining the cost score corresponding to the search scheme according to the score determination method corresponding to the search scheme; in response to determining that the search scheme is not applicable to the current vector search operation according to the filtering condition, setting the cost score corresponding to the search scheme to infinity.

[0129] The scheme disclosed in the present invention may include six search schemes, namely, a first search scheme, a second search scheme, a third search scheme, a fourth search scheme, a fifth search scheme and a sixth search scheme. The specific implementation of each search scheme and the corresponding cost score acquisition method are described below.

[0130] In some embodiments of the present disclosure, in response to determining that the target scheme is the first retrieval scheme, the processing module 203 can determine the candidate vectors that meet the filtering conditions by querying the scalar field data of N candidate vectors, where the filtering conditions are filtering conditions for the scalar field data, and can perform KNN retrieval on the candidate vectors that meet the filtering conditions based on the HNSW index to obtain retrieval results.

[0131] Accordingly, in some embodiments of the present disclosure, the method in which the determination module 202 determines the cost score corresponding to the first retrieval scheme may include: determining the cost score of the scalar field data of the query N candidate vectors, obtaining the ratio of the number of candidate vectors that meet the filtering conditions to N as the row selection rate, determining the cost score of the KNN retrieval based on N and the row selection rate, and taking the sum of the two cost scores as the cost score corresponding to the first retrieval scheme.

[0132] In addition, in some embodiments of the present disclosure, in response to determining that the target scheme is the second retrieval scheme, the processing module 203 can determine the candidate vectors that meet the filtering conditions by querying the scalar field data of N candidate vectors, where the filtering conditions are filtering conditions for the scalar field data, and can perform ANN retrieval on the candidate vectors that meet the filtering conditions based on the HNSW index to obtain retrieval results.

[0133] Accordingly, in some embodiments of the present disclosure, the method in which the determination module 202 determines the cost score corresponding to the second retrieval scheme may include: determining the cost score of the scalar field data of the query N candidate vectors, obtaining the ratio of the number of candidate vectors that meet the filtering conditions to N as the row selectivity, determining the cost score of the ANN retrieval under the HNSW index based on N and the row selectivity, and taking the sum of the two cost scores as the cost score corresponding to the second retrieval scheme.

[0134] In addition, in some embodiments of the present disclosure, in response to determining that the target solution is the third search solution, the processing module 203 can perform a KNN search on the N candidate vectors based on the HNSW index and the filtering condition to obtain a search result, where the filtering condition is a filtering condition for the primary key.

[0135] Accordingly, in some embodiments of the present disclosure, the method in which the determination module 202 determines the cost score corresponding to the third retrieval scheme may include: obtaining the ratio of the number of candidate vectors that meet the filtering conditions to N as the row selection rate, determining the cost score of the KNN retrieval based on N and the row selection rate, and determining the cost score of the primary key of the query N candidate vectors, and adding the two cost scores as the cost score corresponding to the third retrieval scheme.

[0136] In some embodiments of the present disclosure, in response to determining that the target solution is the fourth search solution, the processing module 203 may perform an ANN search on the N candidate vectors based on the HNSW index and the filtering condition to obtain a search result, where the filtering condition is a filtering condition for the primary key.

[0137] Accordingly, in some embodiments of the present disclosure, the method in which the determination module 202 determines the cost score corresponding to the fourth retrieval scheme may include: obtaining the ratio of the number of candidate vectors that meet the filtering conditions to N as the row selectivity, determining the cost score of the ANN retrieval under the HNSW index based on N and the row selectivity, and determining the cost score of the primary key of the query N candidate vectors, and taking the sum of the two cost scores as the cost score corresponding to the fourth retrieval scheme.

[0138] In addition, in some embodiments of the present disclosure, in response to determining that the target scheme is the fifth retrieval scheme and determining that the row selection rate is greater than the first threshold, the processing module 203 can perform an ANN retrieval without filtering conditions based on the HNSW index to obtain K*L intermediate retrieval results, where K is a positive integer, L is a positive integer greater than 1, and the row selection rate is the ratio of the number of candidate vectors that meet the filtering conditions to N. The K*L intermediate retrieval results can be post-filtered according to the filtering conditions to obtain the retrieval results.

[0139] Accordingly, in some embodiments of the present disclosure, the method in which the determination module 202 determines the cost score corresponding to the fifth retrieval scheme may include: in response to determining that the filtering condition is a filtering condition for scalar field data, determining the cost score of the ANN retrieval under the HNSW index based on N and 1, and determining the cost score of the scalar field data for querying K*L intermediate retrieval results, and taking the sum of the two cost scores as the cost score corresponding to the fifth retrieval scheme.

[0140] In addition, in some embodiments of the present disclosure, in response to determining that the target scheme is the sixth retrieval scheme, and determining that the ratio of the number of candidate vectors that simultaneously satisfy the first condition and the second condition to the number of candidate vectors that only satisfy the first condition (Sel(A / B)) is greater than the second threshold, the processing module 203 can perform an ANN search on the N candidate vectors based on the HNSW index and the first condition to obtain K*L intermediate retrieval results, where K is a positive integer, L is a positive integer greater than 1, and the first condition and the second condition constitute a filtering condition, and the K*L intermediate retrieval results can be post-filtered according to the second condition to obtain a retrieval result.

[0141] Accordingly, in some embodiments of the present disclosure, the method in which the determination module 202 determines the cost score corresponding to the sixth retrieval scheme may include: in response to determining that the first condition is a filtering condition for the primary key and the second condition is a filtering condition for scalar field data, determining the cost score for ANN retrieval under the HNSW index based on the ratio of the number of candidate vectors that satisfy the first condition to N and N, and determining the cost score for querying the primary key of N candidate vectors, and determining the cost score for querying the scalar field data of K*L intermediate retrieval results, and taking the sum of the three cost scores as the cost score corresponding to the sixth retrieval scheme.

[0142] Figure 2 The specific working process of the illustrated device embodiment can refer to the relevant description in the aforementioned method embodiment and will not be described in detail.

[0143] The solution disclosed in the present invention can be applied to fields such as artificial intelligence, especially information retrieval, databases, and distributed storage. Artificial intelligence is a discipline that studies how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.). It includes both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing. Artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, machine learning / deep learning, big data processing technology, knowledge graph technology, and other major directions.

[0144] In addition, in the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0145] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.

[0146] Figure 3A schematic block diagram of an electronic device 300 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.

[0147] like Figure 3 As shown, the device 300 includes a computing unit 301, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 302 or a computer program loaded from a storage unit 308 to a random access memory (RAM) 303. In the RAM 303, various programs and data required for the operation of the device 300 can also be stored. The computing unit 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.

[0148] A number of components in the device 300 are connected to the I / O interface 305, including: an input unit 306, such as a keyboard, a mouse, etc.; an output unit 307, such as various types of displays, speakers, etc.; a storage unit 308, such as a disk, an optical disk, etc.; and a communication unit 309, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 309 allows the device 300 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0149] The computing unit 301 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 301 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI, Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSP, Digital Signal Processing), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 301 performs the various methods and processes described above, such as the methods described in the present disclosure. For example, in some embodiments, the methods described in the present disclosure may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 308. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 300 via the ROM 302 and / or the communication unit 309. When the computer program is loaded into the RAM 303 and executed by the computing unit 301, one or more steps of the methods described in the present disclosure may be performed. Alternatively, in other embodiments, the computing unit 301 may be configured to execute the method described in the present disclosure in any other appropriate manner (for example, by means of firmware).

[0150] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard parts (ASSPs), system on chip systems (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0151] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0152] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory (EPROM, Electronically Programmable Read-Only Memory), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM, Compact Disc Read-Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0153] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a cathode ray tube (CRT) or a liquid crystal display (LCD) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0154] The systems and techniques described herein can be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected by digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0155] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.

[0156] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.

[0157] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. A vector retrieval method, comprising: Get vector retrieval request; Determine the cost scores corresponding to the predetermined M retrieval schemes, where M is a positive integer greater than 1, and the cost scores corresponding to any retrieval scheme are: if the retrieval scheme is used to complete the current vector retrieval operation, the evaluation score of the cost required to be consumed, wherein the larger the value of the cost score is, the greater the cost required to be consumed; The cost score with the smallest value is selected, and the search solution corresponding to the selected cost score is used as the target solution, and the target solution is used to complete the vector search operation.

2. The method according to claim 1, wherein: The vector search request includes: a vector to be searched; The use of the target scheme to complete the vector retrieval operation includes: using the target scheme, determining the retrieval result corresponding to the vector to be retrieved based on N candidate vectors in a vector database, and returning the retrieval result, wherein the vector database includes N rows of vector data, and the N rows of vector data are respectively used as the candidate vectors, and N is a positive integer greater than 1.

3. The method according to claim 2, wherein: Each row of vector data includes: a primary key, vector field data and scalar field data, and the vector indexing method corresponding to the vector database is a hierarchical navigation small world index including only the primary key and the vector field data; The vector search request further includes: a filtering condition, wherein the filtering condition is a filtering condition for the primary key and / or the scalar field data; The step of determining the search result corresponding to the vector to be searched according to the N candidate vectors in the vector database includes: determining the search result based on the hierarchical navigation small world index and the filtering condition.

4. The method according to claim 3, wherein: The determining of the cost scores corresponding to the predetermined M search schemes respectively includes: For any search scheme, the following processing is performed respectively: In response to determining that the search scheme is applicable to the current vector search operation according to the filtering condition, determining a cost score corresponding to the search scheme according to a score determination method corresponding to the search scheme; In response to determining, according to the filtering condition, that the retrieval scheme is not applicable to the current vector retrieval operation, setting a cost score corresponding to the retrieval scheme to infinity.

5. The method according to claim 3 or 4, wherein: The adopting the target solution to complete the vector search operation includes: In response to determining that the target solution is the first search solution, determining a candidate vector that meets the filtering condition by querying the scalar field data of the N candidate vectors, wherein the filtering condition is a filtering condition for the scalar field data; Based on the hierarchical navigation small world index, a K nearest neighbor search is performed on the candidate vectors that meet the filtering condition to obtain the search result.

6. The method according to claim 5, wherein: Determining the cost score corresponding to the first search scheme includes: Determining a cost score for querying the scalar field data of the N candidate vectors; Obtaining a ratio of the number of candidate vectors satisfying the filtering condition to N as a row selection rate, and determining a cost score of the K nearest neighbor search according to N and the row selection rate; The sum of the two cost scores is used as the cost score corresponding to the first retrieval scheme.

7. The method according to claim 3 or 4, wherein: The adopting the target solution to complete the vector search operation includes: In response to determining that the target solution is the second search solution, determining a candidate vector that meets the filtering condition by querying the scalar field data of the N candidate vectors, wherein the filtering condition is a filtering condition for the scalar field data; Based on the hierarchical navigation small world index, an approximate nearest neighbor search is performed on the candidate vectors that meet the filtering condition to obtain the search result.

8. The method according to claim 7, wherein: Determining the cost score corresponding to the second search scheme includes: Determining a cost score for querying the scalar field data of the N candidate vectors; Obtaining a ratio of the number of candidate vectors satisfying the filtering condition to N as a row selection ratio, and determining a cost score of the approximate nearest neighbor search under the hierarchical navigation small-world index according to N and the row selection ratio; The sum of the two cost scores is used as the cost score corresponding to the second retrieval scheme.

9. The method according to claim 3 or 4, wherein: The adopting the target solution to complete the vector search operation includes: In response to determining that the target solution is the third search solution, a K nearest neighbor search is performed on the N candidate vectors based on the hierarchical navigation small world index and the filtering condition to obtain the search result, wherein the filtering condition is a filtering condition for the primary key.

10. The method according to claim 9, wherein: Determining the cost score corresponding to the third search scheme includes: Obtaining a ratio of the number of candidate vectors satisfying the filtering condition to N as a row selection rate, and determining a cost score of the K nearest neighbor search according to N and the row selection rate; Determining a cost score for querying the primary key of the N candidate vectors; The sum of the two cost scores is used as the cost score corresponding to the third search scheme.

11. The method according to claim 3 or 4, wherein: The adopting the target solution to complete the vector search operation includes: In response to determining that the target solution is the fourth search solution, an approximate nearest neighbor search is performed on the N candidate vectors based on the hierarchical navigation small world index and the filtering condition to obtain the search result, wherein the filtering condition is a filtering condition for the primary key.

12. The method according to claim 11, wherein: Determining the cost score corresponding to the fourth search scheme includes: Obtaining a ratio of the number of candidate vectors satisfying the filtering condition to N as a row selection ratio, and determining a cost score of the approximate nearest neighbor search under the hierarchical navigation small-world index according to N and the row selection ratio; Determining a cost score for querying the primary key of the N candidate vectors; The sum of the two cost scores is used as the cost score corresponding to the fourth search scheme.

13. The method according to claim 3 or 4, wherein: The adopting the target solution to complete the vector search operation includes: In response to determining that the target solution is the fifth search solution and determining that the row selectivity is greater than a first threshold, performing an approximate nearest neighbor search without a filtering condition based on the hierarchical navigation small world index to obtain K*L intermediate search results, where K is a positive integer, L is a positive integer greater than 1, and the row selectivity is a ratio of the number of candidate vectors that meet the filtering condition to N; The K*L intermediate search results are post-filtered according to the filter condition to obtain the search result.

14. The method according to claim 13, wherein: Determining the cost score corresponding to the fifth search scheme includes: In response to determining that the filtering condition is a filtering condition for scalar field data, determining a cost score for the approximate nearest neighbor search under the hierarchical navigation small world index according to N and 1; Determining a cost score for querying the scalar field data of the K*L intermediate search results; The sum of the two cost scores is used as the cost score corresponding to the fifth search solution.

15. The method according to claim 3 or 4, wherein: The adopting the target solution to complete the vector search operation includes: In response to determining that the target solution is the sixth search solution, and determining that the ratio of the number of candidate vectors that simultaneously satisfy the first condition and the second condition to the number of candidate vectors that only satisfy the first condition is greater than a second threshold, based on the hierarchical navigation small world index and the first condition, performing an approximate nearest neighbor search on the N candidate vectors to obtain K*L intermediate search results, where K is a positive integer, L is a positive integer greater than 1, and the first condition and the second condition constitute the filtering condition; The K*L intermediate search results are post-filtered according to the second condition to obtain the search result.

16. The method according to claim 15, wherein: Determining the cost score corresponding to the sixth search scheme includes: In response to determining that the first condition is a filtering condition for a primary key and the second condition is a filtering condition for scalar field data, determining a cost score for the approximate nearest neighbor search under the hierarchical navigation small world index according to a ratio of the number of candidate vectors satisfying the first condition to N and N; Determining a cost score for querying the primary key of the N candidate vectors; Determining a cost score for querying the scalar field data of the K*L intermediate search results; The sum of the three cost scores is used as the cost score corresponding to the sixth search scheme.

17. A vector search device, comprising: Acquisition module, determination module and processing module; The acquisition module is used to acquire a vector search request; The determination module is used to determine the cost scores corresponding to the predetermined M retrieval schemes, where M is a positive integer greater than 1, and the cost scores corresponding to any retrieval scheme are: if the retrieval scheme is used to complete the current vector retrieval operation, the evaluation score of the cost required to be consumed, wherein the larger the value of the cost score is, the greater the cost required to be consumed; The processing module is used to select the cost score with the smallest value, and use the search solution corresponding to the selected cost score as the target solution, and use the target solution to complete the current vector search operation.

18. The device according to claim 17, wherein: The vector search request includes: a vector to be searched; The processing module adopts the target scheme, determines the search result corresponding to the vector to be searched according to N candidate vectors in the vector database, and returns the search result, wherein the vector database includes N rows of vector data, and the N rows of vector data are respectively used as the candidate vectors, and N is a positive integer greater than 1.

19. The device according to claim 18, wherein: Each row of vector data includes: a primary key, vector field data and scalar field data, and the vector indexing method corresponding to the vector database is a hierarchical navigation small world index including only the primary key and the vector field data; The vector search request further includes: a filtering condition, wherein the filtering condition is a filtering condition for the primary key and / or the scalar field data; The processing module determines the search result based on the hierarchical navigation small world index and the filtering condition.

20. The device according to claim 19, wherein The determination module performs the following processing for any retrieval scheme: in response to determining that the retrieval scheme is applicable to the current vector retrieval operation according to the filtering condition, determining a cost score corresponding to the retrieval scheme according to a score determination method corresponding to the retrieval scheme; in response to determining that the retrieval scheme is not applicable to the current vector retrieval operation according to the filtering condition, setting the cost score corresponding to the retrieval scheme to infinity.

21. The device according to claim 19 or 20, wherein: In response to determining that the target solution is the first retrieval solution, the processing module determines the candidate vectors that meet the filtering condition by querying the scalar field data of the N candidate vectors, where the filtering condition is a filtering condition for the scalar field data, and performs a K nearest neighbor search on the candidate vectors that meet the filtering condition based on the hierarchical navigation small world index to obtain the retrieval result.

22. The device according to claim 21, wherein The determination module determines a cost score for querying the scalar field data of the N candidate vectors, and obtains the ratio of the number of candidate vectors that meet the filtering condition to N as a row selection rate, determines the cost score of the K nearest neighbor retrieval based on N and the row selection rate, and takes the sum of the two cost scores as the cost score corresponding to the first retrieval scheme.

23. The device according to claim 19 or 20, wherein: In response to determining that the target scheme is the second retrieval scheme, the processing module determines the candidate vectors that meet the filtering condition by querying the scalar field data of the N candidate vectors, wherein the filtering condition is a filtering condition for the scalar field data, and performs an approximate nearest neighbor search on the candidate vectors that meet the filtering condition based on the hierarchical navigation small world index to obtain the retrieval result.

24. The device according to claim 23, wherein: The determination module determines a cost score for querying the scalar field data of the N candidate vectors, and obtains the ratio of the number of candidate vectors that meet the filtering condition to N as a row selection ratio, and determines the cost score of the approximate nearest neighbor retrieval under the layered navigation small world index based on N and the row selection ratio, and takes the sum of the two cost scores as the cost score corresponding to the second retrieval scheme.

25. The device according to claim 19 or 20, wherein: In response to determining that the target solution is the third search solution, the processing module performs a K nearest neighbor search on the N candidate vectors based on the hierarchical navigation small world index and the filtering condition to obtain the search result, wherein the filtering condition is a filtering condition for the primary key.

26. The device according to claim 25, wherein The determination module obtains the ratio of the number of candidate vectors that meet the filtering condition to N as the row selection rate, determines the cost score of the K nearest neighbor search based on N and the row selection rate, and determines the cost score of querying the primary key of the N candidate vectors, and uses the sum of the two cost scores as the cost score corresponding to the third search scheme.

27. The device according to claim 19 or 20, wherein: In response to determining that the target solution is the fourth search solution, the processing module performs an approximate nearest neighbor search on the N candidate vectors based on the hierarchical navigation small world index and the filtering condition to obtain the search result, wherein the filtering condition is a filtering condition for the primary key.

28. The device according to claim 27, wherein The determination module obtains the ratio of the number of candidate vectors that meet the filtering condition to N as the row selection rate, determines the cost score of the approximate nearest neighbor retrieval under the layered navigation small world index based on N and the row selection rate, and determines the cost score of querying the primary key of the N candidate vectors, and takes the sum of the two cost scores as the cost score corresponding to the fourth retrieval scheme.

29. The device according to claim 19 or 20, wherein: In response to determining that the target scheme is the fifth retrieval scheme and determining that the row selection rate is greater than a first threshold, the processing module performs an approximate nearest neighbor retrieval without filtering conditions based on the layered navigation small world index to obtain K*L intermediate retrieval results, where K is a positive integer, L is a positive integer greater than 1, and the row selection rate is the ratio of the number of candidate vectors that meet the filtering condition to N, and the K*L intermediate retrieval results are post-filtered according to the filtering condition to obtain the retrieval result.

30. The device according to claim 29, wherein: In response to determining that the filtering condition is a filtering condition for scalar field data, the determination module determines the cost score of the approximate nearest neighbor retrieval under the hierarchical navigation small world index based on N and 1, and determines the cost score of the scalar field data for querying the K*L intermediate retrieval results, and takes the sum of the two cost scores as the cost score corresponding to the fifth retrieval scheme.

31. The device according to claim 19 or 20, wherein: In response to determining that the target scheme is the sixth retrieval scheme and determining that the ratio of the number of candidate vectors that simultaneously satisfy the first condition and the second condition to the number of candidate vectors that only satisfy the first condition is greater than a second threshold, the processing module performs an approximate nearest neighbor search on the N candidate vectors based on the layered navigation small world index and the first condition to obtain K*L intermediate retrieval results, where K is a positive integer, and L is a positive integer greater than 1, and the first condition and the second condition constitute the filtering condition, and post-filters the K*L intermediate retrieval results according to the second condition to obtain the retrieval result.

32. The device according to claim 31, wherein In response to determining that the first condition is a filtering condition for a primary key and the second condition is a filtering condition for scalar field data, the determination module determines a cost score for the approximate nearest neighbor retrieval under the hierarchical navigation small world index based on the ratio of the number of candidate vectors satisfying the first condition to N and N, and determines a cost score for querying the primary key of the N candidate vectors and determines a cost score for querying the scalar field data of the K*L intermediate retrieval results, and takes the sum of the three cost scores as the cost score corresponding to the sixth retrieval scheme.

33. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 13.

34. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to make a computer execute the method according to any one of claims 1 to 13.

35. A computer program product, comprising a computer program / instructions, which implement the method according to any one of claims 1 to 13 when executed by a processor.

Citation Information

Patent Citations

  • Data query method and device

    CN113297257A

  • Data query method and device, electronic equipment and storage medium

    CN114443689A

  • Data retrieval method and device and distributed system

    CN115146019A

  • KNN query method based on learning index

    CN115858629A

  • Data retrieval method and device, equipment and storage medium

    CN116541481A