Skip to main content
Oracle AI Vector Search is designed for Artificial Intelligence (AI) workloads that allows you to query data based on semantics, rather than keywords. One of the biggest benefits of Oracle AI Vector Search is that semantic search on unstructured data can be combined with relational search on business data in one single system. This is not only powerful but also significantly more effective because you don’t need to add a specialized vector database, eliminating the pain of data fragmentation between multiple systems. In addition, your vectors can benefit from all of Oracle Database’s most powerful features, like the following: If you are just starting with Oracle Database, consider exploring the free Oracle 23 AI which provides a great introduction to setting up your database environment. While working with the database, it is often advisable to avoid using the system user by default; instead, you can create your own user for enhanced security and customization. For detailed steps on user creation, refer to our end-to-end guide which also shows how to set up a user in Oracle. Additionally, understanding user privileges is crucial for managing database security effectively. You can learn more about this topic in the official Oracle guide on administering user accounts and security.

Prerequisites

You’ll need to install langchain-oracledb to use this integration. The python-oracledb driver is installed automatically as a dependency of langchain-oracledb.
The following sample code will show how to connect to Oracle Database. By default, python-oracledb runs in a ‘Thin’ mode which connects directly to Oracle Database. This mode does not need Oracle Client libraries. However, some additional functionality is available when python-oracledb uses them. Python-oracledb is said to be in ‘Thick’ mode when Oracle Client libraries are used. Both modes have comprehensive functionality supporting the Python Database API v2.0 Specification. See the following guide that talks about features supported in each mode. You might want to switch to thick-mode if you are unable to use thin-mode.

Import the required dependencies

Load documents

Create vector stores with different distance metrics

First we will create three vector stores each with different distance functions. Since we have not created indices in them yet, they will just create tables for now. Later we will use these vector stores to create HNSW indicies. To understand more about the different types of indices Oracle AI Vector Search supports, refer to the following guide . You can manually connect to the Oracle Database and will see three tables : Documents_DOT, Documents_COSINE and Documents_EUCLIDEAN. We will then create three additional tables Documents_DOT_IVF, Documents_COSINE_IVF and Documents_EUCLIDEAN_IVF which will be used to create IVF indicies on the tables instead of HNSW indices.

Index creation with specific parameters

Oracle Database 23ai supports pre-filtering, in-filtering, and post-filtering to enhance AI Vector Search capabilities. These filtering mechanisms allow users to apply constraints before, during, and after performing vector similarity searches, improving search performance and accuracy. Key Points about Filtering in Oracle 23ai:
  1. Pre-filtering Applies traditional SQL filters to reduce the dataset before performing the vector similarity search. Helps improve efficiency by limiting the amount of data processed by AI algorithms.
  2. In-filtering Utilizes AI Vector Search to perform similarity searches directly on vector embeddings, using optimized indexes and algorithms. Efficiently filters results based on vector similarity without requiring full dataset scans.
  3. Post-filtering Applies additional SQL filtering to refine the results after the vector similarity search. Allows further refinement based on business logic or additional metadata conditions.
Why is this Important?
  • Performance Optimization: Pre-filtering significantly reduces query execution time, making searches on massive datasets more efficient.
  • Accuracy Enhancement: In-filtering ensures that vector searches are semantically meaningful, improving the quality of search results.

Filter Details

OracleVS supports a set of filters that can be applied to metadata fields using filter parameter. These filters allow you to select and refine data based on various criteria. Available Filter Operators:
  • You can combine these filters using logical operators:
Example Filter:
Additional Usage Tips:
  • You can omit $and when all filters in an object must be satisfied. These two are equivalent:
  • The $not clause can negate a comparison operator:
  • Using field: scalar is equivalent to field: { "$eq": scalar }:
For more filter examples, refer to the test specification.

End to End Demo

Please refer to our complete demo guide Oracle AI Vector Search End-to-End Demo Guide to build an end to end RAG pipeline with the help of Oracle AI Vector Search.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.