16.9.7 Creating an Oracle Vector Search

Create an Oracle Vector Search to search both structured and unstructured data by semantics or meaning, and by values, enabling ultra-sophisticated AI search applications.

Note:

Oracle Vector Search requires Oracle Database 23ai or later.

This topic demonstrates how to create a Oracle Vector Search on the EBA_PROJECT_MILESTONES table available in the sample dataset, Project Data. This example assumes you have already installed the sample, dataset, Project Data.

See Also:

Using Sample Datasets in Oracle APEX SQL Workshop Guide

16.9.7.1 About Oracle Vector Search Configurations

Learn about Oracle Vector Search configurations.

Starting with Oracle Database 23ai, you can use the VECTOR data type to store vector embeddings alongside business data in the database. Using embedding models, you can transform unstructured data into vector embeddings that can then be used for semantic queries on business data.

The process of creating an Oracle Vector Search configuration involves the following general steps:

  1. Add a column with a data type of VECTOR to your table.
  2. Create a Vector Provider to create vector embeddings for text strings. See Managing Vector Providers.
  3. Retrieve the embeddings from a Vector Provider using the GET_VECTOR_EMBEDDINGS function in APEX_AI package. See Retrieving the Vector Embeddings from a Vector Provider
  4. Create a Search Configuration based on your Vector Provider and your VECTOR column. See Creating an Oracle Vector Search Configuration.
  5. Create an Oracle Vector Search page. Retrieving the Vector Embeddings from a Vector Provider.

See Also:

  • GET_VECTOR_EMBEDDINGS function in APEX_AI in Oracle APEX API Reference
  • Overview in Oracle Database AI Vector Search User's Guide

16.9.7.2 Adding a Vector Column

Learn how to add a VECTOR column to a table.

The following examples uses the EBA_PROJECT_MILESTONES table which is available in sample dataset, Project Data.

To add a VECTOR column to a table:

  1. On the Workspace home page, click SQL Workshop.
  2. Click SQL Commands.

    The SQL Commands home page appears.

  3. Enter the following SQL command in the command editor:
    ALTER TABLE eba_project_milestones ADD (vector_column vector);
    
  4. Click Run (Ctrl+Enter) to execute the command.

    The results appear in the Results pane.

16.9.7.3 Retrieving the Vector Embeddings from a Vector Provider

Retrieve vector embeddings from a Vector Provider.

A Vector provider enables you to convert text into an embedding. The functionality can be covered by an AI Service, but also locally by an ONNX model in the database or a user-defined PL/SQL function.

The following example assumes you have created Vector Provider and are retrieving the embeddings from the EBA_PROJECT_MILESTONES table using the GET_VECTOR_EMBEDDINGS function in APEX_AI package.

To retrieve vector embeddings from a Vector Provider:

  1. On the Workspace home page, click SQL Workshop.
  2. Click SQL Commands.

    The SQL Commands home page appears.

  3. Enter the following SQL command in the command editor:
    UPDATE eba_project_milestones
       SET vector_column = apex_ai.get_vector_embeddings(
                               p_value             => name || ' ' || description,
                               p_service_static_id => 'VP_OCI_EMBEDDING' )
  4. Click Run (Ctrl+Enter) to execute the command.

    The results appear in the Results pane.

See Also:

GET_VECTOR_EMBEDDINGS functions in APEX_AI in Oracle APEX API Reference

16.9.7.4 Creating an Oracle Vector Search Configuration

Create an Oracle Vector Search configuration.

Note:

An Oracle Vector Search configuration requires Oracle Database 23ai or later. Before you can create an Oracle Vector Search configuration, you must complete all the steps described in About Oracle Vector Search Configurations.

A search configuration contains information about searchable data source.

To create a Oracle Vector Search configuration:

  1. Access the Search Configurations page:
    1. On the Workspace home page, click the App Builder icon.
    2. Select an application.
    3. On the Application home page, click Shared Components.
    4. Under Navigation and Search, click Search Configurations.
      The Search Configurations page appears.
  2. On the Search Configurations page, click Create.
    1. Name - Enter a name for the search configuration (for example, Search Milestones - Vector).
    2. Search Type - Select a type of search. Select Oracle Vector Search:
    3. Click Next.
  3. Source:
    1. Vector Provider - Select a Vector Provider used to get an embedding for a given search term. The search term must be converted using the same embedding model as the dataset in your table.
    2. Source Type - Specify the source of the search configuration. Oracle Vector search configuration can be based on a Table or SQL Query.
    3. Table / View Owner - Select the owner of the table that contains the vector column to be used for the search configuration (for example, Table).
    4. Table / View Name - Select the table that contains the vector column to be used for the search configuration (for example, EBA_PROJECT_MILESTONES).
    5. Click Next.
  4. Column Mapping:
    1. Primary Key Column - Select the primary key column for the Search Configuration Data Source (for example, ID Number).
    2. Vector Column - Select the vector column. For similarity searches through the approximate method, there must be a vector index for this column (for example, VECTOR_COLUMN (Vector)).
    3. Title Column - Select the column to be used as title (for example, NAME (Varchar2)).
    4. Description Column - Select the column to be used as the description (for example, DESCRIPTION (Varchar2)).
    5. Icon Source - Configure the icon that displays in the header of the search result. Options include:
      • Initials - The Title column to be used to display the icon as initials.
      • CSS Classes - The entered CSS classes to be used to display the icon.
      • Class Column - The selected column containing the icon CSS class to be used to display the icon.

      For this example, accept the default, Initials.

  5. Click Create Search Configuration.

    The search configuration is created. The Search Configuration, Edit page appears and displays the message Search configuration created.

  6. Edit the search configuration to link to a report:
    1. Link, Link Type - Select the type of link (for example, Redirect to Page in this Application).
    2. Page - Select or enter the page to redirect to (for example, 2).
    3. Click Apply Changes.
      The Search Configurations page appears with the message Search Configuration updated.
  7. Click the Application ID breadcrumb to return to the Application home page.

16.9.7.5 Creating an Oracle Vector Search Page

Create a Search page by running the Create Page Wizard.

The Create Page Wizard creates a Search field for you and prompts you to select search configurations. Note that you can also add additional search configurations later in Page Designer.

A Search page features a Search field and a Search Results region. In Page Designer, the Search Results region contains Search Sources which map to the search configurations defined in Shared Components.

To create a search page by running the Create Page Wizard:

  1. Navigate to the Application home page:
    1. On the Workspace home page, click the App Builder icon.
    2. Select the application.
  2. On the Application home page, click Create Page.
    Create a Page appears and features three tabs: Component, Feature, and Legacy Pages.
  3. Under Component, select Search Page.
  4. Page Definition:
    1. Page Number - The page number is an integer value that identifies a page within an application.
    2. Name - Specify a text name for this page (for example, Search Projects - Vector).

      This text is also used for page Title. After page creation, you can modify the Title in Page Designer.

    3. Page Mode - Identify the page mode. Accept the default, Normal.
  5. Search Configurations - Select the search configuration to be used by this page (for example, select Search Page - Vector).
  6. Navigation - Accept the default and enable Use Breadcrumb.
  7. Click Create Page.

    Page Designer appears.

    In the Rendering tab, notice the page item, PX_SEARCH (where X is the page number) and the Search Results region. PX_SEARCH is the search field which enables users to submit search terms. The Search Results region contains both the search results and the Search Source which maps to search configurations maintained in Shared Components. You can further refine and control the search display and behavior by editing attributes in the Property Editor.

  8. Run and test the page:
    1. Click Save and Run Page.
      The search page appears.
    2. In the search field, enter a search (for example, bug) and press Enter.

    The search results appear.