Method and apparatus for creating a vector index in a database

By dividing vector data into multiple data shards according to the primary key and creating independent indexes, the problem of excessive memory consumption in existing technologies is solved, and efficient vector index creation and management are achieved.

CN123138249APending Publication Date: 2026-11-20WUHAN DAMENG DATABASE
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611407935.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-11
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

Existing technologies require a large amount of memory to create vector indexes, especially for large-scale data, leading to problems such as insufficient memory and index creation failure.

Method used

By dividing vector data into multiple data shards based on the primary key and creating an independent index for each shard, and using an auxiliary table to store shard metadata and change logs, the amount of data in each shard can be controlled, reducing the memory and computing resources required for a single index building.

Benefits of technology

It effectively reduces the memory requirements of each vector index during creation, improves index building efficiency, reduces memory usage and computing resource consumption, and supports efficient index creation for large-scale data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123138249A_ABST
    Figure CN123138249A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of vector index, in particular to a method and device for creating a vector index in a database. The method comprises the following steps: acquiring vector data in a database table and a primary key of each vector data; dividing all the vector data according to the primary key and a preset size to obtain a plurality of data shards; determining an index algorithm according to the data type of the vector data; using the index algorithm to structurally organize and feature code the vector data in the data shard with a data volume equal to the preset size, so as to obtain a vector index of each data shard. The application can effectively reduce the memory required by each vector index during creation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of vector indexing technology, and in particular to a method and apparatus for creating vector indexes in a database. Background Technology

[0002] With the rapid development of artificial intelligence and big data applications, the demand for processing unstructured data (such as text, images, and audio) is increasing daily. When handling tasks such as semantic understanding, content recommendation, and image recognition, this unstructured data is typically transformed into vector data by deep learning models. How to efficiently store and retrieve this vector data is a problem that needs to be solved. However, in the early days, there were no dedicated databases for storing and managing vector data; instead, vector search engines, such as FAISS (Facebook AI Similarity Search), were used to handle similarity issues in recommendation systems. With technological advancements, some standardized database products, such as Elasticsearch, PostgreSQL, and Remote Dictionary Server (Redis), have integrated vector retrieval functionality. They provide basic vector retrieval capabilities, but their retrieval performance and applicable scenarios are limited, making them unsuitable for high-dimensional vector similarity retrieval tasks. The rapid development of Large Language Models (LLMs), represented by ChatGPT, has driven a dramatic increase in the reliance of Artificial Intelligence (AI) applications on vector data. LLM needs to process and remember massive amounts of embedded vectors during generation, retrieval, and inference, which places higher demands on the storage efficiency, retrieval speed, and system scalability of vector data. Vector databases are designed to store and retrieve vector data. Through efficient indexing algorithms, vector databases greatly improve the speed and performance of large-scale vector similarity searches, thereby supporting the real-time response needs of various AI applications.

[0003] Vector indexing is a key technology in vector databases. It optimizes the retrieval process by intelligently organizing vector embeddings, making it particularly suitable for large and complex datasets. Vector indexing technology uses different algorithms to group similar vectors together, thereby accelerating similarity searches and pattern recognition.

[0004] However, vector indexes have some drawbacks. For example, the time and memory required to create an index are closely related to the amount of data. For large-scale data, creating a vector index requires retrieving all the data in memory and building intermediate structures. The vector index building phase usually requires a large amount of memory, central processing unit (CPU), and temporary disk space. If memory is insufficient, the database will perform frequent disk swapping. In extreme cases (such as memory overflow or timeout), the index creation process may fail directly.

[0005] Therefore, overcoming the shortcomings of the existing technology is an urgent problem to be solved in this technical field. Summary of the Invention

[0006] In view of the above-mentioned defects or improvement needs of the existing technology, the present invention proposes a method and apparatus for creating vector indexes in a database, which can effectively reduce the memory required for each vector index during creation.

[0007] The embodiments of the present invention adopt the following technical solutions: In a first aspect, the present invention provides a method for creating a vector index in a database, specifically: obtaining vector data from a database table, and the primary key of each vector data; Based on the primary key and preset size, all the vector data are divided to obtain multiple data fragments; The indexing algorithm is determined based on the data type of the vector data; For data segments of a preset size, the indexing algorithm is used to perform structured organization and feature encoding of the vector data within the data segments to obtain the vector index of each data segment.

[0008] Preferably, the method further includes: Create an auxiliary table, wherein the auxiliary table is used to store the metadata of each data shard; For a data shard, obtain the identifier of the data shard, the shard range of the data shard, the shard capacity of the data shard, the vector index of the data shard, and the change log of the data shard; The identifier, the shard range, the shard capacity, the vector index, and the change log are stored in an auxiliary table, wherein the change log is used to store the changes in vector data in the data shard.

[0009] Preferably, the method further includes: The data shard corresponding to the largest identifier in the auxiliary table is taken as the first data shard; the shard capacity of the first data shard is obtained; If the fragment capacity is less than the preset capacity, then the insertion record of vector data is stored in the change log of the first data fragment, and the fragment capacity of the first data fragment is updated. If the shard capacity is equal to the preset capacity, then register the metadata of a new data shard in the auxiliary table, use the new data shard as the first data shard, store the insertion record of vector data in the change log of the first data shard, and update the shard capacity of the first data shard.

[0010] Preferably, after updating the fragment capacity of the first data fragment, the following steps are included: Obtain the latest fragment capacity of the first data fragment; If the latest shard capacity is equal to the preset capacity, then within the first data shard, the indexing algorithm is used to perform structured organization and feature encoding of the vector data to obtain the vector index of the first data shard.

[0011] Preferably, the method further includes: Obtain the data to be deleted, and the primary key of the data to be deleted; Determine the second data shard corresponding to the data to be deleted based on the shard range into which the primary key of the data to be deleted falls; The deletion record of the data to be deleted is stored in the change log of the second data segment.

[0012] Preferably, the method further includes: Obtain the data to be updated, and the primary key of the data to be updated; The third data shard corresponding to the data to be updated is determined based on the shard range into which the primary key of the data to be updated falls; The update records of the data to be updated are stored in the change log of the third data shard.

[0013] Preferably, the method further includes: Get the change log for each data shard; All data shards with non-empty change logs are designated as the fourth data shard; Based on the deletion records in the change log of the fourth data shard, mark the vector data that needs to be deleted in the vector index of the fourth data shard; based on the update records in the change log of the fourth data shard, mark the vector data that needs to be updated in the vector index of the fourth data shard. The vector indices of all data shards are traversed in parallel to obtain multiple target vector data corresponding to each data shard; all target vector data are merged, and the first k target vector data are used as the query result.

[0014] Preferably, the method further includes: For a data shard, during the process of traversing the vector index of the data shard, all marked vector data are skipped to obtain at least one original vector data. Traverse the insertion records in the change log of the data shard to obtain at least one intermediate query result; All original vector data and all intermediate vector data are merged to obtain multiple target vector data corresponding to a data slice.

[0015] In a second aspect, the present invention provides an apparatus for creating a vector index in a database, the apparatus comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the processor for performing the method for creating a vector index in a database as described in the first aspect.

[0016] Thirdly, the present invention also provides a non-volatile computer storage medium storing computer-executable instructions that are executed by one or more processors to perform the method for creating a vector index in a database as described in the first aspect.

[0017] Compared with existing technologies, the advantages of this invention are as follows: Existing technologies typically require loading all vector data into memory and constructing intermediate structures when creating vector indexes, thus often consuming a large amount of memory during the index construction phase. However, the method provided in this embodiment divides all vector data according to the primary key to obtain multiple data shards, thereby ensuring that the amount of data in each data shard is controllable, thereby controlling the resources required for index creation for each data shard. Furthermore, each data shard is indexed independently, further reducing the memory and computing resources required for a single index construction. This design can effectively reduce the memory required for each index creation. Attached Figure Description

[0018] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments of the present invention will be briefly described below. Obviously, the drawings described below are merely some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without any creative effort.

[0019] Figure 1 This is a flowchart illustrating a method for creating a vector index in a database, as provided in an embodiment of the present invention. Figure 2 This is a flowchart illustrating a method for inserting vector data into a database table according to an embodiment of the present invention; Figure 3 This is a flowchart illustrating a method for deleting vector data from a database table, as provided in an embodiment of the present invention. Figure 4 This is a flowchart illustrating a method for updating vector data in a database table according to an embodiment of the present invention; Figure 5 This is a flowchart illustrating a method for querying vector data provided in an embodiment of the present invention; Figure 6 A schematic diagram of the structure of a device for creating a vector index in a database, provided in an embodiment of the present invention; The reference numerals in the attached figures are as follows: 21: Processor; 22: Memory. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0021] Unless the context otherwise requires, throughout the specification and claims, the term "comprising" is interpreted as openly inclusive, meaning "including, but not limited to." In the description of the specification, terms such as "one embodiment," "some embodiments," "exemplary embodiment," "example," "specific example," or "some examples" are intended to indicate that a particular feature, structure, material, or characteristic associated with that embodiment or example is included in at least one embodiment or example of this disclosure. The illustrative representations of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics mentioned may be included in any suitable manner in any one or more embodiments or examples; that is, although they may be incorporated into embodiments or examples using the above terms for reasons such as order and position, it does not limit them to be incorporated in combination by a single embodiment or example.

[0022] In the description of this invention, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined with "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of embodiments of this disclosure, unless otherwise stated, "a plurality of" means two or more. Furthermore, for example, the description may use the prefix "A" or "B" to describe the same type of nouns as two independent entities. In this case, the corresponding features defined with "A" and "B" are used only to distinguish between similar entities and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features.

[0023] In the description of this invention, the expression “A and / or B” (where A and B are used to formally represent specific features) will be used. The corresponding expression includes the following three combinations: only A, only B, and a combination of A and B.

[0024] As used in this invention, “about,” “approximately,” or “approximately” includes the stated value and the average value within an acceptable range of deviation from a particular value, wherein the acceptable range of deviation is determined by a person skilled in the art taking into account the measurement under discussion and the error associated with the measurement of the particular quantity (i.e., the limitations of the measurement system).

[0025] Furthermore, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0026] Example 1: like Figure 1 As shown, Embodiment 1 of the present invention provides a method for creating a vector index in a database, which specifically includes the following steps: Step 101: Obtain the vector data from the database table, and the primary key of each vector data.

[0027] In one embodiment, vector data can be obtained from an artificial intelligence model, a recommendation system, or other data sources. When the vector data is stored in the database, it is stored in a prescribed format. That is, each record in the database includes a primary key, corresponding vector data, and other column data (such as timestamps, tags, etc.). The primary key can be a rowid.

[0028] Step 102: Divide all the vector data according to the primary key and the preset size to obtain multiple data fragments.

[0029] In one embodiment, the preset size can be set according to the actual scenario to ensure that the number of vector data in each data shard is moderate, facilitating parallel processing and memory management of subsequent data shards. The primary key is unique and increments sequentially. Vector data in the database table is scanned row by row according to the ascending order of the primary key. Multiple vectors that meet the preset size are divided into a data shard. This scanning continues until all vector data has been scanned, resulting in multiple data shards. At this point, the last data shard contains less than or equal to the preset size, while the other data shards contain the same number of vector data, all within the preset size. For example, if the preset size is set to 65536, the vector data is scanned sequentially. Vector data with a primary key range of 1-65536 is divided into the first data shard, and vector data with a primary key range of 65536-131071 is divided into the second data shard.

[0030] In one embodiment, when scanning vector data in a database table row by row, if the primary key of some vector data is deleted, the primary key is no longer contiguous. It is necessary to recalculate the range of the currently valid primary keys and divide the vector data within the range of valid primary keys into a data shard. That is, it is necessary to ensure that the number of vector data contained in a data shard is a preset size. For example, if primary keys 3, 8, and 345 are deleted during the scanning process, the primary key range of the first data shard is 1-65539.

[0031] Step 103: Determine the indexing algorithm based on the data type of the vector data.

[0032] In one embodiment, since the data types of vector data in a database table may be different, an indexing algorithm suitable for that data type can be determined based on the data type of more than half of all vector data. The vector data types include floating-point numbers or integer vectors. The indexing algorithm can use traditional vector indexing algorithms, such as Inverted File with Flat Quantization (IVFFLAT), Hierarchical Navigable Small World graphs (HNSW), Product Quantizer (PQ), Scalar Quantizer (SQ), etc., or a custom indexing algorithm based on the application scenario. Specifically, the IVFFLAT algorithm relies on a clustering algorithm to calculate several cluster centers from all the vector data used to construct the index, with each cluster center maintaining an inverted index. The HNSW algorithm constructs multi-level small world graphs to represent the similarity relationships between vector data. Both the PQ and SQ algorithms decompose the original vector space of the vector data into the Cartesian product of several low-dimensional vector spaces and quantize these low-dimensional vector spaces separately.

[0033] Step 104: For data segments with a data volume equal to a preset size, use the indexing algorithm to perform structured organization and feature encoding on the vector data within the data segments to obtain the vector index of each data segment.

[0034] In one embodiment, each data shard uses the indexing algorithm determined in step 103 when creating a vector index. Based on the description in step 102 (the number of vector data in the last data shard is less than or equal to a preset size) and the constraints for creating the vector index, it is known that the last data shard may or may not have a vector index. Each of the other data shards, excluding the last one, corresponds to a vector index. The resulting vector index supports efficient similarity retrieval. Specifically, the vector index constructed using the IVFFLAT algorithm divides the vector data into multiple clusters, narrowing the global search to the most relevant clusters, thereby accelerating index query efficiency. The vector index constructed using the HNSW algorithm can narrow the retrieval range through a small world graph, thus accelerating index query efficiency. Furthermore, each data shard can perform index creation in parallel across multiple processing threads, thereby accelerating the index creation process and maximizing the utilization of multi-core processor capabilities.

[0035] In this embodiment, existing technologies typically require loading all vector data into memory and constructing an intermediate structure when creating a vector index, thus consuming a significant amount of memory during the index construction phase. However, the method provided in this embodiment divides all vector data into multiple data shards based on the primary key, thereby ensuring that the data volume of each data shard is controllable. This controls the resources required for index creation for each data shard, and since each data shard is indexed independently, the memory and computing resources required for a single index construction are further reduced. This design effectively reduces the memory required for each index creation.

[0036] An auxiliary table can be created to store the metadata of each data shard. Specifically, the auxiliary table is created to store the metadata of each data shard. For a data shard, the identifier, shard range, shard capacity, vector index, and change log of the data shard are obtained. The identifier, shard range, shard capacity, vector index, and change log are stored in the auxiliary table, where the change log stores the changes in vector data within the data shard. The metadata includes the identifier, shard range, shard capacity, vector index, and change log. To continuously track changes in vector data within the data shard, the creation time and last update information of each shard can also be stored. The structure of the auxiliary table is as follows: CREATE TABLE vector_index_auxiliary ( id INTEGER PRIMARY KEY, start_rowid INTEGER NOT NULL, end_rowid INTEGER NOT NULL, element_count INT NOT NULL, index_blob BLOB NOT NULL, change_log BLOB, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP); Each data shard can be uniquely identified by an identifier, which is incrementing. The last data shard's metadata is stored in the auxiliary table, and its identifier is the largest. The shard range is the range of primary keys for the vector data contained within each shard. The starting primary key of a shard is the primary key of the first vector data contained in that shard, and the ending primary key is the primary key of the last vector data contained in that shard. Vector indexes can be compressed using serialization, and the compressed vector data is stored in the auxiliary table to reduce memory and disk usage and accelerate index loading. The auxiliary table structure includes the identifier in the `id` column, the starting primary key in the `start_rowid` column, the ending primary key in the `end_rowid` column, the shard capacity in the `element_count` column, the compressed vector data in the `index_blob` column, the change log in the `change_log` column, the creation time in the `created_at` column, and the last update information in the `updated_at` column.

[0037] By adding columns for storing vector indexes and change logs to each data shard, the auxiliary table can not only effectively manage vector indexes but also track the addition, deletion, and modification operations of vector data in the data shards.

[0038] like Figure 2 As shown in the figure, this embodiment provides a method for inserting vector data into a database table, which specifically includes the following steps: Step 201: Take the data shard corresponding to the largest identifier in the auxiliary table as the first data shard; obtain the shard capacity of the first data shard.

[0039] In one embodiment, when inserting vector data into the database, due to the unique and auto-incrementing nature of the primary key of the vector data, the vector data will only be inserted at the end of the database table. Therefore, when updating the metadata in the auxiliary table, the vector data is inserted into the last data shard by default. The last data shard (i.e., the first data shard) can be located based on the largest identifier, and the metadata of the first data shard can be updated.

[0040] Step 202: If the shard capacity is less than the preset capacity, then store the insertion record of vector data in the change log of the first data shard and update the shard capacity of the first data shard.

[0041] In one embodiment, the preset capacity is the preset size in step 102, that is, specifying the number of vector data items contained in the data shard. When the shard capacity is less than the preset capacity, it means that the first data shard is not full. At this time, the vector data will be inserted at the end of the database table, forming a corresponding insertion record. The insertion record is stored in the change log of the first data shard in the auxiliary table, and the shard capacity of the first data shard is incremented by one to obtain the latest shard capacity. Accordingly, the primary key of the vector data is used as the end primary key of the first data shard.

[0042] Furthermore, a vector index is only created for a data shard when its capacity equals the preset capacity. Even if a data shard is never full, no index needs to be created. While queries may use a brute-force search method, the limited amount of vector data within the shard results in a low search cost, and the recall rate is the highest compared to all other indexes. Therefore, it does not affect overall query performance and yields better results. This design reduces the overhead of frequently creating indexes and optimizes performance. Therefore, when the capacity of the first data shard is updated, the latest capacity of the first data shard needs to be obtained. If the latest capacity equals the preset capacity, it means the first data shard is full. Then, within the first data shard, the indexing algorithm described in step 103 is used to perform structured organization and feature encoding on the vector data to obtain the vector index of the first data shard. Since the shard range of the first data shard is updated each time new vector data is inserted, the shard range includes the primary key of the newly inserted vector data. When the latest capacity of the first data shard equals the preset capacity, all vector data is retrieved from the database table according to the shard range of the first data shard. At this time, all vector data includes the original vector data in the first data shard and the newly inserted vector data. The indexing algorithm described in step 103 is used to perform structured organization and feature encoding on all vector data to obtain the vector index of the first data shard. If the latest capacity is less than the preset capacity, it means the first data shard is not full, and a vector index is not created for the first data shard.

[0043] Step 203: If the shard capacity is equal to the preset capacity, then register the metadata of a new data shard in the auxiliary table, use the new data shard as the first data shard, store the insertion record of vector data in the change log of the first data shard, and update the shard capacity of the first data shard.

[0044] In one embodiment, if the shard capacity equals the preset capacity, it means the first data shard is full and cannot accommodate new vector data. On one hand, the metadata of the new data shard needs to be registered in the auxiliary table. At this time, the identifier of the new data shard is the largest, indicating that this new data shard has become the last data shard. On the other hand, physical space for storing vector data can be actually allocated in the underlying storage, that is, the physical space of the new data shard. When vector data needs to be inserted later, the metadata of this new data shard is updated until this new data shard can no longer accommodate new vector data, and then the metadata of another new data shard is registered in the auxiliary table. In addition, after the shard capacity of the first data shard is updated, it is determined whether a vector index needs to be created for this data shard according to the method in step 202.

[0045] like Figure 3 As shown in the figure, this embodiment provides a method for deleting vector data in a database table, which specifically includes the following steps: Step 301: Obtain the data to be deleted, and the primary key of the data to be deleted.

[0046] Step 302: Determine the second data shard corresponding to the data to be deleted based on the shard range into which the primary key of the data to be deleted falls.

[0047] In one embodiment, when vector data needs to be deleted from the database, it is necessary to first determine which data shard the deletion operation belongs to based on the primary key of the data to be deleted, and then update the metadata of that data shard. Each data shard is defined by a start primary key and an end primary key, and the shard range of the data shard can be determined based on the shard range into which the primary key of the data to be deleted falls.

[0048] Step 303: Store the deletion record of the data to be deleted in the change log of the second data shard.

[0049] In one embodiment, based on the primary key of the data to be deleted, the corresponding vector data in the database table is deleted, and a corresponding deletion record is formed. However, the vector index of the first data shard in the auxiliary table is not changed at this time. Instead, the deletion record is stored in the change log of the second data shard, and the shard capacity of the second data shard is reduced by one accordingly. If the primary key of the data to be deleted is the starting primary key or the ending primary key of the second data shard, then the starting primary key or the ending primary key of the second data shard needs to be updated. The change log records the change history of the changed data (data to be deleted, data to be updated), including the primary key of the deleted data, the deletion timestamp, and the operation type. Storing the deletion record in the change log can ensure that these deletion operations are taken into account in subsequent queries and index reconstruction.

[0050] like Figure 4 As shown in the figure, this embodiment provides a method for updating vector data in a database table, which specifically includes the following steps: Step 401: Obtain the data to be updated, and the primary key of the data to be updated.

[0051] In one embodiment, a record in a database table includes not only the primary key and vector data, but also non-vector data such as update timestamps and tags. Before updating the metadata of the data shards, it is necessary to determine whether the object to be updated is vector data or non-vector data. If the object to be updated is non-vector data, there is no need to update the metadata of the data shards in the auxiliary table. If the object to be updated is vector data, the primary key of the data to be updated is obtained.

[0052] Step 402: Determine the third data shard corresponding to the data to be updated based on the shard range into which the primary key of the data to be updated falls.

[0053] In one embodiment, the third data shard corresponding to the data to be updated is determined by the shard range into which the primary key of the data to be updated falls.

[0054] Step 403: Store the update record of the data to be updated in the change log of the third data shard.

[0055] In one embodiment, based on the primary key of the data to be updated, the corresponding vector data in the database table is updated, and a corresponding update record is formed. The update record is stored in the change log of the third data shard, and the update operation of the vector data is taken into account in subsequent queries and index reconstruction.

[0056] Furthermore, since the core objective of vector indexing is to quickly find the vector most similar to the query vector in a high-dimensional space, this typically relies on complex structured indexing algorithms, such as IVF, HNSW, PQ, and SQ indexing algorithms. These indexing algorithms are characterized by strong global relevance and high modification costs; frequent insertions, deletions, and updates consume significant memory and CPU resources. Therefore, in this embodiment, insertion, update, and deletion operations do not immediately correspond to the vector index of the data shard. Instead, the vector index of the corresponding shard is updated periodically through index reconstruction to improve efficiency and avoid the performance overhead of real-time cleanup. Index reconstruction specifically involves: retrieving multiple vector data points (including inserted, updated, and deleted vector data) from the database table based on the shard range of the data shard, resulting in a new data shard. Within the new data shard, the indexing algorithm from step 103 is used to perform structured organization and feature encoding on the vector data, yielding a new vector index for the data shard. Based on the shard identifier, the new vector index for the data shard is then re-stored in an auxiliary table. During index reconstruction, for each data shard, the vector index for the data shard is updated, the change log is cleared, while the shard range and shard capacity remain unchanged. Alternatively, the change log can be monitored; when the number of records in the change log reaches a threshold, index reconstruction is performed for the corresponding shard.

[0057] In addition, to further reduce performance overhead, an incremental update method can be adopted, that is, only the vector index of the affected data shard is updated, instead of recreating the vector index of each data shard. The affected data shard refers to the data shard in which new data is inserted, or the vector data contained in the data shard is deleted, or the vector data contained in the data shard is updated.

[0058] like Figure 5 As shown, this embodiment provides a method for querying vector data, which specifically includes the following steps: Step 501: Obtain the change log for each data shard.

[0059] In one embodiment, the change log of each data shard stores insert records, delete records, and update records. Each record has a corresponding primary key, operation type (insert, delete, or update), and operation timestamp.

[0060] In one embodiment, the vector indexes in the auxiliary table can be read, and the vector indexes of each data shard can be loaded into memory, thereby ensuring that frequent disk accesses are not required during the query process, thus improving query speed. Alternatively, a memory pool can be used to manage the vector indexes of the data shards loaded into memory, ensuring that the memory pool maximizes memory reuse, avoids memory fragmentation, and achieves efficient memory allocation and reclamation.

[0061] Furthermore, if the query conditions include primary key range constraints, the data shards to be loaded can be determined through these primary key constraints, thereby reducing the number of vector indexes that need to be traversed for the data shards.

[0062] Step 502: Use all data shards with non-empty change logs as the fourth data shard.

[0063] In one embodiment, since the change log stores changes to vector data within a data shard, it will be empty if no operations are performed on the vector data. Therefore, the emptiness of the change log can be used to determine if a data shard has been changed. If no changes have occurred, the vector indices of the data shards can be directly traversed; if changes have occurred, the insertion, deletion, and update of vector data within the shard must be considered.

[0064] Step 503: Based on the deletion records in the change log of the fourth data shard, mark the vector data that needs to be deleted in the vector index of the fourth data shard; based on the update records in the change log of the fourth data shard, mark the vector data that needs to be updated in the vector index of the fourth data shard.

[0065] In one embodiment, for deleted vector data, since the deleted vector data has not yet been updated in the vector index of the data shard during retrieval (i.e., the deleted vector data is still stored in the vector index), it should not be scanned when scanning the vector index. This embodiment ensures that the deleted vector data will not be scanned by marking it in the vector index. For inserted new vector data, since the new vector data has not yet been updated in the vector index of the data shard during retrieval (i.e., the new vector data does not exist in the vector index), it will not be scanned when scanning the vector index. After scanning the vector index once, the new vector data still needs to be scanned.

[0066] In one embodiment, the type of operation in the change log determines whether the record is an insert, update, or delete record. If it is a delete record, the vector data for which the delete operation needs to be performed is marked in the vector index of the data shard based on the stored delete record, and the vector data is marked as "deleted". If it is an update record, the vector data for which the update operation needs to be performed is marked in the vector index of the data shard based on the stored update record, and the vector data is marked as "updated".

[0067] Step 504: Traverse the vector indices of all data shards in parallel to obtain multiple target vector data corresponding to each data shard; merge all the target vector data and use the first k target vector data as the query result.

[0068] In one embodiment, existing indexing algorithms, such as HNSW's multi-level tree structure, IVF-based clustering algorithms, and quantization algorithms like PQ and SQ, struggle to effectively split tasks when creating and scanning indexes. The creation and scanning of a single vector index are often limited by single CPU core performance and I / O throughput, making it difficult to leverage multi-core advantages. When the index is very large (tens of GB or even hundreds of GB), scanning latency and I / O contention become more pronounced. The difficulty and implementation of parallelization vary, leading to inconsistent results and limited parallelization capabilities. This embodiment, however, shards a large database table, with each shard possessing an independent vector index. Queries can be performed automatically or manually in a distributed parallel manner (e.g., scanning the indexes of each shard separately using concurrent threads), achieving parallel utilization of multi-core CPUs, distributing I / O across multiple storage nodes, and significantly reducing query latency.

[0069] In one embodiment, for a data shard, the vector index of that data shard is read from memory, and the vector index is traversed to obtain multiple target vector data that satisfy the query conditions within that data shard. The same operation is performed on each data shard to obtain multiple target vector data corresponding to each data shard. From the target vector data of all data shards, only the top K most relevant target results are retained as the query results. This design improves query efficiency while reducing unnecessary computation and memory consumption. Furthermore, during the retrieval process, the vector indexes of all data shards can be retrieved in parallel. This parallel processing method can maximize the use of multi-core processors to accelerate the query process. In one embodiment, since an update operation is equivalent to both a delete and an insert operation, to ensure the accuracy and completeness of the query results, during the traversal of the vector index of each data shard, the retrieval engine skips all marked vector data during the first scan. After completion, a brute-force search method is used to further search from the updated data to obtain the target vector data. Specifically, for a data shard, during the traversal of the vector index of the data shard, all marked vector data is skipped to obtain at least one original vector data; the insertion records in the change log of the data shard are traversed to obtain at least one intermediate query result; all original vector data and all intermediate vector data are merged to obtain multiple target vector data corresponding to one data shard.

[0070] Example 2: Based on the method for creating vector indexes in a database provided in the foregoing embodiments, the present invention also provides an apparatus for creating vector indexes in a database that can be used to implement the above method, such as... Figure 6 The diagram shown is a schematic representation of the device architecture according to an embodiment of the present invention. The device for creating vector indexes in the database in this embodiment includes one or more processors 21 and a memory 22. Figure 6 Take a processor 21 as an example.

[0071] Processor 21 and memory 22 can be connected via a bus or other means. Figure 6 Taking the example of a connection between China and Israel via a bus.

[0072] The memory 22 serves as a non-volatile computer-readable storage medium for creating vector indexes in a database. It can be used to store non-volatile software programs and non-volatile computer-executable programs, such as the method for creating vector indexes in a database in the foregoing embodiments. The processor 21 executes various functional applications and data processing of the device for creating vector indexes in a database by running the non-volatile software programs, instructions, and modules stored in the memory 22, thereby implementing the method for creating vector indexes in a database in the foregoing embodiments.

[0073] Memory 22 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 22 may include memory remotely located relative to processor 21, which may be connected to processor 21 via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0074] The program instructions / modules are stored in memory 22. When executed by one or more processors 21, they perform the method for creating the vector index in the database as described in the foregoing embodiments, for example, performing the above-described... Figures 1-5 The steps shown.

[0075] This invention also provides a non-volatile computer storage medium storing computer-executable instructions that are executed by one or more processors, for example... Figure 6 One of the processors 21 can enable the one or more processors to execute the method for creating a vector index in the database as described in the foregoing embodiments, for example, to perform the above-described... Figures 1-5 The steps shown.

[0076] It is worth noting that the information interaction and execution process between the modules and units in the above-mentioned device and system are based on the same concept as the processing method embodiment of the present invention. For details, please refer to the description in the method embodiment of the present invention, and will not be repeated here.

[0077] Those skilled in the art will understand that all or part of the steps in the various methods of the embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, which may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0078] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for creating a vector index in a database, characterized in that, include: Retrieve vector data from a database table, and the primary key of each vector data; Based on the primary key and preset size, all the vector data are divided to obtain multiple data fragments; The indexing algorithm is determined based on the data type of the vector data; For data segments of a preset size, the indexing algorithm is used to perform structured organization and feature encoding of the vector data within the data segments to obtain the vector index of each data segment.

2. The method for creating a vector index in a database according to claim 1, characterized in that, The method further includes: Create an auxiliary table, wherein the auxiliary table is used to store the metadata of each data shard; For a data shard, obtain the identifier of the data shard, the shard range of the data shard, the shard capacity of the data shard, the vector index of the data shard, and the change log of the data shard; The identifier, the shard range, the shard capacity, the vector index, and the change log are stored in an auxiliary table, wherein the change log is used to store the changes in vector data in the data shard.

3. The method for creating a vector index in a database according to claim 2, characterized in that, The method further includes: The data shard corresponding to the largest identifier in the auxiliary table is taken as the first data shard; the shard capacity of the first data shard is obtained; If the fragment capacity is less than the preset capacity, then the insertion record of vector data is stored in the change log of the first data fragment, and the fragment capacity of the first data fragment is updated. If the shard capacity is equal to the preset capacity, then register the metadata of a new data shard in the auxiliary table, use the new data shard as the first data shard, store the insertion record of vector data in the change log of the first data shard, and update the shard capacity of the first data shard.

4. The method for creating a vector index in a database according to claim 3, characterized in that, After updating the fragment capacity of the first data fragment, the following is included: Obtain the latest fragment capacity of the first data fragment; If the latest shard capacity is equal to the preset capacity, then within the first data shard, the indexing algorithm is used to perform structured organization and feature encoding of the vector data to obtain the vector index of the first data shard.

5. The method for creating a vector index in a database according to claim 2, characterized in that, The method further includes: Obtain the data to be deleted, and the primary key of the data to be deleted; Determine the second data shard corresponding to the data to be deleted based on the shard range into which the primary key of the data to be deleted falls; The deletion record of the data to be deleted is stored in the change log of the second data segment.

6. The method for creating a vector index in a database according to claim 2, characterized in that, The method further includes: Obtain the data to be updated, and the primary key of the data to be updated; The third data shard corresponding to the data to be updated is determined based on the shard range into which the primary key of the data to be updated falls; The update records of the data to be updated are stored in the change log of the third data shard.

7. The method for creating a vector index in a database according to claim 2, characterized in that, The method further includes: Get the change log for each data shard; All data shards with non-empty change logs are designated as the fourth data shard; Based on the deletion records in the change log of the fourth data shard, mark the vector data that needs to be deleted in the vector index of the fourth data shard; based on the update records in the change log of the fourth data shard, mark the vector data that needs to be updated in the vector index of the fourth data shard. The vector indices of all data shards are traversed in parallel to obtain multiple target vector data corresponding to each data shard; all target vector data are merged, and the first k target vector data are used as the query result.

8. The method for creating a vector index in a database according to claim 7, characterized in that, The method further includes: For a data shard, during the process of traversing the vector index of the data shard, all marked vector data are skipped to obtain at least one original vector data. Traverse the insertion records in the change log of the data shard to obtain at least one intermediate query result; All original vector data and all intermediate vector data are merged to obtain multiple target vector data corresponding to a data slice.

9. A device for creating vector indexes in a database, characterized in that, The apparatus for creating vector indexes in the database includes: At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor for performing the method for creating a vector index in a database as described in any one of claims 1-8.

10. A non-volatile computer storage medium, characterized in that, The computer storage medium stores computer-executable instructions that are executed by one or more processors to perform the method for creating a vector index in a database as described in any one of claims 1-8.