Skip to content

Commit

Permalink
fix: enforce client parameter validation in WeaviateVectorStore
Browse files Browse the repository at this point in the history
Signed-off-by: hsm207 <[email protected]>
  • Loading branch information
hsm207 committed Dec 9, 2024
1 parent 62bcaf6 commit f344116
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libs/weaviate/langchain_weaviate/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def from_texts(
metadatas: Optional[List[dict]] = None,
*,
tenant: Optional[str] = None,
client: weaviate.WeaviateClient = None,
client: Optional[weaviate.WeaviateClient] = None,
index_name: Optional[str] = None,
text_key: str = "text",
relevance_score_fn: Optional[
Expand Down Expand Up @@ -474,6 +474,9 @@ def from_texts(

attributes = list(metadatas[0].keys()) if metadatas else None

if client is None:
raise ValueError("client must be an instance of WeaviateClient")

weaviate_vector_store = cls(
client,
index_name,
Expand Down
10 changes: 10 additions & 0 deletions libs/weaviate/tests/unit_tests/test_vectorstores_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from langchain_weaviate.vectorstores import (
WeaviateVectorStore,
_default_score_normalizer,
_json_serializable,
)
Expand All @@ -29,3 +30,12 @@ def test_json_serializable(
expected_result: Union[str, int, None],
) -> None:
assert _json_serializable(value) == expected_result


def test_from_texts_raises_value_error_when_client_is_none():
with pytest.raises(
ValueError, match="client must be an instance of WeaviateClient"
):
WeaviateVectorStore.from_texts(
texts=["sample text"], embedding=None, client=None
)

0 comments on commit f344116

Please sign in to comment.