Vector retrieval method and related apparatus
By converting vector attribute values into encoded values and using these encoded values for computation, the problem of increased computation and retrieval overhead in hybrid retrieval is solved, thus improving the efficiency of vector retrieval.
Patent Information
- Application Number
- PCT/CN2025/070914
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-08-29
- Filing Date
- 2025-01-07
- Publication Date
- 2026-03-05
Smart Images

Figure CN2025070914_05032026_PF_FP_ABST
Abstract
Description
A vector retrieval method and related apparatus
[0001] This application claims priority to Chinese Patent Application No. 202411207692.7, filed with the State Intellectual Property Office of China on August 29, 2024, entitled "A Vector Retrieval Method and Related Device", the entire contents of which are incorporated herein by reference. Technical Field
[0002] This application relates to the field of artificial intelligence (AI) technology, and in particular to a vector retrieval method and related apparatus. Background Technology
[0003] Large Language Models (LLMs) are deep learning models trained on massive amounts of text data. They can not only generate natural language text, but also deeply understand the meaning of text and handle various natural language tasks, such as text summarization, intelligent question answering, and text translation.
[0004] Currently, the combination of vector databases and large language models is one of the mainstream research directions in large language models. Generally, vector databases are used to store vectors pre-extracted for various types of data (such as text, audio, images, or video). When a large language model needs to generate text or answer questions, it can retrieve vectors similar to the query vector input to the large language model by searching for similar vectors in the vector database. These retrieved vectors can then guide the large language model in generating text or answering questions, thereby improving the accuracy of the large language model's output.
[0005] As application requirements evolve, in some scenarios, users specify filtering conditions along with the query vector, requiring that the attributes corresponding to the retrieved vectors satisfy the filtering conditions during the retrieval of similar vectors. In this scenario of mixed vector and attribute retrieval, the computational and reading costs of computing devices often increase exponentially, resulting in low efficiency for mixed retrieval. Summary of the Invention
[0006] This application provides a vector retrieval method and related apparatus, which can improve the efficiency of vector retrieval.
[0007] Firstly, a vector retrieval method is provided for retrieving vectors from a vector database. This method includes: firstly, obtaining a first vector and filtering conditions. The filtering conditions include a first attribute and a first condition. The first condition includes a target value, and the filtering conditions indicate that the value of the first attribute of the vector retrieved from the vector database must satisfy the first condition. Here, the first attribute is a certain type of attribute of the original data corresponding to the first vector, and the target value is the specific value of the first attribute corresponding to the first vector, that is, indicating the specific attribute information of the original data corresponding to the first vector. For example, assuming the original data corresponding to the first vector is a document, the first attribute may be, for example, author's age, author's name, or document name. When the first attribute is author's age, the target value may be, for example, 30, 45, or 60; when the first attribute is author's name, the target value may be, for example, JKRowling.
[0008] Then, the target value is converted into a first encoded value according to the first rule. The first rule is used to convert the value of the first attribute of a vector in the vector database into an encoded value. The encoded value of the first attribute of a vector indicates the position of the value of the first attribute among multiple first attribute values arranged in sequence. These multiple first attribute values include the values of the first attributes of all vectors in the vector database. In other words, the first rule used to convert the target value into the first encoded value is actually the rule used to convert the values of the first attributes of vectors in the vector database into encoded values. For example, when performing the encoding value conversion on the values of the first attributes of vectors in the vector database, all the values of the first attributes of all vectors are first deduplicated, and the resulting multiple first attribute values are arranged in sequence to obtain the position of each attribute value, i.e., to obtain the mapping relationship between attribute values and positions. Since each position can be represented by a unique corresponding encoded value, based on the mapping relationship between attribute values and positions, a mapping relationship between attribute values and encoded values can be established, thus forming the aforementioned first rule.
[0009] Finally, based on the first vector and the first encoded value, a vector retrieval is performed in the vector database to obtain the second vector. The distance between the second vector and the first vector meets a preset requirement, and the value of the first attribute of the second vector meets a first condition. The vector retrieval process includes performing operations (e.g., bitwise operations) based on the first encoded value and the corresponding encoded values of the vectors in the vector database to determine the vector that satisfies the first condition.
[0010] In this scheme, by converting the attribute values corresponding to vectors into encoded values, the position of each vector's attribute value among all sequentially arranged attribute values can be indicated based on the encoded values. Thus, when retrieving vectors, by converting the attribute values indicated by the filtering conditions into encoded values according to the same rules, and performing operations on the encoded values of the filtering conditions and the encoded values of the vectors, it is possible to determine whether the vector's attribute values meet the filtering conditions. Since this scheme determines whether a vector meets the filtering conditions by performing operations on the encoded values, it achieves the use of more efficient encoded value operations instead of judging whether a vector meets the filtering conditions based on attribute values, thereby improving the retrieval efficiency when vectors need to be retrieved based on filtering conditions.
[0011] In one possible implementation, the first encoded value and the encoded value of the first attribute of the vector in the vector database are binary values, and the vector retrieval process includes performing bitwise operations based on the first encoded value and the encoded value of the first attribute of the vector in the vector database. With the first encoded value being a binary value, the most efficient bitwise operations can be performed on the encoded value of the vector during vector retrieval, thereby further improving the efficiency of vector retrieval.
[0012] In one possible implementation, the encoded value of the first attribute of the second vector is stored together with the second vector in the vector database. For example, the encoded value corresponding to the second vector is added to the second vector as an extended dimension. That is, this application expands the dimensions based on the original vector, thereby adding the encoded value of the vector to the original dimensions of the vector. In this way, when the execution device reads a vector, it can determine that the first M dimensions (e.g., 1024 dimensions) of the vector belong to the vector itself, while the subsequent dimensions belong to the encoded value corresponding to the vector.
[0013] In this scheme, by storing the encoded value of the vector together with the vector, the integrated storage of the vector and the encoded value can be achieved. This ensures that while calculating the distance between vectors, the operation on the encoded value can be performed simultaneously, reducing the data reading and searching process and improving the efficiency of vector retrieval.
[0014] In one possible implementation, the values of multiple first attributes arranged in sequence are divided into multiple regions, and the encoded value of the first attribute of the second vector is used to indicate that the value of the first attribute of the second vector is located in the first region, which is one of the multiple regions.
[0015] In other words, after arranging the values of multiple first attributes in sequence, the values of these first attributes are divided into regions, resulting in multiple regions. Each region contains one or more values of the first attribute, and the same value of a first attribute will only reside in one region. Furthermore, each region can be represented by a unique encoded value. Therefore, if the value of the first attribute of the second vector resides in the first region, the encoded value of the first attribute of the second vector can be used to indicate that the value of the first attribute of the second vector resides in the first region.
[0016] In this scheme, by dividing the values of attributes into multiple regions and using coded values to represent the region where each attribute value is located, it is possible to use a finite number of coded values to represent the location of all attribute values, thus ensuring the feasibility of the scheme.
[0017] In one possible implementation, the vector database includes a third vector whose first attribute value is located in a second region. The second region is another region different from the first region among multiple regions. The encoded value of the first attribute of the third vector is different from the encoded value of the first attribute of the second vector. That is, each region uniquely corresponds to a encoded value. If the first attribute values of any two vectors are located in different regions, then the encoded values of the first attribute of these two vectors are also different.
[0018] In one possible implementation, the vector database includes a fourth vector whose first attribute value is different from that of the second vector, and the first attribute value of the fourth vector is located in a first region, and the encoded value of the first attribute of the fourth vector is the same as that of the first attribute of the second vector.
[0019] In other words, among the multiple regions divided based on the values of multiple first attributes, one region (e.g., the first region) can include two or more values of the first attribute. In the vector database, although the value of the first attribute of the fourth vector differs from that of the second vector, the sorting position of the first attribute value of the fourth vector is close to that of the second vector. Therefore, the values of the first attributes of both the fourth and second vectors are located in the first region. Furthermore, since both values are located in the first region, and the first region is represented by a single coded value, the first attribute of the fourth vector and the first attribute of the second vector correspond to the same coded value.
[0020] In this scheme, when there are many attribute values in a vector, the attribute values are divided into multiple regions, and each region contains the values of multiple attributes. This enables the representation of the location of multiple attribute values based on a limited set of encoded values, so as to represent the values of each attribute based on encoded values that occupy less storage space, thus ensuring the feasibility of the scheme.
[0021] In one possible implementation, vector retrieval is performed in a vector database, specifically including: performing operations based on a first encoded value and the encoded value of a first attribute of a vector in the vector database, and determining a second vector and a fourth vector based on the results of the operations. The results of the operations between the first encoded value and the encoded value of the first attribute of the second vector, as well as the results of the operations between the first encoded value and the encoded value of the first attribute of the fourth vector, both meet the operational requirements, which are determined based on a first condition.
[0022] Then, based on the values of the first attribute of the second vector and the first attribute of the fourth vector, it is determined that the second vector satisfies the first condition.
[0023] In other words, when a region contains values for multiple attributes, a single encoded value can represent the values of all attributes. Therefore, when determining the computational requirements for encoded values based on filtering conditions, it's possible that multiple vectors may have encoded values that meet the computational requirements (i.e., the range of vectors that initially satisfy the filtering conditions is determined). In this case, based on the encoded values that meet the computational requirements, the specific attribute values of the vectors can be further obtained to determine whether the vectors satisfy the filtering conditions. Because efficient computation is first performed on the encoded values, the range of vectors requiring further comparison of attribute values to determine if they satisfy the filtering conditions can be effectively narrowed, thereby improving vector retrieval efficiency.
[0024] In one possible implementation, in the vector database, the encoded value corresponding to the vector includes multiple parts arranged in sequence, each of which includes multiple bits.
[0025] When i is 1, the bits in the i-th part are used to indicate the partition in which the vector is located among multiple partitions. These multiple partitions are obtained by dividing the values of multiple first attributes. That is, a region division is first performed on the sequentially arranged values of multiple first attributes to obtain multiple partitions. Then, the bits in the first part of the multiple parts included in the encoded value are used to indicate the partition in which the vector is located among the multiple partitions obtained from the first region division.
[0026] When i is an integer greater than 1, the bits in the i-th part are used to indicate the sub-partition in which the vector is located. The multiple sub-partitions are obtained by dividing the attribute values in the partition represented by the (i-1)-th part. That is, since each subsequent region division is based on the original region, the bits in each part after the first part are used to indicate the position of the vector in the further divided sub-partitions.
[0027] In this scheme, by using encoded values to represent the position of each first attribute value among a sequence of first attribute values, more efficient bitwise operations can be used to replace direct filtering conditions based on the encoded values. Furthermore, since an attribute value typically requires 32 bits or more of storage space, while an encoded value can be stored using 16 bits or even less, storage space is saved. In addition, when the encoded values are stored integrated with the vector, the extended dimension added to the original vector is reduced, improving the efficiency of vector retrieval while minimizing the storage space occupied.
[0028] In one possible implementation, when multiple first attributes have numeric values, sorting by order includes sorting by size; that is, the values of the multiple first attributes are arranged in ascending order. Specifically, when the values of multiple first attributes are all numerical, they can be sorted according to their relative magnitudes.
[0029] Alternatively, when multiple first attribute values are strings, sequential arrangement includes arranging according to a preset character order. That is, the values of multiple first attributes are arranged according to a preset character order. In other words, the arrangement order between different characters can be pre-specified. For strings consisting of one or more characters, each character in the string can be compared one by one to achieve sequential arrangement of multiple strings.
[0030] In one possible implementation, the first condition further includes an operator. The operation is performed based on the first encoded value and the encoded value of the first attribute of the vector in the vector database, specifically including: performing an operation on the first encoded value and the encoded value of the first attribute of the vector in the vector database; or, obtaining at least one second encoded value based on the first encoded value and the operator, and performing an operation on the at least one second encoded value and the encoded value of the first attribute of the vector in the vector database.
[0031] In other words, in some scenarios, it is necessary to first determine one or more new encoded values based on the first encoded value corresponding to the target value in the first condition and the operators in the first condition, and then perform operations on the new encoded values and the encoded value of the first attribute of the vector in order to determine whether the value of the first attribute of the vector satisfies the first condition.
[0032] In one possible implementation, the operator includes at least one of the following: equal to, less than, greater than, or within the range specified by the target value. If the operator includes the range specified by the target value, then the target value includes at least two values, and therefore the operator effectively indicates a range of at least two values included by the target value.
[0033] In one possible implementation, vector retrieval is performed in a vector database, specifically including: obtaining a first candidate set, which stores retrieved vectors that meet the filtering conditions; secondly, calculating the target distance between the obtained fifth vector and the first vector, where the fifth vector is any vector in the vector database; and thirdly, if the target distance is less than the distance between the sixth vector in the first candidate set and the first vector, and the fifth vector meets the filtering conditions, replacing the sixth vector in the first candidate set with the fifth vector. The result of the vector retrieval is obtained based on the first candidate set.
[0034] In this scheme, by maintaining a candidate set for storing retrieved vectors that meet the filtering conditions, it is possible to perform distance comparison and filtering condition judgment on the same vector simultaneously during the retrieval process. This avoids the additional data reading overhead caused by first retrieving a portion of vectors based on vector distance and then judging whether these vectors meet the filtering conditions, thereby improving the efficiency of vector retrieval.
[0035] In one possible implementation, performing vector retrieval in the vector database further includes: obtaining a second candidate set, which stores the retrieved vectors and is used to determine the retrieval direction during the vector retrieval process; retrieving a fifth vector from the vector database based on the retrieval direction determined by the second candidate set; and determining whether to update the vectors in the second candidate set based on the distance between the fifth vector and the first vector.
[0036] In this scheme, since the second candidate set itself has the function of guiding the search direction, by maintaining an additional first candidate set on the basis of the second candidate set, it is possible to achieve hybrid search based on filtering conditions with minimal changes to the existing technology, and to maximize the efficiency of hybrid search.
[0037] In one possible implementation, when starting vector retrieval, multiple candidate entry points can be obtained based on a first vector. These entry points are all vectors in a vector database, and each entry point indicates the starting point for the vector retrieval. Then, among these entry points, at least one target entry point that meets the filtering criteria is selected, and this target entry point is used as the starting point for the vector retrieval, performing the vector retrieval in the vector database.
[0038] In other words, given that multiple candidate entry points have been identified, since the candidate entry points themselves are also vectors in the vector database, the entry points that meet the filtering conditions can be selected from the multiple candidate entry points. This ensures that the efficiency of vector retrieval can be further improved when retrieving vectors based on entry points that meet the filtering conditions.
[0039] In one possible implementation, the encoded value of the first attribute of the second vector is obtained based on a first rule. The method further includes converting the value of the second attribute of the second vector into an encoded value of the second attribute of the second vector based on a second rule.
[0040] In other words, a vector in a vector database corresponds to multiple attributes. For each attribute, its value can be converted into an encoded value based on specific rules, so that the encoded value represents the position of the vector's attribute value among a sequence of attribute values. That is, a vector in a vector database corresponds to multiple attribute values of different attribute types and multiple encoded values, and the different encoded values corresponding to the same vector are obtained by converting attribute values of different attribute types. For example, a vector may correspond to four attribute values: the author's age, author's name, document name, and publication date of the document to which the vector belongs.
[0041] In this way, when performing the conversion from attribute value to encoded value, all attribute values belonging to the same attribute type in the vector database can be sorted in order first, and then each attribute value can be converted into the corresponding encoded value based on its position.
[0042] In a second aspect, a vector retrieval device is provided, comprising: an acquisition module for acquiring a first vector and filtering conditions, the filtering conditions including a first attribute and a first condition, the first condition including a target value, the filtering conditions indicating that the value of the first attribute of a vector retrieved from a vector database must satisfy the first condition; a processing module for converting the target value into a first encoded value according to a first rule, wherein the first rule is used to convert the value of the first attribute of a vector in the vector database into an encoded value, the encoded value of the first attribute of the vector can indicate the position of the value of the first attribute of the vector among a plurality of sequentially arranged values of the first attributes, the plurality of values of the first attributes including the values of the first attributes of all vectors in the vector database; the processing module is further configured to perform vector retrieval in the vector database according to the first vector and the first encoded value to obtain a second vector, the distance between the second vector and the first vector satisfying a preset requirement and the value of the first attribute of the second vector satisfying the first condition; wherein the process of performing vector retrieval includes performing operations based on the first encoded value and the encoded value of the first attribute of a vector in the vector database to determine the vector that satisfies the filtering conditions.
[0043] In one possible implementation, the first encoded value and the encoded value of the first attribute of the vector in the vector database are binary values, and the process of performing vector retrieval includes performing bitwise operations based on the first encoded value and the encoded value of the first attribute of the vector in the vector database.
[0044] In one possible implementation, the encoded value of the first attribute of the second vector is stored together with the second vector in the vector database.
[0045] In one possible implementation, the values of multiple first attributes arranged in sequence are divided into multiple regions, and the encoded value of the first attribute of the second vector is used to indicate that the value of the first attribute of the second vector is located in the first region, which is one of the multiple regions.
[0046] In one possible implementation, the vector database includes a third vector whose first attribute value is located in a second region, which is another region different from the first region among multiple regions, and the encoded value of the first attribute of the third vector is different from the encoded value of the first attribute of the second vector.
[0047] In one possible implementation, the vector database includes a fourth vector whose first attribute value is different from that of the second vector, and the first attribute value of the fourth vector is located in a first region, and the encoded value of the first attribute of the fourth vector is the same as that of the first attribute of the second vector.
[0048] In one possible implementation, the processing module is further configured to: perform a calculation based on the first encoded value and the encoded value of the first attribute of the vector in the vector database, and determine the second vector and the third vector based on the result of the calculation; and determine that the second vector satisfies the first condition based on the value of the first attribute of the second vector and the value of the third attribute of the third vector.
[0049] In one possible implementation, when the values of multiple first attributes are numeric data, sequential arrangement includes arranging them in ascending order; or, when the values of multiple first attributes are strings, sequential arrangement includes arranging them in a preset character order.
[0050] In one possible implementation, the first condition further includes an operator, and the processing module is further configured to: perform an operation on the first encoded value and the encoded value of the first attribute of the vector in the vector database; or, obtain at least one second encoded value based on the first encoded value and the operator, and perform an operation on the at least one second encoded value and the encoded value of the first attribute of the vector in the vector database.
[0051] Thirdly, a vector retrieval device is provided, comprising: a processor and a memory; the memory is used to store computer instructions, which, when executed by the processor, cause the vector retrieval device to perform the method described in any of the above aspects.
[0052] Fourthly, a computer-readable storage medium is provided that stores instructions which, when executed on a computer, cause the computer to perform the methods of any of the above aspects.
[0053] Fifthly, a computer program product containing instructions is provided, which, when executed on a computer, enable the computer to perform the methods described above.
[0054] In a sixth aspect, a chip system is provided, the chip system including a processor and a communication interface for communicating with a module other than the chip shown, the processor for running computer programs or instructions such that an apparatus on which the chip system is mounted can perform the methods of any of the above aspects.
[0055] In a seventh aspect, a computing device is provided, which includes a vector retrieval device of the third aspect or a chip system of the sixth aspect, wherein the vector retrieval device or the chip system in the computing device is used to implement the operational steps of the method of any of the above aspects.
[0056] Eighthly, a computing device cluster is provided, comprising at least one computing device, wherein any one computing device is used to run a computer program or instructions, such that the computing device cluster can perform the methods of any of the above aspects. Alternatively, some or all of the computing devices are used together to run a computer program or instructions, such that the computing device cluster can perform the methods of any of the above aspects.
[0057] Based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods. Attached Figure Description
[0058] Figure 1A is a schematic diagram of a vector retrieval method provided in this application;
[0059] Figure 1B is a schematic diagram of a hybrid retrieval process provided in this application;
[0060] Figure 2 is a schematic diagram of a system architecture provided in this application;
[0061] Figure 3 is a flowchart illustrating a vector retrieval method provided in this application;
[0062] Figure 4 is a schematic diagram of the execution flow of a vector retrieval method provided in this application;
[0063] Figure 5 is a schematic diagram of arranging the values of the first attribute of a vector in a vector database in order, as provided in this application;
[0064] Figure 6 is a schematic diagram of another method for sequentially arranging the values of the first attribute of a vector in a vector database, as provided in this application.
[0065] Figure 7 is a schematic diagram of an integrated storage of encoded values and vectors provided in this application;
[0066] Figure 8 is a schematic diagram of converting attribute values into encoded values according to this application;
[0067] Figure 9 is a schematic diagram of another method for converting attribute values into encoded values provided in this application;
[0068] Figure 10 is a schematic diagram of a vector retrieval process provided in this application;
[0069] Figure 11 is a schematic diagram of a hybrid retrieval process provided in this application;
[0070] Figure 12 is a schematic diagram of a vector retrieval device provided in this application;
[0071] Figure 13 is a schematic diagram of the structure of a computing device provided in this application;
[0072] Figure 14 is a schematic diagram of the structure of a computing device cluster provided in this application;
[0073] Figure 15 is a schematic diagram of another computing device cluster provided in this application;
[0074] Figure 16 is a schematic diagram of the structure of a chip provided in this application;
[0075] Figure 17 is a schematic diagram of the structure of a computer-readable storage medium provided in this application. Detailed Implementation
[0076] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application are described below with reference to the accompanying drawings. Obviously, the described embodiments are merely some, and not all, of the embodiments of this application. Those skilled in the art will recognize that, with the emergence of new application scenarios, the technical solutions provided by this application are also applicable to similar technical problems.
[0077] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such descriptions can be used interchangeably where appropriate to allow embodiments to be implemented in a sequence other than that illustrated or described in this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that includes a series of steps or modules is not necessarily limited to those explicitly listed, but may include other steps or modules not explicitly listed or inherent to such processes, methods, products, or devices. The naming or numbering of steps appearing in this application does not imply that the steps in the method flow must be performed in the chronological / logical order indicated by the naming or numbering. The execution order of named or numbered process steps can be changed according to the desired technical purpose, as long as the same or similar technical effect is achieved. The division of units in this application is a logical division. In practical applications, there may be other division methods. For example, multiple units may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the shown or discussed mutual coupling, direct coupling, or communication connection may be through some interface, and the indirect coupling or communication connection between units may be electrical or other similar forms, none of which are limited in this application. Furthermore, the units or sub-units described as separate components may or may not be physically separated, may or may not be physical units, or may be distributed among multiple circuit units. Some or all of the units can be selected to achieve the purpose of the solution in this application according to actual needs.
[0078] To facilitate understanding, some technical terms used in this application will be introduced below.
[0079] (1) Large Language Model (LLM)
[0080] Large language models are deep learning models trained on massive amounts of text data that can generate natural language text or understand the meaning of language text. Large language models can handle various natural language tasks, such as text classification, question answering, and dialogue, and are an important pathway to artificial intelligence.
[0081] Specifically, large language models are a technology that has emerged in recent years. Because large language models undergo meticulous data engineering and training processes, their parameters have learned a wealth of existing natural language processing knowledge. This knowledge can now replace humans in many language-related tasks, such as having large language models write code or perform text summarization.
[0082] (2) Vector Database
[0083] Vector databases are databases specifically designed for storing and retrieving vectors. The vectors they store are derived from the vectorization of text, speech, images, videos, and more. Compared to traditional databases, vector databases can handle more unstructured data (such as images and audio). In machine learning and deep learning, data is often represented in vector form.
[0084] (3) Binary values
[0085] Binary numbers are numbers represented using only two digits: 0 and 1.
[0086] (4) Bitwise operations
[0087] The operations that computers perform on binary numbers are called bitwise operations. In other words, bitwise operations are operations performed on each bit of a binary number.
[0088] Currently, vector databases are used to store pre-extracted vectors for various types of data (such as text, audio, images, or video). When a large language model needs to generate text or answer questions, it can convert the user-input text into a query vector, retrieve vectors similar to the query vectors from the vector database, and use the data (such as text or images) corresponding to the retrieved vectors to guide the large language model in generating text or answering questions, thereby improving the accuracy of the large language model's output.
[0089] As application requirements evolve, in some scenarios, users specify filtering conditions along with the query vector, requiring that the attributes corresponding to the retrieved vectors satisfy the filtering conditions during the retrieval of similar vectors. In this scenario of mixed vector and attribute retrieval, the computational and reading costs of computing devices often increase exponentially, resulting in low efficiency for mixed retrieval.
[0090] Please refer to Figure 1A, which is a schematic diagram of a vector retrieval method provided in this application. As shown in Figure 1A, in a pure vector retrieval scenario, by providing an input vector, the K most similar vectors can be retrieved from the vector database for the input vector.
[0091] In hybrid retrieval scenarios, in addition to providing input vectors, filtering conditions for vector retrieval are also provided. For example, the attribute corresponding to a vector is that the text corresponding to the vector contains the keyword "patent". In this way, when performing vector retrieval in the vector database, it is necessary not only to find similar vectors for the input vector, but also to determine whether the attribute corresponding to the vector meets the filtering conditions, and finally output the K vectors that meet the filtering conditions and are most similar to the input vector.
[0092] Please refer to Figure 1B, which is a schematic diagram of a hybrid retrieval process provided in this application. As shown in Figure 1B, in related technologies, vector retrieval is typically performed first in a vector database based on the input query vector, retrieving K*M vectors that are most similar to the query vector. Then, for the retrieved K*M vectors, the attributes corresponding to these K*M vectors are searched in the vector database to determine the vectors that meet the filtering conditions. Finally, the K vectors that meet the filtering conditions and are most similar to the query vector are output.
[0093] Furthermore, if fewer than K vectors are obtained during the vector filtering stage, vector retrieval and filtering need to be repeated until the K vectors that meet the filtering criteria and are most similar to the query vector are finally obtained. Therefore, in hybrid retrieval scenarios, the computational and retrieval costs of computing devices often increase exponentially, resulting in low efficiency for hybrid retrieval.
[0094] In view of this, this application provides a vector retrieval method that converts the attribute values corresponding to a vector into encoded values, enabling the identification of the position of each vector's attribute value among all sequentially arranged attribute values based on the encoded values. Thus, when retrieving a vector, by converting the attribute values indicated by the filtering conditions into encoded values according to the same rules, and performing operations on the encoded values of the filtering conditions and the encoded values of the vector, it is possible to determine whether the vector's attribute values satisfy the filtering conditions. Since this solution determines whether a vector satisfies the filtering conditions by performing operations on the encoded values, it achieves the use of more efficient encoded value operations instead of judging whether a vector satisfies the filtering conditions based on attribute values, thereby improving the retrieval efficiency when vectors need to be retrieved based on filtering conditions.
[0095] Please refer to Figure 2, which is a schematic diagram of a system architecture provided in this application. As shown in Figure 2, in this system architecture, the execution device 20 for executing the vector retrieval method provided in this application can be implemented by a single physical host (computing device) or multiple physical hosts (computing device cluster).
[0096] In addition, the system architecture includes a data storage system 21, which is used to implement a vector database, i.e., to store the pre-extracted vectors. Furthermore, the data storage system 21 also stores the attribute values of each vector, such as the author's name and age. Optionally, the data storage system 21 can also store the original data corresponding to each vector, such as text data, audio data, image data, or video data. That is, the vectors stored in the data storage system 21 are obtained by performing feature extraction on the original data.
[0097] Optionally, for persistent data storage, the data storage system 21 can be located outside the execution device 20, exchanging data with the execution device 20 via a network. Alternatively, if the execution device 20 is a physical host, the data storage system 21 can also be located inside the execution device 20, such as exchanging data with the processor via a bus. In this case, the data storage system 21 functions as a hard disk. With the data storage system 21, the execution device 20 can use the vectors in the data storage system 21, or call the program code in the data storage system to implement the vector retrieval method provided in this application, thereby retrieving the required vectors.
[0098] Optionally, the execution device 20 may also run a neural network model, such as a large language model. In this way, when the execution device 20 needs to run the neural network model, it first obtains the query vector and filtering conditions based on the data provided by the user; then, the execution device 20 executes the vector retrieval method provided in this application based on the obtained query vector and filtering conditions, thereby retrieving the corresponding similar vectors for the query vector.
[0099] Optionally, the execution device 20 may be connected to a model processing device 22. This model processing device 22 runs a neural network model, such as a large language model. Thus, when the model processing device 22 needs to run the neural network model, it first obtains the query vector and filtering conditions based on the user-provided data. Then, the model processing device 22 sends the query vector and filtering conditions to the execution device 20, which then executes the vector retrieval method provided in this application based on the obtained query vector and filtering conditions, thereby retrieving corresponding similar vectors for the query vector. The model processing device 22 can be implemented by a single physical host (computing device) or multiple physical hosts (computing device cluster).
[0100] Please refer to Figures 3 and 4. Figure 3 is a flowchart illustrating a vector retrieval method provided in this application; Figure 4 is an execution flowchart illustrating a vector retrieval method provided in this application. As shown in Figures 3 and 4, the vector retrieval method includes the following steps 301-303.
[0101] Step 301: Obtain the first vector and the filtering conditions. The filtering conditions include the first attribute and the first condition. The first condition includes the target value. The filtering conditions are used to indicate that the value of the first attribute of the vector retrieved from the vector database must satisfy the first condition.
[0102] In this application, the first vector is the vector to be retrieved, i.e., the first vector is actually the input query vector. Based on the first vector, the execution device needs to retrieve other vectors similar to the first vector from the vector database. Furthermore, the first vector also has corresponding filtering conditions, which are used to indicate, based on a first attribute and a target value, that the value of the first attribute of the vector retrieved from the vector database must satisfy a first condition.
[0103] Specifically, the vectors stored in the vector database have corresponding attribute values, and these attribute values indicate specific attribute information of the original data to which the vector corresponds. For example, suppose the original data corresponding to a vector stored in the vector database is a document, and the document's attributes include information such as author's age, author's name, or document name. Then, when the vector's attribute indicates the author's age, the attribute value could be 30; or, when the attribute indicates the author's name, the attribute value could be JKRowling. In general, the attribute value of a vector can be a numerical value or a string.
[0104] Since vectors in a vector database all have corresponding attribute values, the filtering conditions can include a first attribute and a first condition. The first condition includes a target value, and the filtering conditions are conditions that the value of the first attribute of the retrieved vector must satisfy, as indicated by the target value. For example, the specific filtering condition could be: the author's age (first attribute) corresponding to the retrieved vector is 30 (target value).
[0105] Step 302: Convert the target value into a first encoded value according to the first rule, wherein the first rule is used to convert the value of the first attribute of a vector in the vector database into an encoded value. The encoded value of the first attribute of the vector can indicate the position of the value of the first attribute of the vector among a plurality of first attribute values arranged in order. The plurality of first attribute values include the values of the first attributes of all vectors in the vector database.
[0106] In this application, before performing vector retrieval, the target value indicated in the filtering conditions needs to be converted into a first encoded value according to a first rule. Optionally, the first encoded value may be a binary value, a decimal value, or a hexadecimal value; this application does not specifically limit this. The first rule used to convert the target value into the first encoded value is actually a rule used to convert the value of the first attribute of a vector in the vector database into an encoded value.
[0107] In other words, the first attribute of a vector in the vector database has a corresponding encoded value, and the encoded value of the first attribute of a vector is obtained by converting the value of the first attribute of the vector according to the first rule. After performing the conversion from the value of the first attribute to the encoded value, the encoded value of the vector is used to indicate the position of the value of the first attribute of the vector among a plurality of sequentially arranged values of the first attributes, which include the values of the first attributes of all vectors in the vector database.
[0108] In simple terms, when performing encoding conversion on the first attribute value of a vector in a vector database, the first step is to remove duplicate values from all vectors' first attribute values. These deduplicated values are then arranged in order to determine the position of each first attribute value, thus establishing a mapping between the first attribute value and its position. Since each position can be uniquely represented by an encoding value, a mapping between the first attribute value and its position can be established, forming the first rule. In this way, for each vector's first attribute value, the value can be converted into an encoding value based on this mapping.
[0109] Optionally, when multiple first attributes have numeric values (e.g., integers), the values are arranged in ascending order. That is, when multiple first attributes are all numerical values, they can be sorted according to their relative magnitudes.
[0110] For example, please refer to Figure 5, which is a schematic diagram of sequentially arranging the values of the first attribute of vectors in a vector database according to this application. As shown in Figure 5, when the value of the first attribute of a vector in the vector database is specifically the author's age, assuming that the values of the first attribute corresponding to vectors 1-5 are 20, 35, 60, 42, and 55 respectively, the following order can be obtained by arranging these five first attribute values in descending order: 60→55→42→35→20. Therefore, based on the position of the value of the first attribute of a vector, the value of the first attribute of the vector can be converted into a corresponding encoded value, so as to indicate the position of the value of the first attribute of the vector among the sequentially arranged values of multiple first attributes through the encoded value.
[0111] Alternatively, when multiple first attribute values are strings, the values of these first attributes are arranged according to a preset character order. That is, by pre-specifying the arrangement order among different characters, for a string consisting of one or more characters, each character in the string can be compared one by one to achieve the sequential arrangement of multiple strings.
[0112] For example, when the value of the first attribute of a vector in a vector database is a string composed of letters, the values of multiple first attributes can be arranged sequentially according to the alphabetical order (i.e., A→B→C→D…→Z). Please refer to Figure 6, which is a schematic diagram of another method for sequentially arranging the values of the first attributes of vectors in a vector database according to this application. As shown in Figure 6, assuming that the values of the first attributes of vectors 1-5 are ABDE, CFHK, SJFI, AKGC, and LCDK respectively, the following order can be obtained after arranging these 5 attribute values in descending order: ABDE→AKGC→CFHK→LCDK→SJFI. Specifically, firstly, the first letter of all strings is compared to determine that strings ABDE and AKGC are before string CFHK, and string LCDK is between strings CFHK and string SJFI; then, for strings ABDE and AKGC with the same first letter, the second letter is compared to determine that string ABDE is before string AKGC, thereby determining the arrangement order of the 5 strings.
[0113] Similarly, after sorting the values of the first attribute of a vector, the values of the first attribute of the vector can be converted into corresponding encoded values based on their positions. This allows the encoded values to indicate the position of the first attribute of the vector among the ordered values of the first attribute.
[0114] It should be noted that the above describes the sorting of strings in alphabetical order when the attribute value is a string composed of letters. When the attribute value is a string composed of other characters (such as Chinese characters), the string can also be sorted in order according to a pre-specified order of Chinese characters, or the Chinese characters can be converted into alphabetical characters and then sorted in alphabetical order. This application does not impose specific limitations on how to sort the strings.
[0115] It should be noted that in a vector database, the encoded value of the first attribute of each vector can be stored directly. Alternatively, the database can store the first rule mentioned above and the value of the first attribute of each vector. In this way, when it is necessary to determine the encoded value of the first attribute of each vector, the encoded value of the first attribute of each vector can be determined based on the first rule and the value of the first attribute of each vector.
[0116] Step 303: Based on the first vector and the first encoded value, perform vector retrieval in the vector database to obtain the second vector. The distance between the second vector and the first vector meets the preset requirements, and the value of the first attribute of the second vector meets the first condition.
[0117] The process of performing vector retrieval includes performing operations on the first encoded value and the encoded value of the first attribute of the vector in the vector database to determine the vectors that meet the filtering conditions. For example, when the encoded value is a binary number, the most efficient bitwise operation in a computer can be performed on the first encoded value and the encoded value of the first attribute.
[0118] Specifically, in the vector retrieval process, two operations need to be performed on the vectors in the vector database. One operation is to calculate the distance between the vectors in the vector database and the first vector, in order to determine the K vectors most similar to the first vector (K is an integer greater than or equal to 1). The other operation is to determine whether the vectors in the vector database meet the filtering conditions. Therefore, the distance between the second vector obtained from the above retrieval and the first vector meets the preset requirement can mean that the second vector belongs to the K vectors in the vector database that meet the filtering conditions and have the smallest distance to the first vector.
[0119] In other words, based on the first vector and the first encoded value, K vectors that meet the requirements can be retrieved from the vector database, and the second vector mentioned above can be one of the retrieved K vectors.
[0120] In this application, in order to determine whether a vector in the vector database meets the filtering conditions, an operation can be performed based on the first encoded value and the encoded value of the first attribute of the vector retrieved from the vector database to determine whether the vector meets the filtering conditions.
[0121] Optionally, the first condition mentioned above may also include an operator. Performing an operation based on the first encoded value and the encoded value of the first attribute of the vector in the vector database specifically includes: performing an operation on the first encoded value and the encoded value of the first attribute of the vector in the vector database; or, obtaining at least one second encoded value based on the first encoded value and the operator, and performing an operation on the at least one second encoded value and the encoded value of the first attribute of the vector in the vector database.
[0122] In other words, in some scenarios, it is necessary to first determine one or more new encoded values based on the first encoded value corresponding to the target value in the first condition and the operators in the first condition. Then, an operation is performed on the new encoded values and the encoded value of the vector's first attribute to determine whether the value of the vector's first attribute satisfies the first condition. Optionally, the aforementioned operators include at least one of the following: equal to, less than, greater than, or within the range specified by the target value. If the operator includes equal to, then the filtering condition may specifically include the value of the vector's first attribute being equal to the target value. If the operator includes less than, then the filtering condition may specifically include the value of the vector's first attribute being less than the target value. If the operator includes greater than, then the filtering condition may specifically include the value of the vector's first attribute being greater than the target value.
[0123] If the operator is included within the range specified by the target value, then the target value must include at least two values. Therefore, the operator actually indicates a range of at least two values included in the target value. Specifically, the filtering condition could include the value of the vector's first attribute being within the range of at least two values included in the target value. For example, if the first attribute is the author's age, the filtering condition could be that the author's age corresponding to the vector is in the range of 18-60.
[0124] For example, if the filtering condition is that the value of the first attribute of a vector equals the target value, then it can be determined that vectors whose encoded value of the first attribute is the same as the first encoded value satisfy the filtering condition. Specifically, taking binary encoded values as an example, bitwise operations can be performed on the encoded value of the first attribute and the first encoded value of the vector using the following formula 1 to determine whether the vector satisfies the filtering condition: ((filter & s)^s)==0 Formula 1
[0125] Here, `filter` represents the first encoded value; `s` represents the encoded value of the first attribute of the vector; `&` represents the AND operation; and `^` represents the XOR operation. For two encoded values performing an AND operation, if both bits in the same position of both encoded values are 1, the result for that bit is 1; otherwise, the result for that bit is 0. For two encoded values performing an XOR operation, if the two bits in the same position of both encoded values are different, the result for that bit is 1; otherwise, the result for that bit is 0.
[0126] Therefore, when substituting the encoded value of the vector's first attribute into Formula 1 above to perform bitwise operations, if the result of Formula 1 is 0, it means the vector meets the filtering condition; if the result of Formula 1 is not 0, it means the vector does not meet the filtering condition. The above explanation uses a single encoded value corresponding to a vector. In practical applications, each vector in a vector database can correspond to multiple attribute values of different attribute types and multiple encoded values, and the different encoded values corresponding to the same vector are obtained by converting attribute values based on different attribute types. For example, a vector can correspond to four attribute values: the author's age, author's name, document name, and publication time of the document corresponding to the vector.
[0127] In this way, when performing the conversion from attribute value to encoded value, the values of all attributes belonging to the same attribute type in the vector database can be sorted in order first, and then the value of each attribute can be converted into the corresponding encoded value based on the position of each attribute value.
[0128] For example, in the above embodiments, the encoded value of the first attribute of the second vector is obtained based on a first rule. The method may further include: converting the value of the second attribute of the second vector into an encoded value of the second attribute of the second vector based on a second rule. That is, a vector in the vector database corresponds to multiple attributes. For different attributes, the value of the attribute can be converted into an encoded value based on a specific rule, so that the encoded value of the attribute can represent the position of the vector's attribute value among the values of multiple attributes arranged in sequence.
[0129] Optionally, in the vector database, the encoded value of the first attribute of the second vector is stored together with the second vector. For example, the encoded value corresponding to the second vector is added to the second vector as an extended dimension. Generally, the dimension of each vector in the vector database is fixed, for example, 1024 dimensions. Each dimension typically includes 32 bits, so the size of each vector in the vector database is usually fixed. In this application, the dimensions can be extended based on the original vector, thereby enabling the encoded value of the vector to be added to the original dimension of the vector. In this way, when the execution device reads a vector, it can determine that the first M dimensions (e.g., 1024 dimensions) of the vector belong to the vector itself, while the subsequent dimensions belong to the encoded value corresponding to the vector.
[0130] In other words, the encoded values corresponding to vectors in a vector database can also be added as extended dimensions after the vector, thereby achieving integrated storage of the encoded values and the vector. For example, please refer to Figure 7, which is a schematic diagram of integrated storage of encoded values and vectors provided by this application. As shown in Figure 7, in the vector database, the original vector obtained by performing feature extraction on the data is a 1024-dimensional vector. After adding encoded values to the original vector, a 1025-dimensional vector is obtained. The first 1024 dimensions of this 1025-dimensional vector are the content of the original vector, and the 1025th dimension is the newly added encoded value. It should be noted that Figure 6 illustrates this by showing the encoded value occupying one dimension. In practical applications, the dimension occupied by the encoded value can be determined based on the size of the actual encoded value and the number of encoded values corresponding to the vector; no specific limitation is made here.
[0131] Generally, in vector databases, vectors and their attribute values are stored independently. For example, a vector database might maintain a dedicated attribute table to record the attribute values for each vector. Thus, in typical mixed retrieval scenarios, for each retrieved vector, it's necessary to look up the corresponding attribute in the attribute table to obtain the vector's attribute value, making the vector retrieval process cumbersome and involving numerous data reading steps.
[0132] In this scheme, by storing the encoded value of the vector together with the vector, the integrated storage of the vector and the encoded value can be achieved. This ensures that while calculating the distance between vectors, the operation on the encoded value can be performed simultaneously, reducing the data reading and searching process and improving the efficiency of vector retrieval.
[0133] The above describes the process of quickly determining whether a vector meets filtering conditions by converting its attribute values into encoded values. For ease of understanding, the following will explain how to obtain the encoded value based on the position of the attribute values after arranging them in order.
[0134] For example, the values of multiple first attributes arranged in sequence are divided into multiple regions, and the encoded value of the first attribute of the second vector is used to indicate that the value of the first attribute of the second vector is located in the first region, which is one of the multiple regions.
[0135] In other words, after arranging the values of multiple first attributes in sequence, the values of these first attributes are divided into regions, resulting in multiple regions. Each region contains one or more values of the first attribute, and the same value of a first attribute will only reside in one region. Furthermore, each region can be represented by a unique encoded value. Therefore, if the value of the first attribute of the second vector resides in the first region, the encoded value of the first attribute of the second vector can be used to indicate that the value of the first attribute of the second vector resides in the first region.
[0136] In this scheme, by dividing the values of attributes into multiple regions and using coded values to represent the region where each attribute value is located, it is possible to use a finite number of coded values to represent the location of all attribute values, thus ensuring the feasibility of the scheme.
[0137] In one possible implementation, the vector database includes a third vector whose first attribute value is located in a second region. The second region is another region different from the first region among multiple regions. The encoded value of the first attribute of the third vector is different from the encoded value of the first attribute of the second vector. That is, each region uniquely corresponds to a encoded value. If the first attribute values of any two vectors are located in different regions, then the encoded values of the first attribute of these two vectors are also different.
[0138] In one possible example, the vector database includes a fourth vector whose first attribute value is different from that of the second vector, and the first attribute value of the fourth vector is located in a first region, and the encoded value of the first attribute of the fourth vector is the same as that of the first attribute of the second vector.
[0139] In other words, among the multiple regions divided based on the values of multiple first attributes, one region (e.g., the first region) can include two or more values of the first attribute. In the vector database, although the value of the first attribute of the fourth vector differs from that of the second vector, the sorting position of the first attribute value of the fourth vector is close to that of the second vector. Therefore, the values of the first attributes of both the fourth and second vectors are located in the first region. Furthermore, since both values are located in the first region, and the first region is represented by a single coded value, the first attribute of the fourth vector and the first attribute of the second vector correspond to the same coded value.
[0140] In this scheme, when there are many attribute values in a vector, the attribute values are divided into multiple regions, and each region contains the values of multiple attributes. This enables the representation of the location of multiple attribute values based on a limited set of encoded values, so as to represent the values of each attribute based on encoded values that occupy less storage space, thus ensuring the feasibility of the scheme.
[0141] When a single encoded value can represent multiple values of the first attribute, the vectors determined after performing operations on the first encoded value and the encoded value of the vector may not all satisfy the filtering conditions. Therefore, in this case, after determining the vectors based on the operation results of the encoded values, the values of the vector's attributes are further searched to determine the vectors that satisfy the filtering conditions.
[0142] For example, performing vector retrieval in a vector database specifically includes: performing an operation based on a first encoded value and the encoded value of a first attribute of a vector in the vector database, and determining a second vector and a fourth vector based on the result of the operation. The result of the operation between the first encoded value and the encoded value of the first attribute of the second vector, as well as the result of the operation between the first encoded value and the encoded value of the first attribute of the fourth vector, both meet the operation requirements, which are determined based on a first condition (e.g., the operation requirement is that the result of the operation between the first encoded value and the encoded value of the first attribute of the vector is 0).
[0143] Then, based on the values of the first attribute of the second vector and the first attribute of the fourth vector, it is determined that the second vector satisfies the first condition.
[0144] In other words, when a region contains values for multiple attributes, a single encoded value can represent the values of all attributes. Therefore, when determining the computational requirements for encoded values based on filtering conditions, multiple vectors may have encoded values that meet the computational requirements. In this case, the specific attribute values of the vector can be further obtained based on the encoded values that meet the computational requirements, thereby determining whether the vector satisfies the filtering conditions. By performing efficient computations on the encoded values first, the range of vectors that need further comparison of attribute values to see if they meet the filtering conditions can be effectively narrowed, thus improving the efficiency of vector retrieval.
[0145] Specifically, to divide the values of multiple first attributes into multiple regions, this application can perform multiple region divisions on the sequentially arranged values of the multiple first attributes. After obtaining the partition where each attribute value is located, the corresponding encoding value of the attribute value is determined based on the partition where each attribute value is located. In the process of performing multiple region divisions, the first region division divides the values of the multiple first attributes into multiple regions. Each subsequent region division further refines the division based on the regions obtained in the previous division, thus creating more and smaller regions, ultimately completing the multiple region divisions. In this way, when determining the encoding value corresponding to the attribute value, multiple parts of the encoding value can be used to represent the region where the current attribute value is located in each region division, thereby achieving the representation of the specific position of the attribute value among the sequentially arranged values of the multiple first attributes based on the encoding value.
[0146] For example, in a vector database, the encoded value corresponding to a vector may include multiple parts arranged in sequence, each of which includes multiple bits.
[0147] When i is 1, the bits in the i-th part are used to indicate the partition in which the vector is located among multiple partitions. These multiple partitions are obtained by dividing the values of multiple first attributes. That is, a region division is first performed on the sequentially arranged values of multiple first attributes to obtain multiple partitions. Then, the bits in the first part of the multiple parts included in the encoded value are used to indicate the partition in which the vector is located among the multiple partitions obtained from the first region division.
[0148] When i is an integer greater than 1, the bits in the i-th part are used to indicate the sub-partition in which the vector is located. The multiple sub-partitions are obtained by dividing the attribute values in the partition represented by the (i-1)-th part. That is, since each subsequent region division is based on the original region, the bits in each part after the first part are used to indicate the position of the vector in the further divided sub-partitions.
[0149] For example, please refer to Figure 8, which is a schematic diagram of converting attribute values into encoded values according to this application. Assuming that the values of multiple first attributes include 64 integers from 1 to 64, these 64 integers can be sorted in descending order. For these 64 ordered integers, two region divisions can be performed to obtain encoded values comprising two parts. In the first region division, the 64 integers are divided into 8 equal parts, resulting in 8 partitions, each containing 8 ordered integers. For example, the first partition includes integers 64, 63, 62, 61, 60, 59, 58, and 57; the second partition includes integers 56, 55, 54, 53, 52, 51, 50, and 49; and so on, with the eighth partition including integers 8, 7, 6, 5, 4, 3, 2, and 1.
[0150] In the second partitioning process, for each partition obtained from the first partitioning, the region can be divided into eight equal parts again, thus further dividing each partition into eight smaller partitions. For example, for the first partition obtained from the first partitioning, the first partition can be divided into eight sub-partitions, so that the eight sub-partitions include integers 64, 63, 62, 61, 60, 59, 58, and 57 respectively (that is, the first sub-partition includes 64, the second sub-partition includes 63, and so on).
[0151] In this way, by performing two region partitioning operations, 64 sub-partitions (i.e., 64 regions) can be obtained, each sub-partition containing a corresponding integer. That is, the sub-partition containing each of the 64 integers is unique and definite. Based on this, for any integer among the 64 integers, an encoded value can be used to represent the sub-partition it belongs to, thereby representing the position of the integer within the 64 integers arranged in order.
[0152] As shown in Figure 8, the encoded value can be composed of 16 bits, divided into two parts. The first part, consisting of the first 8 bits, represents the partition where the attribute value was located in the first region division; the second part, consisting of the last 8 bits, represents the partition where the attribute value was located in the second region division. For the integer 62, since it was in the first partition in the first region division, the first bit of the first part can be set to 1; since it was in the third sub-partition in the second region division, the third bit of the second part can be set to 1, resulting in the encoded value 1000000000100000.
[0153] It should be noted that the embodiment shown in Figure 8 is based on the example of performing two region divisions, each of which involves dividing the region into eight equal parts (i.e., resulting in eight partitions). In practical applications, region division can be performed once or multiple times, and the number of partitions obtained in each division can be two or more; no specific limitation is made here.
[0154] For example, please refer to Figure 9, which is a schematic diagram of another method for converting attribute values into encoded values according to this application. Assuming that the values of multiple first attributes include eight integers from 1 to 8, these eight integers can be sorted in descending order. For these eight ordered integers, three region divisions can be performed to obtain encoded values comprising three parts. In the first region division, the eight integers are divided into two equal parts, resulting in two partitions, each containing four ordered integers. For example, the first partition includes the integers 8, 7, 6, and 5; the second partition includes the integers 4, 3, 2, and 1.
[0155] In the second partitioning process, for each partition obtained from the first partitioning, the region can be divided into two equal parts again, thus further dividing each partition into two smaller partitions. For example, for the first partition obtained from the first partitioning, the first partition can be divided into two sub-partitions, so that the two sub-partitions include 8 and 7, and 6 and 5 respectively.
[0156] Similarly, in the third region partitioning process, for each sub-partition obtained from the second region partitioning, the region can be divided into two equal parts again, thereby further dividing each sub-partition obtained from the second region partitioning into two smaller sub-partitions.
[0157] In this way, by performing three region partitions, eight sub-partitions can be obtained, each containing a corresponding integer. The encoded value can then consist of six bits, divided into three parts. The first part, consisting of the first two bits, indicates the partition where the attribute value was located in the first region partition; the second part, consisting of the middle two bits, indicates the sub-partition where the attribute value was located in the second region partition; and the third part, consisting of the last two bits, indicates the partition where the attribute value was located in the third region partition. For the integer 4, since it is in the second partition in the first region division, the second bit of the two bits in the first part can be set to 1; since it is in the first sub-partition in the second region division, the first bit of the two bits in the second part can be set to 1; since it is in the first sub-partition in the third region division, the first bit of the two bits in the third part can be set to 1, and the final encoded value is 011010.
[0158] In summary, this scheme uses encoded values to represent the position of each first attribute value among a sequence of first attribute values. This allows for more efficient bitwise operations based on the encoded values, replacing direct filtering conditions. Furthermore, since an attribute value typically requires 32 bits or more of storage space (e.g., an integer requires 32 bits), while an encoded value can be stored using 16 bits or less, converting space-consuming attribute values into space-efficient encoded values saves storage space and improves the efficiency of bitwise operations. Additionally, storing the encoded values and vectors together reduces the added dimension to the original vector, improving vector retrieval efficiency while minimizing storage space usage.
[0159] The above describes the process of using encoded values to replace attribute values, thereby quickly determining whether a vector meets filtering conditions. The following section will introduce how to further improve the efficiency of vector retrieval using filtering conditions.
[0160] Optionally, when the execution device begins vector retrieval, it may first obtain multiple candidate entry points based on the first vector. These multiple entry points are all vectors in the vector database, and each entry point indicates the starting point for the vector retrieval. Generally, before starting vector retrieval, to improve efficiency and quickly locate the required vector, the execution device often selects a specific vector from the vector database as an entry point and begins the retrieval from that entry point. The method by which the execution device obtains multiple candidate entry points in this application can refer to existing related algorithms and is not specifically limited here.
[0161] Then, the execution device selects at least one target entry point that meets the filtering conditions from among the multiple candidate entry points, and performs vector retrieval in the vector database using at least one target entry point as the starting point for vector retrieval.
[0162] In other words, given that multiple candidate entry points have been identified, since the candidate entry points themselves are also vectors in the vector database, the entry points that meet the filtering conditions can be selected from the multiple candidate entry points. This ensures that the efficiency of vector retrieval can be further improved when retrieving vectors based on entry points that meet the filtering conditions.
[0163] Optionally, the process of performing vector retrieval in the vector database may include the following steps.
[0164] First, a first candidate set is obtained. This first candidate set stores the retrieved vectors that meet the filtering criteria. Specifically, the first candidate set is maintained by the execution device during vector retrieval and is used to store the K retrieved vectors that have the smallest distance to the first vector and meet the filtering criteria. Here, K is an integer greater than or equal to 1, and its size represents the final number of vectors to be returned. Therefore, initially, the first candidate set does not contain any vectors as the execution device begins vector retrieval. The execution device needs to gradually store the retrieved vectors into the first candidate set according to the progress of the retrieval.
[0165] Then, the target distance between the obtained fifth vector and the first vector is calculated. The fifth vector is any vector in the vector database. Specifically, the fifth vector is a vector obtained by the execution device from the vector database based on the current retrieval progress. For the obtained fifth vector, the execution device needs to calculate the target distance between the fifth vector and the first vector to determine whether the fifth vector can be stored in the first candidate set.
[0166] Secondly, if the target distance is less than the distance between the sixth vector and the first vector in the first candidate set, and the fifth vector satisfies the filtering condition, the sixth vector in the first candidate set is replaced with the fifth vector. The first candidate set can be a set of K vectors that already exist, where the distance between the sixth vector and the first vector is the largest among these K vectors. Therefore, the execution device can compare the target distance between the fifth vector and the first vector with the distance between the sixth vector and the first vector. If the target distance between the fifth vector and the first vector is smaller than that between the sixth vector and the first vector, and the fifth vector satisfies the filtering condition, then the fifth vector can replace the sixth vector in the first candidate set, thus completing the update of the first candidate set.
[0167] The result of the vector retrieval is based on the first candidate set, meaning that the second vector retrieved above belongs to the vectors included in the first candidate set when the retrieval is completed.
[0168] In this scheme, by maintaining a candidate set for storing retrieved vectors that meet the filtering conditions, it is possible to perform distance comparison and filtering condition judgment on the same vector simultaneously during the retrieval process. This avoids the additional data reading overhead caused by first retrieving a portion of vectors based on vector distance and then judging whether these vectors meet the filtering conditions, thereby improving the efficiency of vector retrieval.
[0169] Optionally, when performing vector retrieval in the vector database, the execution device can also obtain a second candidate set. This second candidate set stores the retrieved vectors and is used to determine the retrieval direction during the vector retrieval process. The second candidate set is another candidate set maintained by the execution device during the vector retrieval process, specifically used to store the K retrieved vectors with the smallest distance to the first vector. Here, K is an integer greater than or equal to 1, and its size can be the number of vectors ultimately to be returned.
[0170] Furthermore, the execution device retrieves the fifth vector from the vector database according to the search direction, and determines whether to update the vectors in the second candidate set based on the distance between the fifth vector and the first vector. For example, if the distance between the fifth vector and the first vector is greater than the distance between the first vector and all vectors in the second candidate set, then the vectors in the second candidate set are not updated; if the distance between the fifth vector and the first vector is less than the distance between the first vector and a certain vector in the second candidate set, then the fifth vector replaces the vectors in the second candidate set.
[0171] Since the second candidate set stores multiple vectors that have been retrieved and have the smallest distance to the first vector, it can often be used to further determine the search direction during the retrieval process, thereby improving the efficiency of vector retrieval. The method for determining the search direction based on the second candidate set can refer to existing related algorithms, and no specific limitations are made here.
[0172] It should be noted that during vector retrieval, the execution device retrieves vectors from the vector database sequentially according to the retrieval direction and determines whether the vector can be added to the first candidate set and the second candidate set. Therefore, the vectors in the second candidate set are actually obtained based on the retrieval direction determined by the first candidate set.
[0173] It should be noted that in related technologies, when performing pure vector retrieval, a candidate set is typically maintained, and the function and update method of this candidate set are the same as the second candidate set mentioned above. Therefore, this solution actually uses the retrieval method employed in pure vector retrieval, thereby minimizing modifications to existing technologies. Furthermore, since the second candidate set itself guides the retrieval direction, maintaining an additional first candidate set on top of the second candidate set enables hybrid retrieval based on filtering conditions while minimizing modifications to existing technologies and maximizing the efficiency of hybrid retrieval.
[0174] For example, please refer to Figure 10, which is a schematic diagram of a vector retrieval process provided by this application. As shown in Figure 10, during the vector retrieval process, the execution device maintains both a first candidate set and a second candidate set. When the execution device obtains a vector from the vector database, it needs to calculate the distance between the vector and the query vector (i.e., the first vector mentioned above), and decide whether to add the vector to the first candidate set by comparing the vector distances and determining whether the vector meets the filtering conditions. That is, all vectors added to the first candidate set meet the filtering conditions. In addition, the execution device also decides whether to add the vector to the second candidate set by comparing the vector distances, that is, the second candidate set only stores the K vectors with the smallest distance to the query vector.
[0175] For example, in Figure 10, the vectors retrieved and already searched by the execution device from the vector database include vectors 1 through 10. The first candidate set includes vectors 1 through 5, and the second candidate set includes vectors 1, 3, 6, 8, and 9. Specifically, although vectors 6, 8, and 9 are closer to the query vectors than vectors 3 through 5, they do not meet the filtering conditions and therefore will not be added to the first candidate set.
[0176] Please refer to Figure 11, which is a schematic diagram of a hybrid retrieval process provided in this application. As shown in Figure 11, based on the method provided in this application, the hybrid retrieval process can include three stages: vector attribute preprocessing, vector retrieval optimization, and bitwise operation-based vector retrieval and filtering.
[0177] In the vector attribute preprocessing stage, for each vector in the vector database, the attribute value of each vector is obtained. Then, the attribute values are deduplicated and arranged in order. Based on the position of each attribute value among the ordered attribute values, a corresponding encoded value is obtained, thus converting the attribute value of each vector into its corresponding encoded value. Furthermore, after determining the attribute value of each vector, the encoded value is added as an extended dimension to the vector, achieving integrated storage of the vector and its encoded value. Moreover, when a vector has attribute values of multiple different attribute types, the attribute values under each attribute type can be converted into their corresponding encoded values using the above steps, resulting in a vector having multiple corresponding encoded values.
[0178] After converting the attribute values of each vector in the vector database into encoded values, the mapping relationship between attribute values and encoded values can be obtained, thus forming a preset rule (such as the first rule or the second rule mentioned above). This preset rule can indicate how to convert attribute values into encoded values. In this way, when obtaining the query vector and the filtering conditions for retrieving vectors based on the query vector, the attribute values in the filtering conditions can be converted into corresponding encoded values based on the preset rule.
[0179] During the vector retrieval optimization phase, the execution device can first obtain candidate entry points from the vector database based on the query vector, and further filter entry points that meet the filtering conditions based on the encoded values in the filtering conditions, thereby determining the entry points for the vector retrieval process. Furthermore, before starting the retrieval, the execution device needs to maintain two candidate sets: a first candidate set and a second candidate set. The first candidate set stores vectors that are closest to the query vector and meet the filtering conditions. The second candidate set stores vectors that are closest to the query vector and can further indicate the direction of the vector retrieval.
[0180] In the bitwise-based vector retrieval and filtering stage, the execution device can calculate the distance between the obtained vector and the query vector to determine whether the second candidate set needs to be updated. Furthermore, the execution device also needs to perform bitwise operations on the encoded values of the vector and the encoded values corresponding to the attribute values in the filtering conditions to determine whether the obtained vector meets the filtering conditions, and thus whether the vector can be added to the first candidate set. Finally, after completing the vector retrieval process, the execution device can output one or more vectors stored in the first candidate set as the retrieval result.
[0181] The following will use various types of filtering conditions as examples to explain in detail how to determine whether a vector meets the filtering conditions by performing bitwise operations on the encoded value.
[0182] Filter condition 1: The value of the age attribute is equal to 10.
[0183] First, for the age attribute value of 10 in filter condition one, convert 10 into an encoded value, as shown in Table 1.
[0184] Table 1
[0185] As shown in Table 1, 10 can be converted into a 16-bit encoded value `filter`, with the bit numbers of the 16 bits from high to low being 15, 14, 13…0. Specifically, the value of `filter` is 1 at bit number 9 and bit number 2, and 0 at other positions. Therefore, for any vector in the vector database corresponding to the encoded value `s`, we can use Formula 1 above to determine whether the vector meets the filtering condition.
[0186] Filtering condition 2: The value of the age attribute is greater than 10.
[0187] Specifically, for the age attribute value of 10 in filter condition two, 10 can be converted into the encoded value filter as shown in Table 1.
[0188] In addition, since the conversion of attribute values to encoded values is based on the sorting method of the attribute values, filter1 as shown in Table 2 and filter2 as shown in Table 3 can be derived.
[0189] Table 2
[0190] Table 3
[0191] The derivation of filter1 is as follows: Since the lower 8 bits are consistent, the higher 8 bits need to be compared. The higher 8 bits of the number 10 are marked at bit number 9. Based on the ordered encoding rule (assuming it is increasing from left to right), the number marked by bit number 8 is larger than that of bit number 9. Therefore, the filter encoding for a number greater than 10 needs to mark bit 8 as 1.
[0192] The derivation of filter2 is as follows: Based on the ordered encoding rule (assuming it increases from left to right), the lower 8 bits, bit numbers 1 and 0, are marked as 1, both corresponding to numbers greater than 10. The higher bits need to be all marked as 1, because any bit number set to 1 will be greater than 10.
[0193] At this point, for any vector in the vector database and its corresponding encoded value s, we can use Formula 2 to determine whether the vector satisfies the filtering condition: (filter1 & s)^s = 0 or (filter2 & s)^s = 0 (Formula 2)
[0194] That is, as long as (filter1&s)^s is 0 or (filter2&s)^s is 0, it means that the vector satisfies the filtering condition.
[0195] Filtering condition 3: The value of the age attribute is greater than 8 and less than 10, that is, 8 < s < 10.
[0196] Specifically, for the age attribute values 8 and 10 in filter condition two, 8 and 10 can be converted into their corresponding encoded values.
[0197] Then, based on the encoding values corresponding to 8 and 10, filter3 as shown in Table 4, filter4 as shown in Table 5, and filter5 as shown in Table 6 can be derived.
[0198] Table 4
[0199] Table 5
[0200] Table 6
[0201] At this point, for any vector in the vector database and its corresponding encoded value s, we can use Formula 3 to determine whether the vector satisfies the filtering condition. (filter3 & s)^s==0 or (filter4 & s)^s==0 or (filter5 & s)^s==0 Formula 3
[0202] That is, as long as (filter3&s)^s is 0, or (filter4&s)^s is 0, or (filter5&s)^s is 0, it means that the vector satisfies the filtering condition.
[0203] The method provided in this application has been described in detail above. Next, the device provided in this application for performing the above method will be described.
[0204] Please refer to Figure 12, which is a schematic diagram of the structure of a vector retrieval device provided in this application. As shown in Figure 12, the vector retrieval device includes: an acquisition module 1201, used to acquire a first vector and filtering conditions, the filtering conditions including a first attribute and a first condition, the first condition including a target value, the filtering conditions being used to indicate that the value of the first attribute of the vector retrieved from the vector database must satisfy the first condition; a processing module 1202, used to convert the target value into a first encoded value according to a first rule, wherein the first rule is used to convert the value of the first attribute of the vector in the vector database into an encoded value, the encoded value of the first attribute of the vector can indicate the position of the value of the first attribute of the vector among a plurality of first attribute values arranged in sequence, the plurality of first attribute values including the values of the first attribute of all vectors in the vector database; the processing module 1202 is also used to perform vector retrieval in the vector database according to the first vector and the first encoded value to obtain a second vector, the distance between the second vector and the first vector satisfying a preset requirement and the value of the first attribute of the second vector satisfying the first condition; wherein, the process of performing vector retrieval includes performing operations based on the first encoded value and the encoded value of the first attribute of the vector in the vector database to determine the vector that satisfies the filtering conditions.
[0205] In one possible implementation, the first encoded value and the encoded value of the first attribute of the vector in the vector database are binary values, and the process of performing vector retrieval includes performing bitwise operations based on the first encoded value and the encoded value of the first attribute of the vector in the vector database.
[0206] In one possible implementation, the encoded value of the first attribute of the second vector is stored together with the second vector in the vector database.
[0207] In one possible implementation, the values of multiple first attributes arranged in sequence are divided into multiple regions, and the encoded value of the first attribute of the second vector is used to indicate that the value of the first attribute of the second vector is located in the first region, which is one of the multiple regions.
[0208] In one possible implementation, the vector database includes a third vector whose first attribute value is located in a second region, which is another region different from the first region among multiple regions, and the encoded value of the first attribute of the third vector is different from the encoded value of the first attribute of the second vector.
[0209] In one possible implementation, the vector database includes a fourth vector whose first attribute value is different from that of the second vector, and the first attribute value of the fourth vector is located in a first region, and the encoded value of the first attribute of the fourth vector is the same as that of the first attribute of the second vector.
[0210] In one possible implementation, the processing module 1202 is further configured to: perform a calculation based on the first encoded value and the encoded value of the first attribute of the vector in the vector database, and determine the second vector and the third vector based on the result of the calculation; and determine that the second vector satisfies the first condition based on the value of the first attribute of the second vector and the value of the third attribute of the third vector.
[0211] In one possible implementation, when the values of multiple first attributes are numeric data, sequential arrangement includes arranging them in ascending order; or, when the values of multiple first attributes are strings, sequential arrangement includes arranging them in a preset character order.
[0212] In one possible implementation, the first condition further includes an operator, and the processing module 1202 is further configured to: perform an operation on the first encoded value and the encoded value of the first attribute of the vector in the vector database; or, obtain at least one second encoded value based on the first encoded value and the operator, and perform an operation on the at least one second encoded value and the encoded value of the first attribute of the vector in the vector database.
[0213] Both the acquisition module 1201 and the processing module 1202 can be implemented in software or in hardware. For example, the implementation of the processing module 1202 will be described below. Similarly, the implementation of the acquisition module 1201 can be referenced from the implementation of the processing module 1202.
[0214] As an example of a software functional unit, processing module 1202 may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, or a container. Further, the aforementioned computing instance may be one or more. For example, processing module 1202 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed in the same region or in different regions. Further, the multiple hosts / virtual machines / containers used to run the code may be distributed in the same availability zone (AZ) or in different AZs, each AZ including one or more geographically proximate data centers. Typically, a region may include multiple AZs.
[0215] Similarly, multiple hosts / virtual machines / containers used to run this code can be distributed within the same Virtual Private Cloud (VPC) or across multiple VPCs. Typically, a VPC is set up within a region. Communication between two VPCs within the same region, as well as between VPCs in different regions, requires a communication gateway to be set up within each VPC to enable interconnection between VPCs.
[0216] As an example of a hardware functional unit, the processing module 1202 may include at least one computing device, such as a server. Alternatively, the processing module 1202 may be implemented using a central processing unit (CPU), an application-specific integrated circuit (ASIC), or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), a data processing unit (DPU), a neural network processing unit (NPU), a system-on-chip (SoC), an offload card, an accelerator card, or any combination thereof.
[0217] The processing module 1202 includes multiple computing devices that can be distributed within the same region or in different regions. Similarly, the processing module 1202 can be distributed within the same Availability Zone (AZ) or in different AZs. Likewise, the processing module 1202 can be distributed within the same Virtual Private Cloud (VPC) or in multiple VPCs. These multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, GALs, DPUs, NPUs, SoCs, offloading cards, and accelerator cards.
[0218] Please refer to Figure 13, which is a schematic diagram of the structure of a computing device provided in this application. The computing device 1300 shown in Figure 13 can be used to execute the vector retrieval method provided in this embodiment. As shown in Figure 13, the computing device 1300 includes: a bus 1302, a processor 1304, a memory 1306, and a communication interface 1308. The processor 1304, the memory 1306, and the communication interface 1308 communicate with each other via the bus 1302. The computing device 1300 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 1300.
[0219] Bus 1302 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, only one line is used in Figure 13, but this does not imply that there is only one bus or one type of bus. Bus 1302 can include pathways for transmitting information between various components of computing device 1300 (e.g., memory 1306, processor 1304, communication interface 1308).
[0220] The processor 1304 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0221] The memory 1306 may include volatile memory, such as random access memory (RAM). The processor 1304 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD).
[0222] The memory 1306 stores executable program code, and the processor 1304 executes this executable program code to implement the functions of the aforementioned acquisition module and processing module, thereby realizing the model processing method described above. That is, the memory 1306 stores instructions for executing the model processing method.
[0223] The communication interface 1308 uses transceiver modules such as, but not limited to, network interface cards and transceivers to enable communication between the computing device 1300 and other devices or communication networks.
[0224] This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.
[0225] Please refer to Figure 14, which is a schematic diagram of a computing device cluster provided in this application. As shown in Figure 14, the computing device cluster includes at least one computing device 1300. The memory 1306 of one or more computing devices 1300 in the computing device cluster may store the same instructions for executing task processing methods.
[0226] In some possible implementations, the memory 1306 of one or more computing devices 1300 in the computing device cluster may also store partial instructions for executing task processing methods. In other words, a combination of one or more computing devices 1300 can jointly execute instructions for executing task processing methods.
[0227] It should be noted that the memory 1306 in different computing devices 1300 within the computing device cluster can store different instructions, each used to execute a portion of the functions of the data processing device. That is, the instructions stored in the memory 1306 of different computing devices 1300 can implement the functions of one or more of the aforementioned acquisition and processing modules.
[0228] In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Figure 15 illustrates one possible implementation. Figure 15 is a schematic diagram of another computing device cluster structure provided in this application. As shown in Figure 15, in computing device cluster 1500, two computing devices 1300A and 1300B are connected via a network. Specifically, they are connected to the network through communication interfaces in each computing device. In this type of possible implementation, the memory 1306 in computing device 1300A stores instructions for executing the functions of the acquisition module. Simultaneously, the memory 1306 in computing device 1300B stores instructions for executing the functions of the processing module.
[0229] It should be understood that the functions of computing device 1300A shown in Figure 15 can also be performed by multiple computing devices 1300. Similarly, the functions of computing device 1300B can also be performed by multiple computing devices 1300.
[0230] This application also provides a chip comprising a processing unit and a communication unit. The processing unit may be, for example, a processor, and the communication unit may be, for example, an input / output interface, pins, or circuits. The processing unit can execute computer execution instructions stored in a storage unit to cause the chip within the electronic device to perform the methods described in the above embodiments. Optionally, the storage unit may be an in-chip storage unit, such as a register or cache. Alternatively, the storage unit may be an external storage unit located within a wireless access device, such as a read-only memory (ROM) or other types of static storage devices capable of storing static information and instructions, such as random access memory (RAM).
[0231] Specifically, please refer to Figure 16, which is a schematic diagram of the structure of a chip provided in this application. The chip can be represented as a neural processing unit (NPU), a graphics processing unit (GPU), or a tensor processing unit (TPU). The following description will use an NPU 1600 as an example. The NPU 1600 is mounted as a coprocessor on the host CPU, and tasks are assigned by the host CPU. The core of the NPU is the arithmetic circuit 1603, which is controlled by a controller 1604 to retrieve matrix data from memory and perform multiplication operations.
[0232] In some implementations, the arithmetic circuit 1603 internally includes multiple processing engines (PEs). In some implementations, the arithmetic circuit 1603 is a two-dimensional pulsating array. The arithmetic circuit 1603 can also be a one-dimensional pulsating array or other electronic circuits capable of performing mathematical operations such as multiplication and addition. In some implementations, the arithmetic circuit 1603 is a general-purpose matrix processor.
[0233] For example, suppose we have an input matrix A, a weight matrix B, and an output matrix C. The arithmetic circuit retrieves the corresponding data of matrix B from the weight memory 1602 and caches it in each PE of the arithmetic circuit. The arithmetic circuit retrieves the data of matrix A from the input memory 1601 and performs matrix operations with matrix B. The partial result or the final result of the obtained matrix is stored in the accumulator 1608.
[0234] Unified memory 1606 is used to store input and output data. Weight data is directly transferred to weight memory 1602 via Direct Memory Access Controller (DMAC) 1605. Input data is also transferred to unified memory 1606 via DMAC.
[0235] BIU stands for Bus Interface Unit, which is used for interaction between the AXI bus and the DMAC and the Instruction Fetch Buffer (IFB) 1609.
[0236] The Bus Interface Unit (BIU) 1610 is used by the instruction fetch memory 1609 to fetch instructions from external memory, and also by the memory access controller 1605 to fetch the original data of the input matrix A or the weight matrix B from external memory.
[0237] The DMAC is mainly used to move input data from external memory DDR to unified memory 1606, or to weight data to weight memory 1602, or to input data to input memory 1601.
[0238] The vector computation unit 1607 includes multiple processing units that further process the output of the computation circuit 1603 when needed, such as vector multiplication, vector addition, exponential operations, logarithmic operations, size comparisons, etc. It is mainly used for computation in non-convolutional / fully connected layers of neural networks, such as batch normalization, pixel-level summation, and upsampling of feature planes.
[0239] In some implementations, the vector computation unit 1607 can store the processed output vector in the unified memory 1606. For example, the vector computation unit 1607 can apply a linear function, or a nonlinear function, to the output of the computation circuit 1603, such as performing linear interpolation on the feature planes extracted by the convolutional layer, or, for example, accumulating a vector of values to generate activation values. In some implementations, the vector computation unit 1607 generates normalized values, pixel-level summed values, or both. In some implementations, the processed output vector can be used as an activation input to the computation circuit 1603, for example, for use in subsequent layers of the neural network.
[0240] The instruction fetch buffer 1609 connected to the controller 1604 is used to store the instructions used by the controller 1604.
[0241] The unified memory 1606, input memory 1601, weight memory 1602, and instruction fetch memory 1609 are all on-chip memories. External memory is proprietary to this NPU hardware architecture.
[0242] The processor mentioned above can be a general-purpose central processing unit, a microprocessor, an ASIC, or one or more integrated circuits used to control the execution of the above program.
[0243] Referring to Figure 17, which is a schematic diagram of the structure of a computer-readable storage medium provided in this application. This application also provides a computer-readable storage medium in which, in some embodiments, the method disclosed in Figure 3 above can be implemented as computer program instructions encoded in a machine-readable format on a computer-readable storage medium or on other non-transitory media or articles of art.
[0244] Figure 17 schematically illustrates a conceptual partial view of an example computer-readable storage medium arranged according to at least some of the embodiments shown herein, the example computer-readable storage medium including a computer program for executing computer processes on a computing device.
[0245] In one embodiment, the computer-readable storage medium 1700 is provided using a signal bearer medium 1701. The signal bearer medium 1701 may include one or more program instructions 1702, which, when executed by one or more processors, can provide the functions or parts thereof described above with reference to FIG3.
[0246] In some examples, the signal carrying medium 1701 may include a computer-readable medium 1703, such as, but not limited to, a hard disk drive, a compact disc (CD), a digital video disc (DVD), a digital magnetic tape, a memory, ROM, or RAM, etc.
[0247] In some embodiments, the signal-bearing medium 1701 may include a computer-recordable medium 1704, such as, but not limited to, a memory, a read / write (R / W) CD, a R / W DVD, etc. In some embodiments, the signal-bearing medium 1701 may include a communication medium 1705, such as, but not limited to, digital and / or analog communication media (e.g., fiber optic cables, waveguides, wired communication links, wireless communication links, etc.). Therefore, for example, the signal-bearing medium 1701 may be transmitted by a wireless communication medium 1705 (e.g., a wireless communication medium conforming to the IEEE 1202.X standard or other transmission protocols).
[0248] One or more program instructions 1702 may be, for example, computer-executable instructions or logical implementation instructions. In some examples, the computing device may be configured to provide various operations, functions, or actions in response to one or more program instructions 1702 conveyed to the computing device via a computer-readable medium 1703, a computer-recordable medium 1704, and / or a communication medium 1705.
[0249] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the accompanying drawings of the device embodiments provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.
[0250] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods of the various embodiments of this application.
[0251] In the above embodiments, the implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, in the form of a computer program product.
[0252] A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions according to this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another. For example, computer instructions can be transferred from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).
Claims
1. A vector retrieval method, characterized in that, include: Obtain a first vector and a filtering condition. The filtering condition includes a first attribute and a first condition. The first condition includes a target value. The filtering condition is used to indicate that the value of the first attribute of the vector retrieved from the vector database must satisfy the first condition. The target value is converted into a first encoded value according to a first rule, wherein the first rule is used to convert the value of the first attribute of the vector in the vector database into an encoded value, and the encoded value of the first attribute of the vector can indicate the position of the value of the first attribute of the vector in a plurality of first attribute values arranged in order, wherein the plurality of first attribute values include the values of the first attributes of all vectors in the vector database; Based on the first vector and the first encoded value, a vector retrieval is performed in the vector database to obtain a second vector. The distance between the second vector and the first vector meets a preset requirement, and the value of the first attribute of the second vector meets the first condition. The process of performing vector retrieval includes performing operations based on the first encoded value and the encoded value of the first attribute of the vector in the vector database to determine the vectors that meet the filtering conditions.
2. The method according to claim 1, characterized in that, The first encoded value and the encoded value of the first attribute of the vector in the vector database are binary values. The process of performing vector retrieval includes performing bitwise operations based on the first encoded value and the encoded value of the first attribute of the vector in the vector database.
3. The method according to claim 1 or 2, characterized in that, In the vector database, the encoded value of the first attribute of the second vector is stored together with the second vector.
4. The method according to any one of claims 1-3, characterized in that, The values of the plurality of first attributes arranged in sequence are divided into a plurality of regions, and the encoded value of the first attribute of the second vector is used to indicate that the value of the first attribute of the second vector is located in a first region, and the first region is one of the plurality of regions.
5. The method according to claim 4, characterized in that, The vector database includes a third vector, the value of the first attribute of the third vector is located in a second region, the second region is another region different from the first region among the plurality of regions, and the encoded value of the first attribute of the third vector is different from the encoded value of the first attribute of the second vector.
6. The method according to claim 4 or 5, characterized in that, The vector database includes a fourth vector, the value of the first attribute of the fourth vector is different from the value of the first attribute of the second vector, and the value of the first attribute of the fourth vector is located in the first region, and the encoded value of the first attribute of the fourth vector is the same as the encoded value of the first attribute of the second vector.
7. The method according to claim 6, characterized in that, The vector retrieval performed in the vector database includes: The operation is performed based on the first encoded value and the encoded value of the first attribute of the vector in the vector database, and the second vector and the fourth vector are determined based on the result of the operation. Based on the value of the first attribute of the second vector and the value of the first attribute of the fourth vector, it is determined that the second vector satisfies the first condition.
8. The method according to any one of claims 1-7, characterized in that, When the values of the plurality of first attributes are numerical data, the sequential arrangement includes arranging them in order of size; Alternatively, when the values of the plurality of first attributes are strings, the sequential arrangement includes arranging them according to a preset character order.
9. The method according to any one of claims 1-8, characterized in that, The first condition further includes an operator, wherein performing the operation based on the first encoded value and the encoded value of the first attribute of the vector in the vector database includes: Perform operations on the first encoded value and the encoded value of the first attribute of the vector in the vector database; or, At least one second encoded value is obtained based on the first encoded value and the operator, and an operation is performed on the at least one second encoded value and the encoded value of the first attribute of the vector in the vector database.
10. The method according to claim 9, characterized in that, The operator includes at least one of the following: equal to, less than, greater than, or within the range specified by the target value.
11. A vector retrieval device, characterized in that, include: An acquisition module is used to acquire a first vector and a filtering condition. The filtering condition includes a first attribute and a first condition. The first condition includes a target value. The filtering condition is used to indicate that the value of the first attribute of the vector retrieved from the vector database must satisfy the first condition. A processing module is configured to convert the target value into a first encoded value according to a first rule, wherein the first rule is used to convert the value of the first attribute of a vector in the vector database into an encoded value, and the encoded value of the first attribute of the vector can indicate the position of the value of the first attribute of the vector in a plurality of sequentially arranged values of a plurality of first attributes, wherein the plurality of values of the first attributes include the values of the first attributes of all vectors in the vector database; The processing module is further configured to perform vector retrieval in the vector database based on the first vector and the first encoded value to obtain a second vector, wherein the distance between the second vector and the first vector meets a preset requirement and the value of the first attribute of the second vector meets the first condition; The process of performing vector retrieval includes performing operations based on the first encoded value and the encoded value of the first attribute of the vector in the vector database to determine the vectors that meet the filtering conditions.
12. The apparatus according to claim 11, characterized in that, The first encoded value and the encoded value of the first attribute of the vector in the vector database are binary values. The process of performing vector retrieval includes performing bitwise operations based on the first encoded value and the encoded value of the first attribute of the vector in the vector database.
13. The apparatus according to claim 11 or 12, characterized in that, In the vector database, the encoded value of the first attribute of the second vector is stored together with the second vector.
14. The apparatus according to any one of claims 11-13, characterized in that, The values of the plurality of first attributes arranged in sequence are divided into a plurality of regions, and the encoded value of the first attribute of the second vector is used to indicate that the value of the first attribute of the second vector is located in a first region, and the first region is one of the plurality of regions.
15. The apparatus according to claim 14, characterized in that, The vector database includes a third vector, the value of the first attribute of the third vector is located in a second region, the second region is another region different from the first region among the plurality of regions, and the encoded value of the first attribute of the third vector is different from the encoded value of the first attribute of the second vector.
16. The apparatus according to claim 14 or 15, characterized in that, The vector database includes a fourth vector, the value of the first attribute of the fourth vector is different from the value of the first attribute of the second vector, and the value of the first attribute of the fourth vector is located in the first region, and the encoded value of the first attribute of the fourth vector is the same as the encoded value of the first attribute of the second vector.
17. The apparatus according to claim 16, characterized in that, The processing module is further configured to: The operation is performed based on the first encoded value and the encoded value of the first attribute of the vector in the vector database, and the second vector and the third vector are determined based on the result of the operation. Based on the value of the first attribute of the second vector and the value of the third attribute of the third vector, it is determined that the second vector satisfies the first condition.
18. The apparatus according to any one of claims 11-17, characterized in that, When the values of the plurality of first attributes are numerical data, the sequential arrangement includes arranging them in order of size; Alternatively, when the values of the plurality of first attributes are strings, the sequential arrangement includes arranging them according to a preset character order.
19. The apparatus according to any one of claims 11-18, characterized in that, The first condition also includes an operator, and the processing module is further configured to: Perform operations on the first encoded value and the encoded value of the first attribute of the vector in the vector database; or, At least one second encoded value is obtained based on the first encoded value and the operator, and an operation is performed on the at least one second encoded value and the encoded value of the first attribute of the vector in the vector database.
20. A computing device, characterized in that, The device includes a memory and a processor; the memory stores code, and the processor is configured to execute the code, wherein when the code is executed, the computing device performs the method as described in any one of claims 1 to 10.
21. A computing device cluster, characterized in that, It includes at least one computing device, each computing device including a processor and memory; The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the cluster of computing devices to perform the operational steps of the method as described in any one of claims 1 to 10.
22. A computer storage medium, characterized in that, The computer storage medium stores instructions that, when executed by the computer, cause the computer to perform the method according to any one of claims 1 to 10.
23. A computer program product, characterized in that, The computer program product stores instructions that, when executed by a computer, cause the computer to perform the method described in any one of claims 1 to 10.
Citation Information
Patent Citations
Chinese materia medica theory-based Chinese herbal medicine attribute feature coding and retrieval system
CN108460132A
Data retrieval method and device, equipment and storage medium
CN115169489A
Vector retrieval method and device
CN115757465A
Data retrieval method, electronic equipment, storage medium and program product
CN117786144A
Vectorized fuzzy string matching process
US20240062099A1