1 Mm
2 Mm
3 Mm
4 Mm
5 Mm
6 DML Operations on Vectors
6.1
Create a Table with a Vector Column
-
-
-
6.2
New data type to support vector search.
Definition can include:
o Number of dimensions (optional when defining your column)
o Format (optional when defining your column)
CREATE TABLE my_vectors (id NUMBER, emdeddinh VECTOR);
Possible dimension formats are:
o BINARY
o INT8 (8-bit integers)
o FLOAT32 (32-bit floating-point numbers) (IEEE standards)
o FLOAT64 (64-bit floating-point numbers) (IEEE standards)
CREATE TABLE my_vectors (id NUMBER, embedding VECTOR (768, INT8));
Declaration Formats and Explanation
o VECTOR: Vectors can have an arbitrary number of dimensions and formats
o VECTOR (*,*): Vectors can have an artibrary number of dimensions and
formats. VECTOR and VECTOR (*,*) are equivalent.
o VECTOR (number_of_dimensions,*) equivalent to
VECTOR(number_of_dimensions) : Vectors must all have the specified
number of dimensions or an error is thrown. Every vector will have its
dimensions stored without format modification.
o VECTOR (*, dimension_element_format) : Vectors can have an
arbitrary number of dimensions, but their format will be up-converted or
down-converted to the specified dimension element format (INT8, FLOAT32
or FLOAT64)
Vector DML
-
Directly insert vectors into a table:
CREATE TABLE galaxies (id NUMBER, name VARCHAR2(50), doc
VARCHAR2(500), embedding VECTOR);
INSERT INTO galaxies VALUES (1, ‘M31’, ‘Messier 31 is a barred spiral galaxy in
the Andromeda constellation which has a lot of barred spiral galaxies.’,
‘[0,2,2,0,0]’);
-
INSERTupdate
INTO galaxies
VALUES
(9,into
‘NGC1073’,
Directly
or delete
vectors
the table‘NGC 1073 is a barred spiral
galaxy in Cetus constellation.’, ‘[0,1,1,0,0]’);
COMMIT;
-
You can also load data using SQL*Loader
o ! Learn more on the control file.
6.3
Skill Check
7 VECTOR DDL
7.1
Tables with Different Vector Formats
You can have:
- More than one column of VECTOR data type
- Vector columns with different formats within the same table
-
7.2
Insert one row with different formats:
DDL Operations on Vectors
-
Add vector columns to exiting tables:
-
Drop vector columns from existing tables:
-
-
The vector column is designed to be extremely flexible to support vectors of any
number of dimensions and any format for the vector dimensions.
However, you can create a vector index only on a VECTOR column containing
vectors that all have the same number of dimensions.
This is required as you cant compute distances (such as using the
VECTOR_DISTANCE function) over vectors with different dimensions.
For example, if a VECTOR columns is defined as VECTOR (*, FLOAT32), and two
vectors with different dimensions (128 and 256 respectively) are inserted in that
column, when you try to create the vector index on that column, you will get an
error.
You can only create one type of vector index per vector column.
If you are running your Oracle Database on a RAC environment, you cannot create
HNSW indexes. On a non-RAC single instance environment you can create both
HNSW and IVF index. Using HNSW is the preferred type if it fits entirely into
memory.
7.3 VECTOR Data Type Restrictions
You cannot define VECTOR column in/as:
- External Tables
- IOTs (neither as Primary Key or as non-Key column)
- Clusters/Cluster Tables
- Global Temp Tables
- (Sub) Partitioning Key
- Primary Key
- Foreign Key
- Unique Constraint
- Check Constraint
- Default Value
- Modify Column
- MSSM tablespace (only SYS user can create VECTORs as Basicfiles in MSSM
tablespace)
- CQN queries
- Non-vector index such as B-tree, Bitmap, Reverse Key, Text, Spatial Indexes, etc.
APPENDIX
1. Student Guide: https://mylearn.oracle.com/ou/ekit/140188/35573/23a64f1d-d4984453-996e-0e624ac664c7/course
2. Activity Guide: https://mylearn.oracle.com/ekit/140188/35573/071d7311-3ecb-4d658728-dca0bc10f82a/course
3. PL/SQL Udemy Course: https://www.udemy.com/course/learning-plsql-the-exampleway/?ranMID=39197&ranEAID=JVFxdTr9V80&ranSiteID=JVFxdTr9V80eHSDHHkuGuSOQd3zKI6eeQ&LSNPUBID=JVFxdTr9V80&utm_source=affcampaign&utm_medium=udemyads
4.