Using Oracle AI Vector Search in LangChain
Posted: Nov 18, 2024.
Oracle AI Vector Search is a powerful vector store implementation in LangChain that allows you to perform semantic search on documents using Oracle Database's vector search capabilities. It combines the power of vector embeddings with Oracle's enterprise features like clustering, partitioning, and security.
What is OracleVS?
OracleVS is LangChain's vector store implementation that uses Oracle AI Vector Search under the hood. It allows you to:
- Store document embeddings in Oracle Database tables
- Perform similarity searches using different distance metrics (dot product, cosine, euclidean)
- Create HNSW and IVF indices for fast approximate nearest neighbor search
- Filter searches based on document metadata
- Combine semantic search with Oracle's relational database features
The main advantage is that you can keep your vector embeddings alongside your relational data in Oracle Database, avoiding data fragmentation across multiple systems.
Reference
Here are the key methods available in OracleVS:
Method | Description |
---|---|
__init__ | Initialize vector store with Oracle connection, embeddings function, table name and search params |
from_documents | Create vector store from a list of documents |
from_texts | Create vector store from a list of texts |
add_texts | Add new texts to the vector store |
delete | Delete documents by their IDs |
similarity_search | Find similar documents using vector similarity |
similarity_search_with_score | Find similar documents and return relevance scores |
max_marginal_relevance_search | Search optimizing for similarity and diversity |
How to Use OracleVS
Setting Up the Connection
First, you'll need to connect to your Oracle database:
Creating a Vector Store
You can create a vector store from documents using an embedding model:
Performing Similarity Search
You can search for similar documents in different ways:
Creating Search Indices
Oracle AI Vector Search supports two types of indices - HNSW and IVF:
Adding and Removing Documents
You can dynamically add or remove documents:
By leveraging Oracle AI Vector Search through the OracleVS vector store, you get the benefits of semantic search combined with Oracle's enterprise database features. This makes it ideal for production applications that need to maintain both structured and unstructured data in a single system.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.
LangChain DocsJoin 10,000+ subscribers
Every 2 weeks, latest model releases and industry news.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.