I’ve described the types of vector indexes available in AI Vector Search in previous blog posts and have shown examples of their use. In this blog post I am going to explore when you might use each of the vector index types and what you should consider in implementing the one you choose.

As a review, there are four types of vector indexes available in AI Vector Search. There are also permutations of the indexes that I will explore as I discuss how you might use each of them. The following is a brief description of each of the indexes:

  • In-Memory Neighbor Graph Vector Index – Oracle AI Vector Search supports an in-memory Hierarchical Navigable Small World (HNSW) type of In-Memory Neighbor Graph vector index where vertices represent vectors and edges between vertices represent similarity. This is an in-memory only index. This type of index is typically designed to support efficient similarity searches with a balance of search speed and accuracy.
  • Neighbor Partition Vector Index – Oracle AI Vector Search also supports an Inverted File Flat (IVF) partition-based index with vectors clustered into table partitions based on similarity. This type of index typically provides an efficient scale-out index, with support for scalable similarity searches and transactional operations.
  • Hybrid Vector Index – There is also a Hybrid Vector Index that combines the information retrieval capabilities of Oracle Text search indexes and the semantic search capabilities of Oracle AI Vector Search vector indexes.
  • Iceberg Vector Index – On Apache Iceberg tables you can create an IVF vector index within the database on an external table defined on an Iceberg table stored outside the Oracle AI Database.

Which index should you use?

Ignoring the special case of an Iceberg vector index, as a general rule of thumb, if you need high-performance similarity search and you have the memory then you should consider an HNSW index. If however, you have a very large dataset that won’t economically fit in memory, or data retrieval speed is not crucial, then you should consider an IVF index. When should you consider a Hybrid Vector Index? A Hybrid Vector Index is actually a special type of index in that it combines an HNSW or an IVF index along with an Oracle Text index. Why would you want to perform a hybrid search? One motivation for this is to narrow the focus of a similarity search, that is adding a keyword search to a similarity search can help narrow the focus of the search. The other motivation can be to reinforce the similarity search by creating the same query for both the semantic search and the keyword search to help improve result coverage by combining semantic and keyword matches. I talked about these two scenarios in the Using Hybrid Vector Indexes in AI Vector Search blog post.

And for that special case of an Iceberg vector index? You should use that when you want to run efficient similarity searches against your Apache Iceberg tables.

HNSW Vector Indexes

Memory Usage

HNSW indexes are in-memory indexes and use memory from a memory area in the database called the Vector Pool. The Vector Pool is memory allocated from the System Global Area (SGA) to store HNSW type vector indexes and their associated metadata. One thing to note is that this memory area is not a cache. The entire index must fit in memory. However, there are several features that help with automatically adding space or reducing the space that a particular HNSW index uses.

The Vector Pool size is controlled by an initialization parameter. If set to a particular value then it will be fixed in size and all indexes need to fit within that allocated size. If set to a value of 1 then the vector memory pool will be dynamically resized by the database instance to a maximum size of 70% of the PDB’s SGA target size (another initialization parameter). If that doesn’t provide enough space then two other features are available that can be used to reduce the size of the index itself. Using SPARSE vectors may be an option or scalar quantization can be used during index creation. Lastly, there is also the ability to create distributed HNSW indexes across RAC (Real Application Clusters) nodes. This can help scale similarity searches across multiple instances in a RAC environment.

You might be wondering at this point if there is a way to figure out how much space an HNSW index will require? There is a vector index memory advisor available in the DBMS_VECTOR package that you can run to determine the vector memory size needed for a particular vector index. This can help you evaluate the number of indexes that can fit for each simulated vector memory size.

Since the HNSW vector index is an in-memory index it also means that when a database instance is restarted the index must be reloaded. For both RAC and single instance environments this happens automatically. This reload process may be accelerated if there is a recent full checkpoint available and the reload behavior can be adjusted with an instance parameter if needed.

Partition Support

If the base table is partitioned then a global or a local HNSW index can be created. A global HNSW index creates a graph across all vectors in the partitioned table. With a local HNSW index an index is created for each partition or subpartition in the partitioned base table. This allows queries to benefit from any partition pruning that may occur on the base table. In other words, just the necessary local indexes are scanned for the partitions or subpartitions that satisfy the query.

Included Column Support

In addition, HNSW indexes support included columns. This means additional filterable non-vector columns can be added to the index which can avoid having to include a join to the base table to resolve additional attribute filters. It also means that projection columns can be satisfied directly from the index, possibly avoiding any base table access.

Transactional Support

HNSW indexes also have support for transactions and persistence. Since an HNSW index is an in-memory index DML operations (i.e. inserts, updates and deletes) performed on the base table will not immediately be reflected in the index. To support DML changes a private journal and a shared journal are employed to keep track of changes. The private journal is an in-memory per-transaction structure that captures all vectors that are inserted or deleted by an active transaction. The shared journal is an on-disk, table-backed component that holds the history of committed transactions that have modified indexed vector columns.

As changes accumulate queries may experience slower performance since the shared journal must be searched for changed vectors as well as searching the index. To help maintain query performance and search accuracy, Oracle provides automated refresh and persistence mechanisms. This includes an incremental snapshot of an updated in-memory version of the HNSW graph associated with a specific SCN. This can reduce the need to search the shared journal for changes. When an incremental snapshot is not enough a full repopulation can be triggered to rebuild the HNSW index from the base table.

IVF Vector Indexes

IVF vector indexes are storage-based indexes. This means that they are not constrained by the amount of memory available in the vector pool like an HNSW vector index is. Although an IVF index may have different search-performance characteristics than an equivalent HNSW index, depending on workload and configuration, it can be used for very large data sets and can help provide efficient similarity searches when compared to an exhaustive similarity search. Another advantage is that if search performance is not critical then memory can be allocated for other indexes where faster search is needed. More details about how an IVF vector index works are available in this blog post: Using IVF Vector Indexes in AI Vector Search and in the AI Vector Search User’s Guide.

Partition Support

An IVF index is by default a partitioned index and can be used on non-partitioned or partitioned tables. However, on a partitioned table it is possible to create a local IVF index where there is a one-to-one relationship between the base table partitions or subpartitions and the local index partitions. Just like a local HNSW index, this can then take advantage of any partition pruning that may occur on the base table so that just the necessary index partitions or subpartitions will need to be scanned. Furthermore, although IVF vector indexes are storage-based indexes, index creation and DML operations can be accelerated on local IVF indexes if the Vector Pool is enabled. So even if you are not using HNSW indexes you may still want to enable the Vector Pool if you are using local IVF indexes. You can also use the vector index memory advisor mentioned in the HNSW vector index section earlier to determine how much memory will be needed.

Included Column Support

Like HNSW indexes, IVF indexes also support included columns. See the previous HNSW description of the advantages of included columns for more details.

Multi-vector search

IVF indexes support multi-vector similarity searches. Multi-vector searches use the row_limiting_partition_clause of the fetch clause to perform efficient top-K queries with multi-level partitioning. In other words, one query vector is used to rank rows that each hold an embedding and can apply grouping levels, for example books, paragraphs, and sentences, to select the best matches at each level. Included columns, expressions on partitioned columns (i.e. PARTITIONS BY) and joins can further support additional filtering and query-processing options.

Hybrid Vector Indexes

As mentioned at the beginning of this post a hybrid vector index combines an HNSW or IVF, the default, vector index with an Oracle Text index. This combination of a vector index and a text index can help narrow the focus of a similarity search or it can reinforce it by combining keyword and semantic matches to help improve result coverage. One of the interesting aspects of a hybrid vector index is that it supports automatic chunking and vector embedding as part of the index creation.

Once the index is created a hybrid search accesses the hybrid vector index and performs both a keyword search and a similarity search, and then the results are combined into a single result set. A scoring mechanism is used to create the result set, a keyword score for the keyword search, and a semantic score for the similarity search. It is also possible to perform just a keyword search or just a similarity search on the hybrid vector index, and many options are available to adjust how the join and scoring are done.

Vector Indexes on Iceberg Tables

Vector indexes can also be created on Apache Iceberg tables. This is referred to as “Vectors on Ice”. Iceberg tables are an open table format used to simplify the management of large-scale data lakes and data lakehouses while supporting efficient data access and query processing. The Apache Iceberg table format is open source and was designed for large-scale analytics in data lakes. Iceberg tables are self-describing, meaning they contain metadata about their schemas and data, which can simplify querying and management.

Oracle AI Database supports creating an IVF vector index within the database for an Iceberg table stored outside the Oracle AI Database. This design can help support efficient index refresh, predictable query performance, and index maintenance for large datasets. The Iceberg table is defined as an external table in Oracle AI Database and supports cloud object storage such as Oracle Cloud Infrastructure or Amazon S3.

Queries can be run using similarity search that accesses the vector index to help improve search performance, and those queries can also use a combination of internally stored data along with the external Iceberg data providing additional flexibility in querying data across storage environments.