How to Build a Semantic Search Page in Oracle APEX

Let users search by meaning in Oracle APEX 26.1 with a vector provider, a vector search configuration, and a search page, without writing SQL.

Semantic search finds answers by meaning, even when the question shares no words with them. In Oracle APEX 26.1 it needs no SQL at all: a vector provider embeds the user's words, a search configuration of type Oracle AI Vector Search compares them with a vector column, and a search page shows the results.

This guide creates a vector provider that runs an embedding model inside the database, a vector search configuration over a knowledge base, and a search page, and shows how several configurations on one page give hybrid search.

Code for This Guide

The finished application, with the search configuration and page, is apex/f200.sql in the Oracle AI code repository on GitHub.

These examples come from AI Applications with Oracle Database 26ai and APEX 26.1, a book of 237 tested examples of AI in Oracle Database and APEX.

The articles of KB_ARTICLES have an EMBEDDING column computed with the in-database model ALL_MINILM_L12_V2, as shown in how to generate embeddings in SQL with VECTOR_EMBEDDING. The same search written in SQL is in how to build semantic search in Oracle Database.

Step 1: Create a Vector Provider

A vector provider turns text into an embedding for APEX, for search configurations and for APEX_AI.GET_VECTOR_EMBEDDINGS. It comes in three types:

Provider TypeEmbeds withSettings
Database ONNX ModelA model loaded in the databaseONNX Model Owner, ONNX Model Name
Generative AI ServiceA provider's embedding modelAI Provider and its settings
Custom PL/SQLA function you writeCustom Function Name
  1. Go to Workspace Utilities, Vector Providers, and choose Create.
  2. In Provider Type, choose Database ONNX Model; in Name, type Atlas MiniLM.
  3. In ONNX Model Owner, choose ATLAS; in ONNX Model Name, choose ALL_MINILM_L12_V2.
  4. Leave Static ID as APEX derives it, atlas-minilm, and choose Create.
Oracle APEX vector provider Atlas MiniLM of type Database ONNX Model using ALL_MINILM_L12_V2
The vector provider for the model in the database.
Oracle APEX list of workspace vector providers with Atlas MiniLM
The vector providers of the workspace.

The Static ID is locked once the provider is saved, because code and exported applications refer to it, so choose it before you choose Create. A vector provider must embed with the same model as the stored vectors it is compared with.

Step 2: Create a Search Configuration

A search configuration is a shared component. APEX 26.1 offers five search types:

Search TypeHow it searches
StandardA SQL query with LIKE expressions over chosen columns
Oracle AI Vector SearchThe distance between the embedded search words and a vector column
Oracle TextCONTAINS on a column with an Oracle Text index
Oracle Ubiquitous SearchA search index of the DBMS_SEARCH package
ListThe entries of an APEX list
  1. Go to Shared Components, Search Configurations, and choose Create.
  2. In Name, type Knowledge Base; in Search Type, choose Oracle AI Vector Search.
  3. In Vector Provider, choose Atlas MiniLM; in Source Type, Table; in Table / View Name, KB_ARTICLES.
  4. In Primary Key Column, choose ARTICLE_ID; in Vector Column, EMBEDDING; in Title Column, TITLE; in Description Column, BODY.
  5. Choose Create Search Configuration.
Oracle APEX vector search configuration column mapping with primary key, vector, title, and description columns
The column mapping of the vector search configuration.

The Vector Column list offers only VECTOR columns. The column must hold embeddings from the same model as the provider: choosing a column of Gemini embeddings here would compare 384 dimensions with 3,072 and fail. Subtitle, Badge, and custom columns can add more to each result, and a Score Column can show relevance.

Step 3: Set the Vector Attributes

Oracle APEX search configuration vector attributes with provider, search type, distance metric, maximum distance, and maximum rows
The vector attributes of the search configuration.
SettingWhat it does
ProviderThe vector provider that embeds the search words
Column NameThe vector column the words are compared with
Search TypeExact compares every row; Approximate uses a vector index of the column
Distance MetricCosine, Dot, Euclidean, Euclidean Squared, Hamming, or Manhattan; the index's metric if there is one
Maximum Vector DistanceRows farther than this are not returned
Maximum Rows to ReturnThe largest number of results
Where ClauseA condition that limits the rows; it can use APEX$VECTOR_DISTANCE, the row's distance

On this data, right articles lie within 0.75 of their questions and unrelated questions are 0.876 or more from every article, so set Maximum Vector Distance to 0.8 and Maximum Rows to Return to 5, and apply the changes. An unrelated search now returns nothing, and a related one at most five results. With 24 articles, Exact is right; for tens of thousands of rows, choose Approximate with a vector index for the same metric.

Step 4: Create the Search Page

  1. Choose Create Page, then Search Page.
  2. In Name, type Search.
  3. Under the search configurations, check Knowledge Base.
  4. Choose Create Page.
Oracle APEX Create Page wizard for a search page using the Knowledge Base search configuration
Creating a search page on the Knowledge Base configuration.

Run the page and type a question that shares no words with its answer.

Oracle APEX search page finding the mobile app crash article for a question about the phone app closing
The search page finds the article on crashes at startup.

The article on mobile crashes at startup comes first: the search went by meaning, with no SQL written. The other results are the articles within 0.8, nearest first. A question about bills finds the article on invoices the same way.

Oracle APEX search page finding the article on downloading invoices for a question about bills
A question about bills finds the article on invoices.

Combine Configurations for Hybrid Search

A Search region can use several configurations at once, each with its own group of results. A help desk search page might combine:

  • Knowledge Base: vector search over the articles, as above.
  • Documents: vector search over document chunks, with the document title as title and the chunk as description.
  • Codes: an Oracle Text configuration for exact words such as GSTIN or 8.4.1, where semantic search is weak.

That is hybrid search in declarative form: each configuration finds what it is good at, and the user sees both. A Search Query Prefix on a configuration, such as doc:, lets users direct a search to one of them. The SQL version is covered in how to build hybrid search in Oracle Database.

Conclusion

A semantic search page in Oracle APEX 26.1 takes three shared parts: a vector provider that embeds with the same model as your stored vectors, a search configuration of type Oracle AI Vector Search that maps the key, vector, title, and description columns, and a search page from the Create Page wizard. Set Maximum Vector Distance from measured distances to drop unrelated results, and add Oracle Text configurations to the same page for exact codes and names.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted
00