Updating my previous demo that was in 23ai to run in Oracle AI Database 26ai with two enhancements :
vector_memory_size set to 512MB (yes, this is a very small on-premises Free 26ai image)
INMEMORY NEIGHBOR GRAPH Index using Hierarchical Navigable Small World (HNSW)
[oracle@localhost ~]$ sqlplus vector_demo/vector_demo
SQL*Plus: Release 23.26.0.0.0 - Production on Sun Nov 16 09:37:39 2025
Version 23.26.0.0.0
Copyright (c) 1982, 2025, Oracle. All rights reserved.
Last Successful login time: Sun Nov 16 2025 09:32:43 +00:00
Connected to:
Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free
Version 23.26.0.0.0
SQL> set echo on
SQL> !ls *sql
Create_Vector_Index.sql Query_Vectors.sql
SQL> @Create_Vector_Index.sql
SQL> CREATE VECTOR INDEX my_data_vectors_ndx ON my_data_vectors (sentence_vector)
2 ORGANIZATION INMEMORY NEIGHBOR GRAPH
3 DISTANCE COSINE
4 WITH TARGET ACCURACY 95
5 /
Index created.
SQL> show parameter vector_memory
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
vector_memory_size big integer 512M
SQL> @Query_Vectors.sql
SQL> set pages600
SQL> set linesize 156
SQL> col my_sentence format a148 wrap
SQL>
SQL> ACCEPT text_input CHAR PROMPT 'Enter your query : '
Enter your query : image processing
SQL> VARIABLE text_variable VARCHAR2(1000)
SQL> VARIABLE query_vector VECTOR
SQL> BEGIN
2 :text_variable := '&text_input';
3 SELECT vector_embedding(ALL_MINILM_L12_V2_AUGMENTED USING :text_variable as data) into :query_vector;
4 END;
5 /
old 2: :text_variable := '&text_input';
new 2: :text_variable := 'image processing';
PL/SQL procedure successfully completed.
SQL>
SQL>
SQL> SELECT my_sentence, vector_distance(sentence_vector , :query_vector, COSINE) as Calc_Vector_Distance
2 FROM my_data_vectors
3 ORDER BY 2
4 FETCH FIRST 3 ROWS ONLY;
MY_SENTENCE
----------------------------------------------------------------------------------------------------------------------------------------------------
CALC_VECTOR_DISTANCE
--------------------
VanceAI.com image enhancement
5.16E-001
Stable Diffusion: An open source model that generates high quality images from text or other images, offering customization and control
5.51E-001
Hotpot.ai AI image editing
6.109E-001
SQL>
SQL> SELECT my_sentence, vector_distance(sentence_vector , :query_vector, COSINE) as Calc_Vector_Distance
2 FROM my_data_vectors
3 ORDER BY 2
4 FETCH APPROX FIRST 3 ROWS ONLY;
MY_SENTENCE
----------------------------------------------------------------------------------------------------------------------------------------------------
CALC_VECTOR_DISTANCE
--------------------
VanceAI.com image enhancement
5.16E-001
Stable Diffusion: An open source model that generates high quality images from text or other images, offering customization and control
5.51E-001
Hotpot.ai AI image editing
6.109E-001
SQL>
SQL> select * from dbms_xplan.display_cursor();
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID 1z2ujsrc9xsb0, child number 0
-------------------------------------
SELECT my_sentence, vector_distance(sentence_vector , :query_vector,
COSINE) as Calc_Vector_Distance FROM my_data_vectors ORDER BY 2 FETCH
APPROX FIRST 3 ROWS ONLY
Plan hash value: 3894957757
------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 2 (100)| |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | VIEW | | 3 | 6024 | 2 (50)| 00:00:01 |
|* 3 | SORT ORDER BY STOPKEY | | 3 | 4938 | 2 (50)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| MY_DATA_VECTORS | 3 | 4938 | 1 (0)| 00:00:01 |
| 5 | VECTOR INDEX HNSW SCAN | MY_DATA_VECTORS_NDX | 3 | 4938 | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM<=3)
3 - filter(ROWNUM<=3)
25 rows selected.
SQL>
Here I demonstrate querying the same set of 130 sentences about AI as in the previous demo, but now with a Vector Index configured as an In-Memory Neighbour Vector Graph Index and a Target Accuracy of 95% based on COSINE Distance.
My next run would be with a much larger data set (instead of just 130 sentences)
No comments:
Post a Comment