Use JSON Value Expressions as Included Columns with IVF Indexes

Using JSON_VALUE expressions as included columns in IVF vector indexes provides a mechanism to accelerate query performance and reduce index storage for vector search workloads involving projections of and filters on JSON expressions on the base table.

Syntax and Specifications

Create a base table, which contains house sales data with prices, descriptions, vectors, and a JSON column:

CREATE TABLE houses (
    id            NUMBER,
    zip_code      NUMBER,
    price         NUMBER,
    description   CLOB,
    house_details JSON,
    data_vector   VECTOR
);

The house_details JSON documents are structured as follows:

{
    "rooms": {
        "num_bedrooms": 2,
        "num_bathrooms": 2
    },
    "street_name": "Walnut Street",
    "square_feet" : 15213
}

Then you can create an IVF vector index with included JSON_VALUE expressions as follows:

create vector index vidx_ivf
on houses h (data_vector)
include (price, h.house_details.street_name.string(), h.house_details.rooms.num_bedrooms.number())
organization neighbor partitions
with target accuracy 95
distance EUCLIDEAN
parameters(type IVF, neighbor partitions 2) ONLINE;

The above example uses JSON path expressions with the “simple dot-notation” feature to access nested properties inside each JSON, and mixes traditional included columns (price) with included expressions. These can be provided in any order.

Note: The return type of each included expression should be one of the types supported by the included columns feature. The total number of included columns and expressions combined cannot exceed 31.

Usage Notes

Benefits of Using JSON_VALUE Expressions as Included Columns

Note: To achieve such a plan, the expression used in the query must be an exact match for the expression materialized in the index. For example, if the IVF index includes JSON_VALUE(house_details, '$.street_name' RETURNING VARCHAR2(20)), but the query requests JSON_VALUE(house_details, '$.street_name' RETURNING VARCHAR2(200)), the transformation will not take place, as the expressions have different semantics. Similarly, mixing simplified dot notation with explicit JSON_VALUE notation is not recommended since their semantics can differ in unexpected ways, preventing the optimized plan from being selected.