Build a Semantic Search Page in Oracle APEX with AI Vector Search (No External AI)
Users type what they mean in their own words, and the APEX page finds the right record. A search page with a match score, a minimum match, a keyword boost for error codes and a vector index for large tables. All inside the Oracle database, tested for real.
Every APEX application I have built has a search field somewhere. And almost every one of them works the same way. LIKE '%' || :P1_SEARCH || '%', maybe with UPPER around it. It finds what users type, letter for letter. It does not find what they mean.
A user writes "people keep getting kicked out of the app". The task in the system is called "Users get logged out after a few minutes". Not one word in common that matters. LIKE finds nothing, and the user creates a duplicate task.
In part 2 the database got its own embedding model. Today I build the real thing on top of it. A Smart Search page in the Task Board app, the SQL behind it, the fine tuning that makes it usable, and a vector index for when the table gets big. Six real errors included.
LIKE finds nothing.Part 1 installed Oracle AI Database 26ai Free, ORDS and APEX 26.2 in Docker. Part 2 loaded the ONNX embedding model all-MiniLM-L12-v2 into the database and added a vector column with a trigger. This post builds on exactly that state.
What We Build
One new page in the Task Board app from part 1. A text field for the question, a select list for the minimum match, a search button, and a result list ranked by meaning. Behind it is one SQL query. No REST call, no external AI service, no Python. The question is turned into a vector inside the database and compared with the stored vectors of all tasks.
| Piece | What I used | Why |
|---|---|---|
| Search text | Title and description in one vector | Short titles give the model too little context |
| Ranking | VECTOR_DISTANCE(..., COSINE), shown as match % | Users understand 54 % better than 0.463 |
| Junk filter | Minimum match, default 25 % | A vector search always returns rows, even for nonsense |
| Exact terms | Keyword bonus (hybrid search) | Error codes and product names mean nothing to the model |
| APEX region | Classic Report with the Media List template | Title, description, icon and a badge per hit, no extra plug-in |
| Big tables | IVF or HNSW vector index | For tens of thousands of rows and more |
What You Need
The stack from parts 1 and 2. Oracle AI Database 26ai Free 23.26.3 in Docker, APEX 26.2, the model ALL_MINILM_L12_V2 owned by APEXNOTE_VEC and granted to the APEX schema APEXNOTE, and the DEMO_TASKS table with its TITLE_VEC column and trigger. Parts A and B run without any change to the database configuration. Part C changes one memory parameter and restarts the database container once.
I run every SQL script the same way as before. The file goes into the container and SQL*Plus runs it there.
docker cp script.sql apexnote-db:/tmp/ && \ docker exec -i apexnote-db sqlplus -l apexnote/<your_schema_password>@//localhost:1521/FREEPDB1 @/tmp/script.sql
Part A. The Search in SQL
Before I touch APEX, the query has to be right. Everything the page does later is in these seven steps.
Check the Starting Point
A quick look at what part 2 left behind. How many tasks, how many of them have a vector, is the trigger enabled, and can this schema see the model. My first query already failed.
set lines 140 pages 50 col title format a52 col model format a20 select count(*) as tasks, count(title_vec) as with_vector from demo_tasks; select trigger_name, status from user_triggers where table_name = 'DEMO_TASKS'; select model_name as model, mining_function, algorithm from all_mining_models where owner = 'APEXNOTE_VEC'; select id, title from demo_tasks order by id fetch first 5 rows only;
select count(*) as tasks, count(title_vec) as with_vector from demo_tasks * ERROR at line 1: ORA-22849: Type VECTOR is not supported for this function or operator.
set lines 140 pages 50 col title format a52 col model format a20 select count(*) as tasks, count(case when title_vec is not null then 1 end) as with_vector from demo_tasks; select trigger_name, status from user_triggers where table_name = 'DEMO_TASKS'; select model_name as model, mining_function, algorithm from all_mining_models where owner = 'APEXNOTE_VEC'; select id, title from demo_tasks order by id fetch first 5 rows only;
TASKS WITH_VECTOR ---------- ----------- 11 11 TRIGGER_NAME STATUS --------------------- -------- DEMO_TASKS_VEC_BIU ENABLED MODEL MINING_FUNCTION ALGORITHM -------------------- ----------------- ---------- ALL_MINILM_L12_V2 EMBEDDING ONNX
COUNT(title_vec) raises ORA-22849. Aggregate functions do not accept a VECTOR column, not even COUNT.CASE WHEN title_vec IS NOT NULL it works. 11 tasks, all with a vector, trigger enabled, model visible.Give the Search Something to Read
Eleven tasks with titles of four or five words are not enough to show what a search can do. Real tasks have a description, and that is where most of the meaning is. So the table gets a DESCRIPTION column, the open tasks from part 1 get a description, and I add 40 tasks that could come from any APEX team. Logins, slow reports, backups, certificates, Excel imports.
My first version put all 40 tasks into one JSON string and read it with JSON_TABLE. Neat, but SQL*Plus answered with ORA-01704. A string literal in SQL can not be longer than 4,000 characters. Plain INSERT statements are boring and they work.
-- (first try used one big JSON string literal: ORA-01704, literals are limited to 4,000 characters; plain INSERTs instead) set lines 140 pages 60 feedback off alter table demo_tasks add (description varchar2(2000)); update demo_tasks set description = case id when 6 then 'Export the APEXNOTE schema every night with expdp and keep the last seven dump files on the backup volume.' when 7 then 'Step by step notes for the team: stop ORDS first, then the database, start in the reverse order and check the APEX login.' when 8 then 'Import the all-MiniLM-L12-v2 ONNX model into the database so we can create embeddings with plain SQL.' when 9 then 'Users type a question in their own words and get the matching tasks, even when no word matches.' when 10 then 'The database container hit its memory limit during the APEX install. Check mem_limit and cpus in the compose file.' when 22 then 'The certificate of the reverse proxy expires in 14 days. Renew it and reload the proxy without downtime.' else description end; insert into demo_tasks (title, description, status, priority, owner) values ('Users get logged out after a few minutes', 'Several users report that APEX sends them back to the login page while they are still working. Check the session idle timeout and the maximum session length.', 'Open', 'High', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Customer list loads very slowly', 'The interactive report with all customers takes more than ten seconds to open. Look at the execution plan and add an index on the country column.', 'In Progress', 'High', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Send a reminder e-mail before the due date', 'Every morning a job should mail the owner of each task that is due tomorrow. Use APEX_MAIL and a scheduler job.', 'Open', 'Medium', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Fix ORA-01555 in the monthly sales report', 'The long running report fails with ORA-01555 snapshot too old when it runs during the nightly batch. Increase undo retention or move the job.', 'Open', 'High', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('REST call to the payment API fails over HTTPS', 'APEX_WEB_SERVICE returns ORA-29024 certificate validation failure. The wallet in the container is missing the root certificate of the provider.', 'In Progress', 'High', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Translate the app into German', 'Create a German translation of the Task Board, translate the labels and messages and add a language switch in the navigation bar.', 'Open', 'Low', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Dark mode for the Task Board', 'Offer the Vita Dark theme style and let every user choose light or dark in the user settings.', 'Open', 'Low', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Upload attachments to a task', 'Users want to add PDF and image files to a task. Store them in a BLOB table and show them in a small report on the form.', 'Open', 'Medium', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Import tasks from an Excel file', 'The project office keeps a spreadsheet with open items. Use the Data Load wizard so they can upload the XLSX file themselves.', 'Open', 'Medium', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Audit who changed a task', 'Keep a history of every change with old value, new value, user and timestamp, so we can see who closed or edited a task.', 'Open', 'Medium', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Add single sign-on with Microsoft Entra ID', 'Replace the APEX accounts with an OpenID Connect authentication scheme so employees sign in with their company account.', 'Open', 'High', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Rotate the database passwords', 'Change the passwords of SYS, the schema and the ORDS users every 90 days and update the secrets file of the stack.', 'Open', 'Medium', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Disk on the server is almost full', 'Only 8 percent free space left. Old Data Pump dumps and Docker images take most of it. Clean up and add monitoring.', 'In Progress', 'High', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Kanban board view for tasks', 'Show the tasks as cards in three columns Open, In Progress and Done and let users drag a card to change the status.', 'Open', 'Medium', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Calendar of due dates', 'A calendar page that shows every task on its due date, coloured by priority, with a click to open the task.', 'Done', 'Low', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Weekly status report as PDF', 'Every Friday the team lead wants a PDF with the tasks finished this week and the ones that are late.', 'Open', 'Medium', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Mobile layout breaks on small phones', 'On a phone the task form is wider than the screen and the buttons are cut off. Check the grid layout and the region templates.', 'Open', 'Medium', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Restore a single table from last night', 'Somebody deleted rows in the wrong table. Practise how to bring back one table from the Data Pump export without touching the rest.', 'Open', 'High', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Upgrade APEX to the next patch set', 'Download the latest patch set, test it on a copy of the database and plan a short maintenance window.', 'Open', 'Medium', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Speed up the dashboard charts', 'The home page has four charts that each run a full table scan. Pre-aggregate the numbers once per hour.', 'Open', 'Medium', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Password reset link for users', 'Users who forget their password should get a reset link by e-mail instead of asking the admin.', 'Open', 'Medium', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Expose tasks as a REST API', 'Publish GET and POST handlers with ORDS so the mobile app can read and create tasks, protected with OAuth2 client credentials.', 'Open', 'High', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Duplicate tasks are created twice', 'When a user double-clicks Create, the task is inserted twice. Disable the button after the first click and add a unique check.', 'Open', 'Medium', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Log slow pages', 'Find the pages with the highest elapsed time in the APEX activity log and write them to a weekly list.', 'Open', 'Low', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Move the stack to a bigger server', 'The demo server has only 2 CPUs. Copy the volumes, start the containers on the new machine and switch the DNS entry.', 'Open', 'Low', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Firewall only allows the web ports', 'Close every port except 80 and 443 to the outside. The database listener must only be reachable from the ORDS container.', 'Done', 'High', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Onboarding checklist for new developers', 'A short list with the accounts, tools and first steps a new developer needs on day one.', 'Open', 'Low', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Search tasks by meaning', 'Add AI vector search to the Task Board so users find tasks with their own words, using the ONNX model inside the database.', 'In Progress', 'High', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Show overdue tasks in red', 'In the task report, every open task with a due date in the past should be highlighted in red.', 'Done', 'Low', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Export the task list to CSV', 'Business users want to download the filtered task list and open it in Excel.', 'Done', 'Low', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Notifications in Microsoft Teams', 'Post a message to the team channel through an incoming webhook whenever a high priority task is created.', 'Open', 'Medium', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Archive tasks older than two years', 'Move finished tasks older than two years to an archive table to keep the main table small and fast.', 'Open', 'Low', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Database does not start after a reboot', 'After the host was restarted the database container stayed in starting state. The listener came up but the PDB was not opened.', 'Done', 'High', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Charts show wrong numbers for last month', 'The monthly chart counts tasks by created date in UTC, so tasks created late in the evening land in the wrong month.', 'Open', 'Medium', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Give the support team read-only access', 'Support needs to see all tasks but must not change anything. Create an authorization scheme with a reader role.', 'Open', 'Medium', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Write unit tests for the task package', 'Cover the create, update and close procedures with utPLSQL tests and run them before every deployment.', 'Open', 'Low', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Deploy changes with a pipeline', 'Export the application and the database objects to Git and install them on the test server automatically after every merge.', 'Open', 'Medium', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Users cannot upload files larger than 10 MB', 'Bigger uploads end with an error in the browser. Check the ORDS and reverse proxy limits for the request body size.', 'Open', 'Medium', 'Demo Admin'); insert into demo_tasks (title, description, status, priority, owner) values ('Clean up unused APEX pages', 'The app still contains test pages from the first prototype. Remove them and check that no menu entry points to them.', 'Open', 'Low', 'Demo Developer'); insert into demo_tasks (title, description, status, priority, owner) values ('Keep the search vectors up to date', 'When a title or description changes the embedding must change too. A trigger does it on every insert and update.', 'Done', 'High', 'Demo Developer'); commit; select count(*) as tasks, count(description) as with_description from demo_tasks;
One Search Vector for Title and Description
I keep TITLE_VEC from part 2 and add a second vector, SEARCH_VEC, from title and description together. The trigger now fills both, and it also fires when only the description changes.
set lines 140 pages 50 timing on alter table demo_tasks add (search_vec vector(384, float32)); update demo_tasks set search_vec = vector_embedding(apexnote_vec.all_minilm_l12_v2 using title || '. ' || description as data); commit; set timing off create or replace trigger demo_tasks_vec_biu before insert or update of title, description on demo_tasks for each row begin select vector_embedding(apexnote_vec.all_minilm_l12_v2 using :new.title as data), vector_embedding(apexnote_vec.all_minilm_l12_v2 using :new.title || '. ' || :new.description as data) into :new.title_vec, :new.search_vec from dual; end; / show errors select count(*) as tasks, count(case when search_vec is not null then 1 end) as with_search_vec from demo_tasks;
Table altered. Elapsed: 00:00:00.10 51 rows updated. Elapsed: 00:00:01.90 Trigger created. No errors. TASKS WITH_SEARCH_VEC ---------- --------------- 51 51
SELECT ... INTO ... FROM dual form in the trigger is the fix from part 2. VECTOR_EMBEDDING only works in SQL.The model turns one text into one vector. A title like "Disk on the server is almost full" is fine, but "Build the first test app" says almost nothing. The description adds the context that a user later describes in their own words. If the text gets very long, the model only reads the first part of it (this one stops after 512 tokens), so put the important words first.
The Search Query With a Match Score
This is the query the APEX page will run, in its simplest form. The question is embedded once in a WITH clause, then every task is ranked by cosine distance. Cosine distance goes from 0 (same meaning) upwards, and 1 - distance is the cosine similarity. Times 100 gives a match in percent that a user can read.
set lines 150 pages 50 feedback off col title format a50 col match_pct format 990 variable q varchar2(200) exec :q := 'people keep getting kicked out of the app' with question as ( select vector_embedding(apexnote_vec.all_minilm_l12_v2 using :q as data) as v from dual ) select t.id, t.title, round((1 - vector_distance(t.search_vec, question.v, cosine)) * 100) as match_pct from demo_tasks t, question order by vector_distance(t.search_vec, question.v, cosine) fetch first 3 rows only; exec :q := 'the server is running out of storage' / exec :q := 'how do we get yesterdays data back' /
-- 'people keep getting kicked out of the app' ID TITLE MATCH_PCT ---------- -------------------------------------------------- --------- 41 Users get logged out after a few minutes 38 98 Clean up unused APEX pages 25 5 Build the first test app 23 -- 'the server is running out of storage' 72 Disk on the server is almost full 70 97 Users cannot upload files larger than 10 MB 44 10 Review memory and CPU limits of the containers 34 -- 'how do we get yesterdays data back' 77 Restore a single table from last night 54 93 Charts show wrong numbers for last month 38 79 Speed up the dashboard charts 31
With this model 30 to 40 % is already a good match for a short question. What counts is the order and the gap to the next result. The absolute numbers depend on the model, so if you switch to another model, check your thresholds again.
Compare It With LIKE
To be fair to LIKE, I gave it the one word from each question that a user would most likely type, and let it search in title and description.
set lines 160 pages 50 feedback off col question format a42 col keyword format a10 col vector_top_hit format a45 with q (question, keyword) as ( select 'people keep getting kicked out of the app', 'kicked' from dual union all select 'the server is running out of storage', 'storage' from dual union all select 'how do we get yesterdays data back', 'yesterday' from dual union all select 'login with company account', 'company' from dual ) select q.question, q.keyword, (select count(*) from demo_tasks t where lower(t.title || ' ' || t.description) like '%' || q.keyword || '%') as like_hits, (select t.title from demo_tasks t order by vector_distance(t.search_vec, vector_embedding(apexnote_vec.all_minilm_l12_v2 using q.question as data), cosine) fetch first 1 row only) as vector_top_hit from q;
QUESTION KEYWORD LIKE_HITS VECTOR_TOP_HIT ------------------------------------------ ---------- ---------- --------------------------------------------- people keep getting kicked out of the app kicked 0 Users get logged out after a few minutes the server is running out of storage storage 0 Disk on the server is almost full how do we get yesterdays data back yesterday 0 Restore a single table from last night login with company account company 1 Add single sign-on with Microsoft Entra ID
LIKE finds 0, 0, 0 and 1 rows. The vector search finds the right task four times out of four. The one LIKE hit is the same task the vector search found.A Minimum Match Against Nonsense
There is one thing a vector search never does. It never says "nothing found". There is always a closest vector, even if the question has nothing to do with your data.
set lines 150 pages 50 feedback on col title format a50 col match_pct format 990 variable q varchar2(200) exec :q := 'best pizza in town' -- without a threshold: three "results" for a question that has nothing to do with our tasks with question as ( select vector_embedding(apexnote_vec.all_minilm_l12_v2 using :q as data) as v from dual ) select t.title, round((1 - vector_distance(t.search_vec, question.v, cosine)) * 100) as match_pct from demo_tasks t, question order by vector_distance(t.search_vec, question.v, cosine) fetch first 3 rows only; -- with a threshold: only rows with at least 25 % match (cosine distance <= 0.75) with question as ( select vector_embedding(apexnote_vec.all_minilm_l12_v2 using :q as data) as v from dual ) select t.title, round((1 - vector_distance(t.search_vec, question.v, cosine)) * 100) as match_pct from demo_tasks t, question where vector_distance(t.search_vec, question.v, cosine) <= 0.75 order by vector_distance(t.search_vec, question.v, cosine) fetch first 3 rows only; exec :q := 'the server is running out of storage' /
-- without a threshold, 'best pizza in town' TITLE MATCH_PCT -------------------------------------------------- --------- Customer list loads very slowly 6 Build semantic search page 5 Add single sign-on with Microsoft Entra ID 4 -- with a threshold (distance <= 0.75) no rows selected -- with a threshold, 'the server is running out of storage' Disk on the server is almost full 70 Users cannot upload files larger than 10 MB 44 Review memory and CPU limits of the containers 34
I picked 25 % after looking at my real questions. Every good hit was above 30 %, every unrelated row below 25 %. In the APEX page the user can change it.
Hybrid Search for Error Codes
Now the weak spot. Search for ORA-29024. One task mentions exactly this error in its description. The model does not know what ORA-29024 is, for it this is a string of letters and digits, and it ranks the installation tasks first. The real task gets 12 %.
The fix is old school. If the exact search text appears in title or description, the row gets 50 bonus points on top of its vector score. Meaning still decides the order for normal questions, exact matches win for codes, IDs and names.
set lines 150 pages 50 feedback off col title format a48 col vector_pct format 990 col keyword_bonus format 990 col score format 990 variable q varchar2(200) exec :q := 'ORA-29024' -- vector only: the task that really mentions ORA-29024 is not in the top 3 with question as ( select vector_embedding(apexnote_vec.all_minilm_l12_v2 using :q as data) as v from dual ) select t.id, t.title, round((1 - vector_distance(t.search_vec, question.v, cosine)) * 100) as vector_pct from demo_tasks t, question order by vector_distance(t.search_vec, question.v, cosine) fetch first 3 rows only; -- hybrid: + 50 points when the exact search text appears in title or description with question as ( select vector_embedding(apexnote_vec.all_minilm_l12_v2 using :q as data) as v from dual ), scored as ( select t.id, t.title, round((1 - vector_distance(t.search_vec, question.v, cosine)) * 100) as vector_pct, case when instr(lower(t.title || ' ' || t.description), lower(:q)) > 0 then 50 else 0 end as keyword_bonus from demo_tasks t, question ) select id, title, vector_pct, keyword_bonus, vector_pct + keyword_bonus as score from scored order by score desc fetch first 3 rows only; -- and a normal question still ranks by meaning (no keyword bonus anywhere) exec :q := 'people keep getting kicked out of the app' /
-- vector only, 'ORA-29024' ID TITLE VECTOR_PCT ---------- ------------------------------------------------ ---------- 2 Install ORDS and APEX 26.2 41 1 Install Oracle AI Database 26ai Free in Docker 32 63 Fix ORA-01555 in the monthly sales report 30 -- hybrid, 'ORA-29024' ID TITLE VECTOR_PCT KEYWORD_BONUS SCORE ---------- ------------------------------------------------ ---------- ------------- ----- 64 REST call to the payment API fails over HTTPS 12 50 62 2 Install ORDS and APEX 26.2 41 0 41 1 Install Oracle AI Database 26ai Free in Docker 32 0 32 -- hybrid, 'people keep getting kicked out of the app' 41 Users get logged out after a few minutes 38 0 38 98 Clean up unused APEX pages 25 0 25 5 Build the first test app 23 0 23
This keyword bonus only checks the whole search text with INSTR. That is enough for error codes and names, and it needs no extra index. If you need real word matching, stemming and fuzzy search on top, Oracle has hybrid vector indexes that combine Oracle Text and a vector index in one (CREATE HYBRID VECTOR INDEX, searched with DBMS_HYBRID_VECTOR.SEARCH). That is a topic for its own post.
Part B. The APEX Page
The query is ready. The page around it is small, and nothing on it needs a plug-in.
Build the Smart Search Page
In the Task Board app, create a new blank page called Smart Search (page 4 in my app, with a navigation menu entry). Then add the following in Page Designer.
| Component | Type | Settings that matter |
|---|---|---|
| Ask the Task Board | Static Content region | A short help text for the user |
| P4_SEARCH | Text Field | Submit when Enter pressed = On, a placeholder with an example question |
| P4_MIN_MATCH | Select List | Static values Any;0, 20 %;20, 25 %;25, 30 %;30, 40 %;40. Default 25. Page Action on Selection = Submit Page |
| SEARCH | Button | Action Submit Page, Hot, icon fa-search |
| Results | Classic Report | Source SQL Query (below). Appearance Template = Media List, template options Show Description and Show Badges. Server-side Condition Item is NOT NULL, P4_SEARCH |
| P3_DESCRIPTION | Textarea on page 3 (the task form) | Source column DESCRIPTION, so users can write descriptions |
The Media List template expects columns with fixed names. LIST_TITLE, LIST_TEXT, LIST_BADGE, ICON_CLASS, ICON_COLOR_CLASS and LINK, plus three optional ones. So the region SQL is the hybrid query from step 7 with these aliases. The status becomes the icon, the priority its colour, and APEX_PAGE.GET_URL opens the task form as a drawer when you click a hit.
with question as ( select vector_embedding(apexnote_vec.all_minilm_l12_v2 using :P4_SEARCH as data) as v from dual ), scored as ( select t.id, t.title, t.description, t.status, t.priority, round((1 - vector_distance(t.search_vec, question.v, cosine)) * 100) as vector_pct, case when instr(lower(t.title || ' ' || t.description), lower(:P4_SEARCH)) > 0 then 50 else 0 end as keyword_bonus from demo_tasks t, question ) select title as list_title, description as list_text, to_char(least(vector_pct + keyword_bonus, 100), 'fm990') || ' %' as list_badge, case status when 'Done' then 'fa fa-check-circle' when 'In Progress' then 'fa fa-spinner' else 'fa fa-circle-o' end as icon_class, case priority when 'High' then 'u-danger' when 'Medium' then 'u-warning' else 'u-success' end as icon_color_class, apex_page.get_url(p_page => 3, p_items => 'P3_ID', p_values => id) as link, null as link_class, null as link_attr, null as list_class from scored where vector_pct + keyword_bonus >= nvl(:P4_MIN_MATCH, 0) order by vector_pct + keyword_bonus desc fetch first 10 rows only
P4_SEARCH. A normal text field, nothing special about it.The first version of the page had a small surprise in it.
VECTOR_DISTANCE returns a BINARY_DOUBLE, so ROUND returns one too, and converting that to text gives scientific notation. The icons were empty as well.least(vector_pct + keyword_bonus, 100) || ' %' as list_badge
to_char(least(vector_pct + keyword_bonus, 100), 'fm990') || ' %' as list_badge
The empty icons had a simple reason. The Media List template writes ICON_CLASS into a t-Icon span, and Font APEX icons need the base class fa next to the icon name. So fa fa-check-circle, not just fa-check-circle.
The region runs in the parsing schema of the app, APEXNOTE. That is why the grant from part 2 (GRANT SELECT ON MINING MODEL ... TO apexnote) is needed. Without it, the page shows ORA-40284 "model does not exist".
Try It in the App
Now as a normal user in the running app. The home page has a new card, and the search page starts empty.
New Tasks Are Searchable Right Away
The real test for the trigger. I create a new task in the app and search for it with completely different words.
The form from part 1 has a hidden item for CREATED_ON. On insert it sends NULL for that column, and a normal DEFAULT systimestamp is ignored when a value, even NULL, is given. DEFAULT ON NULL handles exactly this case.
-- A plain DEFAULT does not help when NULL is passed explicitly; DEFAULT ON NULL does. -- connect: app set lines 140 pages 50 col column_name format a12 col data_default format a40 select column_name, data_default, default_on_null from user_tab_columns where table_name = 'DEMO_TASKS' and column_name = 'CREATED_ON'; alter table demo_tasks modify created_on default on null systimestamp; select column_name, data_default, default_on_null from user_tab_columns where table_name = 'DEMO_TASKS' and column_name = 'CREATED_ON';
COLUMN_NAME DATA_DEFAULT DEF ------------ --------------- --- CREATED_ON systimestamp NO Table altered. CREATED_ON systimestamp YES
NO to YES. The form works without any change in APEX.Part C. A Vector Index for Big Tables
With 51 tasks the database compares the question with every row, and nobody notices. That is called an exact search. To see where an index starts to make sense, I needed a bigger table.
20,000 Support Tickets and an Exact Search
A TICKETS table with 20,000 generated support tickets. Eight systems, seven problems, five situations and three reporters, so every sentence is different.
set lines 140 pages 50 timing on feedback on create table tickets ( id number generated always as identity primary key, text varchar2(400) not null, vec vector(384, float32) ); insert into tickets (text) select 'Ticket ' || level || ': ' || case mod(level, 8) when 0 then 'the customer portal' when 1 then 'the invoice report' when 2 then 'the login page' when 3 then 'the nightly backup' when 4 then 'the REST API' when 5 then 'the mobile app' when 6 then 'the e-mail service' else 'the order form' end || ' ' || case mod(level, 7) when 0 then 'is very slow' when 1 then 'shows an error message' when 2 then 'does not load at all' when 3 then 'sends wrong data' when 4 then 'times out' when 5 then 'logs users out' else 'works only sometimes' end || ' ' || case mod(level, 5) when 0 then 'since the last release' when 1 then 'for customers in Germany' when 2 then 'on Monday mornings' when 3 then 'after the server restart' else 'when many users are online' end || case mod(level, 3) when 0 then ', reported by sales' when 1 then ', reported by support' else ', reported by finance' end from dual connect by level <= 20000; commit; update tickets set vec = vector_embedding(apexnote_vec.all_minilm_l12_v2 using text as data); commit; set timing off select count(*) as tickets, count(distinct text) as distinct_texts from tickets; select round(sum(bytes) / 1024 / 1024) as table_mb from user_segments where segment_name = 'TICKETS' or segment_name like 'SYS_LOB%';
Table created. 20000 rows created. Elapsed: 00:00:00.12 20000 rows updated. Elapsed: 00:05:18.80 TICKETS DISTINCT_TEXTS ---------- -------------- 20000 20000 TABLE_MB ---------- 41
set lines 150 pages 50 feedback off timing on col text format a100 variable q varchar2(200) exec :q := 'the phone app keeps signing people out' select id, text from tickets order by vector_distance(vec, vector_embedding(apexnote_vec.all_minilm_l12_v2 using :q as data), cosine) fetch first 5 rows only; / / set timing off explain plan for select id from tickets order by vector_distance(vec, vector_embedding(apexnote_vec.all_minilm_l12_v2 using :q as data), cosine) fetch first 5 rows only; select plan_table_output from table(dbms_xplan.display(format => 'BASIC'));
7005 Ticket 7005: the mobile app logs users out since the last release, reported by sales 4765 Ticket 4765: the mobile app logs users out since the last release, reported by support 14565 Ticket 14565: the mobile app logs users out since the last release, reported by sales ... Elapsed: 00:00:00.89 <- first call in this session (model is loaded) Elapsed: 00:00:00.03 Elapsed: 00:00:00.04 | Id | Operation | Name | | 0 | SELECT STATEMENT | | | 1 | COUNT STOPKEY | | | 2 | VIEW | | | 3 | SORT ORDER BY STOPKEY| | | 4 | TABLE ACCESS FULL | TICKETS |
For an APEX app with a few thousand or even 20,000 rows you do not need a vector index. An exact search is also always 100 % accurate. Indexes become important with hundreds of thousands or millions of rows, or with many users searching at the same time. I still wanted to know what it takes, so here it is.
HNSW Fails, IVF Works
Oracle has two kinds of vector index. HNSW (INMEMORY NEIGHBOR GRAPH) is a graph that lives completely in memory and is the fastest. IVF (NEIGHBOR PARTITIONS) groups the vectors into partitions around centre points and lives on disk like a normal index. I tried HNSW first.
set lines 140 pages 50 timing on create vector index tickets_vec_hnsw on tickets (vec) organization inmemory neighbor graph distance cosine with target accuracy 95;
create vector index tickets_vec_hnsw on tickets (vec) * ERROR at line 1: ORA-51962: The vector memory area is out of space for the current container.
vector_memory_size is 0. We saw that value in part 2 already.set lines 150 pages 50 feedback off timing on col text format a100 create vector index tickets_vec_ivf on tickets (vec) organization neighbor partitions distance cosine with target accuracy 95; variable q varchar2(200) exec :q := 'the phone app keeps signing people out' select id, text from tickets order by vector_distance(vec, vector_embedding(apexnote_vec.all_minilm_l12_v2 using :q as data), cosine) fetch approx first 5 rows only; / / set timing off explain plan for select id from tickets order by vector_distance(vec, vector_embedding(apexnote_vec.all_minilm_l12_v2 using :q as data), cosine) fetch approx first 5 rows only; select plan_table_output from table(dbms_xplan.display(format => 'BASIC'));
Index created. Elapsed: 00:00:06.16 Elapsed: 00:00:00.87 <- first call in this session Elapsed: 00:00:00.01 Elapsed: 00:00:00.02 | 13 | TABLE ACCESS FULL | VECTOR$TICKETS_VEC_IVF$..._IVF_FLAT_CENTROIDS | | 14 | PARTITION LIST JOIN-FILTER| | | 15 | TABLE ACCESS FULL | VECTOR$TICKETS_VEC_IVF$..._IVF_FLAT_CENTROID_PARTITIONS |
FETCH APPROX, without APPROX Oracle does an exact search and ignores the index.Vector Memory and HNSW
For HNSW the database needs a vector pool. A normal ALTER SYSTEM in the CDB root, I thought.
set lines 140 pages 50 col name format a22 col value format a12 alter system set vector_memory_size = 256M scope = both; select name, display_value as value from v$parameter where name in ('sga_target', 'vector_memory_size'); select pool, round(sum(bytes) / 1024 / 1024) as mb from v$sgastat where pool = 'vector pool' group by pool;
alter system set vector_memory_size = 256M scope = both * ERROR at line 1: ORA-02097: parameter cannot be modified because specified value is invalid ORA-51950: The Oracle Database Vector Memory size cannot be increased.
set lines 140 pages 50 alter system set vector_memory_size = 256M scope = spfile;
set -e cd /opt/apexnote-demo start=$(date +%s) docker compose restart db until [ "$(docker inspect -f '{{.State.Health.Status}}' apexnote-db)" = "healthy" ]; do sleep 3; done echo "database healthy after $(( $(date +%s) - start )) s" curl -s -o /dev/null -w "APEX answers with HTTP %{http_code}\n" http://127.0.0.1:8190/ords/r/apexnote/task-board/
Container apexnote-db Restarting Container apexnote-db Started database healthy after 11 s APEX answers with HTTP 302
vector_memory_size = 0, it can not be raised online. It goes into the spfile and needs a restart.docker compose restart db. Healthy after 11 seconds, APEX answers again. Plan this for a maintenance window on a real system.set lines 150 pages 50 feedback off col text format a100 drop index tickets_vec_ivf; set timing on create vector index tickets_vec_hnsw on tickets (vec) organization inmemory neighbor graph distance cosine with target accuracy 95; variable q varchar2(200) exec :q := 'the phone app keeps signing people out' select id, text from tickets order by vector_distance(vec, vector_embedding(apexnote_vec.all_minilm_l12_v2 using :q as data), cosine) fetch approx first 5 rows only; / / set timing off explain plan for select id from tickets order by vector_distance(vec, vector_embedding(apexnote_vec.all_minilm_l12_v2 using :q as data), cosine) fetch approx first 5 rows only; select plan_table_output from table(dbms_xplan.display(format => 'BASIC'));
Index created. Elapsed: 00:00:10.46 Elapsed: 00:00:01.16 <- first call after the restart Elapsed: 00:00:00.01 Elapsed: 00:00:00.01 | 4 | TABLE ACCESS BY INDEX ROWID| TICKETS | | 5 | VECTOR INDEX HNSW SCAN | TICKETS_VEC_HNSW |
set lines 150 pages 50 col pool format a12 select pool, round(alloc_bytes / 1024 / 1024) as alloc_mb, round(used_bytes / 1024 / 1024, 1) as used_mb from v$vector_memory_pool order by pool;
POOL ALLOC_MB USED_MB ------------ ---------- ---------- 1MB POOL 224 38 64KB POOL 16 .7
VECTOR INDEX HNSW SCAN. Same five tickets as the exact search.| Option | Build | Search (warm) | Needs | When I would use it |
|---|---|---|---|---|
| No index (exact) | none | 30 to 40 ms | nothing | Up to tens of thousands of rows, always 100 % accurate |
| IVF | 6.2 s | 10 to 20 ms | nothing extra | Large tables, many changes, little memory |
| HNSW | 10.5 s | about 10 ms | vector pool (38 MB here) | Very large tables, many parallel searches, enough RAM |
On 20,000 rows all three options are fast, and a big part of the 10 ms is embedding the question itself. The first search in a new database session takes about one second more, because the model is loaded into that session. ORDS reuses its database sessions, so in APEX this hits only the first search after a restart or after a quiet period.
Troubleshooting. The Six Errors I Hit
| Error | Where | Real cause | Fix |
|---|---|---|---|
| ORA-22849 Type VECTOR is not supported for this function or operator | COUNT(vector_column) | Aggregates do not take VECTOR | COUNT(CASE WHEN v IS NOT NULL THEN 1 END) |
| ORA-01704 string literal too long | Seed data as one big JSON string | SQL literals are limited to 4,000 characters | Plain INSERTs, or a CLOB bind variable |
| 3.8E+001 % in the APEX badge | Report column built from ROUND(1 - VECTOR_DISTANCE(...)) | VECTOR_DISTANCE returns BINARY_DOUBLE | TO_CHAR(value, 'fm990') |
| ORA-01400 cannot insert NULL into CREATED_ON | APEX form with a hidden item for the column | The form sends NULL, a plain default is ignored | DEFAULT ON NULL systimestamp |
| ORA-51962 vector memory area is out of space | CREATE VECTOR INDEX ... INMEMORY NEIGHBOR GRAPH | vector_memory_size = 0 | Give the database a vector pool, or use IVF |
| ORA-51950 (with ORA-02097) vector memory size cannot be increased | ALTER SYSTEM ... SCOPE = BOTH | The instance started with 0 | SCOPE = SPFILE and restart |
Speed and Memory
set lines 150 pages 50 feedback off timing on col list_title format a50 col list_badge format a6 variable P4_SEARCH varchar2(200) variable P4_MIN_MATCH number exec :P4_SEARCH := 'people keep getting kicked out of the app'; :P4_MIN_MATCH := 25 with question as ( select vector_embedding(apexnote_vec.all_minilm_l12_v2 using :P4_SEARCH as data) as v from dual ), scored as ( select t.id, t.title, t.description, round((1 - vector_distance(t.search_vec, question.v, cosine)) * 100) as vector_pct, case when instr(lower(t.title || ' ' || t.description), lower(:P4_SEARCH)) > 0 then 50 else 0 end as keyword_bonus from demo_tasks t, question ) select title as list_title, to_char(least(vector_pct + keyword_bonus, 100), 'fm990') || ' %' as list_badge from scored where vector_pct + keyword_bonus >= nvl(:P4_MIN_MATCH, 0) order by vector_pct + keyword_bonus desc fetch first 10 rows only; / /
LIST_TITLE LIST_B -------------------------------------------------- ------ Users get logged out after a few minutes 38 % Clean up unused APEX pages 25 % Elapsed: 00:00:01.15 <- first call in this session Elapsed: 00:00:00.01 Elapsed: 00:00:00.01
| What | Measured |
|---|---|
| Embed 51 tasks (title and description) | 1.9 s |
| Smart Search page query, 51 tasks | about 10 ms, 1.15 s for the first call in a session |
| Embed 20,000 tickets | 5 min 19 s (about 16 ms per row) |
| Exact search, 20,000 rows | 30 to 40 ms |
| IVF index build / search | 6.2 s / 10 to 20 ms |
| HNSW index build / search | 10.5 s / about 10 ms |
| HNSW graph in the vector pool | 38 MB of 256 MB |
| Database restart for the vector pool | healthy after 11 s |
| Database container RAM after everything | 2.3 GiB of 4 GiB |
Semantic search, duplicate detection, similar records or chat with your own data. We build AI features into Oracle APEX applications that run inside your database, without sending your data anywhere. Get in touch.
What Comes Next
From an empty Linux server to an APEX app that understands questions, in three posts. A few ideas where to go from here.
Part 4 is online: Private AI Search in Oracle APEX: Data In-House, Tenants Apart. What really leaves the server, and how Virtual Private Database keeps franchises and tenants apart.
- Find duplicates while typing. The same query, run on the title field of the create form, shows "similar tasks already exist" before somebody creates the task a second time.
- Other languages. For German or mixed texts, swap the model for multilingual-e5-small, as described in part 2. Re-embed once, check the threshold again.
- Real hybrid indexes. Oracle Text and vectors in one index, with word matching and fuzzy search on top.
- Chat with your data. The top hits of this search are exactly what you give a language model as context (RAG), so it answers from your own tasks.
Final Thoughts
The part that took the longest was not the vectors. It was the details around them. A threshold, so the page can say "nothing found". A keyword bonus, so error codes still work. A TO_CHAR, so the badge does not show scientific notation. Those are the things that decide whether users trust a search or ignore it.
The search itself is one SQL query in a Classic Report. No plug-in, no service next to the database, no API key, and no data leaving the server. For most APEX apps the table is small enough that you do not even need an index. I find that the most surprising result of this whole series.
If you build this into your own app and something does not work the way it did here, write to me. I read every message.
{fullWidth}