Vector database index construction and retrieval method, medium and product
By intelligently initializing the cluster center and setting the number of query clusters, the problem of the inability of the clustering algorithm to reach the global minimum and the missing of nearest neighbors in the query during vector database index construction is solved, and efficient index construction and accurate query of the vector database are realized.
Patent Information
- Application Number
- CN202410831917.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-25
- Publication Date
- 2024-10-01
AI Technical Summary
During the index construction process of the vector database, randomly initializing the cluster center may cause the clustering algorithm to fail to reach the global minimum, resulting in the problem of missing neighbor vectors during the query. Especially when the vector to be queried is located at the edge of the cluster, the query results are inconsistent. precise.
An intelligent initialization method is used to select the cluster center to avoid falling into the local optimal solution, and the error caused by edge problems is reduced by setting the number of query clusters to ensure the accuracy and speed of the query. Specific steps include establishing a table in the vector database, inserting vector data, randomly selecting initial clustering centers, and selecting other clustering centers by calculating the maximum distance of vector samples until N clustering centers are determined, and clustering is set during query number to cover potential neighbor classes.
It effectively avoids the problem of local optimal solution, improves the quality of index construction and accuracy of query, reduces edge errors, increases query speed, and ensures the complete process of index construction and retrieval of vector database.
Smart Images

Figure CN118733587A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of databases, and in particular to an index construction and retrieval method, medium and product of a vector database. Background Art
[0002] With the explosive growth of large-scale data, text, pictures, or audio can be transformed into feature vectors that represent entity features through models. Quantifying entities can achieve more efficient processing, thereby enabling subsequent vector query operations, which has become the mainstream trend in the processing of unstructured data. Compared with traditional methods of analyzing unstructured data, it is more efficient to quantify it through embedding technology and then further process it. Corresponding to this is the emergence of vector databases. As a database, it first needs to have the function of persistent data storage. As a special database for storing vectors, users can store the vectors converted from unstructured texts through embedding technology into the database, thereby supporting long-term storage of vectors for subsequent query operations.
[0003] In addition to persistent storage, the vector database also needs to have the function of querying the top K nearest neighbor vectors. When calculating the K nearest neighbor vectors, the general strategy is to calculate the distance between each vector in the vector database and the vector to be queried. The vector index construction strategy is to build N clusters for all vectors. Each vector belongs to one of the classes. Each class has a cluster center. The distance between classes is the farthest, and each vector in a cluster is closest to the cluster center of the class to which it belongs. The query strategy is to return the K results that are most similar to the vector to be queried. In order to achieve this clustering function, it is first necessary to cluster the existing vectors. The most common clustering strategy is to randomly initialize the cluster center, then assign all vectors to the class where the cluster center is closest to them, update the cluster center, and iterate until the cluster center no longer changes.
[0004] When indexing a vector column, you first need to randomly initialize N cluster centers. The initialization of cluster centers plays an important role in indexing, which determines whether the clustering algorithm can converge to the global minimum. If most or all cluster centers are initialized to the same cluster, the clustering algorithm may not achieve the best clustering results.
[0005] After the index is established, each vector is assigned to the corresponding cluster center. When performing a nearest neighbor vector query, only the closest class will be queried. If the vector to be queried is located at the edge of the cluster, there will be the following problem: if its other nearest data points are included in the adjacent class, because when querying, only all vectors in the class closest to the query vector and the cluster center will be queried, and the correct vector of the neighboring class will not be searched, so there will be omission problems, resulting in query errors. Summary of the invention
[0006] An object of the present invention is to provide a vector database index construction and retrieval method, medium and product that can solve any of the above problems.
[0007] A further object of the present invention is to implement a complete process of inserting vector data into a vector database, indexing vector fields, and querying nearest neighbor vectors.
[0008] Another further object of the present invention is to select initial cluster centers through an intelligent initialization method to better avoid falling into the problem of local optimal solutions.
[0009] Another further object of the present invention is to reduce the error caused by edge problems by setting the number of query clusters.
[0010] In particular, the present invention provides an index construction and retrieval method for a vector database, including: establishing a table in the vector database, the table containing vector fields of fixed dimensions; inserting vector data of the same dimension into the table as vector samples; indexing the vector fields; and using the index to perform an approximate query on the nearest neighbor vector of the query vector.
[0011] Optionally, the step of indexing the vector field includes: initializing N cluster centers; calculating the first distance between all vector samples outside the cluster center and each cluster center, and assigning each vector sample to the class to which the nearest cluster center belongs; recalculating the cluster center of each class; determining whether the cluster center has changed; and if not, determining that clustering is completed.
[0012] Optionally, when the cluster center changes, return to execute the step of calculating the first distance between all vector samples other than the cluster center and each cluster center.
[0013] Optionally, the step of initializing N cluster centers includes: randomly selecting a vector sample as the first cluster center; calculating the second distance between all vector samples other than the first cluster center and the first cluster center, and selecting the vector sample with the largest second distance as the next cluster center; calculating the third distance between all vector samples other than the cluster center and the cluster center closest to it, and selecting the vector sample with the largest third distance as the next cluster center; determining whether N cluster centers have been selected; and if so, determining that initialization is complete.
[0014] Optionally, when N cluster centers are not selected, the step of returning to the step of calculating the third distances from all vector samples other than the cluster center to the cluster center closest thereto is performed.
[0015] Optionally, the step of using the index to perform an approximate query on the nearest neighbor vector of the query vector includes: setting the number of clusters M to be queried, where the number of clusters M is a positive integer between 1 and N; calculating the fourth distance between the query vector and each cluster center, and sorting the classes according to the size of the fourth distance; and calculating the fifth distance between the query vector and each vector sample in the M classes with the smallest fourth distance, sorting the vector samples in the M classes according to the size of the fifth distance, and returning k vector samples with the smallest fifth distance as the result.
[0016] Optionally, the first distance includes Euclidean distance, cosine distance, negative inner product distance, or a user-defined distance.
[0017] Optionally, the step of recalculating the cluster center of each class includes: taking an average value of all vector samples in each class as a new cluster center.
[0018] According to another aspect of the present invention, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the index construction and retrieval method of the vector database described above is implemented.
[0019] According to another aspect of the present invention, there is provided a computer program product, including a computer program, characterized in that when the computer program is executed by a processor, it implements any of the above-mentioned vector database index construction and retrieval methods.
[0020] The index construction and retrieval method of the vector database of the present invention establishes a table in the vector database, the table contains vector fields of fixed dimensions; inserts vector data of the same dimension into the table as vector samples; indexes the vector fields; and uses the index to perform an approximate query on the nearest neighbor vector of the query vector, which can realize the complete process of inserting vector data into the vector database, indexing the vector fields and querying the nearest neighbor vector.
[0021] Furthermore, the index construction and retrieval method of the vector database of the present invention randomly selects a vector sample as the first cluster center; calculates the second distance between all vector samples other than the first cluster center and the first cluster center, and selects the vector sample with the largest second distance as the next cluster center; calculates the third distance between all vector samples other than the cluster center and the cluster center closest to it, and selects the vector sample with the largest third distance as the next cluster center; determines whether N cluster centers have been selected; and if so, determines that initialization is completed, and selects the initial cluster center through an intelligent initialization method to better avoid falling into the problem of local optimal solution.
[0022] Furthermore, the index construction and retrieval method of the vector database of the present invention comprises the steps of using the index to perform an approximate query on the nearest neighbor vector of the query vector: setting the number of clusters M to be queried, wherein the number of clusters M is a positive integer between 1 and N; calculating the fourth distance between the vector to be queried and each cluster center, and sorting the classes according to the size of the fourth distance; and calculating the fifth distance between the vector to be queried and each vector sample in the M classes with the smallest fourth distance, sorting the vector samples in the M classes according to the size of the fifth distance, and returning k vector samples with the smallest fifth distance as the result. By setting the number of query clusters, the error caused by edge problems is reduced, and a balance is struck between accuracy and query time, thereby speeding up the query.
[0023] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more aware of the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Hereinafter, some specific embodiments of the present invention will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:
[0025] Figure 1 is a schematic flow chart of a method for index construction and retrieval of a vector database according to an embodiment of the present invention;
[0026] Figure 2 is a schematic flow chart of establishing an index in a method for index construction and retrieval of a vector database according to an embodiment of the present invention;
[0027] Figure 3 is a schematic flow chart of initializing cluster centers in a method for index construction and retrieval of a vector database according to an embodiment of the present invention;
[0028] Figure 4It is a schematic diagram of initializing cluster centers and completing clustering in the prior art;
[0029] Figure 5 is a schematic flow chart of querying the nearest neighbor vector in the index construction and retrieval method of the vector database according to an embodiment of the present invention;
[0030] Figure 6 is a schematic diagram of querying a nearest neighbor vector in a method for constructing and retrieving an index of a vector database according to an embodiment of the present invention;
[0031] Figure 7 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention;
[0032] Figure 8 is a schematic diagram of a computer program product according to an embodiment of the present invention; and
[0033] Fig. 9 is a schematic diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0034] It should be understood by those skilled in the art that the embodiments described below are only some embodiments of the present invention, rather than all embodiments of the present invention, and these embodiments are intended to explain the technical principles of the present invention, rather than to limit the protection scope of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should still fall within the protection scope of the present invention.
[0035] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or equipment (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or equipment and execute instructions), or used in combination with these instruction execution systems, devices or equipment.
[0036] The purpose of the index building and retrieval method for a vector database in this embodiment is to implement the complete process of inserting vector data into a vector database, building an index for a vector field, and querying the nearest neighbor vector. Figure 1 is a schematic flow chart of a method for constructing and retrieving an index of a vector database according to an embodiment of the present invention. Figure 1 As shown, in one embodiment, the index construction and retrieval method of the vector database may generally include the following steps:
[0037] Step S102: Create a table in the vector database, the table containing vector fields of fixed dimensions. Specifically, the table contains at least one vector field.
[0038] Step S104: insert vector data of the same dimension into the table as vector samples. Specifically, insert vector data of the same dimension into a column of a vector field of a fixed dimension.
[0039] Step S106: Create an index for the vector field. Specifically, after the index is created, each vector sample has been assigned to a corresponding cluster center.
[0040] Step S108: Use the index to perform an approximate query on the nearest neighbor vector of the query vector, thereby balancing the accuracy and query time, thereby speeding up the query.
[0041] In the scheme of this embodiment, a table is established in a vector database, the table contains vector fields of fixed dimensions; vector data of the same dimension are inserted into the table as vector samples; the vector fields are indexed; and the index is used to perform an approximate query on the nearest neighbor vector of the query vector, thereby realizing the complete process of inserting vector data into the vector database, indexing the vector fields, and querying the nearest neighbor vector.
[0042] Figure 2 FIG. 1 is a schematic flow chart of establishing an index in a method for index construction and retrieval of a vector database according to an embodiment of the present invention. Figure 2 As shown, indexing a vector field may generally include the following steps:
[0043] Step S202, initialize N cluster centers. Specifically, when selecting the initial point, it is not randomly initialized, but an existing vector sample is selected as the initial point, and the next vector sample that is farthest from this vector sample and not used as a cluster center is selected as the next cluster center, and the loop is iterated until N cluster centers are selected. In the method of this embodiment, selecting an existing vector sample as the initial point is the primary condition. When selecting the next cluster center, the vector sample farthest from this vector sample is not a necessary condition, and a relatively far vector sample can also be selected.
[0044] Step S204, calculate the first distance between all vector samples other than the cluster center and each cluster center, and assign each vector sample to the class to which the nearest cluster center belongs. Specifically, the first distance may include Euclidean distance, cosine distance, negative inner product distance or user-defined distance.
[0045] Step S206, recalculate the cluster center of each class. Specifically, the average value of all vector samples in each class can be taken as the new cluster center.
[0046] Step S208, determine whether the cluster center has changed, if so, return to step S204, if not, execute step S210. Specifically, if the judgment result of step S208 is yes, that is, if the cluster center has changed, return to step S204. If the judgment result of step S208 is no, that is, if the cluster center has not changed, execute step S210.
[0047] Step S210, determining that clustering is completed. That is, step S204 and step S206 are repeatedly executed until step S208 determines that the cluster center does not change any more, then clustering is considered to be completed, and an index is established for the vector field.
[0048] Figure 3 FIG. 1 is a schematic flow chart of initializing cluster centers in a method for index construction and retrieval of a vector database according to an embodiment of the present invention. Figure 3 As shown, initializing N cluster centers can generally include the following steps:
[0049] Step S302: randomly select a vector sample as the first cluster center. Specifically, the vector sample is an existing vector among all vector samples.
[0050] Step S304, calculate the second distance between all vector samples other than the first cluster center and the first cluster center, and select the vector sample with the largest second distance as the next cluster center. In some other embodiments, selecting the vector sample with the largest second distance as the next cluster center may be a non-essential condition, and a vector sample with a relatively far second distance may also be selected.
[0051] Step S306, calculate the third distances from all vector samples other than the cluster center to the nearest cluster center, and select the vector sample with the largest third distance as the next cluster center. Specifically, the nearest cluster center of all vector samples other than the cluster center can be determined first, and then the third distance from each vector sample to the nearest cluster center can be calculated, and finally the vector sample with the largest third distance can be selected as the next cluster center.
[0052] Step S308, determine whether N cluster centers have been selected, if yes, execute step S310, if no, return to execute step S306. Specifically, if the judgment result of step S308 is yes, that is, if N cluster centers have been selected, execute step S310. If the judgment result of step S308 is no, that is, if N cluster centers have not been selected, return to execute step S306.
[0053] Step S310, determining that the initialization is completed. That is, step S306 is repeatedly executed until step S308 determines that N cluster centers have been selected, then it is considered that the initialization is completed and N cluster centers have been initialized.
[0054] In the scheme of this embodiment, a vector sample is randomly selected as the first cluster center; the second distance between all vector samples other than the first cluster center and the first cluster center is calculated, and the vector sample with the largest second distance is selected as the next cluster center; the third distance between all vector samples other than the cluster center and the cluster center closest to it is calculated, and the vector sample with the largest third distance is selected as the next cluster center; it is determined whether N cluster centers have been selected; and if so, it is determined that initialization is completed, and an intelligent initialization method is used to select the initial cluster center to better avoid falling into the problem of local optimal solution.
[0055] Figure 4 This is a schematic diagram of initializing cluster centers and completing clustering in the prior art. The initialization of cluster centers plays an important role in indexing, which determines whether the clustering algorithm can converge to the global minimum. If most or all cluster centers are initialized to the same cluster, the clustering algorithm may not be able to achieve the best clustering results. For example Figure 4 As shown in the left figure, when the cluster centers are initialized, the distance between the cluster centers is very close. After iteration, the cluster centers converge and no longer change, and the clustering is considered complete. Figure 4 As shown in the right figure, the clustering result is that the top cluster is divided into two clusters, and the two clusters below are divided into one cluster, which is quite different from the actual result.
[0056] The solution of this embodiment uses an intelligent initialization method to select the initial cluster center, which can better avoid falling into the problem of local optimal solution. When the cluster centers are initialized at the beginning, the cluster centers are far apart, so the final clusters will not appear Figure 4 In this case, this is an improvement on the clustering method when building indexes in vector databases.
[0057] Figure 5 FIG. 1 is a schematic flow chart of querying the nearest neighbor vector in the index construction and retrieval method of the vector database according to an embodiment of the present invention. Figure 5 As shown, using an index to perform an approximate query on the nearest neighbor vector of a query vector may generally include the following steps:
[0058] Step S502, setting the number of clusters to be queried M. Specifically, the number of clusters M is a positive integer between 1 and N. If not set, M defaults to 1.
[0059] Step S504, calculate the fourth distance between the query vector and each cluster center, and sort the clusters according to the size of the fourth distance. Specifically, the clusters can be sorted from small to large according to the fourth distance.
[0060] Step S506, calculate the fifth distance between the query vector and each vector sample in the M classes with the smallest fourth distance, sort the vector samples in the M classes according to the size of the fifth distance, and return k vector samples with the smallest fifth distance as the result. Specifically, each vector sample in the M classes can be sorted from small to large according to the fifth distance, and the k vector samples with the smallest fifth distance can be returned to the user as the nearest neighbor vectors of the query vector.
[0061] In the scheme of this embodiment, the step of using an index to perform an approximate query on the nearest neighbor vector of a query vector includes: setting the number of clusters M to be queried, where the number of clusters M is a positive integer between 1 and N; calculating the fourth distance between the query vector and each cluster center, and sorting the classes according to the size of the fourth distance; and calculating the fifth distance between the query vector and each vector sample in the M classes with the smallest fourth distance, sorting the vector samples in the M classes according to the size of the fifth distance, and returning K vector samples with the smallest fifth distance as the result. By setting the number of query clusters, the error caused by edge problems is reduced, and a balance is struck between accuracy and query time, thereby speeding up the query.
[0062] Figure 6 FIG. 1 is a schematic diagram of querying the nearest neighbor vector in the index construction and retrieval method of the vector database according to an embodiment of the present invention. Figure 6 As shown, the vector to be queried is indicated by a star, and it is located at the edge of the cluster in the lower left corner. By calculating it with each cluster center, it can be obtained that it is closest to the cluster center in the lower left corner. The prior art only calculates all vectors in the cluster in the lower left corner when calculating its nearest neighbor vector, but in fact the vector closest to it is the vector in the cluster in the lower right corner, which will be missed. The method of this embodiment can reduce the error caused by the edge problem by setting the number of query clusters during query. For example, if the number of clusters to be queried M is set to 2, the cluster in the lower right corner can be covered, thereby obtaining the correct result.
[0063] The flow chart that the above-described embodiment provides is not intended to indicate that the operation of the method will be performed in any particular order, or that all operations of the method are included in all every case. In addition, the method may include additional operations. Within the scope of the technical ideas that the above-described embodiment method provides, additional changes may be made to the above-described method.
[0064] This embodiment also provides a computer-readable storage medium, a computer program product, and a computer device. Figure 7 is a schematic diagram of a computer-readable storage medium 300 according to one embodiment of the present invention. Figure 8 is a schematic diagram of a computer program product 500 according to one embodiment of the present invention. Fig. 9is a schematic diagram of a computer device 400 according to one embodiment of the present invention.
[0065] The computer program product 500 includes a computer program 310, which implements any of the above-mentioned vector database index construction and retrieval methods when executed by a processor 410. The computer-readable storage medium 300 stores the above-mentioned computer program 310, which implements the vector database index construction and retrieval method of any of the above-mentioned embodiments when executed by the processor 410. The computer device 400 may include a memory 420, a processor 410, and a computer program 310 stored in the memory 420 and running on the processor 410.
[0066] The computer program 310 used to perform the operations of the present invention can be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, configuration data of an integrated circuit, or source code or object code written in any combination of one or more programming languages and procedural programming languages.
[0067] The computer program 310 may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet Service Provider).
[0068] In some embodiments, in order to perform various aspects of the present invention, electronic circuits including, for example, programmable logic circuits, field programmable gate arrays (FPGAs) or programmable logic arrays (PLAs) can execute computer-readable program instructions by utilizing state information of the computer-readable program instructions to personalize the electronic circuits.
[0069] For the description of this embodiment, the computer program product 500 is a related product including the computer program 310. For the description of this embodiment, the computer-readable storage medium 300 is a tangible device capable of retaining and storing the computer program 310, which can be any device that can contain, store, communicate, propagate or transmit the program 310 for use in an instruction execution system, device or apparatus or in conjunction with these instruction execution systems, devices or apparatuses.
[0070] More specific examples (a non-exhaustive list) of computer-readable storage media 300 include the following: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, and any suitable combination of the foregoing.
[0071] The computer device 400 may include a memory 420, a processor 410, and a computer program 310 stored in the memory 420 and running on the processor 410, and when the processor 410 executes the computer program 310, the index construction and retrieval method of the vector database in any of the above embodiments is implemented.
[0072] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any machine-readable storage medium for use by an instruction execution system, device or equipment (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or equipment and execute instructions), or used in combination with these instruction execution systems, devices or equipment.
[0073] It should be understood that each part of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.
[0074] Computer device 400 can be, for example, a server, a desktop computer, a notebook computer, a tablet computer, or a smart phone. In some examples, computer device 400 can be a cloud computing node. Computer device 400 can be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, a program module can include routines, programs, target programs, components, logic, data structures, etc. that perform specific tasks or implement specific abstract data types. Computer device 400 can be implemented in a distributed cloud computing environment where remote processing devices linked through a communication network perform tasks. In a distributed cloud computing environment, program modules can be located on a local or remote computing system storage medium including a storage device.
[0075] The computer device 400 may include a processor 410 adapted to execute stored instructions, and a memory 420 providing temporary storage space for the operation of instructions during operation. The processor 410 may be a single-core processor, a multi-core processor, a computing cluster, or any number of other configurations. The memory 420 may include a random access memory (RAM), a read-only memory, a flash memory, or any other suitable storage system.
[0076] The processor 410 may be connected to an I / O interface (input / output interface) suitable for connecting the computer device 400 to one or more I / O devices (input / output devices) through a system interconnect (e.g., PCI, PCI-Express, etc.). The I / O devices may include, for example, a keyboard and a pointing device, wherein the pointing device may include a touch pad or a touch screen, etc. The I / O devices may be built-in components of the computer device 400, or may be devices externally connected to the computing device.
[0077] Processor 410 may also be linked to a display interface suitable for connecting computer device 400 to a display device through a system interconnect. Display device may include a display screen as a built-in component of computer device 400. Display device may also include a computer monitor, a television or a projector, etc., externally connected to computer device 400. In addition, a network interface controller (NIC) may be suitable for connecting computer device 400 to a network through a system interconnect. In some embodiments, NIC may use any suitable interface or protocol (such as an Internet small computer system interface, etc.) to transmit data. The network may be a cellular network, a radio network, a wide area network (WAN), a local area network (LAN) or the Internet, etc. A remote device may be connected to a computing device through a network.
[0078] At this point, those skilled in the art should recognize that, although multiple exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all these other variations or modifications.
Claims
1. A method for constructing and retrieving an index of a vector database, comprising: Establishing a table in the vector database, wherein the table includes vector fields of fixed dimensions; Inserting vector data of the same dimension into the table as vector samples; Creating an index on the vector field; and The index is used to perform an approximate query on the nearest neighbor vector of the query vector.
2. The method according to claim 1, wherein the step of indexing the vector field comprises: Initialize N cluster centers; Calculating a first distance between all the vector samples other than the cluster center and each of the cluster centers, and assigning each of the vector samples to the class to which the nearest cluster center belongs; Recalculating the cluster center of each of the classes; Determining whether the cluster center changes; as well as If not, it is determined that clustering is complete.
3. The method according to claim 2, wherein: In the case where the cluster center changes, the step of returning to the step of calculating the first distance between all the vector samples other than the cluster center and each of the cluster centers is executed.
4. The method according to claim 2, wherein the step of initializing N cluster centers comprises: Randomly select one of the vector samples as the first cluster center; Calculating the second distances between all the vector samples other than the first cluster center and the first cluster center, and selecting the vector sample with the largest second distance as the next cluster center; Calculating the third distances of all the vector samples other than the cluster center to the nearest cluster center, and selecting the vector sample with the largest third distance as the next cluster center; Determining whether N cluster centers have been selected; as well as If so, confirm that initialization is complete.
5. The method according to claim 4, wherein: In the case that the N cluster centers are not selected, the step of returning to the step of calculating the third distances from all the vector samples other than the cluster centers to the cluster centers closest thereto is performed.
6. The method according to claim 2, wherein the step of using the index to perform an approximate query on the nearest neighbor vector of the query vector comprises: Set the number of clusters to be queried M, where the number of clusters M is a positive integer between 1 and N; Calculating a fourth distance between the query vector and each of the cluster centers, and sorting the clusters according to the fourth distances; as well as Calculate the fifth distance between the query vector and each of the vector samples in the M classes with the smallest fourth distance, sort the vector samples in the M classes according to the magnitude of the fifth distance, and return k vector samples with the smallest fifth distance as a result.
7. The method according to claim 2, wherein: The first distance includes Euclidean distance, cosine distance, negative inner product distance or user-defined distance.
8. The method according to claim 2, wherein the step of recalculating the cluster center of each of the classes comprises: The average value of all the vector samples in each of the classes is taken as the new cluster center.
9. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the index construction and retrieval method of the vector database described in any one of claims 1 to 8 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the index construction and retrieval method of the vector database described in any one of claims 1 to 8 is implemented.
Citation Information
Cited By
Systems and methods for multi-stage search and distance approximation in high-dimensional feature vector spaces
TWI929893B
