Method and system for optimizing HNSW index algorithm based on graph database and computer equipment

By introducing a heat gradient table into the HNSW index and optimizing the data hierarchy, the problem of low query efficiency and inability to guarantee the accuracy of HNSW index under large data volume is solved, and more efficient and accurate query is achieved.

CN119474469APending Publication Date: 2025-02-18JIANGSU DAMENG DATABASE CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411609577.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-12
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

Due to data hierarchy randomness, HNSW indexes cannot guarantee the inefficiency and accuracy of query when large data volumes are not available.

Method used

Introduce a heat gradient table to optimize the HNSW data hierarchy, determine the hierarchy position of the data through the heat gradient table, and ensure that high-frequency data is at the high level to improve query efficiency and accuracy.

Benefits of technology

It improves the query efficiency and accuracy of HNSW index, is suitable for more business scenarios, and solves the problem that traditional HNSW algorithms have too long or cannot query high-frequency data query time under large data volumes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119474469A_ABST
    Figure CN119474469A_ABST
Patent Text Reader

Abstract

The invention discloses an HNSW index algorithm optimization method and system based on a graph database and computer equipment, and the method comprises the steps: obtaining a current heat gradient table, comparing the current heat gradient table with a heat gradient table snapshot of a last optimization record, and obtaining a heat gradient table relative difference; only when the relative difference of the popularity gradient tables is greater than a set threshold value, optimization is carried out according to the following contents: data not in the current popularity gradient table are randomly sent to a low level of the HNSW index; inserting data in the current popularity gradient table into the upper hierarchy of the HNSW index, and updating the current popularity gradient table; after the optimization is completed, recording a current heat gradient table snapshot; by introducing the heat gradient table, the data hierarchy of the HNSW index algorithm is optimized, so that the retrieval speed of the high-frequency data is higher, the accuracy is higher, and the method is suitable for more business scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of data storage and retrieval technology, and specifically relates to a HNSW index algorithm optimization method, system and computer equipment based on a graph database. Background Art

[0002] The HNSW index (Hierarchical Navigable Small World Index) is an efficient approximate nearest neighbor search algorithm that uses the characteristics of the small world graph structure to achieve fast search through a hierarchical structure. Currently, the industry still uses random seeds to randomly determine the data hierarchy for the stratification of HNSW data. However, since the inserted data will randomly enter each layer, when the amount of data is large enough, the query efficiency will still be limited. As an approximate search algorithm, the accuracy cannot be guaranteed.

[0003] Specifically, when a query begins to search, it will search from the top-level entrance, from top to bottom. The high-level data is one entrance at a time, and the neighbors of the search provide the entrance to the next level until the bottom level. Since HNSW will randomly place data at different levels, it is very easy to cause high-frequency data or data in the center of the data set to fail to be stored at higher levels, and even low-frequency data at the corners to occupy high-level positions. When searching, it will take more paths (entrances) to find the required data through the high-level entrance, or even fail to find it (HNSW will not search the full text, and data that is far away will be sacrificed). Therefore, a method is needed to further improve query efficiency and accuracy. Summary of the invention

[0004] Purpose of the invention: HNSW has certain limitations when it comes to large amounts of data due to the randomness of inserted data. In order to solve the performance bottleneck and accuracy problems of HNSW indexes when it comes to large amounts of data, the present invention proposes a HNSW index algorithm optimization method, system, and computer device based on a graph database. By introducing a heat gradient table into the database, the HNSW data hierarchy is optimized to achieve the effect of improving query efficiency and accuracy.

[0005] Technical solution: A method for optimizing the HNSW index algorithm based on a graph database, comprising the following steps:

[0006] Get the current heat gradient table, compare the current heat gradient table with the heat gradient table snapshot recorded in the last optimization, and get the relative difference of the heat gradient table;

[0007] Only when the relative difference of the heat gradient table is greater than the set threshold, the optimization is performed as follows: data not in the current heat gradient table is randomly moved to the lower level of the HNSW index; data in the current heat gradient table is inserted into the upper level of the HNSW index, and the current heat gradient table is updated;

[0008] After the optimization is completed, the current thermal gradient table snapshot is recorded;

[0009] The heat gradient table determines the table structure of the data at the upper level of the HNSW index based on the data heat, or determines the table structure of the data at the upper level of the HNSW index based on user customization.

[0010] Furthermore, the data heat is determined by the sum of the data's entry and exit points.

[0011] Furthermore, the data heat is determined by the frequency with which the data is accessed.

[0012] Furthermore, an array is used to record the thermal gradient table snapshots, and the thermal gradient table snapshots can only be written sequentially or cleared completely. In the array, a header structure is added to record the relative differences of the thermal gradient table.

[0013] Furthermore, the index dictionary table is used to store the index ID, the thermal gradient table, the thermal gradient table snapshot and the thermal gradient table status field, wherein the thermal gradient table status field is used to identify whether the thermal gradient table exists.

[0014] Furthermore, initially, data is inserted into the HNSW index as follows:

[0015] Check the heat gradient table status field of the index dictionary table by index ID to check whether there is a user-defined heat gradient table for the index ID:

[0016] If it exists, the user-defined heat gradient table is found through the index ID, and the data to be inserted is checked whether it is in the user-defined heat gradient table. If it exists, the gradient of the data to be inserted is determined according to the user-defined heat gradient table, and the data is placed in the data level of the HNSW index. The heat gradient table is updated. If it does not exist, the data to be inserted is randomly inserted into the lower level of the HNSW index.

[0017] If it does not exist, the data to be inserted will be randomly inserted into each level of the HNSW index.

[0018] Furthermore, only when the relative difference of the heat gradient table is greater than the set threshold, the optimization is performed according to the following contents: data not in the current heat gradient table is randomly moved to the lower level of the HNSW index; data in the current heat gradient table is inserted into the upper level of the HNSW index, and the current heat gradient table is updated; the specific operations include:

[0019] Check the heat gradient table status field of the index dictionary table by index ID to check whether there is a user-defined heat gradient table for the index ID:

[0020] If it exists, find the user-defined heat gradient table through the index ID, and check whether the data to be inserted is in the user-defined heat gradient table. If it exists, place the data in the data level of the HNSW index according to the user-defined heat gradient table. If it does not exist, find the data's heat gradient table through the index ID, and check whether the data to be inserted is in the data's heat gradient table. If it exists, determine the gradient of the data to be inserted according to the data's heat gradient table, and place the data in the data level of the HNSW index. If it does not exist, randomly insert the data to be inserted into the lower level of the HNSW index.

[0021] If it does not exist, find the data's heat gradient table through the index ID and check whether the data to be inserted is in the data's heat gradient table. If it exists, determine the gradient of the data to be inserted based on the data's heat gradient table and place the data in the corresponding data level of the HNSW index. If it does not exist, randomly insert the data to be inserted into the lower level of the HNSW index.

[0022] Furthermore, only when the relative difference of the heat gradient table is greater than the set threshold, the optimization is performed according to the following contents: data not in the current heat gradient table is randomly moved to the lower level of the HNSW index; data in the current heat gradient table is inserted into the upper level of the HNSW index, and the current heat gradient table is updated; the specific operations include:

[0023] Create a new index for backup;

[0024] Use the old index ID to find its heat gradient table for snapshot and record the data position P1 of the old index at this time;

[0025] The insert thread is enabled, and data is inserted into the new index. The heat gradient table of the old index is used for structural optimization until the P1 node is reached, and the insert thread finishes its work.

[0026] Lock the data table;

[0027] The reorganization thread records the data position P2 of the old index at this time; makes the new index inherit the heat gradient table of the old index; deletes the old index and replaces it with the new one; enables the insertion thread and continues to update the new index until it reaches the P2 node, and the insertion thread finishes its work;

[0028] The reorganization thread unlocks the data table.

[0029] The present invention discloses a HNSW index algorithm optimization system based on a graph database, comprising:

[0030] The heat gradient table relative difference calculation module is used to obtain the current heat gradient table, compare the current heat gradient table with the heat gradient table snapshot recorded in the last optimization, and obtain the relative difference of the heat gradient table;

[0031] The optimization module is used to optimize according to the following contents only when the relative difference of the heat gradient table is greater than the set threshold: the data not in the current heat gradient table is randomly moved to the lower level of the HNSW index; the data in the current heat gradient table is inserted into the upper level of the HNSW index, and the current heat gradient table is updated;

[0032] The snapshot module is used to record the current thermal gradient table snapshot after the optimization is completed;

[0033] The heat gradient table determines the table structure of the data at the upper level of the HNSW index based on the data heat, or determines the table structure of the data at the upper level of the HNSW index based on user customization.

[0034] The present invention also discloses a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above-disclosed HNSW index algorithm optimization method based on a graph database are implemented.

[0035] The present invention also discloses a storage medium, wherein the storage medium stores an HNSW index algorithm optimization program, and when the HNSW index algorithm optimization program is executed by at least one processor, the steps of the above-disclosed HNSW index algorithm optimization method based on a graph database are implemented.

[0036] Beneficial effect: Compared with the prior art, the present invention optimizes the data hierarchy of the HNSW indexing algorithm by introducing a heat gradient table, making the retrieval speed of high-frequency data faster, more accurate, and applicable to more business scenarios; it solves the problem of the traditional HNSW algorithm that the high-frequency data may take too long to query or even cannot be queried due to the completely random data hierarchy. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] Figure 1Diagram of the process of inserting data to create HNSW;

[0038] Figure 2 A process diagram for optimizing and reorganizing the HNSW data hierarchy when a large amount of data already exists;

[0039] Figure 3 A process diagram for detecting whether to perform HNSW data hierarchy optimization and reorganization;

[0040] Figure 4 Diagram showing the process of using the newly created index to prevent the optimization process from locking the table for too long. DETAILED DESCRIPTION

[0041] The technical solution of the present invention is now further described in conjunction with the accompanying drawings and embodiments.

[0042] Embodiment 1:

[0043] The technical terms involved in the embodiments are explained as follows:

[0044] HNSW is an efficient approximate nearest neighbor search algorithm that uses the characteristics of the small world graph structure to achieve fast search through a hierarchical structure. During the creation process, the level at which the vector data is inserted is random. Through the random algorithm, the higher the level, the less data there is, and the lower the level, the more data there is. When querying, the top-level vector data is selected as the entry point, and data is retrieved from top to bottom.

[0045] If the vector data close to the upper layer is located in a very remote position in the data set (low popularity), the difficulty of searching for the target data will increase, and it is necessary to search layer by layer to obtain the data in the target area, and efficiency and accuracy cannot be guaranteed. Taking the coordinate set of Chinese cities and landmark buildings such as high-speed rail stations as an example, if the top-level entrance is Urumqi in Xinjiang, and the user wants to query the surrounding areas of Nanjing, then the HNSW algorithm will traverse Xining, Lanzhou, Xi'an, Wuhan, Hefei and other cities along the way to find Nanjing and its surrounding facilities. As an approximate search algorithm, HNSW will not exhaust all data. If the data is far apart, it may not be able to search for the coordinates of Nanjing.

[0046] To solve the above problems, it is necessary to optimize the data hierarchy of HNSW so that high-frequency vector data is as close to the upper layer as possible for easy retrieval. Therefore, this embodiment proposes an optimization method for HNSW indexing algorithm based on a graph database, which introduces a heat gradient table to determine which data is more suitable to be located close to the upper layer, thereby improving the query efficiency and query accuracy of the HNSW indexing algorithm.

[0047] The introduced heat gradient table is now further explained.

[0048] 1)Use out and in points

[0049] The more the sum of the data's in and out points, the more likely it is that it is hotter. Based on this, a heat gradient table is created in the graph database, using the sum of the data's in and out points as the ranking factor. The more the sum of the data's in and out points, the higher the ranking.

[0050] The levels are divided according to the heat gradient table. The higher the ranking, the higher the level. The highest ranked data is used as the top-level entrance.

[0051] To prevent the storage space required for the heat gradient table from being too large, only the top 10,000 most popular data are recorded. The specific number of data is configurable and determined by the user. Data not in the gradient table is still inserted into the lower layer according to the original random logic of HNSW.

[0052] The statistics of the entry and exit points of each data can be directly obtained through the dictionary of the graph database.

[0053] 2) Take advantage of high-frequency access

[0054] Record the number of times data is accessed in a day or a week, and determine the popularity based on the frequency of data access. Prevent excessive memory usage and persist to the storage node of HNSW. Clean and update regularly to prevent statistical information from being too old and unsuitable for new business scenarios.

[0055] Optimize the HNSW data hierarchy based on heat, which is similar to the heat gradient table using entry and exit points, and will not be described in detail.

[0056] The implementation of the heat gradient table is now further explained.

[0057] 1) Table structure implementation

[0058] The heat gradient table will change in real time, requiring flexible data insertion, deletion, and update, which is implemented here using a linked list. At the same time, a hash index is created for the heat gradient table to quickly find the data that needs to be updated or deleted.

[0059] 2) Snapshot Implementation

[0060] At the end of each optimization, a snapshot of the heat gradient table is recorded. It is used for regular comparison with the latest heat gradient table. When the difference is too large, the optimization process is enabled. The data records of the snapshot will only be written sequentially and cleared completely, using an array. Each time a snapshot is taken, the heat gradient table at that time is recorded in the array. A new header structure is added to record the difference and reduce repeated calculations. The snapshot and the latest heat gradient table need to be persisted to physical storage to ensure the accuracy of the heat gradient table.

[0061] 3) Dictionary maintenance

[0062] The heat gradient table and snapshot metadata are stored in a separate system table dict_heat_gradient, which is associated with the index ID and stores the heat gradient table physical file information and the ID in the memory. The heat gradient table status field is introduced into the index dictionary to indicate whether the heat gradient table exists.

[0063] The process of inserting and creating HNSW data is now further explained.

[0064] 1) Create HNSW from an empty data table

[0065] When the data table is empty, the heat gradient table has not been generated yet. It is built as the data is inserted. At this time, the heat gradient table has no reference significance. Here, a user-defined heat gradient table is introduced. The user specifies the location of some high-frequency data based on known information and creates it. If a user-defined heat gradient table is not specified, random hierarchical data is inserted without optimization.

[0066] Now Figure 1 Take this as an example to show the process of creating HNSW from an empty data table and inserting data.

[0067] S101, the insert thread checks the heat gradient table status field of the index dictionary table through the index ID, and queries whether there is a user-defined heat gradient table for the index ID. If so, jump to S102, if not, jump to S104.

[0068] S102, the insert thread finds the user-defined heat gradient table through the index ID, and checks whether the data Data1 to be inserted is in the user-defined heat gradient table. If so, jump to S103, if not, jump to S104.

[0069] S103, the insertion thread determines the gradient of the data Data1 to be inserted according to the user-defined heat gradient table, places the data Data1 in the appropriate data level of the HNSW index, and jumps to S105.

[0070] S104, the insert thread randomly inserts the data Data1 to be inserted into each level of the HNSW index, and jumps to S105.

[0071] S105, the insert thread uses the data Data1 to update the data heat gradient table, and jumps to S106.

[0072] S106, the insert thread persists each data into the storage.

[0073] When an empty table creates an HNSW, the generated heat gradient table is still changing significantly and has no reference value. It is not used to determine the level at which data is inserted.

[0074] 2) Optimize HNSW for tables with existing data

[0075] When the data volume reaches a certain level, optimization is triggered, or the user actively calls the optimization process to rebuild the index. When rebuilding the index, the HNSW data hierarchy is reorganized according to the heat gradient table. A snapshot of the heat gradient table is recorded at the end of each optimization as the basis for the next optimization trigger.

[0076] Now Figure 2 Take as an example to show the process of optimizing the HNSW data hierarchy reorganization when there is already a large amount of data. The reorganization thread will clear the index content and reinsert the data according to the heat gradient table.

[0077] S201, the reorganization thread checks the heat gradient table status field of the index dictionary table through the index ID, and queries whether there is a user-defined heat gradient table for the index. If so, jump to S202, if not, jump to S203.

[0078] S202, the reorganization thread finds the user-defined heat gradient table through the index ID, and checks whether the data Data1 to be inserted is in the user-defined heat gradient table. If so, jump to S204, if not, jump to S203.

[0079] S203, the reorganization thread finds the data heat gradient table through the index ID, and checks whether the data Data1 to be inserted is in the data heat gradient table. If so, jump to S204, if not, jump to S205.

[0080] S204, the reorganization thread determines the gradient of the data Data1 to be inserted according to the heat gradient table, places the data Data1 in a data level suitable for the HNSW index, and ends.

[0081] S205, the reorganization thread randomly inserts the data Data1 to be inserted into the lower level of the HNSW index, and ends.

[0082] The user-defined heat gradient table has a higher priority here, which can be flexibly modified during implementation. Data is optimized based on the two heat gradient tables and does not need to be inserted into the heat gradient table. Data that cannot be detected in the heat gradient table is stored at a lower level according to probability.

[0083] 3) Long-term maintenance of HNSW

[0084] Check the heat gradient table from time to time and compare it with the heat gradient table snapshot recorded in the last optimization. If the relative difference of the heat gradient table is too large, the HNSW data hierarchy reorganization is triggered. Insert, delete, and update operations can be performed, or the detection can be triggered at a scheduled time. According to the business scenario, when the triggering optimization conditions are met, HNSW optimization can be delayed until midnight or other scenarios where the index is not used frequently. If the optimization process takes too long and the business needs to be added, deleted, modified, and checked from time to time, a new index can be created for optimization. After the optimization is completed, delete the old index and replace it with a new index to minimize the table lock time.

[0085] Now Figure 3 Take as an example to show the process of detecting whether to perform HNSW data hierarchy optimization and reorganization.

[0086] S301, insert thread data, update the heat gradient table, and enable the check thread.

[0087] S302, the checking thread compares the current heat gradient table with the heat gradient table snapshot generated in the last optimization to generate a difference. If the difference is greater than 30%, jump to S303, otherwise end.

[0088] S303, the checking thread enables the reorganization thread, and the reorganization thread optimizes and reorganizes the HNSW and rebuilds the index.

[0089] You can insert data for checking each time, or start a thread to check regularly, actively call, etc. Set a suitable difference standard, and when the standard is reached, trigger the optimization, or delay the optimization operation until the usage frequency is low.

[0090] Now Figure 4 Taking MySQL as an example, this article shows how to use a new index to prevent the optimization process from locking the table for too long.

[0091] S401: The reorganization thread creates a new empty HNSW index for standby.

[0092] S402, the reorganization thread searches the heat gradient table through the old index ID to take a snapshot, and records the data position P1 of the old index at this time.

[0093] S403, the reorganization thread activates the insertion thread, starts inserting data into the new index, and uses the heat gradient table of the old index to perform structural optimization until it reaches the P1 node, and the insertion thread finishes its work.

[0094] S404, the reorganization thread locks the data table to prohibit other users from performing add, delete, modify, and query operations.

[0095] S405, the reorganization thread records the data position P2 of the old index at this time; makes the new index inherit the heat gradient table of the old index; deletes the old index and replaces it with the new index; enables the insertion thread and continues to update the new index until it reaches the P2 node, and the insertion thread finishes its work.

[0096] S406, the reorganization thread unlocks the data table and removes restrictions. At this time, the entire optimization process is completed and the reorganization thread exits. During the optimization, the old index continues to work, P1 records the data position at the beginning of the optimization, and P2 records the data position after the optimization is completed. After the new index optimization reaches P1, continue to insert data to reach P2. This embodiment uses multiple indexes to complete most of the optimization work before locking the table as much as possible, so that only a small part of the work needs to be completed during the locking period, that is, the data table is only locked during the process of replacing the old table with the new table, so as to minimize the interference with the add, delete, modify and query functions, so as to achieve the shortest possible table lock time and not affect the business.

[0097] After optimization using this embodiment, according to the heat gradient table, Nanjing, the provincial capital, and high-frequency locations such as Nanjing Station and Nanjing South Station will be at a high level. When it is necessary to query Nanjing Station, it will be much easier. Based on Nanjing Station, it will be easier to query surrounding accommodation attractions, etc., which is convenient for users to find quickly and query the surrounding areas.

[0098] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).

[0099] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0100] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A HNSW index algorithm optimization method based on a graph database, characterized by: The following steps are involved: Get the current heat gradient table, compare the current heat gradient table with the heat gradient table snapshot recorded in the last optimization, and get the relative difference of the heat gradient table; Only when the relative difference of the heat gradient table is greater than the set threshold, the optimization is performed as follows: data not in the current heat gradient table is randomly moved to the lower level of the HNSW index; data in the current heat gradient table is inserted into the upper level of the HNSW index, and the current heat gradient table is updated; After the optimization is completed, the current thermal gradient table snapshot is recorded; The heat gradient table determines the table structure of the data at the upper level of the HNSW index based on the data heat, or determines the table structure of the data at the upper level of the HNSW index based on user customization.

2. According to claim 1, a HNSW index algorithm optimization method based on a graph database is characterized in that: The data heat is determined by the sum of the data's entry and exit points.

3. According to claim 1, a HNSW index algorithm optimization method based on a graph database is characterized in that: The data heat is determined by the frequency with which the data is accessed.

4. According to claim 1, a HNSW index algorithm optimization method based on a graph database is characterized in that: An array is used to record the thermal gradient table snapshots, which can only be written sequentially or cleared completely. In the array, a header structure is added to record the relative differences of the thermal gradient table.

5. According to claim 1, a HNSW index algorithm optimization method based on a graph database is characterized in that: The index dictionary table is used to store the index ID, the thermal gradient table, the thermal gradient table snapshot and the thermal gradient table status field, and the thermal gradient table status field is used to identify whether the thermal gradient table exists.

6. The HNSW index algorithm optimization method based on graph database according to claim 5 is characterized in that: Initially, follow these steps to insert data into the HNSW index: Check the heat gradient table status field of the index dictionary table by index ID to check whether there is a user-defined heat gradient table for the index ID: If it exists, find the user-defined heat gradient table through the index ID, check whether the data to be inserted is in the user-defined heat gradient table, if it exists, determine the gradient of the data to be inserted according to the user-defined heat gradient table, put the data in the data level of the HNSW index, and update the heat gradient table of the data, if it does not exist, randomly insert the data to be inserted into the lower level of the HNSW index, and update the heat gradient table of the data; If it does not exist, the data to be inserted will be randomly inserted into each level of the HNSW index, and the heat gradient table of the data will be updated.

7. The HNSW index algorithm optimization method based on graph database according to claim 6 is characterized in that: The above-mentioned optimization is performed according to the following contents only when the relative difference of the heat gradient table is greater than the set threshold: the data not in the current heat gradient table is randomly moved to the lower level of the HNSW index; The data in the current heat gradient table is inserted into the upper level of the HNSW index, and the current heat gradient table is updated; the specific operations include: Check the heat gradient table status field of the index dictionary table by index ID to check whether there is a user-defined heat gradient table for the index ID: If it exists, find the user-defined heat gradient table through the index ID, and check whether the data to be inserted is in the user-defined heat gradient table. If it exists, place the data in the data level of the HNSW index according to the user-defined heat gradient table. If it does not exist, find the data's heat gradient table through the index ID, and check whether the data to be inserted is in the data's heat gradient table. If it exists, determine the gradient of the data to be inserted according to the data's heat gradient table, and place the data in the data level of the HNSW index. If it does not exist, randomly insert the data to be inserted into the lower level of the HNSW index. If it does not exist, find the data's heat gradient table through the index ID and check whether the data to be inserted is in the data's heat gradient table. If it exists, determine the gradient of the data to be inserted based on the data's heat gradient table and place the data in the corresponding data level of the HNSW index. If it does not exist, randomly insert the data to be inserted into the lower level of the HNSW index.

8. The HNSW index algorithm optimization method based on graph database according to claim 1 is characterized in that: The above-mentioned optimization is performed according to the following contents only when the relative difference of the heat gradient table is greater than the set threshold: the data not in the current heat gradient table is randomly moved to the lower level of the HNSW index; The data in the current heat gradient table is inserted into the upper level of the HNSW index, and the current heat gradient table is updated; the specific operations include: Create a new index for backup; Use the old index ID to find its heat gradient table for snapshot and record the data position P1 of the old index at this time; The new index uses the heat gradient table of the old index to insert data until it reaches data position P1, and the insertion work is completed; Lock the data table; Record the data position P2 of the old index at this time; let the new index inherit the heat gradient table of the old index; delete the old index and replace it with the new index; continue to use the heat gradient table of the old index to insert data and update the new index until the data position P2 is reached, and the insertion work is completed; Unlock the data table.

9. A HNSW index algorithm optimization system based on graph database, characterized by: include: The heat gradient table relative difference calculation module is used to obtain the current heat gradient table, compare the current heat gradient table with the heat gradient table snapshot recorded in the last optimization, and obtain the relative difference of the heat gradient table; The optimization module is used to optimize according to the following contents only when the relative difference of the heat gradient table is greater than the set threshold: the data not in the current heat gradient table is randomly moved to the lower level of the HNSW index; the data in the current heat gradient table is inserted into the upper level of the HNSW index, and the current heat gradient table is updated; The snapshot module is used to record the current thermal gradient table snapshot after the optimization is completed; The heat gradient table determines the table structure of the data at the upper level of the HNSW index based on the data heat, or determines the table structure of the data at the upper level of the HNSW index based on user customization.

10. A computer device, characterized in that: The invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of a method for optimizing an HNSW index algorithm based on a graph database as claimed in any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Intelligent analysis computer algorithm operating system

    CN120070609A

  • Computer device

    CN121330088A