From 7ea97035ac9d8d32a79e986ac19d7bd5695b6b8a Mon Sep 17 00:00:00 2001 From: harupy <17039389+harupy@users.noreply.github.com> Date: Tue, 8 Apr 2025 10:43:11 +0900 Subject: [PATCH 1/3] Validate that the index name is a UC index Signed-off-by: harupy <17039389+harupy@users.noreply.github.com> --- .../langchain/src/databricks_langchain/vectorstores.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/integrations/langchain/src/databricks_langchain/vectorstores.py b/integrations/langchain/src/databricks_langchain/vectorstores.py index ae24f7b4..d78185b5 100644 --- a/integrations/langchain/src/databricks_langchain/vectorstores.py +++ b/integrations/langchain/src/databricks_langchain/vectorstores.py @@ -230,6 +230,11 @@ def __init__( f"The `index_name` parameter must be a string, but got {type(index_name).__name__}." ) + if index_name.count(".") != 3: + raise ValueError( + f"The `index_name` parameter must be in the format 'catalog.schema.name', but got {index_name!r}." + ) + try: from databricks.vector_search.client import ( # type: ignore[import] VectorSearchClient, From 407e111133852be17d206f46e5bd6f78de02bc7a Mon Sep 17 00:00:00 2001 From: harupy <17039389+harupy@users.noreply.github.com> Date: Tue, 8 Apr 2025 10:43:31 +0900 Subject: [PATCH 2/3] add test case Signed-off-by: harupy <17039389+harupy@users.noreply.github.com> --- integrations/langchain/tests/unit_tests/test_vectorstores.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/langchain/tests/unit_tests/test_vectorstores.py b/integrations/langchain/tests/unit_tests/test_vectorstores.py index dd92be1f..fe458a08 100644 --- a/integrations/langchain/tests/unit_tests/test_vectorstores.py +++ b/integrations/langchain/tests/unit_tests/test_vectorstores.py @@ -52,7 +52,7 @@ def test_init_with_endpoint_name() -> None: assert vectorsearch.index.describe() == INDEX_DETAILS[DELTA_SYNC_INDEX] -@pytest.mark.parametrize("index_name", [None, 123, MagicMock(spec=VectorSearchIndex)]) +@pytest.mark.parametrize("index_name", [None, 123, "invalid.name", MagicMock(spec=VectorSearchIndex)]) def test_init_fail_invalid_index_name(index_name) -> None: with pytest.raises(ValueError, match="The `index_name` parameter must be"): DatabricksVectorSearch(index_name=index_name) From 221ccb3ef95bcc08ca210af7c6b5461887926c97 Mon Sep 17 00:00:00 2001 From: harupy <17039389+harupy@users.noreply.github.com> Date: Tue, 8 Apr 2025 11:08:29 +0900 Subject: [PATCH 3/3] fix --- .../langchain/src/databricks_langchain/vectorstores.py | 2 +- integrations/langchain/tests/unit_tests/test_vectorstores.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/integrations/langchain/src/databricks_langchain/vectorstores.py b/integrations/langchain/src/databricks_langchain/vectorstores.py index d78185b5..1ec73856 100644 --- a/integrations/langchain/src/databricks_langchain/vectorstores.py +++ b/integrations/langchain/src/databricks_langchain/vectorstores.py @@ -230,7 +230,7 @@ def __init__( f"The `index_name` parameter must be a string, but got {type(index_name).__name__}." ) - if index_name.count(".") != 3: + if index_name.count(".") != 2: raise ValueError( f"The `index_name` parameter must be in the format 'catalog.schema.name', but got {index_name!r}." ) diff --git a/integrations/langchain/tests/unit_tests/test_vectorstores.py b/integrations/langchain/tests/unit_tests/test_vectorstores.py index fe458a08..b352b548 100644 --- a/integrations/langchain/tests/unit_tests/test_vectorstores.py +++ b/integrations/langchain/tests/unit_tests/test_vectorstores.py @@ -52,7 +52,9 @@ def test_init_with_endpoint_name() -> None: assert vectorsearch.index.describe() == INDEX_DETAILS[DELTA_SYNC_INDEX] -@pytest.mark.parametrize("index_name", [None, 123, "invalid.name", MagicMock(spec=VectorSearchIndex)]) +@pytest.mark.parametrize( + "index_name", [None, 123, "invalid.name", MagicMock(spec=VectorSearchIndex)] +) def test_init_fail_invalid_index_name(index_name) -> None: with pytest.raises(ValueError, match="The `index_name` parameter must be"): DatabricksVectorSearch(index_name=index_name)