- Partitioning Support
- Real Application Clusters scalability
- Exadata smart scans
- Shard processing across geographically distributed databases
- Transactions
- Parallel SQL
- Disaster recovery
- Security
- Oracle Machine Learning
- Oracle Graph Database
- Oracle Spatial and Graph
- Oracle Blockchain
- JSON
Prerequisites
You’ll need to installlangchain-oracledb to use this integration.
The python-oracledb driver is installed automatically as a dependency of langchain-oracledb.
Connect to Oracle AI Vector Search
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.Add and delete operations for texts, along with basic similarity search
Index creation with specific parameters
Advanced search
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:- 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.
- 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.
- 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.
- 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:
| Operator | Description |
|---|---|
\$exists | Field exists. |
\$eq | Field value equals the operand value (=). |
\$ne | Field exists and value does not equal the operand value (!=). |
\$gt | Field value is greater than the operand value (>). |
\$lt | Field value is less than the operand value (<). |
\$gte | Field value is greater than or equal to the operand value (>=). |
\$lte | Field value is less than or equal to the operand value (<=). |
\$between | Field value is between (or equal to) two values in the operand array. |
\$startsWith | Field value starts with the operand value. |
\$hasSubstring | Field value contains the operand as a substring. |
\$instr | Field value contains the operand as a substring. |
\$regex | Field value matches the given regular expression pattern. |
\$like | Field value matches the operand pattern (using SQL-like syntax). |
\$in | Field value equals at least one value in the operand array. |
\$nin | Field exists, but its value is not equal to any in the operand array, or the field does not exist. |
\$all | Field value is an array containing all items from the operand array, or a scalar matching a single operand. |
- You can combine these filters using logical operators:
| Logical Operator | Description |
|---|---|
\$and | Logical AND |
\$or | Logical OR |
\$nor | Logical NOR |
- You can omit
$andwhen all filters in an object must be satisfied. These two are equivalent:
- The
$notclause can negate a comparison operator:
- Using
field: scalaris equivalent tofield: { "$eq": scalar }: