Database Management-Issue 160 Oracle Vector DB & AI-11 (20240312)

Database Management-Issue 160 Oracle Vector DB & AI-11 (20240312)

Author: Fat-headed Fish’s Fish Tank (Yin Haiwen)
Oracle ACE Associate: Database (Oracle and MySQL)
DBA director of a domestic technology company
with 10 years of experience in the database industry. Currently mainly engaged in database services
. He has OCM 11g/12c/19c, MySQL 8.0 OCP, Exadata, CDP and other certifications
Mo Tianlun MVP, certified technical expert, annual Moli Star, ITPUB certified expert, OCM lecturer
circle has titles such as "Director", "Security", "The Biggest Enemy of Domestic Databases", non-famous social terror (social Terrorist)
Official account: Fat-headed fish’s fish tank; CSDN: Fat-headed fish’s fish tank (Yin Haiwen); Mo Tianlun: Fat-headed fish’s fish tank; ITPUB: yhw1809.
Unless reprinted with permission and the source is indicated, it is "illegal" plagiarism.

We have reached the final stage of the basic introduction to Oracle Vector DB. This issue will talk about other vector functions, including vector function operations, vector conversion and binding operations.

1 Function operations on vectors

to_vector()

The to_vector() function converts a string into a vector, just like the vector() function.

SELECT to_vector('[34.6, 77.8]', 2, float32) FROM dual;

SELECT to_vector('[34.6, 77.8, -89.34]', 3, float32);

image.png
Note: The new features in Oracle DB 23c are also demonstrated here, and from dual is not required.

Convert vector to standard value

vector_norm()

The vector_norm() function outputs the distance from the origin to the vector point:

SELECT vector_norm(vector('[4, 3]', 2, float32) );

SELECT vector_norm(vector('[4, 3]', 2, float64) );

SELECT vector_norm(vector('[4, 3]', 2, int8) );

image.png

vector_dimension_count()

The vector_dimension_count() function outputs the number of dimensions of the vector:

SELECT vector_dimension_count(vector('[34.6, 77.8]', 2, float64));

SELECT vector_dimension_count(vector('[34.6, 77.8, 9]', 3, float32));

SELECT vector_dimension_count(vector('[34.6, 77.8, 9, 10]', 3, int8));

image.png

vector_dimension_format()

The vector_dimension_format() function outputs the dimension type of the vector:

SELECT vector_dimension_format(vector('[34.6, 77.8]', 2, float64));

SELECT vector_dimension_format(vector('[34.6, 77.8, 9]', 3, float32));

SELECT vector_dimension_format(vector('[34.6, 77.8, 9, 10]', 3, int8));

image.png

2 Convert vector to string or CLOB

Currently, the python-oracledb and node-oracledb SQL drivers support native binding of input and output vectors (i.e. using the vectors directly). Other SQL drivers such as JDBC and ODP.NET SQL only allow vectors to be bound as strings or CLOBs. When Oracle 23.4 provides Oracle AI Vector Search, all Oracle SQL drivers should support native vector binding.
Older SQL drivers [21c and prior] require you to explicitly convert by using the vector() or to_vector() function Vector input, and convert the vector output to a string or CLOB via from_vector() or vector_serialize().
Note: If you run this lab in SQL*Plus, sqlcl, or SQL Developer, you will not see a noticeable difference in the output, but you can be confident that the Vector transformation has been performed.

vector_serialize()

The vector_serialize() function can convert a vector to a string or CLOB:

SELECT vector_serialize(vector('[1.1, 2.2, 3.3]', 3, float32));

SELECT vector_serialize(vector('[1.1, 2.2, 3.3]', 3, float32)
       returning varchar2(1000));

SELECT vector_serialize(vector('[1.1, 2.2, 3.3]', 3, float32)
       returning clob);

image.png

from_vector()

The from_vector() function can convert a vector into a string or CLOB, which is equivalent to the vector_serialize() function:

SELECT from_vector(vector('[1.1, 2.2, 3.3]', 3, float32));

SELECT from_vector(vector('[1.1, 2.2, 3.3]', 3, float32) returning varchar2(1000));

SELECT from_vector(vector('[1.1, 2.2, 3.3]', 3, float32) returning clob);

image.png

Summarize

This issue briefly demonstrates other functions related to vector.
You may have to wait for a while in the next issue, and you will make a demonstration DEMO to more intuitively demonstrate the functions of Oracle Vector DB and AI Vector Search.
The old rule is to know what is written.

Guess you like

Origin blog.csdn.net/yhw1809/article/details/136649695