Oracle AI Vector Search
Overview
In 2024, Oracle introduced AI Vector Search, a groundbreaking advancement in their database technology. This
solution extends beyond vector capabilities, offering a full suite for working with embeddings, integrating
with large language models (LLMs), and enabling complete Retrieval-Augmented Generation (RAG) pipelines.
Developers can now build powerful AI applications while benefiting from Oracle’s robust database ecosystem.
Oracle AI Vector Search simplifies workflows by enabling tasks such as embedding generation, document chunking,
and LLM-based text processing directly within the database. It also supports external processing, maintaining
flexibility for diverse use cases. Features like ONNX model integration and third-party service compatibility
further enhance its utility. By combining traditional database strengths with advanced vector search, Oracle
AI Vector Search empowers semantic searches, recommender systems, and RAG implementations.
To understand how the Oracle Vector Database enhances AI vector search, visit our page on the Oracle Vector Database.
Generate Embeddings
Oracle Database offers versatile options for generating embeddings, whether in-database or externally.
In-Database
Oracle supports embedding models in the ONNX format. The DBMS_VECTOR.LOAD_ONNX_MODEL
procedure
allows importing pre-trained models up to 1GB. Once loaded, embeddings can be generated directly in SQL:
SELECT TO_VECTOR(VECTOR_EMBEDDING(doc_model USING 'example text' AS data)) AS embedding
FROM DUAL;
External Providers
Oracle integrates with external providers like OpenAI, Hugging Face, and Cohere. To use these, credentials
are securely managed within the database, and the DBMS_VECTOR.UTL_TO_EMBEDDING
function facilitates
embedding generation:
SELECT DBMS_VECTOR.UTL_TO_EMBEDDING('example text', json(:params))
FROM DUAL;
Developers can also generate embeddings externally using libraries like langchain_cohere
, then
store them in Oracle Database.
Store Embeddings
Oracle Database offers a specialized VECTOR data type, designed to efficiently store vector embeddings for a wide range of applications. In this section,
we’ll walk you through how to define a table specifically for storing embeddings.
CREATE TABLE my_vectors ( id NUMBER, embedding VECTOR(768, INT8) );
In this example, the table is created with two columns: an ID column and an embedding column. The embedding column uses the VECTOR data type to store vector
embeddings with 768 dimensions, each represented in the INT8 format. You can also choose other formats like FLOAT32 or FLOAT64 depending on your specific
requirements, and specifying the dimension count is optional.
Oracle allows you to perform conversions between common data types like VARCHAR2 or CLOB
and the VECTOR type, making it easier to work with various data sources and integrate them into your vector-based storage system.
When dealing with large datasets, Oracle’s SQLLoader tool comes in handy. It supports bulk loading of vectors from both text and binary formats,
including .fvec files. This ensures that importing large volumes of vector data into your database is fast and efficient.
Vector Indexes
Efficient vector searches rely on indexes. Oracle supports two primary types of vector indexes:
- IVF (Inverted File): Partitions data into clusters for targeted searching.
- HNSW (Hierarchical Navigable Small World): Creates an in-memory graph for rapid searches.
Indexes can be fine-tuned for target accuracy, and Oracle provides tools to monitor and optimize index performance.
CREATE VECTOR INDEX galaxies_ivf_idx
ON galaxies (embedding)
ORGANIZATION NEIGHBOR PARTITIONS
DISTANCE COSINE
WITH TARGET ACCURACY 95;
Vector Distance
Oracle simplifies vector similarity calculations with the VECTOR_DISTANCE
function and shorthand
operators like L2_DISTANCE
and COSINE_DISTANCE
. These functions enable both exact
and approximate similarity searches:
-- Exact Similarity Search
SELECT docID
FROM vector_tab
ORDER BY VECTOR_DISTANCE(embedding, :query_vector, EUCLIDEAN_SQUARED)
FETCH FIRST 10 ROWS ONLY;
-- Approximate Similarity Search
SELECT name
FROM galaxies
WHERE name <> 'NGC1073'
ORDER BY VECTOR_DISTANCE(embedding, TO_VECTOR('[0,1,1,0,0]'), COSINE)
FETCH APPROXIMATE FIRST 3 ROWS ONLY;
Retrieval-Augmented Generation (RAG)
Retrieval-Augmented Generation (RAG) enhances LLM outputs by providing context from reliable data sources.
Oracle’s in-database RAG solution streamlines this process, ensuring data security and efficiency.
Implementation Steps
- Data Preparation: Load documents into tables, preprocess into chunks, and generate embeddings using
DBMS_VECTOR_CHAIN
utilities.
- Query Processing: Convert user queries into vectors and perform similarity searches with
VECTOR_DISTANCE
.
- LLM Integration: Use the
UTL_TO_GENERATE_TEXT
function to enhance outputs with
relevant context from your data.
RAG reduces hallucinations in LLMs and ensures responses are grounded in factual data, making it ideal for
applications like chatbots and content filtering.
Conclusion
Oracle AI Vector Search revolutionizes data interaction by combining advanced AI capabilities with enterprise-grade
database features. Its RAG capabilities and seamless LLM integration make it a strong choice for businesses
embracing AI-driven solutions. With Oracle Cloud’s free tier, developers can explore its potential and create
intelligent, context-aware applications with ease.