From 15e735316841ba15920d21c9a4dcfbbfe337e709 Mon Sep 17 00:00:00 2001 From: William Smith <104857768+willsmithDB@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:03:53 -0500 Subject: [PATCH] langchain_community: updated query constructor for Databricks Vector Search due to LangChainDeprecationWarning: `filters` was deprecated since langchain-community 0.2.11 and will be removed in 0.3. Please use `filter` instead. (#27974) - **Description:** Updated the kwargs for the structured query from filters to filter due to deprecation of 'filters' for Databricks Vector Search. Also changed the error messages as the allowed operators and comparators are different which can cause issues with functions such as get_query_constructor_prompt() - **Issue:** Fixes the Key Error for filters due to deprecation in favor for 'filter': LangChainDeprecationWarning: DatabricksVectorSearch received a key `filters` in search_kwargs. `filters` was deprecated since langchain-community 0.2.11 and will be removed in 0.3. Please use `filter` instead. - **Dependencies:** N/A - **Twitter handle:** N/A --------- Co-authored-by: Erick Friis --- .../query_constructors/databricks_vector_search.py | 2 +- .../query_constructors/test_databricks_vector_search.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_community/query_constructors/databricks_vector_search.py b/libs/community/langchain_community/query_constructors/databricks_vector_search.py index 03e7de8efa7..f79a690c9ba 100644 --- a/libs/community/langchain_community/query_constructors/databricks_vector_search.py +++ b/libs/community/langchain_community/query_constructors/databricks_vector_search.py @@ -90,5 +90,5 @@ class DatabricksVectorSearchTranslator(Visitor): if structured_query.filter is None: kwargs = {} else: - kwargs = {"filters": structured_query.filter.accept(self)} + kwargs = {"filter": structured_query.filter.accept(self)} return structured_query.query, kwargs diff --git a/libs/community/tests/unit_tests/query_constructors/test_databricks_vector_search.py b/libs/community/tests/unit_tests/query_constructors/test_databricks_vector_search.py index 1f38f3b1b60..e71e32c34eb 100644 --- a/libs/community/tests/unit_tests/query_constructors/test_databricks_vector_search.py +++ b/libs/community/tests/unit_tests/query_constructors/test_databricks_vector_search.py @@ -109,7 +109,7 @@ def test_visit_structured_query_with_one_arg_filter() -> None: filter=comp, ) - expected = (query, {"filters": {"country": "France"}}) + expected = (query, {"filter": {"country": "France"}}) actual = DEFAULT_TRANSLATOR.visit_structured_query(structured_query) assert expected == actual @@ -134,7 +134,7 @@ def test_visit_structured_query_with_multiple_arg_filter_and_operator() -> None: expected = ( query, - {"filters": {"country": "France", "year >=": 1888, "year <=": 1900}}, + {"filter": {"country": "France", "year >=": 1888, "year <=": 1900}}, ) actual = DEFAULT_TRANSLATOR.visit_structured_query(structured_query)