MLE JavaScript Support for the VECTOR Data Type
Oracle Multilingual Engine (MLE) supports conversions between JavaScript
TypedArrays and SQL vectors with formats INT8
, FLOAT32
,
and FLOAT64
. Data exchanges between JavaScript and the
VECTOR
data type are supported by the MLE JavaScript SQL driver, MLE
call specifications, and MLE JavaScript bindings.
The VECTOR
data type can appear as an IN
,
OUT
, and IN OUT
bind argument, as well as a return
type. The SIGNATURE
clause of an MLE call specification supports the
following JavaScript types:
Float32Array
Float64Array
Int8Array
Table A-5 Mapping from VECTOR Data Type to JavaScript Types
SQL Type | JavaScript Type |
---|---|
VECTOR(*, float32) |
Float32Array (TypedArray)
|
VECTOR(*, float64) |
Float64Array (TypedArray)
|
VECTOR(*, int8) |
Int8Array (TypedArray)
|
VECTOR(*) |
Float64Array Foot 1 (TypedArray)
|
Footnote 1 When no
vector format is specified, Float64Array
is used by
default
Table A-6 Mapping from JavaScript Types to VECTOR Data Type
JavaScript Type | SQL Type |
---|---|
Float32Array |
VECTOR(*, float32) |
Float64Array |
VECTOR(*, float64) |
Int8Array |
VECTOR(*, int8) |
Array |
VECTOR(*, float64) |
See Also:
-
Oracle Database AI Vector Search User's Guide for more information about the
VECTOR
data type and Oracle AI Vector Search capabilities
Example A-1 Use VECTOR Data Type with MLE
This example demonstrates support of the VECTOR
data
type used in arguments and as return type in MLE call specifications.
SET SERVEROUTPUT ON;
CREATE OR REPLACE MLE MODULE vec_mod
LANGUAGE JAVASCRIPT AS
/**
* Add two vectors
* @param v1 the first vector
* @param v2 the second vector
* @returns the resulting vector after adding v1 and v2
*/
export function addVectors(v1, v2){
return v1.map((element, index) => element + v2[index]);
}
/**
* Subtract two vectors
* @param v1 the first vector
* @param v2 the second vector
* @returns the resulting vector after subtracting v2 from v1
*/
export function subtractVectors(v1, v2){
return v1.map((element, index) => element - v2[index]);
}
/
CREATE OR REPLACE PACKAGE mle_vec_pkg AS
FUNCTION addVectors(
input_vector1 IN VECTOR,
input_vector2 IN VECTOR
)
RETURN VECTOR
AS MLE MODULE vec_mod
SIGNATURE 'addVectors';
FUNCTION subtractVectors(
input_vector1 IN VECTOR,
input_vector2 IN VECTOR
)
RETURN VECTOR
AS MLE MODULE vec_mod
SIGNATURE 'subtractVectors';
END mle_vec_pkg;
/
SELECT mle_vec_pkg.addVectors(
VECTOR('[1, 2]'),
VECTOR('[3, 4]')
) AS result;
Result:
RESULT
---------------------------------------------
[4.0E+000,6.0E+000]
SELECT mle_vec_pkg.subtractVectors(
VECTOR('[3, 4]'),
VECTOR('[1, 2]')
) AS result;
Result:
RESULT
---------------------------------------------
[2.0E+000,2.0E+000]
Parent topic: MLE Type Conversions