Vector retrieval method, device, memristor storage and computing integrated chip and electronic device

By converting the Euclidean distance formula into a target formula that supports matrix multiplication and accumulation operations, and using a memristor storage and calculation integrated chip to perform vector retrieval, the problem of low efficiency of vector retrieval in large-scale data is solved and efficient calculation results are achieved.

CN118113975BActive Publication Date: 2024-10-01BEIJING YIYUAN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410305187.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-18
Publication Date
2024-10-01
Estimated Expiration
2044-03-18

AI Technical Summary

Technical Problem

In large-scale data processing, the calculation time of vector retrieval is too long, especially when the amount of data is billions or tens of billions, resulting in low efficiency. The existing memristor storage and calculation integrated chip only supports matrix multiplication and accumulation calculations and does not support Euclidean Direct calculation of distance makes it difficult to improve vector retrieval efficiency.

Method used

By converting the Euclidean distance formula into a target formula that supports matrix multiplication and accumulation operations, a vector adapted to the memristor storage and calculation integrated chip is constructed, and the inner product operation is performed to improve efficiency. The specific steps include obtaining the square value of the target vector and the bottom library vector. , construct the first and second vectors of the adaptation, increase the dimension and perform an inner product operation, and compare the calculation results to determine the similarity.

Benefits of technology

The vector retrieval based on the memristor storage and calculation integrated chip is realized, which improves the calculation efficiency, avoids the time consumption of directly calculating the Euclidean distance, and improves the performance of vector retrieval.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118113975B_ABST
    Figure CN118113975B_ABST
Patent Text Reader

Abstract

The present application discloses a vector retrieval method, device, memristor storage and computing integrated chip and electronic device, the method comprising: obtaining a target vector, a base library vector and the square value of the base library vector; determining a target value according to the square value of the base library vector, the target value being the operation value of the second operation term in the target formula converted from the Euclidean distance formula; constructing a first vector and a second vector of the same dimension, so that the inner product result of the first vector and the second vector is the target value; adding elements of the first vector to the target vector to obtain the target vector with increased dimension, and adding elements in the second vector to the base library vector to obtain the base library vector with increased dimension; performing inner product operation on the target vector with increased dimension and the base library vector with increased dimension based on the array structure of the memristor storage and computing integrated chip to obtain the calculation result of the target formula; determining K base library vectors with the highest similarity to the target vector by comparing the calculation results corresponding to different base library vectors.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of vector retrieval technology, and more specifically, to a vector retrieval method, device, memristor storage and computing integrated chip, and electronic device. Background Art

[0002] In scenarios such as vector retrieval, each target vector needs to be compared with multiple base vectors to obtain a relative distance, and the similarity is judged by comparing the relative distances. The algorithms for calculating distances currently include the cosine theorem formula, Euclidean distance, Manhattan distance, Hamming distance, and so on. The von Neumann computer system is basically used to implement the relevant distance calculations, that is, vector calculations or matrix multiplication calculations are implemented through memory and processors. However, when the amount of data reaches a certain level, such as billions, tens of billions, and above, the data calculation process takes a very long time, resulting in significant delays, which seriously affects efficiency.

[0003] Although the currently developed Resistive Random Access Memory (RRAM) has faster and more energy-efficient data processing and storage capabilities, the internal array structure of the memristor chip only supports matrix multiplication and accumulation calculations, but does not support direct calculations of distance formulas such as Euclidean distance. Therefore, how to improve the efficiency of vector retrieval is still a difficult problem that needs to be solved urgently. Summary of the invention

[0004] The present application provides a vector retrieval method, device, memristor storage and computing integrated chip and electronic device, which can improve the efficiency of vector retrieval.

[0005] The specific technical solutions are as follows:

[0006] In a first aspect, an embodiment of the present application provides a vector retrieval method, the method comprising:

[0007] Obtaining a target vector, a base vector, and a square value of the base vector;

[0008] Determine a target value according to the square value of the base vector, wherein the target value is the operation value of the second operation term in the target formula converted from the Euclidean distance formula, the target formula includes a first operation term and a second operation term, and the first operation term is the inner product of the target vector and the base vector;

[0009] Constructing a first vector and a second vector of the same dimension, so that an inner product result of the first vector and the second vector is the target value;

[0010] Adding the elements in the first vector to the target vector to obtain the target vector with increased dimension, and adding the elements in the second vector to the base vector to obtain the base vector with increased dimension;

[0011] Based on the array structure of the memristor storage-computation integrated chip, an inner product operation is performed on the target vector after the dimension is increased and the base vector after the dimension is increased to obtain the calculation result of the target formula;

[0012] By comparing the calculation results corresponding to different base library vectors, K base library vectors having the highest similarity to the target vector are determined, where K is a positive integer.

[0013] In a possible implementation, the target formula includes:

[0014] Wherein, y represents the calculation result of the target formula, a represents the target vector, b represents the base vector, a·b represents the first operation term, represents the second operand.

[0015] In a possible implementation, constructing the first vector and the second vector of the same dimension so that the inner product result of the first vector and the second vector is the target value includes:

[0016] Determining second dimensions of the first vector and the second vector according to the first dimension of the target vector;

[0017] A constant vector of the second dimension is constructed as the first vector, and the second vector is constructed according to the first vector and the target value, so that the inner product result of the first vector and the second vector is the target value.

[0018] In a possible implementation, constructing the constant vector of the second dimension as the first vector, and constructing the second vector according to the first vector and the target value, so that the inner product result of the first vector and the second vector is the target value includes:

[0019] constructing a constant vector whose dimension is the second dimension and all elements of which are the first constants as the first vector;

[0020] According to the target value, the second dimension and the first constant, a target element value is calculated, and a vector whose dimension is the second dimension and all elements are the target element values ​​is constructed as the second vector.

[0021] In a possible implementation, constructing the constant vector of the second dimension as the first vector, and constructing the second vector according to the first vector and the target value, so that the inner product result of the first vector and the second vector is the target value includes:

[0022] constructing a constant vector whose dimension is the second dimension and all elements are second constants as the first vector;

[0023] Calculate the value of m according to the target value and the second constant;

[0024] Set the first m elements in the second vector to a third constant, wherein the third constant is the opposite of the second constant;

[0025] The remaining elements in the second vector are set to 0 according to the m and the second dimension.

[0026] In a possible implementation manner, the second dimension is represented by M, and the first vector and the second vector are both integer vectors;

[0027] The step of constructing the constant vector of the second dimension as the first vector, and constructing the second vector according to the first vector and the target value so that the inner product result of the first vector and the second vector is the target value includes:

[0028] The first M-2 elements in the first vector are respectively set to a third constant, the M-1th element is set to a fourth constant, and the Mth element is set to 1, wherein the fourth constant is between 1 and the third constant;

[0029] According to the first formula, the value of the M-1th element in the second vector is determined, wherein the first formula includes:

[0030] According to the second formula, the value of the Mth element in the second vector is determined, wherein the second formula includes:

[0031] According to a third formula, a first intermediate value is determined, wherein the third formula includes:

[0032] According to a fourth formula, a second intermediate value is determined, wherein the fourth formula includes:

[0033] Set the first second intermediate value elements in the second vector to the opposite of the first intermediate value minus 1 respectively;

[0034] The remaining elements in the second vector are respectively set to the opposite numbers of the first intermediate values.

[0035] In a second aspect, an embodiment of the present application provides a vector search device, the device comprising:

[0036] An acquisition unit, used for acquiring a target vector, a base vector and a square value of the base vector;

[0037] A first determining unit is used to determine a target value according to the square value of the base vector, wherein the target value is an operation value of a second operation term in a target formula converted from a Euclidean distance formula, the target formula includes a first operation term and a second operation term, and the first operation term is an inner product of the target vector and the base vector;

[0038] a construction unit, configured to construct a first vector and a second vector of the same dimension, so that an inner product result of the first vector and the second vector is the target value;

[0039] an amplification unit, configured to add the elements in the first vector to the target vector to obtain the target vector with increased dimension, and to add the elements in the second vector to the base vector to obtain the base vector with increased dimension;

[0040] A computing unit, configured to perform an inner product operation on the target vector after the dimension is increased and the base vector after the dimension is increased based on the array structure of the memristor storage and computing integrated chip, to obtain a calculation result of the target formula;

[0041] The second determining unit is used to determine K base-base vectors having the highest similarity to the target vector by comparing the calculation results corresponding to different base-base vectors, wherein K is a positive integer.

[0042] In a possible implementation, the target formula includes:

[0043] Wherein, y represents the calculation result of the target formula, a represents the target vector, b represents the base vector, a·b represents the first operation term, represents the second operand.

[0044] In a possible implementation, the construction unit includes:

[0045] a determination module, configured to determine second dimensions of the first vector and the second vector according to the first dimension of the target vector;

[0046] A construction module is used to construct a constant vector of the second dimension as the first vector, and to construct the second vector according to the first vector and the target value, so that the inner product result of the first vector and the second vector is the target value.

[0047] In one possible implementation, the construction module is used to construct a constant vector whose dimension is the second dimension and all elements are the first constant, as the first vector; calculate the target element value according to the target value, the second dimension and the first constant, and construct a vector whose dimension is the second dimension and all elements are the target element values, as the second vector.

[0048] In one possible implementation, the construction module is used to construct a constant vector whose dimension is the second dimension and all elements are second constants, as the first vector; calculate the value of m according to the target value and the second constant; set the first m elements in the second vector to a third constant, wherein the third constant is the opposite of the second constant; and set the remaining elements in the second vector to 0 according to m and the second dimension.

[0049] In a possible implementation manner, the second dimension is represented by M, and the first vector and the second vector are both integer vectors;

[0050] The construction module is used to set the first M-2 elements in the first vector to a third constant, the M-1th element to a fourth constant, and the Mth element to 1, wherein the fourth constant is between 1 and the third constant;

[0051] According to the first formula, the value of the M-1th element in the second vector is determined, wherein the first formula includes:

[0052] According to the second formula, the value of the Mth element in the second vector is determined, wherein the second formula includes:

[0053] According to a third formula, a first intermediate value is determined, wherein the third formula includes:

[0054] According to a fourth formula, a second intermediate value is determined, wherein the fourth formula includes:

[0055] Set the first second intermediate value elements in the second vector to the opposite of the first intermediate value minus 1 respectively;

[0056] The remaining elements in the second vector are respectively set to the opposite numbers of the first intermediate values.

[0057] In a third aspect, an embodiment of the present application provides a memristor storage and computing integrated chip, which is at least used to implement the inner product operation on the vector in the method described in any possible implementation method of the first aspect.

[0058] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising at least one memristor storage and computing integrated chip as described in the third aspect.

[0059] The vector retrieval method, device, memristor storage and computing integrated chip and electronic device provided in the embodiments of the present application can first obtain the target vector, the base library vector and the square value of the base library vector when vector retrieval is needed, and determine the target value according to the square value of the base library vector (the target value is the operation value of the second operation term in the target formula converted from the Euclidean distance formula, the target formula includes the first operation term and the second operation term, and the first operation term is the inner product of the target vector and the base library vector), and then construct the first vector and the second vector of the same dimension, so that the inner product result of the first vector and the second vector is the target value, add the elements in the first vector to the target vector to obtain the target vector with increased dimension, and add the elements in the second vector to the base library vector to obtain the base library vector with increased dimension, so that the original target formula is converted into an inner product operation of the target vector with increased dimension and the base library vector with increased dimension, and after obtaining the calculation result of the inner product operation corresponding to each base library vector, the K base library vectors with the highest similarity to the target vector can be determined by comparing the sizes of the calculation results. It can be seen from this that the embodiment of the present application no longer directly calculates the Euclidean distance, but instead realizes the function of vector retrieval based on the memristor storage and computing chip by converting the Euclidean distance formula into a matrix multiplication and addition operation supported by the memristor storage and computing chip, thereby improving the computational efficiency of vector retrieval.

[0060] In addition, the technical effects that can be achieved by the embodiments of the present application include:

[0061] The embodiment of the present application can improve the overall construction efficiency of the two vectors by constructing the first vector as a constant vector and constructing the second vector as a vector that changes with the change of the first vector; after the first vector is constructed as a constant vector, according to the hardware characteristics of the memristor storage and computing integrated chip itself, it is selected to set the second vector as a vector with the same elements or to set some elements in the second vector to 0, which can further improve the efficiency of subsequent vector inner product calculations, thereby improving the efficiency of vector retrieval. BRIEF DESCRIPTION OF THE DRAWINGS

[0062] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the prior art description are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings without creative work.

[0063] Figure 1 A schematic diagram of a flow chart of a vector search method provided in an embodiment of the present application;

[0064] Figure 2 A block diagram of a vector search device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0065] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0066] It should be noted that, in the absence of conflict, the embodiments in the present application and the features in the embodiments can be combined with each other. The terms "including" and "having" in the embodiments of the present application and the accompanying drawings and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices.

[0067] In order to improve the efficiency of vector retrieval, the present application embodiment provides a vector retrieval method, such as Figure 1 As shown, the method includes:

[0068] S110: Obtain the target vector, the base vector, and the square value of the base vector.

[0069] The target vector is the target demand vector, the base vector is the vector stored in the database, and the vector retrieval requirement is to retrieve one or more vectors that are closest to the target vector from multiple base vectors. The target vector and the base vector have the same dimension.

[0070] The square value of the base vector can be calculated before the vector is retrieved and stored in the base, and when the vector is needed, it can be directly read from the base. Of course, the square value of the base vector can also be calculated in real time during the vector retrieval and cached.

[0071] It should be added that the embodiments of the present application can be applied to various vector retrieval scenarios, such as cross-modal recognition, face and body recognition, fuzzy text recognition, and other scenarios in which target retrieval is completed through vectors. For example, when the embodiments of the present application are applied to face and body recognition scenarios, the target vector can be a feature vector extracted from the target face (or body) image, and the base library vector can be a feature vector extracted from the face (or body) image stored in the base library; when the embodiments of the present application are applied to fuzzy text recognition scenarios, the target vector can be a feature vector extracted from the target text, and the base library vector can be a feature vector extracted from the text stored in the base library.

[0072] S120: Determine the target value according to the square value of the base vector.

[0073] Among them, the target value is the operation value of the second operation term in the target formula converted from the Euclidean distance formula. The target formula includes a first operation term and a second operation term. The first operation term is the inner product of the target vector and the base vector. The inner product can be understood as a dot product.

[0074] The target formula includes:

[0075] Where y represents the calculation result of the target formula, a represents the target vector, b represents the base vector, and a·b represents the first operation term. Represents the second operand.

[0076] The specific process of converting the Euclidean distance formula into the target formula includes:

[0077] Known Euclidean distance formulas include Where d represents the Euclidean distance between vector a and vector b, n represents the dimension of the two vectors, i represents the i-th dimension, and a i represents the element of the i-th dimension in vector a, b i Represents the element of the i-th dimension in vector b;

[0078] The process of simplifying and converting the above Euclidean distance formula includes:

[0079] d 2 =(ab) 2 =a 2 +b 2 -2ab

[0080] d 2 -a 2 =b 2 -2ab

[0081] a 2 -d 2 =2ab-b 2

[0082]

[0083] From this we can see that since vector a can be regarded as a quantity, the smaller d is, The bigger, the The larger the value, the smaller the vector similarity. The larger the value, the higher the vector similarity. Calculate the target value, where ab refers to a·b.

[0084] S130: Construct a first vector and a second vector of the same dimension, so that the inner product result of the first vector and the second vector is a target value.

[0085] After calculating the target value, construct the first vector and the second vector of the same dimension so that the inner product of the first vector and the second vector is the target value, such as constructing the first vector a′ and the second vector b′ of the same dimension so that

[0086] The embodiment of the present application does not limit the specific method of constructing the first vector and the second vector of the same dimension, as long as the inner product of the two can be the target value. For example, the first vector and the second vector can be constructed by pseudo code, or by multiplying coefficients with fixed vectors, setting them as periodic functions, generating random numbers, etc.

[0087] Specifically, in order to improve the efficiency of vector construction, the second dimensions of the first vector and the second vector can be determined according to the first dimension of the target vector, and then a constant vector of the second dimension can be constructed as the first vector. Finally, the second vector can be constructed according to the first vector and the target value, so that the inner product result of the first vector and the second vector is the target value. Alternatively, a first preset vector and a second preset vector whose dimension is the second dimension and whose inner product is 1 can be obtained, and the product of the first preset vector and the target value can be used as the first vector and the second preset vector can be used as the second vector, or the first preset vector can be used as the first vector and the product of the second preset vector and the target value can be used as the second vector.

[0088] In an embodiment of the present application, the second dimension of the first vector and the second vector can be randomly determined, that is, there is no restriction on the value of the second dimension, or the second dimension of the first vector and the second vector can be determined according to the first dimension of the target vector. Determining the second dimension of the first vector and the second vector according to the first dimension of the target vector includes: obtaining the first dimension of the target vector, directly determining the first dimension as the second dimension of the first vector and the second vector, or determining the range of the second dimension according to the first dimension and the preset dimension floating range, and selecting a value from the range of the second dimension as the value of the second dimension. The preset dimension floating range can be an empirical value.

[0089] It should be supplemented that the first preset vector and the second preset vector whose dimension is the second dimension and whose inner product is 1 can be pre-set, so that when used later, one of the preset vectors can be directly multiplied by the target value; of course, the inner product of the first preset vector and the second preset vector can also be pre-set to a fixed constant other than 1. When used later, the coefficient that needs to be multiplied by any preset vector is first calculated, and then the first vector and the second vector are determined, where the coefficient that needs to be multiplied = target value / fixed constant other than 1.

[0090] In a possible implementation, the specific implementation method of the step of "constructing a constant vector of the second dimension as the first vector, and constructing a second vector based on the first vector and the target value, so that the inner product result of the first vector and the second vector is the target value" can be: constructing a constant vector with the second dimension as the first vector and all elements being the first constant; calculating the target element value based on the target value, the second dimension and the first constant, and constructing a vector with the second dimension as the second vector and all elements being the target element values.

[0091] When the memristor storage-computing integrated chip is good at calculating smaller elements, the first constant can be a smaller constant; when the memristor storage-computing integrated chip is good at calculating larger elements, the first constant can be a larger constant.

[0092] According to the target value, the second dimension and the first constant, the formula for calculating the target element value includes:

[0093]

[0094] in, represents the target value, M represents the second dimension, and c1 represents the first constant.

[0095] For example, when M=4 and the memristor storage and computing chip is good at calculating smaller elements, the first vector can be set to [8, 8, 8, 8]. If the target value = -100, then the second vector = [-3.125, -3.125, -3.125, -3.125].

[0096]

[0097]

[0098] In a possible implementation, the specific implementation method of the step of "constructing a constant vector of the second dimension as the first vector, and constructing a second vector based on the first vector and the target value, so that the inner product result of the first vector and the second vector is the target value" can also be: constructing a constant vector whose dimension is the second dimension and all elements are second constants as the first vector; calculating the value of m based on the target value and the second constant; setting the first m elements in the second vector to the third constant, wherein the third constant is the opposite of the second constant; and setting the remaining elements in the second vector to 0 based on m and the second dimension.

[0099] When the memristor storage and computing integrated chip is good at calculating 0 elements, the first vector can be set to a constant vector, and some elements of the second vector can be set to 0. The second constant can be an integer. According to the target value and the second constant, the method for calculating the value of m includes: determining the quotient between the opposite of the target value and the square of the second constant as the value of m. is the target value, c2 represents the second constant,

[0100] For example, when M=4 and the memristor integrated storage and computing chip is good at calculating 0 elements, the first vector can be set to [10, 10, 10, 10]. If the target value = -100, then the second vector = [-10, 0, 0, 0].

[0101] In addition, when the memristor storage-computing integrated chip only allows integers to be written, the first vector and the second vector can be constructed by controlling the remainder. Specifically, the second dimension is represented by M, and the first vector and the second vector are both integer vectors.

[0102] Constructing a constant vector of the second dimension as the first vector, and constructing a second vector according to the first vector and the target value, so that the inner product result of the first vector and the second vector is the target value, including: setting the first M-2 elements in the first vector to the third constant, the M-1th element to the fourth constant, and the Mth element to 1, wherein the fourth constant is between 1 and the third constant; determining the value of the M-1th element in the second vector according to the first formula, wherein the first formula includes: According to the second formula, the value of the Mth element in the second vector is determined, wherein the second formula includes: According to the third formula, the first intermediate value is determined, wherein the third formula includes: According to the fourth formula, the second intermediate value is determined, wherein the fourth formula includes: The first second intermediate value elements in the second vector are respectively set to the opposite number of the first intermediate value minus 1; and the remaining elements in the second vector are respectively set to the opposite number of the first intermediate value.

[0103] For example, when M=8, the first vector can be set to [4,4,4,4,4,4,2,1], and the remainder can be controlled by the last two digits. If the target value = -101, then the second vector = [-5,-4,-4,-4,-4,-4,0,1].

[0104]

[0105] S140: adding the elements in the first vector to the target vector to obtain the target vector with increased dimension, and adding the elements in the second vector to the base vector to obtain the base vector with increased dimension.

[0106] After obtaining the first vector and the second vector, the elements in the first vector can be added to the tail of the target vector, and the elements in the second vector can be added to the tail of the base vector, respectively, to increase the dimension of the target vector and the base vector. For example, when the target vector = [2, 2], the base vector = [3, 3], the first vector = [1, 1], and the second vector = [-4.5, -4.5], the target vector after the dimension increase = [2, 2, 1, 1], and the base vector after the dimension increase = [3, 3, -4.5, -4.5].

[0107] S150: Based on the array structure of the memristor storage-computing integrated chip, an inner product operation is performed on the target vector after the dimension is increased and the base vector after the dimension is increased to obtain the calculation result of the target formula.

[0108] If the target vector after the dimension increase is represented by a″, and the base vector after the dimension increase is represented by b″, then a″=[a,a′], b″=[b,b′], Therefore, by performing an inner product operation on the target vector after the dimension is increased and the base vector after the dimension is increased, the calculation result of the target formula can be obtained.

[0109] S160: Determine K base-base vectors with the highest similarity to the target vector by comparing calculation results corresponding to different base-base vectors, where K is a positive integer.

[0110] After calculating the calculation results corresponding to each base vector, the calculation results corresponding to each base vector can be sorted, and the calculation results of K with the largest calculation results can be found, and the base vectors corresponding to the K calculation results can be determined as the K base vectors with the highest similarity to the target vector. K can be 1 or an integer greater than 1.

[0111] For example, if the target vector = [0, 1, 2, 1, 1], the base vector 1 = [1, 2, 0, 0, 1], the base vector 2 = [2, 1, 1, 1, 0], the square of the base vector 1 = 6, and the square of the base vector 2 = 7, then when the target vector after the dimension increase = [0, 1, 2, 1, 1, -0.5], the base vector 1 after the dimension increase = [1, 2, 0, 0, 1, 6], and the base vector 2 after the dimension increase = [2, 1, 1, 1, 0, 7], the result of calculating the inner product of the target vector after the dimension increase and the base vector 1 after the dimension increase is equal to 0, and the result of calculating the inner product of the target vector after the dimension increase and the base vector 2 after the dimension increase is equal to 0.5. It can be seen that the base vector 2 has the highest similarity with the target vector.

[0112] The vector retrieval method provided by the embodiment of the present application can first obtain the target vector, the base vector and the square value of the base vector when vector retrieval is needed, and determine the target value according to the square value of the base vector (the target value is the operation value of the second operation term in the target formula converted from the Euclidean distance formula, the target formula includes the first operation term and the second operation term, and the first operation term is the inner product of the target vector and the base vector), and then construct the first vector and the second vector of the same dimension, so that the inner product result of the first vector and the second vector is the target value, add the elements in the first vector to the target vector to obtain the target vector with increased dimension, and add the elements in the second vector to the base vector to obtain the base vector with increased dimension, so that the original target formula is converted into an inner product operation of the target vector with increased dimension and the base vector with increased dimension, and after obtaining the calculation result of the inner product operation corresponding to each base vector, the K base vectors with the highest similarity to the target vector can be determined by comparing the sizes of the calculation results. It can be seen from this that the embodiment of the present application no longer directly calculates the Euclidean distance, but instead realizes the function of vector retrieval based on the memristor storage and computing chip by converting the Euclidean distance formula into a matrix multiplication and addition operation supported by the memristor storage and computing chip, thereby improving the computational efficiency of vector retrieval.

[0113] It should be noted that the memristor storage and computing integrated chip can execute all the steps in the vector retrieval method provided in the above embodiment, including steps S110 to S160; the memristor storage and computing integrated chip can also execute some steps in the above method, which at least include the step of vector inner product operation (such as step S150), and the remaining steps can be executed by processors, field programmable gate arrays (Field Programmable Gate Array, FPGA for short) and other devices.

[0114] Based on the above method embodiment, another embodiment of the present application provides a vector retrieval device, such as Figure 2As shown, the device comprises:

[0115] An acquisition unit 210, configured to acquire a target vector, a base vector, and a square value of the base vector;

[0116] A first determining unit 220 is used to determine a target value according to the square value of the base vector, wherein the target value is an operation value of a second operation term in a target formula converted from a Euclidean distance formula, the target formula includes a first operation term and a second operation term, and the first operation term is an inner product of the target vector and the base vector;

[0117] A construction unit 230, configured to construct a first vector and a second vector of the same dimension, so that an inner product result of the first vector and the second vector is the target value;

[0118] an amplification unit 240, configured to add the elements in the first vector to the target vector to obtain the target vector with increased dimension, and to add the elements in the second vector to the base vector to obtain the base vector with increased dimension;

[0119] The operation unit 250 is used to perform an inner product operation on the target vector after the dimension is increased and the base vector after the dimension is increased based on the array structure of the memristor storage and computing integrated chip to obtain the calculation result of the target formula;

[0120] The second determining unit 260 is configured to determine K base-base vectors having the highest similarity to the target vector by comparing the calculation results corresponding to different base-base vectors, wherein K is a positive integer.

[0121] In a possible implementation, the target formula includes:

[0122] Wherein, y represents the calculation result of the target formula, a represents the target vector, b represents the base vector, a·b represents the first operation term, represents the second operand.

[0123] In a possible implementation, the construction unit 230 includes:

[0124] a determination module, configured to determine second dimensions of the first vector and the second vector according to the first dimension of the target vector;

[0125] A construction module is used to construct a constant vector of the second dimension as the first vector, and to construct the second vector according to the first vector and the target value, so that the inner product result of the first vector and the second vector is the target value.

[0126] In one possible implementation, the construction module is used to construct a constant vector whose dimension is the second dimension and all elements are the first constant, as the first vector; calculate the target element value according to the target value, the second dimension and the first constant, and construct a vector whose dimension is the second dimension and all elements are the target element values, as the second vector.

[0127] In one possible implementation, the construction module is used to construct a constant vector whose dimension is the second dimension and all elements are second constants, as the first vector; calculate the value of m according to the target value and the second constant; set the first m elements in the second vector to a third constant, wherein the third constant is the opposite of the second constant; and set the remaining elements in the second vector to 0 according to m and the second dimension.

[0128] In a possible implementation manner, the second dimension is represented by M, and the first vector and the second vector are both integer vectors;

[0129] The construction module is used to set the first M-2 elements in the first vector to a third constant, the M-1th element to a fourth constant, and the Mth element to 1, wherein the fourth constant is between 1 and the third constant;

[0130] According to the first formula, the value of the M-1th element in the second vector is determined, wherein the first formula includes:

[0131] According to the second formula, the value of the Mth element in the second vector is determined, wherein the second formula includes:

[0132] According to a third formula, a first intermediate value is determined, wherein the third formula includes:

[0133] According to a fourth formula, a second intermediate value is determined, wherein the fourth formula includes:

[0134] Set the first second intermediate value elements in the second vector to the opposite of the first intermediate value minus 1 respectively;

[0135] The remaining elements in the second vector are respectively set to the opposite numbers of the first intermediate values.

[0136] The vector retrieval device provided by the embodiment of the present application can first obtain the target vector, the base vector and the square value of the base vector when vector retrieval is needed, and determine the target value according to the square value of the base vector (the target value is the operation value of the second operation term in the target formula converted from the Euclidean distance formula, the target formula includes the first operation term and the second operation term, and the first operation term is the inner product of the target vector and the base vector), and then construct the first vector and the second vector of the same dimension, so that the inner product result of the first vector and the second vector is the target value, add the elements in the first vector to the target vector to obtain the target vector with increased dimension, and add the elements in the second vector to the base vector to obtain the base vector with increased dimension, so that the original target formula is converted into an inner product operation of the target vector with increased dimension and the base vector with increased dimension, and after obtaining the calculation result of the inner product operation corresponding to each base vector, the K base vectors with the highest similarity to the target vector can be determined by comparing the sizes of the calculation results. It can be seen from this that the embodiment of the present application no longer directly calculates the Euclidean distance, but instead realizes the function of vector retrieval based on the memristor storage and computing chip by converting the Euclidean distance formula into a matrix multiplication and addition operation supported by the memristor storage and computing chip, thereby improving the computational efficiency of vector retrieval.

[0137] Based on the above method embodiments, another embodiment of the present application provides a memristor storage and computing integrated chip, which is at least used to implement the inner product operation on the vector in the method described in any embodiment.

[0138] Based on the above method embodiment, another embodiment of the present application provides an electronic device, which includes at least one memristor storage and computing integrated chip as described above.

[0139] The above device embodiment corresponds to the method embodiment and has the same technical effect as the method embodiment. For specific description, please refer to the method embodiment. The device embodiment is obtained based on the method embodiment. For specific description, please refer to the method embodiment part, which will not be repeated here. It can be understood by those skilled in the art that the accompanying drawings are only schematic diagrams of one embodiment, and the modules or processes in the accompanying drawings are not necessarily required to implement the present application.

[0140] Those skilled in the art can understand that the modules in the device in the embodiment can be distributed in the device in the embodiment according to the description of the embodiment, or can be changed accordingly and located in one or more devices different from the embodiment. The modules in the above embodiment can be combined into one module, or can be further divided into multiple sub-modules.

[0141] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A vector retrieval method, characterized in that: The method comprises: Obtaining a target vector, a base vector, and a square value of the base vector; Determine a target value according to the square value of the base vector, wherein the target value is the operation value of the second operation term in the target formula converted from the Euclidean distance formula, the target formula includes a first operation term and a second operation term, and the first operation term is the inner product of the target vector and the base vector; Constructing a first vector and a second vector of the same dimension, so that an inner product result of the first vector and the second vector is the target value; Adding the elements in the first vector to the target vector to obtain the target vector with increased dimension, and adding the elements in the second vector to the base vector to obtain the base vector with increased dimension; Based on the array structure of the memristor storage-computation integrated chip, an inner product operation is performed on the target vector after the dimension is increased and the base vector after the dimension is increased to obtain the calculation result of the target formula; By comparing the calculation results corresponding to different base library vectors, determining K base library vectors having the highest similarity to the target vector, wherein K is a positive integer; The target formula includes: Wherein, y represents the calculation result of the target formula, a represents the target vector, b represents the base vector, a·b represents the first operation term, represents the second operand.

2. The method according to claim 1, characterized in that: The constructing the first vector and the second vector having the same dimension so that the inner product result of the first vector and the second vector is the target value includes: Determining second dimensions of the first vector and the second vector according to the first dimension of the target vector; A constant vector of the second dimension is constructed as the first vector, and the second vector is constructed according to the first vector and the target value, so that the inner product result of the first vector and the second vector is the target value.

3. The method according to claim 2, characterized in that The step of constructing the constant vector of the second dimension as the first vector, and constructing the second vector according to the first vector and the target value so that the inner product result of the first vector and the second vector is the target value includes: constructing a constant vector whose dimension is the second dimension and all elements of which are the first constants as the first vector; According to the target value, the second dimension and the first constant, a target element value is calculated, and a vector whose dimension is the second dimension and all elements are the target element values ​​is constructed as the second vector.

4. The method according to claim 2, characterized in that: The step of constructing the constant vector of the second dimension as the first vector, and constructing the second vector according to the first vector and the target value so that the inner product result of the first vector and the second vector is the target value includes: constructing a constant vector whose dimension is the second dimension and all elements are second constants as the first vector; Calculate the value of m according to the target value and the second constant; Set the first m elements in the second vector to a third constant, wherein the third constant is the opposite of the second constant; The remaining elements in the second vector are set to 0 according to the m and the second dimension.

5. The method according to claim 2, characterized in that: The second dimension is represented by M, and the first vector and the second vector are both integer vectors; The step of constructing the constant vector of the second dimension as the first vector, and constructing the second vector according to the first vector and the target value so that the inner product result of the first vector and the second vector is the target value includes: The first M-2 elements in the first vector are respectively set to a third constant, the M-1th element is set to a fourth constant, and the Mth element is set to 1, wherein the fourth constant is between 1 and the third constant; According to the first formula, the value of the M-1th element in the second vector is determined, wherein the first formula includes: According to the second formula, the value of the Mth element in the second vector is determined, wherein the second formula includes: According to a third formula, a first intermediate value is determined, wherein the third formula includes: According to a fourth formula, a second intermediate value is determined, wherein the fourth formula includes: Set the first second intermediate value elements in the second vector to the opposite of the first intermediate value minus 1 respectively; The remaining elements in the second vector are respectively set to the opposite numbers of the first intermediate values.

6. A vector search device, characterized in that: The device comprises: An acquisition unit, used for acquiring a target vector, a base vector and a square value of the base vector; A first determining unit is used to determine a target value according to the square value of the base vector, wherein the target value is an operation value of a second operation term in a target formula converted from a Euclidean distance formula, the target formula includes a first operation term and a second operation term, and the first operation term is an inner product of the target vector and the base vector; a construction unit, configured to construct a first vector and a second vector of the same dimension, so that an inner product result of the first vector and the second vector is the target value; an amplification unit, configured to add the elements in the first vector to the target vector to obtain the target vector with increased dimension, and to add the elements in the second vector to the base vector to obtain the base vector with increased dimension; A computing unit, configured to perform an inner product operation on the target vector after the dimension is increased and the base vector after the dimension is increased based on the array structure of the memristor storage and computing integrated chip, to obtain a calculation result of the target formula; A second determining unit is used to determine K base-base vectors having the highest similarity to the target vector by comparing the calculation results corresponding to different base-base vectors, wherein K is a positive integer; The target formula includes: Wherein, y represents the calculation result of the target formula, a represents the target vector, b represents the base vector, a·b represents the first operation term, represents the second operand.

7. A memristor storage and computing integrated chip, characterized in that: The memristor storage-computing integrated chip is at least used to implement the inner product operation on the vector in the method as described in any one of claims 1-5.

8. An electronic device, characterized in that: The electronic device comprises at least one memristor storage-computing integrated chip as described in claim 7.