Vector retrieval method and apparatus

By clustering the vector base database and calculating the similarity of the partition center vectors, the problem of slow speed in large-scale vector retrieval is solved, realizing an efficient vector retrieval method and improving retrieval speed and accuracy.

CN119474463BActive Publication Date: 2025-11-28HUAWEI TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411310692.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-28
Publication Date
2025-11-28
Estimated Expiration
2042-09-28

AI Technical Summary

Technical Problem

Existing vector retrieval methods have low retrieval speed when dealing with vector databases of hundreds of millions or even billions of data points, and cannot balance retrieval accuracy and speed.

Method used

By clustering the vector base library, M cluster partitions are formed. Each partition has a partition center vector. First, the similarity between the query vector and the partition center vector is calculated. Then, K retrieval partitions are selected, and the probability value of containing the target vector in these partitions is determined until it is greater than a preset threshold. Finally, the query results are output.

Benefits of technology

It reduces computational load, improves retrieval speed and accuracy, reduces unnecessary similarity calculations, and enhances the efficiency of the retrieval system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119474463B_ABST
    Figure CN119474463B_ABST
Patent Text Reader

Abstract

A vector retrieval method and device are used to solve the problem of slow retrieval speed of existing retrieval methods. In the application, the method comprises: obtaining a to-be-queried vector; performing similarity calculation on the to-be-queried vector and M cluster partition center vectors respectively to obtain M first similarities; determining K retrieval partitions according to the M first similarities; and performing the following operations in a loop until the probability value of a target retrieval partition containing a target vector is greater than a first preset threshold: selecting a retrieval partition as the target retrieval partition from the K retrieval partitions; calculating second similarities between the to-be-queried vector and each vector contained in the target retrieval partition; determining the probability value of the target retrieval partition containing the target vector according to each second similarity; and outputting a query result based on at least one selected retrieval partition. Without calculating the similarity between the to-be-queried vector and all vectors in the vector base library to obtain the query result, the calculation amount can be reduced, and the query speed can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application is a divisional application, the original application number is 202211193810.4, the original application date is September 28, 2022, and the entire contents of the original application are incorporated herein by reference. TECHNICAL FIELD

[0002] The present application relates to the technical field of retrieval, in particular to a vector retrieval method and device. BACKGROUND

[0003] Vector retrieval plays an important role in the field of information retrieval. The process of vector retrieval is as follows: first, a vector base library is constructed, which contains a large number of vectors obtained by feature extraction on a large amount of data, which can be in the form of pictures, videos, audio, text, etc.; then the similarity between the user input query vector and all vectors in the vector base library is calculated respectively, and the vectors corresponding to the top W similar degrees in descending order are returned as the query result of the query vector.

[0004] This method performs global search comparison on a vector base library containing hundreds of millions or even billions of vectors, and has low retrieval throughput (Query Per Second, speed) and low retrieval speed. SUMMARY

[0005] The present application provides a vector retrieval method and device to solve the problem of low retrieval speed in existing vector retrieval methods.

[0006] In a first aspect, the present application provides a vector retrieval method, which can be executed by a computing device or a chip inside the computing device, or a processor in the computing device. The method comprises: obtaining a query vector;

[0007] Calculating the similarity between the query vector and the partition center vector of each of the M cluster partitions to obtain M first similarities; the M cluster partitions are obtained by clustering each vector in the vector base library according to the similarity between the vectors; the partition center vector of any cluster partition is determined according to the plurality of vectors contained in the cluster partition; M is an integer greater than 1; in the M first similarities, select the top K first similarities in descending order, and determine the K cluster partitions corresponding to the K first similarities as K retrieval partitions, K is an integer greater than or equal to 1 and less than M;

[0008] Loop the following operation until the probability value that the target retrieval partition selected in the K retrieval partitions contains the target vector is greater than the first preset threshold, the target vector is a vector with a similarity to the query vector within a preset range:

[0009] selecting an unselected search partition from the K search partitions as a target search partition; calculating second similarities between the to-be-queried vector and each vector contained in the target search partition; and determining a probability value of a target vector contained in the target search partition according to each second similarity.

[0010] outputting a query result based on the at least one selected search partition and the to-be-queried vector.

[0011] In the technical solution, the to-be-queried vector does not need to be compared with all vectors in the vector base to obtain a query result, but each vector in the vector base is clustered to obtain M clustering partitions, each of which corresponds to a partition center vector; K search partitions are selected from the M clustering partitions by calculating first similarities between the to-be-queried vector and the partition center vectors of the M clustering partitions; a target search partition is selected from the K search partitions in turn, and a probability value of a vector identical to or similar to the to-be-queried vector falling in the selected target search partition is determined for each selected target search partition until a target search partition with a probability value greater than a first preset threshold is selected. Then, a query result of the to-be-queried vector is determined in the at least one selected target search partition. In this way, the amount of calculation can be reduced and the query speed can be improved.

[0012] In a possible implementation, the outputting of the query result based on the at least one selected search partition and the to-be-queried vector includes: outputting, as the query result, each vector contained in a search partition with a probability value greater than the first preset threshold in the at least one selected search partition; or outputting, as the query result, W vectors corresponding to W second similarities in order from high to low, the W second similarities being between each vector contained in a search partition with a probability value greater than the first preset threshold in the at least one selected search partition and the to-be-queried vector, the W being a positive integer.

[0013] In the technical solution, since there is only one search partition with a probability value greater than the first preset threshold, outputting all vectors contained in the search partition with the probability value greater than the first preset threshold as the query result can effectively reduce the amount of calculation and improve the search speed. Or, outputting W vectors corresponding to W second similarities in order from high to low, the W second similarities being between each vector contained in a search partition with a probability value greater than the first preset threshold in the at least one selected search partition and the to-be-queried vector, as the query result can further simplify the output result.

[0014] In a possible implementation, based on the at least one selected search partition and the to-be-searched vector, the query result is output, including: outputting each vector contained in the at least one selected search partition as the query result; or outputting W vectors corresponding to the W highest second similarities between each vector contained in the at least one selected search partition and the to-be-searched vector as the query result, where W is a positive integer.

[0015] In the technical solution, the query result is output based on the at least one selected search partition instead of the search partition with the probability value greater than the first preset threshold. Since the vector similar to the to-be-searched vector may exist in the search partition with the probability value not greater than the first preset threshold, the technical solution can improve the accuracy of vector search.

[0016] In a possible implementation, the unselected search partition in the K search partitions is selected as the target search partition, which can be selecting the unselected search partition in the K search partitions in descending order of the K first similarities.

[0017] In this way, the target search partition is selected in descending order of the K first similarities, so that the target search partition with the probability value greater than the first preset threshold can be determined as early as possible, the possibility of reselecting the target search partition is reduced as much as possible, and the similarity between the to-be-searched vector and the vector in the reselected target search partition does not need to be calculated, so that the calculation amount is reduced and the search speed is improved.

[0018] In a possible implementation, the unselected search partition in the K search partitions is selected as the target search partition, which can be selecting the unselected search partition in the K search partitions in descending order of the K first similarities.

[0019] In this way, by further clustering the vectors in the search partitions, a plurality of search sub-partitions are obtained, each of which corresponds to a sub-partition center vector. Since more detailed division is performed, the sub-partition center vectors obtained by division can more accurately represent the vectors in the search sub-partitions. Sorting the K search partitions based on a plurality of third similarities between the to-be-queried vector and the plurality of sub-partition center vectors in each search partition can improve the accuracy of sorting. In this way, the target search partition with the probability value greater than the first preset threshold can be determined as early as possible, and the possibility of reselecting the target search partition is minimized, so that the similarity between the to-be-queried vector and the vectors in the reselected target search partition does not need to be calculated, thereby reducing the amount of calculation and improving the search speed.

[0020] In a possible implementation, the sorting of the K search partitions based on the plurality of third similarities between the to-be-queried vector and the plurality of sub-partition center vectors in each search partition includes: sorting the K search partitions based on the number of third similarities between the to-be-queried vector and the plurality of sub-partition center vectors in each search partition that exceed a second preset threshold; or sorting the K search partitions based on the maximum similarity between the to-be-queried vector and the plurality of sub-partition center vectors in each search partition.

[0021] Sorting the K search partitions based on the number of third similarities between the to-be-queried vector and the plurality of sub-partition center vectors in each search partition that exceed the second preset threshold or based on the maximum similarity between the to-be-queried vector and the plurality of sub-partition center vectors in each search partition can reduce the difficulty of sorting, improve the speed of sorting, and further improve the search speed. At the same time, the accuracy of sorting can also be improved. In this way, the target search partition with the probability value greater than the first preset threshold can be determined as early as possible.

[0022] In a possible implementation, the determining of the probability value that the target vector is contained in the target search partition based on the second similarities includes: determining, in the second similarities, t target second similarities that are ordered in a descending order of the second similarities; and inputting the to-be-queried vector, the K first similarities, and the t target second similarities into a prediction model to obtain the probability value, where the prediction model is configured to predict the probability value that the target vector is contained in the target search partition.

[0023] The prediction model is used to predict the probability value, which improves the accuracy and speed of determining the probability value. In the second similarities, the t target second similarities that are ordered in a descending order of the second similarities are selected, and the t target second similarities are input into the prediction model, which can reduce the amount of calculation of the prediction model, improve the speed of predicting the probability value, and does not affect the prediction accuracy.

[0024] In a possible implementation, the to-be-queried vectors are N, and N is a positive integer greater than 1; correspondingly, inputting the to-be-queried vectors, the K first similarities and the t target second similarities into a prediction model to obtain the probability value includes: inputting a matrix formed by the N to-be-queried vectors and a matrix formed by the K first similarities corresponding to each of the N to-be-queried vectors into a first prediction model to obtain N initial probability values corresponding to the N to-be-queried vectors; the initial probability value is used to represent a probability that any to-be-queried vector contains a target vector in the K search partitions corresponding to the to-be-queried vector; for any to-be-queried vector, inputting the initial probability value corresponding to the to-be-queried vector and the t target second similarities corresponding to the to-be-queried vector into a second prediction model to obtain a final probability value corresponding to the to-be-queried vector.

[0025] The prediction of the probability value is divided into two stages, the first stage adopts the first prediction model, and the second stage adopts the second prediction model. Specifically, inputting a matrix formed by the N to-be-queried vectors and a matrix formed by the K first similarities corresponding to each of the N to-be-queried vectors into the first prediction model, so that the first prediction model can use the matrix multiplication method to predict the initial probability value, fully exerting the computing power, improving the calculation efficiency, and further improving the speed of vector retrieval.

[0026] In a second aspect, an embodiment of the present application provides a vector retrieval device, which has the functions of implementing the method in the first aspect or any possible implementation manner of the first aspect. The device can be a computing device or a processor included in the computing device. The functions of the vector retrieval device can be implemented by hardware, or by executing corresponding software by hardware. The hardware or software includes one or more modules or units or means corresponding to the above functions.

[0027] In a possible implementation, the structure of the device includes a processing module and a transceiver module. The processing module is configured to support the device to perform the method in the first aspect or any implementation manner of the first aspect. The transceiver module is used to support the communication between the device and other devices, for example, can receive data from a collection device. The vector retrieval device can further include a storage module coupled to the processing module, which stores necessary program instructions and data of the device. As an example, the processing module can be a processor, the transceiver module can be a transceiver, and the storage module can be a memory. The memory can be integrated with the processor, or can be separately arranged from the processor.

[0028] In another possible implementation, the apparatus includes a processor in its structure, and can further include a memory. The processor is coupled to the memory and is configured to execute computer program instructions stored in the memory to enable the apparatus to perform the method in the first aspect or any possible implementation of the first aspect. Optionally, the apparatus further includes a communication interface, and the processor is coupled to the communication interface. When the apparatus is a computing device, the communication interface can be a transceiver or an input / output interface.

[0029] In a third aspect, an embodiment of the present application provides a chip including a processor, and the processor is coupled to a memory. The memory is configured to store a program or instructions, and the program or instructions, when executed by the processor, enable the chip to perform the method in the first aspect or any possible implementation of the first aspect.

[0030] Optionally, the chip further includes an interface circuit configured to interact code instructions with the processor.

[0031] Optionally, the processor in the chip can be one or more processors, and the processor can be implemented by hardware or software. When implemented by hardware, the processor can be a logic circuit, an integrated circuit, or the like. When implemented by software, the processor can be a general-purpose processor, and the processor can be implemented by reading software code stored in the memory.

[0032] Optionally, the memory in the chip can also be one or more memories. The memory can be integrated with the processor or can be separately arranged from the processor. For example, the memory can be a non-transient processor, such as a read-only memory (ROM), which can be integrated on the same chip as the processor or can be separately arranged on different chips.

[0033] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium having stored thereon a computer program or instructions, and the computer program or instructions, when executed, enable a computer to perform the method in the first aspect or any possible implementation of the first aspect.

[0034] In a fifth aspect, an embodiment of the present application provides a computer program product, and when a computer reads and executes the computer program product, the computer program product enables the computer to perform the method in the first aspect or any possible implementation of the first aspect.

[0035] The technical effects achieved by any one of the second aspect to the fifth aspect can refer to the description of the beneficial effects of the first aspect, which will not be repeated here. BRIEF DESCRIPTION OF DRAWINGS

[0036] Figure 1a A schematic diagram of vector retrieval in a scenario of image search by image is provided in the present application;

[0037] Figure 1b A schematic diagram of vector retrieval in the context of drug discovery is provided for the present application;

[0038] Figure 2 A schematic diagram of a system architecture is provided for the present application;

[0039] Figure 3 A schematic diagram of the structure of a computing device is provided for the present application;

[0040] Figure 4 A schematic diagram of the structure of a processor is provided for the present application;

[0041] Figure 5a A schematic diagram of the flow of a vector retrieval technique is provided for the present application;

[0042] Figure 5b A schematic diagram of M clustering partitions obtained by clustering vectors in a vector base library is provided for the present application;

[0043] Figure 6 A schematic diagram of the flow of a vector retrieval method is provided for the present application;

[0044] Figure 7 A schematic diagram of dividing a search sub-partition from any search partition is provided for the present application;

[0045] Figure 8 A schematic diagram of the second similarity between a to-be-queried vector and the partition center vector of each search partition and the third similarity between the to-be-queried vector and the sub-partition center vector of each search sub-partition is provided for the present application;

[0046] Figure 9 A schematic diagram of the flow of a method for obtaining a probability value according to each second similarity is provided for the present application;

[0047] Figure 10 A schematic diagram of the flow of another method for obtaining a probability value according to each second similarity is provided for the present application;

[0048] Figure 11a A schematic diagram of a matrix of M first similarities between any to-be-queried vector and M partition center vectors obtained by using a hardware accelerator to perform matrix multiplication is provided for the present application;

[0049] Figure 11b A schematic diagram of a matrix formed by three first similarities corresponding to each to-be-queried vector in two to-be-queried vectors is provided for the present application;

[0050] Figure 12 A schematic diagram of a method for judging a probability value is provided for the present application;

[0051] Figure 13 A schematic diagram of the overall process of a vector retrieval method provided in the present application is shown.

[0052] Figure 14 A schematic diagram of a vector retrieval device provided in the present application is shown. DETAILED DESCRIPTION

[0053] In order to better explain the present application, the following first explains the technologies or terms involved in the present application.

[0054] 1. Vector retrieval technology, in a given vector dataset, according to a certain metric, retrieve the similar vectors to the query vector.

[0055] 2. K-means clustering algorithm, is an iterative solution of clustering analysis algorithm. Specifically, given the number of categories k, the entire dataset is clustered, the objective function is the minimum distance sum of all samples to the class center, and the objective function is iteratively calculated and optimized to obtain k class centers and the category to which each sample belongs.

[0056] 3. Retrieval accuracy, also known as recall rate. Given a query vector, the retrieval system retrieves the query vector and returns W vectors as the query result. Let the set of the W returned vectors be X, and the set of the W vectors ordered from high to low in similarity to the query vector in the entire vector database be Y, then the retrieval accuracy of the retrieval system for the query vector is |X∩Y| / |Y|.

[0057] Figure 1a A schematic diagram of vector retrieval in a picture-to-picture search scenario is shown. Specifically, a large number of pictures are first feature-extracted to obtain a large number of vectors, and these large number of vectors form a vector database; the query vector obtained by feature-extracting the query picture is retrieved in the vector database, and the vectors that meet the similarity requirement with the query vector are retrieved; determine which pictures these vectors that meet the similarity requirement are extracted from, and return the determined pictures as the query result. For example, in an Internet application, according to the user-input query product picture, retrieve the pictures containing the product appearance similar to the product picture input by the user; for example, according to the pictures of the videos frequently browsed by the user, retrieve other videos similar to these pictures and push them to the user, etc. The growing data size of the Internet puts higher requirements on the retrieval speed and efficiency of the retrieval system.

[0058] Figure 1bA schematic diagram of vector retrieval in the scenario of drug discovery is shown. A large number of vectors obtained after encoding a large number of compounds by an encoder form a vector library; a query vector obtained after encoding an active fragment or a lead compound of a drug to be queried is retrieved in the vector library, and vectors meeting a similarity requirement with the query vector are retrieved; and the compounds corresponding to the vectors meeting the similarity requirement are returned as query results. The research and development of new drugs requires searching for similar compounds to the active fragment or lead compound of the new drug in a compound library of hundreds of millions / billions of compounds as potential drugs. Since the selection of similar compounds will affect the subsequent animal experiments and clinical experiments for a long period of time, the retrieval speed of the retrieval system is also required to be high.

[0059] How to determine the vectors meeting the similarity requirement with the query vector, two ways can be provided as follows:

[0060] Way 1: The similarity of the query vector with all vectors in the vector library is calculated, and W vectors with the highest similarity are selected as query results.

[0061] Way 2: The similarity of the query vector with each vector in the vector library is calculated in turn until W vectors meeting a preset threshold are found, and then the similarity between the query vector and the remaining vectors in the vector library is stopped.

[0062] Way 1 needs to calculate the similarity of the query vector with all vectors in the vector library, which can guarantee the retrieval accuracy, but the number of vectors in the vector library is very large, generally hundreds of millions / billions. This will result in a large amount of calculation, limiting the improvement of retrieval speed. The calculation amount in way 2 is lower than that in way 1, but if the preset threshold is set high, the calculation amount is still large, and the retrieval speed is slow; if the preset threshold is set low, the retrieval accuracy is affected. Therefore, the setting of the preset threshold is required to be high when the vector retrieval is performed by way 2, and even different preset thresholds need to be set for different query vectors, and the retrieval method is not flexible enough.

[0063] In summary, the above-mentioned vector retrieval methods cannot balance the retrieval accuracy and retrieval speed. Based on this, the examples of the present application provide a vector retrieval method to improve the retrieval speed while guaranteeing the retrieval accuracy.

[0064] Figure 2A system architecture diagram to which embodiments of the present application can be applied is provided, which includes a collection device 10, a computing device 20 and a storage device 30. Among them, the collection device 10 can be one or more, the computing device 20 can also be one or more, and the storage device 30 can also be one or more. One or more collection devices 10, one or more computing devices 20 and one or more storage devices 30 can be connected through a network.

[0065] The collection device 10 can be used to collect data, and send the collected data to the computing device 20 through the network. The collection device 10 can be a camera, a mobile phone, a computer, etc., and the data collected by the collection device 10 can be picture, video, audio, text, etc. data. For example, in a video monitoring scene, the collection device 10 can be a camera, and the data collected by the camera can be pictures and / or videos taken by the camera.

[0066] The computing device 20 is used to extract features of any obtained data to obtain a vector corresponding to the data; a large number of vectors corresponding to a large number of data form a vector library, and a large number of vectors in the vector library are clustered according to the similarity between the vectors, thereby obtaining M cluster partitions, and the similarity between the vectors in each cluster partition is high, wherein M is an integer greater than 1. Each cluster partition has a corresponding partition center vector, and the partition center vector of each cluster partition is determined according to the multiple vectors contained in the cluster partition, for example, the partition center vector of the cluster partition can be determined according to the mean, mode or median of the multiple vectors contained in the cluster partition. The partition center vector can be understood as a representative of the multiple vectors contained in the cluster partition, representing the features of each vector contained in the cluster partition. Embodiments of the present application do not limit the clustering algorithm, for example, the k-means clustering algorithm, the mean shift clustering and the density-based clustering method can be used to cluster the large number of vectors in the vector library according to the similarity between the vectors, thereby obtaining M cluster partitions.

[0067] The storage device 30 can be used to store the multiple cluster partitions calculated by the computing device. For example, as shown in FIG. 3, the storage device 30 can store the multiple cluster partitions 301, 302, 303, 304 and 305. Figure 5b A possible schematic diagram of M cluster partitions obtained after clustering the vectors in the vector library is shown, in which Figure 5bIn the figure, it is assumed that 8 cluster partitions are obtained by clustering the vectors according to the similarity between the vectors, and the cluster partitions are distinguished by solid lines; the center vector of each cluster partition is obtained by averaging the vectors in the cluster partition, and the center vector of the cluster partition is represented by a pentagram in the figure, and a plurality of black solid points are used to represent a plurality of vectors in the cluster partition other than the center vector of the cluster partition. For example, a cluster partition contains 3 vectors, which are [1, 1, 1], [2, 2, 2] and [3, 3, 3], and the center vector of the cluster partition can be [2, 2, 2].

[0068] After the computing device 20 clusters the vectors in the vector library to obtain M cluster partitions, the computing device 20 can send the center vector of each cluster partition in the M cluster partitions and the vectors contained in each cluster partition to the storage device 30 for storage. That is, the storage device 30 can store a data structure as shown in Figure 5b for subsequent vector retrieval by the computing device 20.

[0069] In the vector retrieval stage, the collection device 10 can be used to collect or acquire the to-be-queried data and send the to-be-queried data to the computing device 20. For example, a user opens a shopping application and inputs a to-be-queried picture containing a commodity to be queried in the shopping application. The collection device collects the to-be-queried picture and can send the to-be-queried picture to the computing device 20.

[0070] The computing device 20 is configured to perform feature extraction on the to-be-queried picture to obtain a to-be-queried vector corresponding to the to-be-queried picture, and then search for a similar vector in the M cluster partitions stored in the storage device 30 according to the to-be-queried vector, and feed back the similar vector found to the user.

[0071] It should be understood that the collection device 10, the computing device 20 and the storage device 30 can be integrated in the same device, or can be separately arranged in different devices. For example, the computing device 20 and the storage device 30 can be integrated in a server, and the collection device 10 can be integrated in a terminal device.

[0072] Further, as Figure 3 is a possible structure diagram of the computing device 20, the computing device 20 includes a processor 201, a memory 202 and a communication interface 203. Any two of the processor 201, the memory 202 and the communication interface 203 can be connected through a bus 204.

[0073] The processor 201 can be a central processing unit (CPU) that can be used to execute software programs in the memory 202 to implement one or more functions, such as feature extraction on data, etc. In addition to the CPU, the processor 201 can also be an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), a system on chip (SoC), or a complex programmable logic device (CPLD), a graphics processing unit (GPU), a neural-network processing unit (NPU), etc.

[0074] It should be noted that in actual applications, the number of processors 201 can be multiple, and the multiple processors 201 can include multiple processors of the same type or multiple processors of different types, for example, the multiple processors 201 are multiple CPUs. For another example, the multiple processors 201 include one or more CPUs and one or more GPUs. For another example, the multiple processors 201 include one or more CPUs and one or more NPUs. Or, the multiple processors 201 include one or more CPUs, one or more GPUs, and one or more NPUs, etc. Among them, the processor 201 (such as CPU, NPU, etc.) can include one core or multiple cores.

[0075] The memory 202 refers to a device for storing data, which can be a memory or a hard disk.

[0076] The memory refers to an internal memory directly exchanging data with the processor 201, which can read and write data at any time and has high speed, and is used as a temporary data storage of an operating system or other programs running on the processor 201. The memory includes volatile memory such as random access memory (RAM), dynamic random access memory (DRAM), and the like, and can also include non-volatile memory such as storage class memory (SCM) and the like, or a combination of volatile memory and non-volatile memory, and the like. In actual application, multiple memories can be configured in the computing device 20, and optionally, the multiple memories can be of different types. The embodiments do not limit the number and type of the memory. In addition, the memory can be configured to have a power retention function. The power retention function refers to that when the system is powered off and then powered on again, the data stored in the memory will not be lost. The memory with the power retention function is referred to as non-volatile memory.

[0077] The hard disk is used to provide storage resources, for example, to store data such as pictures, videos, audio, text, and the like collected by the collection device 10. The hard disk includes but is not limited to non-volatile memory such as read-only memory (ROM), a hard disk drive (HDD), or a solid-state disk (SSD), and the like. Unlike the memory, the hard disk has a slower read-write speed and is usually used to store data persistently. In an embodiment, the data, program instructions, and the like in the hard disk need to be loaded into the memory first, and then the processor obtains these data and / or program instructions from the memory.

[0078] The communication interface 203 is used for communication with other devices, such as for the computing device 20 to communicate with the collection device 10 or the storage device 30.

[0079] In actual application, as shown in Figure 4 The computing device 20 can include two processors 201, which can be a CPU and an NPU, respectively. The CPU can include 6 CPU cores, and the NPU can include 2 NPU cores, which can also be referred to as AI cores. The computing power of the NPU is higher than that of the CPU. The CPU can be used to perform similarity sorting in the data retrieval process, and the NPU can be used to perform similarity calculation in the data retrieval process. For details, refer to Figure 4 The structure of the processor 201 in one of the computing devices 20 shown.

[0080] Based on the above Figure 2 The system architecture shown in FIG. 1, Figure 3 And Figure 4 The hardware architecture of the computing device shown in FIG. 2, the present application exemplarily provides a flowchart of vector retrieval, which can be seen from FIG. 3. Figure 5a Specifically, the flow can be executed by the computing device 20 shown in FIG. 2, and the flow can be roughly divided into the following three stages: Figure 3 to Figure 4

[0081] I. Feature extraction stage

[0082] The computing device 20 inputs each sample picture to a preset feature extraction model for the obtained plurality of sample pictures, and the type of the feature extraction model is not limited in the embodiments of the present application. For example, the feature extraction can be performed by inputting to a convolutional neural network (CNN) model, so that the CNN model outputs a vector corresponding to each sample picture. Subsequently, the computing device 20 stores the vector corresponding to each sample picture in a vector library, which can be located in the memory 202 of the computing device 20 or in the storage device 30, which can be an independent storage medium or a memory, etc.

[0083] II. Clustering stage

[0084] The computing device 20 clusters each vector in the vector library according to the similarity between the vectors to obtain M clustering partitions, wherein each clustering partition corresponds to a partition center vector, and M is an integer greater than 1. Exemplarily, each vector in the vector library can be clustered in the following two ways to obtain M clustering partitions:

[0085] Implementation manner one, each vector in the vector library is directly clustered to obtain M clustering partitions and the partition center vector of each clustering partition. The partition center vector is obtained from each vector in the clustering partition, for example, the average value, the median value, etc., which are not limited in the embodiments of the present application. The specific clustering algorithm can be k-means clustering algorithm, fuzzy c-means clustering algorithm, mean shift clustering and density-based clustering method, etc., which are not limited in the embodiments of the present application.

[0086] ​In a second implementation, a preset proportion (e.g., about 10%) of vectors in the vector base library are randomly selected as training samples, and the training samples are clustered to obtain M cluster partitions and a partition center vector of each cluster partition. The specific clustering algorithm can be a k-means clustering algorithm, a fuzzy c-means clustering algorithm, a mean shift clustering, a density-based clustering method, etc., and the embodiments of the present application do not limit this. The vectors in the vector base library other than the training samples are respectively clustered into the M cluster partitions with the M partition center vectors as the center. In this way, the amount of calculation for determining the partition center vector can be reduced, and the speed of determining the partition center vector can be improved.

[0087] III. Vector retrieval stage

[0088] After the processing based on the above feature extraction stage and clustering stage, a plurality of cluster centers can be obtained, and each cluster center has its own corresponding partition center vector. Subsequently, when a user has a query request, the client can input data to be queried to the computing device 20, the computing device 20 performs feature extraction based on the obtained data to be queried, obtains a query vector, and then performs similarity calculation between the query vector and the partition center vectors of the M cluster partitions to obtain M first similarities. Further, in the M first similarities, the K first similarities in the front of the high-to-low order are selected, and the cluster partitions corresponding to the K first similarities are determined as K retrieval partitions.

[0089] In the K retrieval partitions, an unselected retrieval partition is selected as a target retrieval partition, and second similarities between the query vector and each vector contained in the target retrieval partition are calculated. According to each second similarity, a probability value that the target vector is contained in the target retrieval partition is determined, where the target vector refers to a vector having a similarity to the query vector within a preset range. For example, the target vector refers to a vector having a similarity greater than 0.9 to the query vector. If the probability value is greater than a first preset threshold, the next target retrieval partition is not selected from the unselected retrieval partitions, and the retrieval for the query vector can be terminated. If the probability value is not greater than the first preset threshold, the next target retrieval partition is selected from the unselected retrieval partitions, and the second similarities between the query vector and each vector contained in the newly selected target retrieval partition are calculated. According to each second similarity, a probability value that the target vector is contained in the newly selected target retrieval partition is determined, and the probability value is compared with the first preset threshold again. The above steps are repeatedly executed until the probability value corresponding to the selected target retrieval partition is greater than the first preset threshold, and the next target retrieval partition is stopped from being selected from the unselected retrieval partitions.

[0090] It can be seen that the vector retrieval method provided in the embodiments of the present application improves the speed of vector retrieval by reasoning whether to terminate the retrieval in advance for the current to-be-queried vector in the process of vector retrieval. For example, the second similarities of the to-be-queried vector and each vector in the first retrieval partition are calculated first, the probability that the target vector is contained in the first retrieval partition is determined according to the second similarities, and if the probability is high, the second similarities of the to-be-queried vector and each vector in other retrieval partitions are not calculated. In this way, the amount of retrieval calculation can be reduced, and the speed of vector retrieval can be improved.

[0091] The vector retrieval method provided in the embodiments of the present application will be described in detail through specific steps as follows. Figure 6 As shown in the method can be executed by the computing device in the above Figure 2 , or a chip in the computing device, and includes the following steps.

[0092] Step 601, a to-be-queried vector is obtained. For example, the to-be-queried vector can be a certain vector input by a user to a computing device through a query client, or any vector obtained by the computing device from a vector base. The embodiments of the present application do not limit this.

[0093] Step 602, the to-be-queried vector is respectively compared with the center vectors of M cluster partitions to obtain M first similarities, the M cluster partitions are obtained by clustering each vector in the vector base according to the similarity between the vectors, the center vector of any cluster partition is determined according to a plurality of vectors contained in any cluster partition, and M is an integer greater than 1. In the M first similarities, K first similarities in the front are selected in descending order, and the K cluster partitions corresponding to the K first similarities are determined as K retrieval partitions, K is an integer greater than or equal to 1, and K is less than M.

[0094] Step 603, the following operations are repeatedly performed until the probability value that the target vector is contained in the target retrieval partition selected from the K retrieval partitions is greater than a first preset threshold, and the target vector is a vector having a similarity to the to-be-queried vector within a preset range:

[0095] An unselected retrieval partition is selected as a target retrieval partition from the K retrieval partitions, the second similarities between the to-be-queried vector and each vector contained in the target retrieval partition are calculated, and the probability value that the target vector is contained in the target retrieval partition is determined according to each second similarity.

[0096] It should be noted that the order of selecting the target search partition from the K search partitions is not limited here and can be selected at will. For example, assuming that the K search partitions include search partition A, search partition B and search partition C respectively, a target search partition can be selected at will from the search partition A, the search partition B and the search partition C, such as selecting the search partition A. There are 100 vectors in the search partition A, and 100 second similarities between the to-be-queried vector and the 100 vectors in the search partition A are calculated. The vectors corresponding to the second similarities greater than 0.9 in the 100 second similarities can be taken as target vectors. For example, 20 target vectors are determined, and it can be determined that the probability value of the search partition A containing the target vectors is 20 / 100 = 0.2.

[0097] If the determined probability value is greater than the first preset threshold value, it is not necessary to select the next target search partition in the remaining search partitions, and it is not necessary to calculate the second similarities between the to-be-queried vector and the vectors in the next target search partition, so that the search calculation amount can be saved. For example, when the first preset threshold value is 0.18, the probability value of the search partition A containing the target vectors determined above is 0.2, which is greater than 0.18, so it is not necessary to calculate the second similarities between the to-be-queried vector and the vectors in the search partition B and the search partition C, and it can be seen that a lot of calculation work can be saved.

[0098] If the determined probability value is not greater than the first preset threshold value, it indicates that the number of target vectors contained in the currently selected target search partition is too small, and the search precision of searching the to-be-queried vector based on such a target search partition is likely to be relatively low. Therefore, a target search partition is continuously selected from the remaining search partitions that have not been selected. For example, the search partition B is continuously selected, and the steps after the search partition A is selected are repeated until the probability value obtained is greater than the first preset threshold value, and then the selection of the search partition is stopped.

[0099] In the above manner, it is not necessary to calculate the similarities between the to-be-queried vector and all the vectors in the K search partitions, but only a part of the search partitions are selected, and the similarities between the to-be-queried vector and the vectors in the part of the search partitions are calculated. In this way, the search calculation amount can be reduced, and the search speed can be improved.

[0100] In step 604, when the loop execution in step 603 is stopped, a query result is output based on the at least one selected search partition and the to-be-queried vector. The output of the query result based on the at least one selected search partition and the to-be-queried vector can include but is not limited to the following possible ways:

[0101] One possible way, in the at least one selected search partition, the search partition with the probability value greater than the first preset threshold value is determined, since the termination loop condition of step 603 is that the probability value is greater than the first preset threshold value, so here "the search partition with the probability value greater than the first preset threshold value" is only one, that is, the last selected target search partition, such as the above example "the search partition with the probability value greater than the first preset threshold value" is search partition A. Then the query result of the query vector is searched in this search partition. For example, each vector in the search partition is output or fed back to the user as the query result of the query vector. For another example, the second similarity between the query vector and the W vectors corresponding to the W second similarities in descending order can also be output or fed back to the user as the query result.

[0102] In the above technical solution, since there is only one search partition with a probability value greater than the first preset threshold value, outputting all vectors contained in the search partition with a probability value greater than the first preset threshold value as the query result can further effectively reduce the search calculation amount and improve the search speed. Or the W vectors corresponding to the W second similarities in descending order of the second similarity between the query vector and the vectors contained in the search partition with a probability value greater than the first preset threshold value are output as the query result, which can further simplify the query result.

[0103] Another possible way, in the multiple vectors included in the at least one selected search partition, the query result of the query vector is searched. In step 603, if the probability value of the first selected target search partition is not greater than the first preset threshold value, a second target search partition can be selected, and if the probability value corresponding to the second target search partition is greater than the first preset threshold value, the next target search partition is not selected. Therefore, the number of "at least one selected search partition" here can be greater than 1. For example, in the last example, search partition A and search partition B may be finally selected to find the search partition with a probability value greater than the first preset threshold value, and the query result of the query vector can be searched in the multiple vectors included in search partition A and search partition B. For example, each vector contained in the at least one selected search partition can be output or fed back to the user as the query result. For another example, the W vectors corresponding to the W second similarities in descending order of the second similarity between the query vector and the vectors in the at least one selected search partition can be output or fed back to the user as the query result.

[0104] For example, in step 603, the first target search partition is selected as search partition A, the second similarities of the to-be-queried vector and each vector in search partition A are calculated, the probability value is determined according to the second similarities, the probability value is not greater than the first preset threshold, the next target search partition is selected as search partition B, the second similarities of the to-be-queried vector and each vector in search partition B are calculated, the probability value is determined according to the second similarities, the probability value is greater than the first preset threshold, and the target search partition is not selected any more. Then, in step 604, the at least one search partition that has been selected includes search partition A and search partition B. Since the second similarities of the to-be-queried vector and each vector in search partition A and the second similarities of the to-be-queried vector and each vector in search partition B have been calculated in step 603, it is not necessary to repeat the calculation in step 604, and therefore the calculation amount is not increased. Instead, the second similarities of the to-be-queried vector and each vector in search partition A and the second similarities of the to-be-queried vector and each vector in search partition B are sorted from high to low, and the W vectors corresponding to the W second similarities in the front of the sorting are taken as the query result.

[0105] In the technical solution, the query result is output based on the at least one search partition that has been selected, instead of the search partition whose probability value is greater than the first preset threshold. Since the vector that is the same as or similar to the to-be-queried vector falls in the search partition whose probability value is not greater than the first preset threshold, there may also be a vector that is similar to the to-be-queried vector with a high similarity. Therefore, more accurate search results can be output based on the calculated second similarities of the to-be-queried vector and each vector in the search partition that has been selected, and the accuracy of vector search can be improved.

[0106] In a possible implementation, the target search partition in the K search partitions can also not be selected at random, but selected according to a certain rule. Two methods of selecting the K search partitions are introduced below.

[0107] Method one: the K search partitions are sorted according to the K first similarities from high to low. In this way, the search partitions that have not been selected can be selected as the target search partition in the sorted K search partitions in sequence.

[0108] For example, the first similarity of the to-be-queried vector and the partition center vector of search partition A is 0.9, the first similarity of the to-be-queried vector and the partition center vector of search partition B is 0.8, and the first similarity of the to-be-queried vector and the partition center vector of search partition C is 0.7. Then, the K search partitions are sorted according to the following order: search partition A-search partition B-search partition C. In this way, the target search partition is also selected according to the order.

[0109] The K search partitions corresponding to each to-be-queried vector are scientifically and reasonably sorted, a target search partition is selected according to the order, and undoubtedly, the search partition with a probability value greater than the first preset threshold can be found as soon as possible, thereby the speed of vector search can be improved and the search time consumption can be reduced. For example, in the above example, the probability value of search partition A is calculated first, and the probability value greater than the first preset threshold can be obtained, thereby the search can be terminated as soon as possible. If the probability value of search partition B is calculated first, the search partition with the probability value greater than the first preset threshold cannot be obtained, and the similarity between the to-be-queried vector and each vector in search partition A needs to be calculated again, which undoubtedly increases the calculation amount and increases the search time consumption.

[0110] In this way, the target search partition with the probability value greater than the first preset threshold can be determined as early as possible by selecting the target search partition according to the size order of the K first similarities, the possibility of selecting the target search partition again is reduced as much as possible, and the similarity between the to-be-queried vector and the vector in the target search partition selected again does not need to be calculated, thereby the calculation amount can be reduced and the search speed can be improved.

[0111] Method two, the vectors in each search partition are clustered according to the similarity between the vectors, and then a plurality of search sub-partitions are obtained, and each search sub-partition also has a corresponding sub-partition center vector; a third similarity between the to-be-queried vector and the sub-partition center vectors of the plurality of search sub-partitions is calculated, and the K search partitions are sorted according to the plurality of third similarities between the to-be-queried vector and the plurality of sub-partition center vectors in each search partition. In this way, the search partition that has not been selected can be selected as the target search partition in the K search partitions sorted in order.

[0112] Figure 7 A diagram for dividing a search sub-partition for any search partition is shown. As shown in the figure, three search partitions are shown, and for any search partition, the vectors in the search partition are clustered, for example, each search partition is divided into five search sub-partitions. Of course, the number of search sub-partitions divided by different search partitions can be different. In Figure 7 In the figure, the search partitions are distinguished by solid lines, and the search sub-partitions are distinguished by dashed lines. The pentagram in the figure indicates the partition center vector of the search partition, and the triangle in the figure indicates the sub-partition center vector of the search sub-partition. The clustering manner of the vectors in any search partition is not limited in the embodiments of the present application, and the method for clustering the vectors in the vector library to obtain a plurality of clustering partitions can be referred to.

[0113] When the search partitions are sorted, the K search partitions can be sorted according to the maximum similarity in the plurality of third similarities between the to-be-queried vector and the plurality of sub-partition center vectors in each search partition. For example,Figure 8 The second similarity between the query vector and the center vector of each search partition and the third similarity between the query vector and the center vector of each search sub-partition are shown. As shown in Figure 8 The search partition A, the search partition B and the search partition C are shown in the figure, and each search partition is divided into 5 search sub-partitions. The 5 third similarities between the query vector and the center vectors of the 5 search sub-partitions in the search partition A are calculated, and the maximum similarity is selected from the 5 third similarities; the 5 third similarities between the query vector and the center vectors of the 5 search sub-partitions in the search partition B are calculated, and the maximum similarity is selected from the 5 third similarities; the 5 third similarities between the query vector and the center vectors of the 5 search sub-partitions in the search partition C are calculated, and the maximum similarity is selected from the 5 third similarities; the 3 maximum similarities are sorted in descending order, and the sorting of the 3 search partitions is obtained accordingly.

[0114] The K search partitions can also be sorted according to the number of third similarities between the query vector and the center vectors of the plurality of search sub-partitions in each search partition that exceed the second preset threshold. For example, in Figure 8 The 5 third similarities between the query vector and the center vectors of the 5 search sub-partitions in the search partition A are calculated, and the number x1 of third similarities exceeding the second preset threshold is determined; the 5 third similarities between the query vector and the center vectors of the 5 search sub-partitions in the search partition B are calculated, and the number x2 of third similarities exceeding the second preset threshold is determined; the 5 third similarities between the query vector and the center vectors of the 5 search sub-partitions in the search partition C are calculated, and the number x3 of third similarities exceeding the second preset threshold is determined; x1, x2 and x3 are sorted in descending order, and the sorting of the 3 search partitions is obtained accordingly.

[0115] Since the center vectors of the search sub-partitions can more accurately represent the vectors in the search sub-partitions, sorting the K search partitions based on the plurality of third similarities between the query vector and the center vectors of the plurality of search sub-partitions in each search partition can improve the accuracy of the sorting. In this way, the target search partition with a probability value greater than the first preset threshold can be determined as soon as possible, the possibility of reselecting the target search partition can be minimized, and the calculation of the similarity between the query vector and the vectors in the reselected target search partition can be avoided, thereby reducing the calculation amount and improving the search speed.

[0116] Figure 8 The pentagram in the figure represents the center vector of the search partition, the triangle represents the center vector of the search sub-partition, and the square represents the query vector. According to the above method, the K search partitions can be sorted according to the number of third similarities between the query vector and the center vectors of the plurality of search sub-partitions in each search partition that exceed the second preset threshold.Figure 8 It can be seen that the different sorting methods have an impact on the sorting of the K search partitions. When the 3 search partitions are sorted according to the order of the 3 first similarities from high to low, the sorting of the search partitions according to the order of the 3 first similarities is: search partition A-search partition B-search partition C. Figure 8 The 3 first similarities (the 3 first similarities are respectively represented by the distances from the square to the three pentagons in FIG. 6) are shown. Figure 8 The closer the distance, the higher the similarity.

[0117] When the 3 search partitions are sorted according to the maximum similarity in the plurality of third similarities between the query vector and the plurality of sub-partition center vectors in each search partition, the sorting of the 3 search partitions is: search partition B-search partition A-search partition C. Figure 8 The maximum similarity in the third similarities between the query vector and the 5 sub-partition center vectors in each search partition (the maximum similarity is respectively represented by the distance from the square to the three triangles in FIG. 7) is shown. Figure 9 The closer the distance, the higher the similarity.

[0118] It can be seen that by dividing more detailed search sub-partitions, the sorting of the search partitions can be optimized and corrected. In specific implementations, the search sub-partitions can be further divided, for example, each search sub-partition is further divided into a plurality of small partitions, which can further improve the search accuracy and speed. This application will not be repeated here.

[0119] In a possible implementation, the probability value that the target vector is contained in the target search partition according to the second similarity can also be predicted by a prediction model. The prediction model can be a single-stage model or a two-stage model, regardless of whether a single-stage model or a two-stage model is used.

[0120] A possible way to train the prediction model can be to train the prediction model by using a large amount of sample data with labels. For example, for any sample data, feature extraction is performed on the sample data to obtain a sample vector; M first similarities between the sample vector and M clustering partitions are calculated, and K search partitions are determined according to the size of the M first similarities; a target search partition is selected from the K search partitions, and each second similarity between the sample vector and each vector in the target search partition is calculated, and t target second similarities are selected from the second similarities; the sample vector, the K first similarities between the sample vector and the K search partitions, the t target second similarities, and the label are input into the prediction model, and the label is the probability value that the target vector is contained in the target search partition. Through multiple training, the parameters of the prediction model can be better optimized and adjusted.

[0121] Another possible way of training the prediction model is to train the prediction model with a large amount of sample data, and parameters of the prediction model are adjusted according to an objective function. Embodiments of the present application do not limit the form of the objective function. Through multiple training, the parameters of the prediction model are optimized and adjusted.

[0122] If a single-stage model is used, the method of obtaining the probability value according to each second similarity in step 603 can be further refined, Figure 11a An exemplary method of obtaining the probability value according to each second similarity is shown, which can specifically include the following steps:

[0123] Step 901, in the K search partitions, any unselected search partition is selected as a target search partition; each second similarity between the query vector and each vector in the target search partition is calculated. In each second similarity, t target second similarities are determined in order from high to low.

[0124] The method of determining the target search partition for the query vector is as described above, and will not be repeated here.

[0125] The method of determining t target second similarities for the query vector is described in detail below.

[0126] For example, each second similarity between the query vector and each vector in the target search partition is taken as a target second similarity; for example, the second similarity satisfying a certain threshold in each second similarity is taken as a target second similarity; for example, the first t second similarities in each second similarity in order from high to low are taken as target second similarities; for example, the maximum second similarity in each second similarity is taken as a target second similarity. The above is only an example, and embodiments of the present application do not limit the way of determining the target second similarity. The fewer the number of target second similarities, the less the calculation of the prediction model, and the higher the search speed. For example, the maximum second similarity between the query vector and all vectors in the target search partition is taken as a target second similarity, which can reduce the calculation of the prediction model without affecting the accuracy of the final probability value, and further improve the speed of vector search.

[0127] For example, for the query vector q1, 100 second similarities between q1 and 100 vectors in search partition A are calculated, and the maximum second similarity in the 100 second similarities is taken as a target second similarity.

[0128] Step 902, input the query vector, K first similarities and t target second similarities into the prediction model to obtain a probability value.

[0129] The probability value is predicted by the prediction model, the accuracy of determining the probability value is improved, and compared with a non-model prediction method, the speed of determining the probability value by the prediction model is faster. In the second similarities, the t target second similarities in which the second similarities are ranked from high to low are selected, and the t target second similarities are input into the prediction model, which can further reduce the calculation amount of the prediction model, thereby further improving the speed of predicting the probability value without affecting the prediction accuracy.

[0130] For example, each vector in the vector library is clustered to obtain 10 clustering partitions, and each clustering partition corresponds to a partition center vector. The first similarity between the query vector q1 and the partition center vectors of the 10 clustering partitions is calculated, the first K clustering partitions with the highest first similarity are selected as the retrieval partitions, or the K clustering partitions with the first similarity satisfying a preset threshold are selected as the retrieval partitions. Assuming that 3 retrieval partitions are determined, which are retrieval partition A, retrieval partition B and retrieval partition C, then 3 first similarities between the query vector q1 and the partition center vectors of the 3 retrieval partitions are determined. The target retrieval partition is determined as retrieval partition A, 10 second similarities between the query vector q1 and the 10 vectors in retrieval partition A are calculated, and 5 target second similarities are selected from the 10 second similarities. The query vector q1, the 3 first similarities and the 5 target second similarities are input into the single-stage model, and the single-stage model outputs a probability value. The probability value represents the probability that the target vector is included in retrieval partition A. The probability value can reflect the current retrieval accuracy. If the probability value is high, the current retrieval accuracy is high, and if the probability value is low, the current retrieval accuracy is low. If the probability value satisfies a first preset threshold, for example, the probability value is 0.98, which is greater than the first preset threshold 0.9, it means that most of the target vectors are included in retrieval partition A, and the retrieval accuracy is high, and the query vector can be terminated.

[0131] The above method can reduce the possibility of calculating the similarity between the query vector and the vectors in the remaining retrieval partitions by reasoning and judging whether to terminate the retrieval of the current query vector in advance, thereby reducing the retrieval calculation amount and improving the vector retrieval speed.

[0132] However, the single-stage model has a problem, which causes the method in the above embodiments to be able to only use the matrix multiplication vector calculation mode when running in the hardware accelerator, and cannot fully exert the computing power of the hardware accelerator. Specifically, in the above embodiments, the input of the single-stage model is the query vector, the K first similarities, and the t target second similarities. Since different query vectors determine different retrieval partitions, and the corresponding target retrieval partitions are different, each second similarity between each query vector and each vector in the target retrieval partition is calculated separately, and then input into the single-stage model. Therefore, the single-stage model can only use the matrix multiplication vector calculation mode of the hardware accelerator. For example, the retrieval partition determined by the query vector q1 is the retrieval partition A, the retrieval partition B, and the retrieval partition C, and the corresponding target retrieval partition is the retrieval partition A; the retrieval partition determined by the query vector q2 is the retrieval partition D, the retrieval partition E, and the retrieval partition F, and the corresponding target retrieval partition is the retrieval partition D. The vectors in the retrieval partition A and the retrieval partition D are different, so the matrix multiplication vector calculation mode of the hardware accelerator can be used to first calculate the second similarity between the query vector q1 and each vector in the retrieval partition A, and then calculate the second similarity between the query vector q2 and each vector in the retrieval partition D. Therefore, the probability value corresponding to the query vector q1 and the probability value corresponding to the query vector q2 can only be output by the single-stage model respectively, and the single-stage model can only use the matrix multiplication vector calculation mode to calculate the probability value. For example, for the query vector q1, the query vector q1, the three first similarities between the query vector q1 and the partition center vectors of the three retrieval partitions, and the t target second similarities between the query vector q1 and each vector in the retrieval partition A are input into the single-stage model, and the single-stage model uses the matrix multiplication vector calculation mode of the hardware accelerator to output the probability value of the query vector q1. Then, the query vector q2, the three first similarities between the query vector q2 and the partition center vectors of the three retrieval partitions, and the t target second similarities between the query vector q2 and each vector in the retrieval partition D are input into the single-stage model, and the single-stage model uses the matrix multiplication vector calculation mode of the hardware accelerator to output the probability value of the query vector q2.

[0133] It can be seen that the single-stage model can only predict one query vector at a time. This results in the use of only the matrix multiplication vector calculation mode of the hardware accelerator. The calculation efficiency of the matrix multiplication vector calculation mode of the hardware accelerator is much lower than that of the matrix multiplication matrix calculation mode of the hardware accelerator. This results in a waste of the computing power of the hardware accelerator. In addition, the single-stage model can only predict one query vector at a time, and if there are multiple query vectors, the prediction time will increase. If a two-stage model is used, the problems in the single-stage model can be overcome to some extent, and the retrieval speed can be further improved based on the single-stage model.

[0134] If the two-stage model is adopted, the number of the query vectors in step 601 can be N, N being a positive integer greater than 1. When N is greater than 1, the advantage of the vector retrieval method provided by the embodiments of the present application can be fully exerted, the retrieval speed is improved, and the retrieval time consumption is reduced. The embodiments of the present application do not limit the way of obtaining N query vectors. For example, in batch query, a plurality of query vectors are obtained in batch at one time, and the plurality of query vectors are taken as input. For example, after a single query vector is obtained (such as user input in Internet application), the single query vector obtained in sequence is integrated by the computing device, and the plurality of query vectors are taken as input. The integration manner can be various manners known by those skilled in the art, and the embodiments of the present application do not limit this.

[0135] The method for obtaining M first similarities in step 602 is as follows: according to the N query vectors and the M partition center vectors of the M cluster partitions, the matrix multiplication manner of the hardware accelerator is adopted to obtain M first similarities between any query vector and the M partition center vectors. In the M first similarities, K first similarities in front of the high-to-low order are selected, and the K cluster partitions corresponding to the K first similarities are determined as K retrieval partitions, K being an integer greater than or equal to 1 and smaller than M.

[0136] The M cluster partitions are obtained by clustering each vector in the vector library according to the similarity between the vectors. M first similarities between each query vector and the M partition center vectors of the M cluster partitions need to be calculated. In order to speed up the calculation, the N query vectors can form a matrix, the M partition center vectors can form a matrix, and the matrix multiplication manner of the hardware accelerator is adopted to calculate, so that M first similarities between any query vector in the N query vectors and the M partition center vectors can be quickly obtained.

[0137] For example, the query vectors are q1 and q2, and the formed matrix is [q1, q2]. The M partition center vectors are m1, m2, m3, m4, m5, m6, m7, m8, m9 and m10, and the formed matrix is [m1, m2, m3, m4, m5, m6, m7, m8, m9, m10]. Figure 10 A matrix of M first similarities between any query vector and the M partition center vectors obtained by the matrix multiplication manner of the hardware accelerator is shown. Wherein s11 represents the first similarity between q1 and m1, s12 represents the first similarity between q1 and m2, and so on, which will not be repeated here.

[0138] For any to-be-queried vector, according to the M first similarities between the to-be-queried vector and the M partition center vectors, the K retrieval partitions of the to-be-queried vector are the K clustering partitions corresponding to the K first similarities ranked from high to low. For example, each to-be-queried vector determines 3 retrieval partitions. The retrieval partitions determined by to-be-queried vector q1 are retrieval partition A, retrieval partition B and retrieval partition C; the retrieval partitions determined by to-be-queried vector q2 are retrieval partition D, retrieval partition E and retrieval partition F.

[0139] The method for obtaining the probability value according to each second similarity in step 603 can be further refined, Figure 11b An example is shown, which is a method for obtaining the probability value according to each second similarity, and can specifically include the following steps:

[0140] In step 1001, input the matrix formed by the N to-be-queried vectors and the matrix formed by the K first similarities corresponding to each to-be-queried vector in the N to-be-queried vectors into the first prediction model, and obtain the N initial probability values corresponding to the N to-be-queried vectors by using the matrix multiplication method of the hardware accelerator; the initial probability value is used to represent the probability of the target vector containing the to-be-queried vector in the K retrieval partitions corresponding to any to-be-queried vector.

[0141] For example, the to-be-queried vectors are q1 and q2, and the matrix formed is [q1, q2]; the three first similarities corresponding to the three retrieval partitions of to-be-queried vector q1 are s11, s12 and s13, respectively, corresponding to retrieval partition A, retrieval partition B and retrieval partition C; the three first similarities corresponding to the three retrieval partitions of to-be-queried vector q2 are s24, s25 and s26, respectively, corresponding to retrieval partition D, retrieval partition E and retrieval partition F. Figure 12 A matrix formed by the three first similarities corresponding to each to-be-queried vector in the two to-be-queried vectors is shown. In this matrix, it is not necessary to pay attention to which retrieval partitions correspond to each to-be-queried vector, because the first prediction model only needs to calculate the initial probability value for each to-be-queried vector and the three first similarities corresponding to each to-be-queried vector.

[0142] For example, two initial probability values p11 and p12 are generated for to-be-queried vector q1 and to-be-queried vector q2, respectively, where p11 represents the probability of the target vector containing to-be-queried vector q1 in retrieval partition A, retrieval partition B and retrieval partition C. Where p12 represents the probability of the target vector containing to-be-queried vector q2 in retrieval partition D, retrieval partition E and retrieval partition F. The above is only an example.

[0143] It can be seen that, since the input of the first prediction model is N query vectors and K first similarities corresponding to each of the N query vectors, these features can be input in matrix form, and therefore the matrix multiplication of the hardware accelerator can be used to obtain N initial probability values corresponding to the N query vectors. In this way, the computing power of the hardware accelerator is fully utilized, and compared with the single-stage model, the computing efficiency, the vector retrieval speed, and the retrieval time consumption can be further improved.

[0144] In step 1002, for any query vector, any unselected search partition is selected as a target search partition in K search partitions, and second similarities between the query vector and vectors in the target search partition are determined. In the second similarities, t target second similarities ranked from high to low are determined.

[0145] For example, for the query vector q1, the target search partition is search partition A, and 100 second similarities between q1 and 100 vectors in search partition A are calculated. The second similarity with the largest value in the 100 second similarities is taken as the target second similarity. For the query vector q2, the target search partition is search partition D, and 200 second similarities between q1 and 200 vectors in search partition D are calculated. The second similarity with the largest value in the 200 second similarities is taken as the target second similarity.

[0146] In step 1003, for any query vector, the initial probability value corresponding to the query vector and the t target second similarities corresponding to the query vector are input into the second prediction model to obtain a final probability value corresponding to the query vector.

[0147] Since the target search partition corresponding to each query vector is different, the t target second similarities corresponding to different query vectors cannot be obtained at the same time, but are calculated respectively, as described in step 1002. Therefore, in step 1003, each query vector is calculated respectively, and the matrix-vector calculation mode of the hardware accelerator is used.

[0148] For example, for the query vector q1, the initial probability value p11 corresponding to the query vector and the target second similarity are input into the second prediction model, and the final probability value p21 is obtained by using the matrix-vector calculation mode of the hardware accelerator. P21 reflects the probability that the target vector containing the query vector q1 is in search partition A.

[0149] For the query vector q2, the initial probability value p12 corresponding to the query vector and the target second similarity are input into the second prediction model, and the final probability value p22 is obtained by using the matrix-vector calculation mode of the hardware accelerator. P22 reflects the probability that the target vector containing the query vector q2 is in search partition D.

[0150] In the technical solution, the prediction of the probability value is divided into two stages, the first stage uses the first prediction model, and the second stage uses the second prediction model. Specifically, the matrix formed by the N query vectors and the matrix formed by the K first similarities corresponding to each of the N query vectors are input into the first prediction model. In this way, the first prediction model can use the matrix multiplication method to predict the initial probability value, fully exert the computing power, improve the computing efficiency, and further improve the speed of vector retrieval.

[0151] If the two-stage model is used, after step 1003, the step of judging the probability value can also be further refined. Figure 13 An example of a method for judging the probability value is shown, which can specifically include the following steps:

[0152] In step 1201, if the final probability value is not greater than the first preset threshold, the next unselected search partition is selected as the target search partition in the K search partitions.

[0153] For example, the first similarities of the query vector q1 with the search partition A, the search partition B and the search partition C are 0.9, 0.8 and 0.7 respectively, and the target search partition of the query vector q1 is the search partition A, and the next target search partition is the search partition B.

[0154] In step 1202, the final probability value corresponding to the query vector and the target second similarity between the query vector and each vector in the next target search partition are input into the second prediction model, and the matrix-vector multiplication of the hardware accelerator is used to obtain the updated probability value corresponding to the query vector.

[0155] Here, the method for determining the target second similarity is the same as the method for determining the target second similarity in the target search partition, which will not be described here.

[0156] For example, the second similarities between the query vector q1 and each vector in the search partition B are calculated, and the value with the maximum second similarity is determined as the target second similarity. The final probability value p21 corresponding to the query vector q1 and the target second similarity corresponding to the query vector q1 are input into the second prediction model, and the matrix-vector multiplication of the hardware accelerator is used to obtain the updated probability value corresponding to the query vector q1. The updated probability value represents the probability that the target vector is included in the current all target search partitions. In this example, the updated probability value represents the probability that the target vector is included in the search partition A and the search partition B.

[0157] If the updated probability value is not greater than the first preset threshold, the final probability value in step 1202 is updated as the updated probability value, and the step of selecting the next unselected search partition as the target search partition in the K search partitions in step 1201 is returned.

[0158] If the updated probability value is not greater than the first preset threshold, it indicates that the probability of the target vector being contained in the current all target search partitions is low, and the search accuracy is not high, and the search should be continued.

[0159] If the updated probability value is greater than the first preset threshold, it indicates that the probability of the target vector being contained in the current all target search partitions is high, and the search accuracy is high, and the search should be terminated. Alternatively, the K search partitions are polled, and the search should also be terminated to save computing power.

[0160] The final probability value is input into the second prediction model to obtain an updated probability value. If the updated probability value is not greater than a second preset threshold, the updated probability value is updated as the final probability value, and the judgment of whether to terminate the search is performed in a loop. The accuracy of the judgment of whether to terminate the search is improved, and the vector search accuracy can be improved.

[0161] For the convenience of understanding, the vector search method provided by the embodiments of the application is described in the whole. Figure 14 The whole flowchart of the vector search method provided by the embodiments of the application can include the following steps.

[0162] In step 1301, the to-be-queried vectors q1 and q2 are obtained.

[0163] In step 1302, the matrix formed by the to-be-queried vectors q1 and q2 and the matrix formed by the partition center vectors of the 10 cluster partitions are input into the hardware accelerator to perform matrix multiplication to obtain 10 first similarities between any to-be-queried vector and the 10 partition center vectors.

[0164] In step 1303, the first three values of the 10 first similarities corresponding to the to-be-queried vector q1 from high to low are determined as the first three values of the 10 first similarities corresponding to the to-be-queried vector q2 from high to low.

[0165] For example, the three search partitions corresponding to the to-be-queried vector q1 are search partition A, search partition B, and search partition C. The three search partitions corresponding to the to-be-queried vector q2 are search partition D, search partition E, and search partition F.

[0166] Step 1304, input the matrix formed by the to-be-queried vectors q1 and q2 and the matrix formed by the three first similarities corresponding to the to-be-queried vectors q1 and q2 into the first prediction model.

[0167] Step 1305, in the first prediction model, the initial probability values corresponding to the to-be-queried vectors q1 and q2 are obtained by using the hardware accelerator to perform matrix multiplication on the matrix.

[0168] Step 1306, for the to-be-queried vector q1, the three search partitions are sorted according to the sizes of the first similarities.

[0169] For example, the first similarities corresponding to the search partition A, the search partition B and the search partition C are 0.9, 0.8 and 0.7 respectively.

[0170] Step 1307, the search partition with the largest first similarity is determined as the target search partition of the to-be-queried vector q1. For example, the search partition A is determined as the i-th target search partition of the to-be-queried vector q1.

[0171] Step 1308, the second similarities between the to-be-queried vector q1 and the vectors in the target search partition are calculated, and the maximum value of the second similarities is taken as the target second similarity of the target search partition.

[0172] Step 1309, the initial probability value corresponding to the to-be-queried vector q1 and the target second similarity are input into the second prediction model, and the final probability value corresponding to the to-be-queried vector q1 is obtained by using the hardware accelerator to perform matrix multiplication on the vector.

[0173] Step 1310, it is judged whether the final probability value is greater than a first preset threshold value, if yes, step 1311 is entered, if not, step 1312 is entered.

[0174] Step 1311, the search for the to-be-queried vector q1 is terminated, and the vectors in the current all target search partitions that satisfy the similarity requirement with the to-be-queried vector are taken as the query result and returned. For example, the final probability value corresponding to the search partition A is 0.98, which is greater than the first preset threshold value, and the vectors corresponding to the first W second similarities from large to small in the search partition A are taken as the query result and returned.

[0175] Step 1312, the next unselected search partition is selected as the target search partition from the three search partitions.

[0176] For example, the final probability value corresponding to the search partition A is 0.58, which is not greater than the first preset threshold value, and the search partition B is selected as the target search partition.

[0177] Step 1313, a second similarity between the query vector q1 and each vector in the next target search partition is calculated, and a maximum value of the second similarity is taken as a target second similarity of the next target search partition.

[0178] Step 1314, the final probability value and the target second similarity of the next target search partition are input into the second prediction model, and a matrix multiplication vector mode of a hardware accelerator is used to obtain an updated probability value corresponding to the query vector q1.

[0179] Step 1315, it is judged whether the updated probability value is greater than a first preset threshold value, if yes, step 1311 is entered, if no, step 1316 is entered.

[0180] Step 1316, the final probability value in step 1314 is updated as the updated probability value, and step 1312 is returned.

[0181] For the query vector q2, please refer to the processing steps of the query vector q1 in steps 1306-1316 described above to determine the query result of the query vector q2, which will not be repeated here.

[0182] It should be pointed out that the steps in the above method embodiments are exemplarily described by taking the execution of the computing device 20 as an example, and the steps in the above method embodiments can also be executed by the processor 201 in the computing device 20.

[0183] Based on the above content and the same technical concept, the embodiments of the present application provide a vector search device, as shown in the figure, which includes an acquisition unit 1401 and a processing unit 1402. The vector search device is used to execute the method embodiments shown in the above Figure 5a 、 Figure 6 、 Figure 9 、 Figure 10 、 Figure 12 、 Figure 13 or Figure 13 .

[0184] When the vector search device is used to implement the method embodiments shown in the above ​In the function of the method embodiment shown, the acquisition unit 1401 is configured to acquire a query vector; the processing unit 1402 is configured to: perform similarity calculation on the query vector and partition center vectors of M cluster partitions respectively, to obtain M first similarities; the M cluster partitions are obtained by clustering each vector in a vector library according to the similarity between the vectors; the partition center vector of any cluster partition is determined according to a plurality of vectors contained in the cluster partition; M is an integer greater than 1; in the M first similarities, K first similarities in front of the high-to-low order are selected, and the cluster partitions corresponding to the K first similarities are determined as K search partitions, K is an integer greater than or equal to 1 and smaller than M; the following operations are repeatedly performed until the probability value that a target search partition selected from the K search partitions contains a target vector is greater than a first preset threshold, the target vector is a vector having a similarity to the query vector within a preset range: a search partition that has not been selected is selected from the K search partitions as the target search partition; second similarities between the query vector and each vector contained in the target search partition are calculated; the probability value that the target search partition contains the target vector is determined according to the second similarities; and a query result is output based on at least one search partition that has been selected and the query vector.

[0185] In a possible implementation, when the processing unit 1402 outputs the query result based on at least one search partition that has been selected and the query vector, the processing unit 1402 is specifically configured to: output, as the query result, each vector contained in a search partition that has the probability value greater than the first preset threshold in the at least one search partition that has been selected; or output, as the query result, W vectors corresponding to the second similarities in a high-to-low order, W being a positive integer.

[0186] In a possible implementation, when the processing unit 1402 outputs the query result based on at least one search partition that has been selected and the query vector, the processing unit 1402 is specifically configured to: output, as the query result, each vector contained in the at least one search partition that has been selected; or output, as the query result, W vectors corresponding to the second similarities in a high-to-low order, W being a positive integer.

[0187] In a possible implementation, when the processing unit 1402 selects a search partition that has not been selected from the K search partitions as the target search partition, the processing unit 1402 is specifically configured to: select, as the target search partition, a search partition that has not been selected from the K search partitions in a high-to-low order of the K first similarities.

[0188] In a possible implementation, when the processing unit 1402 selects an unselected search partition as the target search partition from the K search partitions, specifically for: clustering the vectors in the search partition according to the similarity between the vectors to obtain a plurality of search sub-partitions for any search partition in the K search partitions; determining a sub-partition center vector of any search sub-partition according to the plurality of vectors contained in the search sub-partition; calculating a third similarity between the to-be-queried vector and the sub-partition center vectors of the plurality of search sub-partitions; sorting the K search partitions according to the plurality of third similarities between the to-be-queried vector and the plurality of sub-partition center vectors in each search partition; and selecting an unselected search partition as the target search partition from the sorted K search partitions.

[0189] In a possible implementation, when the processing unit 1402 sorts the K search partitions according to the plurality of third similarities between the to-be-queried vector and the plurality of sub-partition center vectors in each search partition, specifically for: sorting the K search partitions according to the number of third similarities between the to-be-queried vector and the plurality of sub-partition center vectors in each search partition that exceed the second preset threshold; or sorting the K search partitions according to the maximum similarity between the to-be-queried vector and the plurality of sub-partition center vectors in each search partition.

[0190] In a possible implementation, when the processing unit 1402 determines the probability value that the target vector is contained in the target search partition according to the second similarities, specifically for: determining t target second similarities in descending order in the second similarities; inputting the to-be-queried vector, the K first similarities, and the t target second similarities into a prediction model to obtain the probability value; and the prediction model is used to predict the probability value that the target vector is contained in the target search partition.

[0191] In a possible implementation, the to-be-queried vector is N, and N is a positive integer greater than 1; when the processing unit 1402 inputs the to-be-queried vector, the K first similarities, and the t target second similarities into the prediction model to obtain the probability value, specifically for: inputting a matrix formed by the N to-be-queried vectors and a matrix formed by the K first similarities corresponding to each of the N to-be-queried vectors into a first prediction model to obtain N initial probability values corresponding to the N to-be-queried vectors; the initial probability value is used to represent the probability that the target vector containing the to-be-queried vector is contained in the K search partitions corresponding to any to-be-queried vector; and inputting the initial probability value corresponding to the to-be-queried vector and the t target second similarities corresponding to the to-be-queried vector into a second prediction model to obtain a final probability value corresponding to the to-be-queried vector.

[0192] Based on the above content and the same technical concept, the embodiment of the present application further provides a computer readable storage medium, and the computer readable storage medium stores a computer program or instructions, and when the computer program or instructions are executed, the computer executes the method in the method embodiment.

[0193] Based on the above content and the same technical concept, the embodiment of the present application further provides a computer readable storage medium, and the computer readable storage medium stores a computer program or instructions, and when the computer program or instructions are executed, the computer executes the method in the method embodiment.

[0194] It can be understood that various digital numbers involved in the embodiments of the present application are only distinguished for convenience of description, and are not used to limit the scope of the embodiments of the present application. The size of the serial number of the above processes does not mean the order of execution, and the execution order of the processes should be determined according to its function and inherent logic.

[0195] Obviously, those skilled in the art can make various modifications and variations to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application belong to the scope of the claims of the present application and the equivalent technology, the present application also intends to include these modifications and variations.

Claims

1. A vector retrieval method, characterized in that, include: The similarity between the vector to be queried and the partition center vectors of M clustering partitions is calculated to obtain M first similarity scores; the M clustering partitions are obtained by clustering each vector in the vector base according to the similarity between the vectors; the partition center vector of any of the clustering partitions is determined based on the multiple vectors contained in any of the clustering partitions, where M is an integer greater than 1; From the M first similarities, the top K first similarities are determined, wherein the clustering partitions corresponding to the K first similarities are respectively used as K retrieval partitions, where K is an integer greater than or equal to 1 and K is less than M; A target retrieval partition is determined from the K retrieval partitions, wherein the probability value of the target retrieval partition containing the target vector is greater than a first preset threshold, and the target vector is a vector whose similarity to the query vector is within a preset range; Based on at least one selected search partition and the vector to be queried, the query result is output, wherein the at least one selected search partition is the partition selected in the process of determining the target search partition, and the at least one search partition includes the target search partition and the search partition in the process of determining the target search partition whose probability value of containing the target vector is not greater than a first preset threshold.

2. The method as described in claim 1, characterized in that, A target retrieval partition is determined from the K retrieval partitions, wherein the probability value of the target retrieval partition containing the target vector is greater than a first preset threshold, and the target vector is a vector whose similarity to the query vector is within a preset range, including: Select the K previously unselected search partitions as the target search partitions; Calculate the second similarity between the query vector and each vector contained in the target retrieval partition; Based on each of the second similarities, the probability value that the target vector is contained in the target retrieval partition is determined; If the probability value of the target retrieval partition containing the target vector is greater than the first preset threshold, the above operation is terminated.

3. The method as described in claim 1, characterized in that, Based on at least one selected retrieval partition and the vector to be queried, the query results are output, including: The vectors contained in the search partitions whose probability values ​​are greater than a first preset threshold, which have already been selected at least one search partition, are output as query results; or Based on the second similarity between each vector in the selected at least one retrieval partition (where the probability value is greater than the first preset threshold) and the vector to be queried, in descending order of their respective second similarity, the W vectors corresponding to the first W of the sorted second similarity are output as query results, where W is a positive integer.

4. The method as described in claim 1, characterized in that, Based on at least one selected retrieval partition and the vector to be queried, the query results are output, including: Output the vectors contained in at least one selected search partition as the query results; or Based on the second similarity between each vector contained in at least one selected retrieval partition and the query vector, ordered from high to low, the W vectors corresponding to the second similarity at the top of the sorted list are output as query results, where W is a positive integer.

5. The method as described in claim 1, characterized in that, Selecting previously unselected search partitions from the K search partitions as target search partitions includes: According to the K first similarity scores in descending order, select the unselected search partitions from the K search partitions as the target search partitions.

6. The method as described in claim 1, characterized in that, Selecting previously unselected search partitions from the K search partitions as target search partitions includes: For any of the K search partitions, the vectors in the search partition are clustered according to the similarity between the vectors to obtain multiple search sub-partitions; the sub-partition center vector of any search sub-partition is determined based on the multiple vectors contained in any search sub-partition. Calculate the third similarity between the query vector and the sub-partition center vectors of the multiple retrieval sub-partitions; The K retrieval partitions are sorted based on the third similarity between the query vector and the center vectors of multiple sub-partitions in each retrieval partition; Select the unselected search partition from the sorted K search partitions as the target search partition.

7. The method as described in claim 6, characterized in that, The K retrieval partitions are sorted based on multiple third similarities between the query vector and the center vectors of multiple sub-partitions in each retrieval partition, including: The K search partitions are sorted based on the number of third similarities between the query vector and the center vectors of multiple sub-partitions in each search partition that exceed a second preset threshold; or The K retrieval partitions are sorted based on the maximum similarity among the third similarity scores between the query vector and the center vectors of multiple sub-partitions in each retrieval partition.

8. The method as described in claim 2, characterized in that, Based on each of the second similarities, the probability value that the target retrieval partition contains the target vector is determined, including: Among the various second similarities, determine the t target second similarities that are ranked from high to low; The query vector, the K first similarities, and the t second similarities are input into the prediction model to obtain the probability value; the prediction model is used to predict the probability value that the target vector is contained in the target retrieval partition.

9. The method as described in claim 8, characterized in that, The number of vectors to be queried is N, where N is a positive integer greater than 1; The query vector, the K first similarities, and the t second similarities of the targets are input into the prediction model to obtain the probability value, including: The matrix formed by the N query vectors and the matrix formed by the K first similarity values ​​corresponding to each of the N query vectors are input into the first prediction model to obtain N initial probability values ​​corresponding to the N query vectors; the initial probability values ​​are used to characterize the probability that the target vector of the query vector is contained in the K search partitions corresponding to any query vector; For any query vector, the initial probability value corresponding to the query vector and the second similarity of the t targets corresponding to the query vector are input into the second prediction model to obtain the final probability value corresponding to the query vector.

10. A vector retrieval device, characterized in that, include: Processing unit, used for: The similarity between the vector to be queried and the partition center vectors of M clustering partitions is calculated to obtain M first similarity scores; the M clustering partitions are obtained by clustering each vector in the vector base according to the similarity between the vectors; the partition center vector of any of the clustering partitions is determined based on the multiple vectors contained in any of the clustering partitions, where M is an integer greater than 1; From the M first similarities, the top K first similarities are determined, wherein the clustering partitions corresponding to the K first similarities are respectively used as K retrieval partitions, where K is an integer greater than or equal to 1 and K is less than M; A target retrieval partition is determined from the K retrieval partitions, wherein the probability value of the target vector contained in the target retrieval partition is greater than a first preset threshold, and the target vector is a vector whose similarity to the query vector is within a preset range. Based on at least one selected search partition and the vector to be queried, the query result is output, wherein the at least one selected search partition is the partition selected in the process of determining the target search partition, and the at least one search partition includes the target search partition and the search partition in the process of determining the target search partition whose probability value of containing the target vector is not greater than a first preset threshold.

11. The apparatus as claimed in claim 10, characterized in that, The processing unit determines a target retrieval partition from the K retrieval partitions. The probability value of the target retrieval partition containing the target vector is greater than a first preset threshold. The target vector is a vector whose similarity to the query vector is within a preset range. Specifically, it is used for: Select the K previously unselected search partitions as the target search partitions; Calculate the second similarity between the query vector and each vector contained in the target retrieval partition; Based on each of the second similarities, the probability value that the target vector is contained in the target retrieval partition is determined; If the probability value of the target retrieval partition containing the target vector is greater than the first preset threshold, the above operation is terminated.

12. The apparatus as claimed in claim 10, characterized in that, When the processing unit outputs query results based on at least one selected retrieval partition and the query vector, it is specifically used for: The vectors contained in the search partitions whose probability values ​​are greater than a first preset threshold, which have already been selected at least one search partition, are output as query results; or Based on the second similarity between each vector in the selected at least one retrieval partition (where the probability value is greater than the first preset threshold) and the vector to be queried, in descending order of their respective second similarity, the W vectors corresponding to the first W of the sorted second similarity are output as query results, where W is a positive integer.

13. The apparatus as claimed in claim 10, characterized in that, When the processing unit outputs query results based on at least one selected retrieval partition and the query vector, it is specifically used for: Output the vectors contained in at least one selected search partition as the query results; or Based on the second similarity between each vector contained in at least one selected retrieval partition and the query vector, ordered from high to low, the W vectors corresponding to the second similarity at the top of the sorted list are output as query results, where W is a positive integer.

14. The apparatus as claimed in claim 10, characterized in that, When the processing unit selects an unselected search partition as the target search partition from the K search partitions, it is specifically used for: According to the K first similarity scores in descending order, select the unselected search partitions from the K search partitions as the target search partitions.

15. The apparatus as claimed in claim 10, characterized in that, When the processing unit selects an unselected search partition as the target search partition from the K search partitions, it is specifically used for: For any of the K search partitions, the vectors in the search partition are clustered according to the similarity between the vectors to obtain multiple search sub-partitions; the sub-partition center vector of any search sub-partition is determined based on the multiple vectors contained in any search sub-partition. Calculate the third similarity between the query vector and the sub-partition center vectors of the multiple retrieval sub-partitions; The K retrieval partitions are sorted based on the third similarity between the query vector and the center vectors of multiple sub-partitions in each retrieval partition; Select the unselected search partition from the sorted K search partitions as the target search partition.

16. The apparatus as claimed in claim 10, characterized in that, When the processing unit sorts the K retrieval partitions based on multiple third similarities between the query vector and the center vectors of multiple sub-partitions in each retrieval partition, it is specifically used for: The K search partitions are sorted according to the number of third similarities between the query vector and the center vectors of multiple sub-partitions in each search partition that exceed the second preset threshold. or The K retrieval partitions are sorted based on the maximum similarity among the third similarity scores between the query vector and the center vectors of multiple sub-partitions in each retrieval partition.

17. The apparatus as claimed in claim 11, characterized in that, When the processing unit determines the probability value that the target retrieval partition contains the target vector based on each of the second similarities, it is specifically used for: Among the various second similarities, determine the t target second similarities that are ranked from high to low; The query vector, the K first similarities, and the t second similarities are input into the prediction model to obtain the probability value; the prediction model is used to predict the probability value that the target vector is contained in the target retrieval partition.

18. The apparatus as claimed in claim 17, characterized in that, The number of vectors to be queried is N, where N is a positive integer greater than 1; When the processing unit inputs the query vector, the K first similarities, and the t second similarities of the targets into the prediction model to obtain the probability value, it is specifically used for: The matrix formed by the N query vectors and the matrix formed by the K first similarities corresponding to each of the N query vectors are input into the first prediction model to obtain the N initial probability values ​​corresponding to the N query vectors. The initial probability value is used to characterize the probability that the target vector of any query vector is contained in the K search partitions corresponding to the query vector; For any query vector, the initial probability value corresponding to the query vector and the second similarity of the t targets corresponding to the query vector are input into the second prediction model to obtain the final probability value corresponding to the query vector.

19. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program or instructions that, when executed by the vector retrieval device, implement the method as described in any one of claims 1 to 9.

20. A chip, characterized in that, It includes at least one processor and an interface; the interface is used to provide program instructions or data to the at least one processor; the at least one processor is used to execute the program instructions to implement the method as described in any one of claims 1 to 9.

Citation Information

Patent Citations

  • Vector retrieval method and device

    CN113449132A

  • Image processing method and device and computer equipment

    CN113704534A

  • Data processing method and device

    CN114020746A