Skip to main content
Version: V1.4.0

Choose an index type

seekdb provides various vector indexes with different algorithms. You can choose an appropriate index type based on your use case.

HNSW or IVF?​

The dense indexes of seekdb are divided into two major categories:

  • Graph-based HNSW series indexes: HNSW, HNSW_SQ, and HNSW_BQ.
  • Disk-based IVF series indexes: IVF and IVF_PQ.

Each type of index has its own strengths. HNSW series indexes typically offer higher query performance but require more memory. IVF series indexes perform well when cache is sufficient and can operate without relying on memory. However, choosing between HNSW and IVF is not solely based on memory considerations. Business scenarios, data volume, performance metrics, and resource constraints must all be considered. The following sections compare their core differences and provide recommendations for selection.

Core Differences​

DimensionHNSW SeriesIVF Series
Storage MethodMemory-based graph structure indexDisk-based index
Memory UsageRequires full memory loading, high memory usageDoes not require memory, low memory usage
Query Performance (QPS)Extremely high, millisecond-level responseHigh, nearly comparable to HNSW when cache is sufficient
Recall RateHigh, up to 99%High, slightly lower than HNSW, can be optimized through parameters
Build SpeedSlower, requires building the graph structureFaster, based on clustering algorithms
Applicable Data VolumeMillions to billionsMillions to tens of billions
CostHigh memory costLow storage cost, suitable for large-scale data
Real-time SupportSupports real-time DML operationsSupports real-time DML operations

Decision Flowchart​

info
  • Before selecting an index type, you need to estimate the memory usage based on Vector Index Memory Management.
  • The recommendations in the decision flowchart are based on 1024-dimensional vectors. If the actual dimensions differ, you can approximately calculate the required resources based on the proportion.
  • The decision flowchart primarily considers memory costs to help you choose an index type.
  • Even with sufficient memory, it's not always optimal to choose the highest specification indexes like HNSW. If you have high performance requirements, consider cost-effective options like HNSW_SQ.

Decision Flowchart

tip

This section lists only some common scenarios. If you cannot determine the index type based on the above flowchart or have other requirements, please contact seekdb Technical Support.

Should I use partitioned tables?​

The primary purpose of using partitioned tables is to handle large-scale data scenarios. Additionally, if the query conditions can be used as partition keys, partition pruning can enhance query performance. We recommend using partitioned tables in the following scenarios:

  • The data volume reaches tens of millions or even hundreds of millions: When the data volume is very large, using partitioned tables can distribute the data across multiple partitions, with each partition independently building an index. This reduces the load of a single query and improves overall query performance.
  • The query conditions contain scalar columns that can be used for partition pruning: For example, if the label field always appears in the WHERE condition, you can consider creating a partitioned table with label as the partition key. This reduces the number of partitions to be queried through partition pruning.

Specific recommendations are as follows:

Partitioning​

When using vector indexes, the number of partitions should not be excessive. Unlike scalar indexes, vector indexes (such as HNSW) do not significantly increase the computational overhead for querying the TopK results when the index size increases from 1 million to 2 million vectors under the same configuration. Therefore, if partition pruning cannot be utilized, having too many partitions may actually degrade performance. Additionally, a single partition that is too large not only increases the time required for index rebuilding but also affects the efficiency of joint queries with scalar conditions.

In summary, we recommend keeping the data volume in each partition below 20 million and preferentially selecting fields that support partition pruning as the partition key.

Algorithm Selection​

For large-scale data, we recommend using the HNSW_BQ or IVF_PQ index. If you need to use other indexes, refer to the Memory Usage section for estimation.

Memory Usage​

HNSW_BQ​

For the HNSW_BQ index, configure vector_memory_limit so that it is greater than the total memory required for HNSW_BQ queries plus the memory required by the HNSW_SQ index for one partition. Make sure that memory_budget can accommodate this vector-memory allocation together with the other instance modules. Estimate the required memory as follows:

  1. First, use the INDEX_VECTOR_MEMORY_ADVISOR function to calculate the recommended memory values for the HNSW_BQ and HNSW_SQ indexes during construction and query.
  2. Use the recommendation to determine vector_memory_limit and the total memory_budget required by the instance.

For example, if you have 100 million 1024-dimensional vector data across 10 partitions (approximately 10 million vectors per partition), the calculation process is as follows:

-- Specify REFINE_TYPE=SQ8 to directly and accurately obtain the recommended memory values for the HNSW_BQ index during construction and query.
-- This eliminates the need for separately calculating the memory usage of the HNSW_SQ index. This is because the HNSW_BQ index is constructed using the SQ8 quantization algorithm by default.
-- After specifying refine_type=sq8, the function automatically includes the memory required for the SQ8 quantized vectors in the calculation.
-- The recommended memory value for the HNSW_BQ index is 74.6 GB, and the memory consumption during query is 57.4 GB. We use the recommended memory value.
SELECT DBMS_VECTOR.INDEX_VECTOR_MEMORY_ADVISOR('HNSW_BQ',100000000,1024,'FLOAT32','M=32,DISTANCE=COSINE,REFINE_TYPE=SQ8', 10000000);
+------------------------------------------------------------------------------------------------------------------------------+
| DBMS_VECTOR.INDEX_VECTOR_MEMORY_ADVISOR('HNSW_BQ',100000000,1024,'FLOAT32','M=32,DISTANCE=COSINE,REFINE_TYPE=SQ8', 10000000) |
+------------------------------------------------------------------------------------------------------------------------------+
| Suggested minimum vector memory is 74.6 GB, memory consumption when providing search service is 57.4 GB |
+------------------------------------------------------------------------------------------------------------------------------+
1 row in set

-- By default, vector_memory_limit is 50% of memory_budget. Therefore, the required memory budget is
SELECT 74.6/0.5;
+--------------------------------------------------------------------------------------------------------------+
| 74.6/0.5 = 149.2 GB |
+--------------------------------------------------------------------------------------------------------------+
1 row in set

-- Considering that new data may not be compressed in the actual environment, we recommend reserving some redundancy.
SELECT 149.2 * 1.2;
+--------------------------------------------------------------------------------------------------------------+
| 149.2 * 1.2 = 179.04 GB |
+--------------------------------------------------------------------------------------------------------------+
1 row in set

-- Therefore, it is recommended to configure memory_budget as 179 GB.

IVF Series​

For IVF and IVF_PQ indexes, configure vector_memory_limit so that it is greater than the memory required to build one partition plus the total resident memory required by all partitions. The following example uses distance=cosine: with 100 million rows and 10 partitions (approximately 10 million vectors per partition), building one partition requires about 2.7 GB, and each partition requires about 11.4 MB of resident memory during queries, or about 114 MB in total. Therefore, vector_memory_limit must be at least approximately 2.9 GB; after reserving headroom, 6 GB is recommended. If you keep vector_memory_limit=0M, its effective value is 50% of memory_budget, so a 6 GB vector-memory limit requires at least a 12 GB memory_budget, with additional capacity reserved for other modules. For distance=l2, building one partition requires about 4.0 GB and each partition requires about 1.3 GB of resident memory, or about 13 GB for 10 partitions. In that case, vector_memory_limit must be at least approximately 17 GB, and the preceding 6 GB recommendation does not apply. Other data volumes can be estimated in the same way.

Construction and Query Parameters​

We recommend setting the index construction and query parameters based on the maximum data volume of a single partition. For more details, see the Index Parameter Recommendations section.

Performance and Recall Rate​

  • If the query conditions can prune to a single partition: The performance and recall rate are the same as in the single-partition scenario. For more details, see the section on different data volume scales.
  • If the query conditions cannot prune to a single partition: The QPS can be estimated proportionally based on the number of partitions per OBServer node (e.g., if a single node contains 3 partitions, the QPS is approximately one-third of the single-partition performance). Since cross-partition queries merge more candidate results, the actual recall rate is typically higher than in the single-partition scenario.

Index parameter recommendations​

HNSW series​

The recommended index construction and query parameters vary depending on the data volume within the same series. This section provides suggested configurations for 768-dimensional vectors with 1 million and 10 million data points for HNSW, HNSW_SQ, and HNSW_BQ indexes. For vector data in the billions, refer to the subsequent sections of this document for IVF_PQ indexes or HNSW_BQ indexes within partitioned tables.

tip
  • For scenarios where data volume is expected to grow, it is recommended to set parameters based on the final data volume.
  • HNSW_BQ is a high-compression quantization algorithm. The recall rate may be relatively low in low-dimensional vectors. To avoid performance loss, it is recommended to use HNSW_BQ for vectors with 512 dimensions or more.
ScenarioIndex TypeParameter Recommendations
Maximum Recall
(Highest memory usage)
HNSW1 million data points: m = 16, ef_construction = 200, ef_search = 100, other parameters default
Highest Performance
(Lowest memory usage)
HNSW_SQ1 million data points: m = 16, ef_construction = 200, ef_search = 100, other parameters default
10 million data points: m = 32, ef_construction = 400, ef_search = 350, other parameters default
Best Cost-Performance
(Low memory usage, good performance)
HNSW_BQ1 million data points: m = 16, ef_construction = 200, ef_search = 100, other parameters default
10 million data points: m = 32, ef_construction = 400, ef_search = 1000, refine_k = 10, other parameters default
1 billion data points: Use partitioned tables, m = 32, ef_construction = 400, ef_search = 1000, refine_k = 10, other parameters default

Detailed Explanation for 1 Million Data Points​

Take 1 million 768-dimensional vectors as an example (using the construction parameters from the table above). Additional details on memory usage and recall rate optimization are provided below:

Memory Usage:

Index TypeRecommended memory_budgetDescription
HNSW15 GBThe recommended vector index memory is 7.3 GB. With vector_memory_limit=0M, the vector module can use 50% of memory_budget, so a memory budget of approximately 15 GB is required.
HNSW_SQ6 GBThe recommended size for the vector index is 2.1 GB.
HNSW_BQ6 GBHNSW_BQ requires high-precision vectors while the index is being built, so its build-time memory requirement is the same as HNSW_SQ: 6 GB. HNSW_BQ uses SQ8 quantization by default. After the index is built, memory usage decreases significantly to about 405 MB.
This estimate applies to a non-partitioned table. For a partitioned table, seekdb dynamically adjusts the number of partitions built concurrently according to vector_memory_limit. Configure enough vector memory for HNSW_BQ queries and for the HNSW_SQ memory required to build one partition, with additional headroom. For the calculation method, see Memory Usage above.

Recall Rate Optimization:

By adjusting the ef_search and refine_k (only for HNSW_BQ) parameters, you can increase the recall rate through more vector calculations, but this will also reduce query performance. You can set the parameters to the recommended values in the table below for different TopN scenarios. If you need to further improve the recall rate, you can set the parameter values higher.

tip

The recall rate is directly related to the data characteristics. The following table provides the recommended values for a standard dataset of 768 dimensions where the recall rate reaches approximately 0.95.

TopNef_searchrefine_k (only for HNSW_BQ)
Top10644
Top1002404

Extreme Recall Rate:

The maximum recall rates vary among different indexing algorithms. When using the recommended construction parameters from this section and setting ef_search to 1000, the query recall rate may improve, but the QPS will drop to one-third of the value at a 0.95 recall rate. Increasing ef_search does not guarantee an unlimited increase in recall rate for all index types. Only HNSW can achieve a recall rate of 0.99 or higher. For HNSW_BQ, you can further increase the refine_k parameter to improve the recall rate, but this will also result in a decrease in performance.

Extreme Recall Rate Reference Values (ef_search = 1000):

  • HNSW Index: Recall Rate 0.991
  • HNSW_SQ Index: Recall Rate 0.9786
  • HNSW_BQ Index: Recall Rate 0.9897 (ef_search = 1000, refine_k = 10)

Detailed Explanation for 10 Million Data Points​

Take 10 million 768-dimensional vectors as an example (using the construction parameters from the table above). Additional details on memory usage and recall rate optimization are provided below:

Memory Usage:

Index TypeRecommended memory_budgetDescription
HNSW160 GBThe recommended size for the vector index is 76.3 GB.
HNSW_SQ48 GBThe recommended size for the vector index is 22.6 GB.
HNSW_BQ48 GBDuring construction, HNSW_BQ requires high-precision vectors. By default, HNSW_BQ uses HNSW_SQ as the cache during index construction. Therefore, for non-partitioned tables, the memory required for HNSW_BQ is the same as HNSW_SQ. After construction, the HNSW_BQ index only occupies about 5.4 GB of memory.

Recall Rate Optimization:

By adjusting the ef_search and refine_k (only for HNSW_BQ) parameters, you can increase the recall rate through more vector calculations, but this will also reduce query performance. You can set the parameters to the recommended values in the table below for different TopN scenarios. If you need to further improve the recall rate, you can set the parameter values higher.

tip

The recall rate is directly related to the data characteristics. The following table provides the recommended values for a standard dataset of 768 dimensions where the recall rate reaches approximately 0.95.

TopNef_searchrefine_k (only for HNSW_BQ)
Top101004
Top100 (HNSW/HNSW_SQ)350-
Top100 (HNSW_BQ)100010

IVF series​

ScenarioIndex TypeParameter Recommendation
Low-dimensional
(384 dimensions or less)
IVFFor 10 million data: use partitioned tables, nlist=3000
For 100 million data: use partitioned tables, nlist=3000
Low cost
(minimal memory usage)
IVF_PQFor 1 million data: nlist=1000, m=vector dimension/2
For 10 million data: nlist=3000, m=vector dimension/2
For 100 million data: use partitioned tables, nlist=3000, m=vector dimension/2

To balance the number of cluster centers and the amount of data per center, it is generally recommended to set nlist to the square root of the data volume. For example, for 10 million data, nlist is recommended to be around 3000. When using IVF_PQ, the m parameter is recommended to be half of the vector dimension.

tip
  • IVF_PQ is a high-compression quantization algorithm. In low-dimensional vectors, the recall rate may be relatively low. To avoid performance loss, it is recommended to use IVF_PQ for vectors with 128 dimensions or more.
  • For scenarios where the data volume is expected to grow, it is recommended to set the parameters based on the final data volume.

10 million data volume (with partitioned tables)​

For example, for 10 million vectors with 768 dimensions (using the construction parameters in the table above), additional explanations on memory usage and recall rate optimization are provided:

Memory usage:

Index TypeIndex ParametersMemory Usage (Construction Overhead / Resident Overhead)
IVFdistance=l2, nlist=30002.7 GB / 10.5 MB
IVF_PQdistance=l2, nlist=3000, m=3844.0 GB / 1.3 GB
IVF_PQdistance=cosine, nlist=3000, m=3842.7 GB / 11.4 MB

In the table, Construction Overhead refers to the temporary memory occupied during index creation, which is released after construction; Resident Overhead refers to the memory continuously occupied by the IVF vector index after construction.

For IVF_PQ indexes, if you choose distance=l2, more resident memory will be occupied due to the need to store additional precomputed results. In contrast, using distance=inner_product or cosine typically consumes less resident memory. Therefore, in practical applications, it is recommended to prioritize inner_product or cosine as the distance type to optimize memory resources.

Recall rate optimization:

By adjusting the nprobes parameter, you can increase the recall rate through more vector calculations, but this will also reduce query performance. You can set the parameter to the recommended values in the table below for different TopN scenarios. If you need to further improve the recall rate, you can set the parameter value to a larger value.

tip

Recall rate is directly related to data characteristics. The values in the table below are recommended for a standard dataset with 768 dimensions to achieve a recall rate of around 0.95.

TopNnprobes
Top101
Top10020

100 million data volume (with partitioned tables)​

When the vector data volume reaches 100 million or more, it is strongly recommended to use partitioned tables combined with IVF-type indexes. As the data scale and nlist parameter increase, the query overhead of a single IVF index will also significantly increase. By splitting the data into multiple partitions and building smaller-scale IVF indexes for each partition, the query load can be effectively reduced. Additionally, parallel queries across partitions can further improve overall query performance and recall rate.

In multi-partition table scenarios, since IVF indexes are local, each partition will independently build its own IVF index. Therefore, it is recommended to calculate the nlist value based on the average data volume of each partition. For example, for 100 million vectors with 768 dimensions split into 10 partitions, each partition contains about 10 million vectors, and nlist is recommended to be sqrt(10 million) = 3162.

For example, for 100 million vectors with 768 dimensions (using the construction parameters in the table above), additional explanations on memory usage and recall rate optimization are provided:

Memory usage:

In multi-partition scenarios, since IVF indexes are local, each partition will independently build and maintain its own IVF index. Therefore, the total resident memory usage must be summed across all partitions. For example, in the table below, the resident memory of a single IVF index is 10.5 MB. If there are 10 partitions, the total resident memory is approximately 10.5 × 10 = 105 MB.

Index TypeIndex ParametersMemory Usage (Construction Overhead / Resident Overhead)
IVFdistance=l2, nlist=30002.7 GB / 10.5 MB × 10
IVF_PQdistance=l2, nlist=3000, m=3844.0 GB / 1.3 GB × 10
IVF_PQdistance=cosine, nlist=3000, m=3842.7 GB / 11.4 MB × 10

In the table, Construction Overhead refers to the temporary memory occupied during index creation, which is released after construction; Resident Overhead refers to the memory continuously occupied by the IVF vector index after construction.

Recall rate optimization:

By adjusting the nprobes parameter, you can increase the recall rate through more vector calculations, but this will also reduce query performance. You can set the parameter to the recommended values in the table below for different TopN scenarios. If you need to further improve the recall rate, you can set the parameter value to a larger value.

In partitioned table scenarios, since each partition will independently execute IVF index queries, when querying across multiple partitions, TopN results will be retrieved from each partition and then aggregated and re-ranked. This not only improves overall search accuracy but also typically results in a higher actual recall rate compared to single-partition scenarios. Therefore, in multi-partition tables, you can appropriately reduce the nprobes parameter to achieve a recall rate comparable to that in single-partition tables.

tip

Recall rate is directly related to data characteristics. The values in the table below are recommended for a standard dataset with 768 dimensions to achieve a recall rate of around 0.95.

TopNnprobes
Top101
Top10010

References​