This topic describes how to estimate and manage the memory usage of all types of vector indexes in OceanBase Database.
Configure the memory for vector indexes
OceanBase Database allows you to configure the memory for vector indexes by setting the ob_vector_memory_limit_percentage parameter:
The default value of this parameter is 0, which indicates the adaptive mode. In this mode, the system automatically adjusts the memory usage ratio for vector index data in the tenant without manual intervention:
- If the actual memory of the tenant is 8 GB or less, the value is automatically set to
40. - If the actual memory of the tenant exceeds 8 GB, the value is automatically set to
50.
Query the estimated and actual memory usage of indexes
You can use the DBMS_VECTOR system package to estimate the memory usage of indexes:
- Before you create a table, you can call the INDEX_VECTOR_MEMORY_ADVISOR procedure to estimate the memory usage of indexes.
- After you create a table and insert data into it, you can call the INDEX_VECTOR_MEMORY_ESTIMATE procedure to analyze the memory usage of indexes.
The memory usage of vector indexes includes the following two pieces of information: the minimum memory configuration required to create vector indexes, and the actual memory usage after the HNSW_SQ and IVF indexes are created.
Notice
For sparse indexes
- The
IDX_TYPEparameter must be set toSINDIorSINDI_SQ(case-insensitive). - The memory usage of sparse vectors depends on the average length of sparse vectors, which is the average number of non-zero dimensions per vector.
You can query the GV$OB_VECTOR_MEMORY or V$OB_VECTOR_MEMORY view to obtain detailed information about the actual memory usage.
Optimize memory usage for index rebuilds
For partitioned tables, you can use the vector_index_memory_saving_mode parameter to control the memory usage during index rebuilds. Enabling this mode reduces the memory consumption during the rebuild process of vector indexes on partitioned tables. Typically, vector index rebuilds require twice the memory of the index. When the memory-saving mode is enabled, the system temporarily deletes the memory indexes of each partition after the index is built in the partition. This effectively reduces the total memory required for the rebuild operation. For syntax and examples, see vector_index_memory_saving_mode.
HNSW series index incremental segment data persistence and merge control
Vector indexes are organized by segments within partitions. According to Vector index principles, they can be divided into:
- Baseline segments: Read-only segments, typically one per partition.
- Incremental segments: Generated by DML operations, including active segments, frozen segments, and persistence incremental segments.
For a single partition, you can control the freezing and persistence timing of active segments, as well as the merge timing between incremental and baseline segments, using the following configuration parameters:
ob_vector_index_active_segment_max_size
ob_vector_index_active_segment_max_size controls the maximum memory usage of active segments within a single partition for HNSW series indexes. When the memory usage of an active segment exceeds this threshold, the system triggers a freeze. After freezing, the segment becomes a frozen segment. Once the frozen segment is persisted, it becomes a persistence incremental segment.
Notice
After a frozen segment is persisted as a persistence incremental segment, the memory is not immediately released. It will be reduced only after the background merge task merges the segment into the baseline segment.
For syntax and examples, see ob_vector_index_active_segment_max_size.
ob_vector_index_merge_trigger_percentage
ob_vector_index_merge_trigger_percentage controls the ratio of memory usage of persistence incremental segments to the total memory of the partition index after persistence. When this ratio exceeds the specified value, the system automatically triggers a segment merge to combine the incremental segment with the baseline segment.
The differences between the two configuration parameters are as follows:
| Parameter | Controlled Object | Triggered Operation |
|---|---|---|
| ob_vector_index_active_segment_max_size | Memory usage of active segments (absolute value) | Freezing and persistence, transforming into a frozen segment or a persistence incremental segment |
| ob_vector_index_merge_trigger_percentage | Ratio of memory usage of persistence incremental segments to the total memory of the partition index after persistence | Segment merge, combining with the baseline segment |
Note
The above configurations apply to the "incremental writing and persistence" and "incremental segment and baseline segment compaction" processes, respectively. Together, they help balance write performance, query performance, and memory usage.
For syntax and examples, see ob_vector_index_merge_trigger_percentage.
References
- Overview of vector indexes
- For information about viewing segment information, understanding the automatic rebuild feature of index partitions, and manually forcing a merge, see Monitor and maintain indexes
- Vector index principles
