diff --git a/reference/packages.yml b/reference/packages.yml index 7073114cb2..42113b3e67 100644 --- a/reference/packages.yml +++ b/reference/packages.yml @@ -773,3 +773,8 @@ packages: path: libs/voyageai downloads: 55000 downloads_updated_at: "2025-11-10T00:06:22.543193+00:00" +- name: langchain-oracledb + name_title: Oracle AI Vector Search + repo: oracle/langchain-oracle + downloads: 700 + downloads_updated_at: "2025-11-25T00:06:22.543193+00:00" diff --git a/src/oss/python/integrations/document_loaders/oracleadb_loader.mdx b/src/oss/python/integrations/document_loaders/oracleadb_loader.mdx index f70fb36427..47499292e9 100644 --- a/src/oss/python/integrations/document_loaders/oracleadb_loader.mdx +++ b/src/oss/python/integrations/document_loaders/oracleadb_loader.mdx @@ -4,21 +4,24 @@ title: Oracle Autonomous Database Oracle Autonomous Database is a cloud database that uses machine learning to automate database tuning, security, backups, updates, and other routine management tasks traditionally performed by DBAs. -This notebook covers how to load documents from Oracle Autonomous Database, the loader supports connection with connection string or tns configuration. +This notebook covers how to load documents from Oracle Autonomous Database. ## Prerequisites -1. Install `python-oracledb`: `pip install oracledb` - 1. See [Installing `python-oracledb`](https://python-oracledb.readthedocs.io/en/latest/user_guide/installation.html). +A database that `python-oracledb`'s default `'Thin'` mode can connected to. This is true of Oracle Autonomous Database, see [`python-oracledb` Architecture](https://python-oracledb.readthedocs.io/en/latest/user_guide/introduction.html#architecture). -## Instructions +You'll need to install `langchain-oracledb` to use this integration. + +The `python-oracledb` driver is installed automatically as a dependency of langchain-oracledb. ```python -pip install oracledb +# python -m pip install -U langchain-oracledb ``` +## Instructions + ```python -from langchain_community.document_loaders import OracleAutonomousDatabaseLoader +from langchain_oracledb.document_loaders import OracleAutonomousDatabaseLoader from settings import s ``` @@ -35,7 +38,7 @@ doc_loader_1 = OracleAutonomousDatabaseLoader( config_dir=s.CONFIG_DIR, wallet_location=s.WALLET_LOCATION, wallet_password=s.PASSWORD, - tns_name=s.TNS_NAME, + dsn=s.DSN, ) doc_1 = doc_loader_1.load() @@ -44,7 +47,7 @@ doc_loader_2 = OracleAutonomousDatabaseLoader( user=s.USERNAME, password=s.PASSWORD, schema=s.SCHEMA, - connection_string=s.CONNECTION_STRING, + dsn=s.DSN, wallet_location=s.WALLET_LOCATION, wallet_password=s.PASSWORD, ) @@ -62,7 +65,7 @@ doc_loader_3 = OracleAutonomousDatabaseLoader( password=s.PASSWORD, schema=s.SCHEMA, config_dir=s.CONFIG_DIR, - tns_name=s.TNS_NAME, + dsn=s.DSN, parameters=["Direct Sales"], ) doc_3 = doc_loader_3.load() @@ -72,7 +75,7 @@ doc_loader_4 = OracleAutonomousDatabaseLoader( user=s.USERNAME, password=s.PASSWORD, schema=s.SCHEMA, - connection_string=s.CONNECTION_STRING, + dsn=s.DSN, parameters=["Direct Sales"], ) doc_4 = doc_loader_4.load() diff --git a/src/oss/python/integrations/document_loaders/oracleai.mdx b/src/oss/python/integrations/document_loaders/oracleai.mdx index 9ede18e2f5..390799bb6c 100644 --- a/src/oss/python/integrations/document_loaders/oracleai.mdx +++ b/src/oss/python/integrations/document_loaders/oracleai.mdx @@ -28,10 +28,12 @@ If you are just starting with Oracle Database, consider exploring the [free Orac ### Prerequisites -Please install Oracle Python Client driver to use LangChain with Oracle AI Vector Search. +You'll need to install `langchain-oracledb` to use this integration. + +The `python-oracledb` driver is installed automatically as a dependency of langchain-oracledb. ```python -# pip install oracledb +# python -m pip install -U langchain-oracledb ``` ### Connect to Oracle Database @@ -43,17 +45,13 @@ import sys import oracledb -# please update with your username, password, hostname and service_name +# Please update with your username, password, hostname, port and service_name username = "" password = "" -dsn = "/" +dsn = ":/" -try: - conn = oracledb.connect(user=username, password=password, dsn=dsn) - print("Connection successful!") -except Exception as e: - print("Connection failed!") - sys.exit(1) +connection = oracledb.connect(user=username, password=password, dsn=dsn) +print("Connection successful!") ``` Now let's create a table and insert some sample docs to test. @@ -102,10 +100,10 @@ Users have the flexibility to load documents from either the Oracle Database, a A significant advantage of utilizing OracleDocLoader is its capability to process over 150 distinct file formats, eliminating the need for multiple loaders for different document types. For a complete list of the supported formats, please refer to the [Oracle Text Supported Document Formats](https://docs.oracle.com/en/database/oracle/oracle-database/23/ccref/oracle-text-supported-document-formats.html). -Below is a sample code snippet that demonstrates how to use OracleDocLoader +Below is a sample code snippet that demonstrates how to use `OracleDocLoader`: ```python -from langchain_community.document_loaders.oracleai import OracleDocLoader +from langchain_oracledb.document_loaders.oracleai import OracleDocLoader from langchain_core.documents import Document """ @@ -141,7 +139,7 @@ The documents may vary in size, ranging from small to very large. Users often pr Below is a sample code illustrating how to implement this: ```python -from langchain_community.document_loaders.oracleai import OracleTextSplitter +from langchain_oracledb.document_loaders.oracleai import OracleTextSplitter from langchain_core.documents import Document """ diff --git a/src/oss/python/integrations/providers/oracleai.mdx b/src/oss/python/integrations/providers/oracleai.mdx index 3923b14f90..bb6d7cda8c 100644 --- a/src/oss/python/integrations/providers/oracleai.mdx +++ b/src/oss/python/integrations/providers/oracleai.mdx @@ -1,5 +1,5 @@ --- -title: OracleAI Vector Search +title: Oracle AI Vector Search --- Oracle AI Vector Search is designed for Artificial Intelligence (AI) workloads that allows you to query data based on semantics, rather than keywords. @@ -8,27 +8,26 @@ This is not only powerful but also significantly more effective because you don' In addition, your vectors can benefit from all of Oracle Database’s most powerful features, like the following: - * [Partitioning Support](https://www.oracle.com/database/technologies/partitioning.html) - * [Real Application Clusters scalability](https://www.oracle.com/database/real-application-clusters/) - * [Exadata smart scans](https://www.oracle.com/database/technologies/exadata/software/smartscan/) - * [Shard processing across geographically distributed databases](https://www.oracle.com/database/distributed-database/) - * [Transactions](https://docs.oracle.com/en/database/oracle/oracle-database/23/cncpt/transactions.html) - * [Parallel SQL](https://docs.oracle.com/en/database/oracle/oracle-database/21/vldbg/parallel-exec-intro.html#GUID-D28717E4-0F77-44F5-BB4E-234C31D4E4BA) - * [Disaster recovery](https://www.oracle.com/database/data-guard/) - * [Security](https://www.oracle.com/security/database-security/) - * [Oracle Machine Learning](https://www.oracle.com/artificial-intelligence/database-machine-learning/) - * [Oracle Graph Database](https://www.oracle.com/database/integrated-graph-database/) - * [Oracle Spatial and Graph](https://www.oracle.com/database/spatial/) - * [Oracle Blockchain](https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/dbms_blockchain_table.html#GUID-B469E277-978E-4378-A8C1-26D3FF96C9A6) - * [JSON](https://docs.oracle.com/en/database/oracle/oracle-database/23/adjsn/json-in-oracle-database.html) - +* [Partitioning Support](https://www.oracle.com/database/technologies/partitioning.html) +* [Real Application Clusters scalability](https://www.oracle.com/database/real-application-clusters/) +* [Exadata smart scans](https://www.oracle.com/database/technologies/exadata/software/smartscan/) +* [Shard processing across geographically distributed databases](https://www.oracle.com/database/distributed-database/) +* [Transactions](https://docs.oracle.com/en/database/oracle/oracle-database/23/cncpt/transactions.html) +* [Parallel SQL](https://docs.oracle.com/en/database/oracle/oracle-database/21/vldbg/parallel-exec-intro.html#GUID-D28717E4-0F77-44F5-BB4E-234C31D4E4BA) +* [Disaster recovery](https://www.oracle.com/database/data-guard/) +* [Security](https://www.oracle.com/security/database-security/) +* [Oracle Machine Learning](https://www.oracle.com/artificial-intelligence/database-machine-learning/) +* [Oracle Graph Database](https://www.oracle.com/database/integrated-graph-database/) +* [Oracle Spatial and Graph](https://www.oracle.com/database/spatial/) +* [Oracle Blockchain](https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/dbms_blockchain_table.html#GUID-B469E277-978E-4378-A8C1-26D3FF96C9A6) +* [JSON](https://docs.oracle.com/en/database/oracle/oracle-database/23/adjsn/json-in-oracle-database.html) ## Document loaders Please check the [usage example](/oss/integrations/document_loaders/oracleai). ```python -from langchain_community.document_loaders.oracleai import OracleDocLoader +from langchain_oracledb.document_loaders.oracleai import OracleDocLoader ``` ## Text Splitter @@ -36,7 +35,7 @@ from langchain_community.document_loaders.oracleai import OracleDocLoader Please check the [usage example](/oss/integrations/document_loaders/oracleai). ```python -from langchain_community.document_loaders.oracleai import OracleTextSplitter +from langchain_oracledb.document_loaders.oracleai import OracleTextSplitter ``` ## Embeddings @@ -44,7 +43,7 @@ from langchain_community.document_loaders.oracleai import OracleTextSplitter Please check the [usage example](/oss/integrations/text_embedding/oracleai). ```python -from langchain_community.embeddings.oracleai import OracleEmbeddings +from langchain_oracledb.embeddings.oracleai import OracleEmbeddings ``` ## Summary @@ -52,7 +51,7 @@ from langchain_community.embeddings.oracleai import OracleEmbeddings Please check the [usage example](/oss/integrations/tools/oracleai). ```python -from langchain_community.utilities.oracleai import OracleSummary +from langchain_oracledb.utilities.oracleai import OracleSummary ``` ## Vector Store @@ -60,7 +59,7 @@ from langchain_community.utilities.oracleai import OracleSummary Please check the [usage example](/oss/integrations/vectorstores/oracle). ```python -from langchain_community.vectorstores.oraclevs import OracleVS +from langchain_oracledb.vectorstores.oraclevs import OracleVS ``` ## End to End Demo diff --git a/src/oss/python/integrations/text_embedding/oracleai.mdx b/src/oss/python/integrations/text_embedding/oracleai.mdx index 9557e8be56..19520dbc8a 100644 --- a/src/oss/python/integrations/text_embedding/oracleai.mdx +++ b/src/oss/python/integrations/text_embedding/oracleai.mdx @@ -28,10 +28,12 @@ If you are just starting with Oracle Database, consider exploring the [free Orac ### Prerequisites -Ensure you have the Oracle Python Client driver installed to facilitate the integration of LangChain with Oracle AI Vector Search. +You'll need to install `langchain-oracledb` to use this integration. + +The `python-oracledb` driver is installed automatically as a dependency of langchain-oracledb. ```python -# pip install oracledb +# python -m pip install -U langchain-oracledb ``` ### Connect to Oracle Database @@ -43,17 +45,13 @@ import sys import oracledb -# Update the following variables with your Oracle database credentials and connection details +# Please update with your username, password, hostname, port and service_name username = "" password = "" -dsn = "/" +dsn = ":/" -try: - conn = oracledb.connect(user=username, password=password, dsn=dsn) - print("Connection successful!") -except Exception as e: - print("Connection failed!") - sys.exit(1) +connection = oracledb.connect(user=username, password=password, dsn=dsn) +print("Connection successful!") ``` For embedding generation, several provider options are available to users, including embedding generation within the database and third-party services such as OcigenAI, Hugging Face, and OpenAI. Users opting for third-party providers must establish credentials that include the requisite authentication information. Alternatively, if users select 'database' as their provider, they are required to load an ONNX model into the Oracle Database to facilitate embeddings. @@ -69,7 +67,7 @@ A significant advantage of utilizing an ONNX model directly within Oracle is the Below is the example code to upload an ONNX model into Oracle Database: ```python -from langchain_community.embeddings.oracleai import OracleEmbeddings +from langchain_oracledb.embeddings.oracleai import OracleEmbeddings # Update the directory and file names for your ONNX model # make sure that you have onnx file in the system @@ -144,7 +142,7 @@ proxy = "" The following sample code will show how to generate embeddings: ```python -from langchain_community.embeddings.oracleai import OracleEmbeddings +from langchain_oracledb.embeddings.oracleai import OracleEmbeddings from langchain_core.documents import Document """ diff --git a/src/oss/python/integrations/tools/oracleai.mdx b/src/oss/python/integrations/tools/oracleai.mdx index a2ff52072c..a99e25566f 100644 --- a/src/oss/python/integrations/tools/oracleai.mdx +++ b/src/oss/python/integrations/tools/oracleai.mdx @@ -28,10 +28,12 @@ If you are just starting with Oracle Database, consider exploring the [free Orac ### Prerequisites -Please install Oracle Python Client driver to use LangChain with Oracle AI Vector Search. +You'll need to install `langchain-oracledb` to use this integration. + +The `python-oracledb` driver is installed automatically as a dependency of langchain-oracledb. ```python -# pip install oracledb +# python -m pip install -U langchain-oracledb ``` ### Connect to Oracle Database @@ -39,21 +41,15 @@ Please install Oracle Python Client driver to use LangChain with Oracle AI Vecto 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](https://python-oracledb.readthedocs.io/en/latest/user_guide/appendix_a.html#featuresummary) that talks about features supported in each mode. You might want to switch to thick-mode if you are unable to use thin-mode. ```python -import sys - import oracledb -# please update with your username, password, hostname and service_name +# Please update with your username, password, hostname, port and service_name username = "" password = "" -dsn = "/" - -try: - conn = oracledb.connect(user=username, password=password, dsn=dsn) - print("Connection successful!") -except Exception as e: - print("Connection failed!") - sys.exit(1) +dsn = ":/" + +connection = oracledb.connect(user=username, password=password, dsn=dsn) +print("Connection successful!") ``` ### Generate Summary @@ -70,7 +66,7 @@ proxy = "" The following sample code will show how to generate summary: ```python -from langchain_community.utilities.oracleai import OracleSummary +from langchain_oracledb.utilities.oracleai import OracleSummary from langchain_core.documents import Document """ diff --git a/src/oss/python/integrations/vectorstores/index.mdx b/src/oss/python/integrations/vectorstores/index.mdx index d2e053db38..e784092521 100644 --- a/src/oss/python/integrations/vectorstores/index.mdx +++ b/src/oss/python/integrations/vectorstores/index.mdx @@ -666,6 +666,7 @@ vector_store = QdrantVectorStore( | [`Weaviate`](/oss/integrations/vectorstores/weaviate) | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | | [`SQLServer`](/oss/integrations/vectorstores/sqlserver) | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | | [`ZeusDB`](/oss/integrations/vectorstores/zeusdb) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | +| [`Oracle AI Vector Search`](/oss/integrations/vectorstores/oracle) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ## All vector stores @@ -787,5 +788,6 @@ vector_store = QdrantVectorStore( + diff --git a/src/oss/python/integrations/vectorstores/oracle.mdx b/src/oss/python/integrations/vectorstores/oracle.mdx index 5440b658c2..99bd339d1b 100644 --- a/src/oss/python/integrations/vectorstores/oracle.mdx +++ b/src/oss/python/integrations/vectorstores/oracle.mdx @@ -24,14 +24,14 @@ In addition, your vectors can benefit from all of Oracle Database’s most power If you are just starting with Oracle Database, consider exploring the [free Oracle 23 AI](https://www.oracle.com/database/free/#resources) 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](https://github.com/langchain-ai/langchain/blob/v0.3/cookbook/oracleai_demo.ipynb) 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](https://docs.oracle.com/en/database/oracle/oracle-database/19/admqs/administering-user-accounts-and-security.html#GUID-36B21D72-1BBB-46C9-A0C9-F0D2A8591B8D) on administering user accounts and security. -### Prerequisites for using LangChain with Oracle AI Vector Search +### Prerequisites -You'll need to install `langchain-community` with `pip install -qU langchain-community` to use this integration +You'll need to install `langchain-oracledb` to use this integration. -Please install Oracle Python Client driver to use LangChain with Oracle AI Vector Search. +The `python-oracledb` driver is installed automatically as a dependency of langchain-oracledb. ```python -# pip install oracledb +# python -m pip install -U langchain-oracledb ``` ### Connect to Oracle AI Vector Search @@ -41,28 +41,26 @@ The following sample code will show how to connect to Oracle Database. By defaul ```python import oracledb -username = "username" -password = "password" -dsn = "ipaddress:port/orclpdb1" +# Please update with your username, password, hostname, port and service_name +username = "" +password = "" +dsn = ":/" -try: - connection = oracledb.connect(user=username, password=password, dsn=dsn) - print("Connection successful!") -except Exception as e: - print("Connection failed!") +connection = oracledb.connect(user=username, password=password, dsn=dsn) +print("Connection successful!") ``` -### Import the required dependencies to use Oracle AI Vector Search +### Import the required dependencies ```python -from langchain_community.vectorstores import oraclevs -from langchain_community.vectorstores.oraclevs import OracleVS +from langchain_oracledb.vectorstores import oraclevs +from langchain_oracledb.vectorstores.oraclevs import OracleVS from langchain_community.vectorstores.utils import DistanceStrategy from langchain_core.documents import Document from langchain_huggingface import HuggingFaceEmbeddings ``` -### Load Documents +### Load documents ```python # Define a list of documents (The examples below are 5 random documents from Oracle Concepts Manual ) @@ -102,7 +100,7 @@ for doc in documents_json_list: documents_langchain.append(doc_langchain) ``` -### Create Vector Stores with different distance metrics using AI Vector Search +### 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](https://docs.oracle.com/en/database/oracle/oracle-database/23/vecse/manage-different-categories-vector-indexes.html) . @@ -167,7 +165,7 @@ vector_store_euclidean_ivf = OracleVS.from_documents( ) ``` -### Demonstrating add and delete operations for texts, along with basic similarity search +### Add and delete operations for texts, along with basic similarity search ```python def manage_texts(vector_stores): @@ -212,7 +210,7 @@ vector_store_list = [ manage_texts(vector_store_list) ``` -### Demonstrating index creation with specific parameters for each distance strategy +### Index creation with specific parameters ```python def create_search_indices(connection): @@ -293,7 +291,114 @@ def create_search_indices(connection): create_search_indices(connection) ``` -### Demonstrate advanced searches on all six vector stores, with and without attribute filtering – with filtering, we only select the document id 101 and nothing else +### 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: + +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:** + +| 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 | + +**Example Filter:** + +```json +{ + "age": 65, + "name": {"$regex": "*rk"}, + "$or": [ + { + "$and": [ + {"name": "Jason"}, + {"drinks": {"$in": ["tea", "soda"]}} + ] + }, + { + "$nor": [ + {"age": {"$lt": 65}}, + {"name": "Jason"} + ] + } + ] +} +``` + +**Additional Usage Tips:** + +* You can omit `$and` when all filters in an object must be satisfied. These two are equivalent: + +```json +{ "$and": [ + { "name": { "$startsWith": "Fred" } }, + { "salary": { "$gt": 10000, "$lte": 20000 } } +]} +``` + +```json +{ + "name": { "$startsWith": "Fred" }, + "salary": { "$gt": 10000, "$lte": 20000 } +} +``` + +* The `$not` clause can negate a comparison operator: + +```json +{ "address.zip": { "$not": { "$eq": "90001" } } } +``` + +* Using `field: scalar` is equivalent to `field: { "$eq": scalar }`: + +```json +{ "animal": "cat" } +``` + +For more filter examples, refer to the [test specification](https://github.com/oracle/langchain-oracle/blob/main/libs/oracledb/tests/integration_tests/vectorstores/test_oraclevs.py). ```python # Conduct advanced searches after creating the indices @@ -301,7 +406,23 @@ def conduct_advanced_searches(vector_stores): query = "How are LOBS stored in Oracle Database" # Constructing a filter for direct comparison against document metadata # This filter aims to include documents whose metadata 'id' is exactly '2' - filter_criteria = {"id": ["101"]} # Direct comparison filter + db_filter = { + "$and": [ + {"id": "101"}, # FilterCondition + { + "$or": [ # FilterGroup + {"status": "approved"}, + {"link": "Document Example Test 2"}, + { + "$and": [ # Nested FilterGroup + {"status": "approved"}, + {"link": "Document Example Test 2"}, + ] + }, + ] + }, + ] + } for i, vs in enumerate(vector_stores, start=1): print(f"\n--- Vector Store {i} Advanced Searches ---") @@ -311,7 +432,7 @@ def conduct_advanced_searches(vector_stores): # Similarity search with a filter print("\nSimilarity search results with filter:") - print(vs.similarity_search(query, 2, filter=filter_criteria)) + print(vs.similarity_search(query, 2, filter=db_filter)) # Similarity search with relevance score print("\nSimilarity search with relevance score:") @@ -319,7 +440,7 @@ def conduct_advanced_searches(vector_stores): # Similarity search with relevance score with filter print("\nSimilarity search with relevance score with filter:") - print(vs.similarity_search_with_score(query, 2, filter=filter_criteria)) + print(vs.similarity_search_with_score(query, 2, filter=db_filter)) # Max marginal relevance search print("\nMax marginal relevance search results:") @@ -329,7 +450,7 @@ def conduct_advanced_searches(vector_stores): print("\nMax marginal relevance search results with filter:") print( vs.max_marginal_relevance_search( - query, 2, fetch_k=20, lambda_mult=0.5, filter=filter_criteria + query, 2, fetch_k=20, lambda_mult=0.5, filter=db_filter ) )