diff --git a/langchain_weaviate/vectorstores.py b/langchain_weaviate/vectorstores.py index 19eca88..ad1f6d5 100644 --- a/langchain_weaviate/vectorstores.py +++ b/langchain_weaviate/vectorstores.py @@ -94,15 +94,14 @@ def __init__( relevance_score_fn: Optional[ Callable[[float], float] ] = _default_score_normalizer, - by_text: bool = True, use_multi_tenancy: bool = False, ): """Initialize with Weaviate client.""" if not isinstance(client, weaviate.WeaviateClient): raise ValueError( - "client should be an instance of " - "weaviate.WeaviateClient, got {type(client)}" + "client should be an instance of" + f" weaviate.WeaviateClient, got {type(client)}" ) self._client = client self._index_name = index_name or f"LangChain_{uuid4().hex}" @@ -110,7 +109,6 @@ def __init__( self._text_key = text_key self._query_attrs = [self._text_key] self.relevance_score_fn = relevance_score_fn - self._by_text = by_text if attributes is not None: self._query_attrs.extend(attributes) @@ -410,7 +408,6 @@ def from_texts( *, index_name: Optional[str] = None, text_key: str = "text", - by_text: bool = False, relevance_score_fn: Optional[ Callable[[float], float] ] = _default_score_normalizer, @@ -433,7 +430,6 @@ def from_texts( tenant: The tenant name. Defaults to None. index_name: Index name. text_key: Key to use for uploading/retrieving text to/from vectorstore. - by_text: Whether to search by text or by embedding. relevance_score_fn: Function for converting whatever distance function the vector store uses to a relevance score, which is a normalized similarity score (0 means dissimilar, 1 means similar). @@ -462,7 +458,6 @@ def from_texts( embedding=embedding, attributes=attributes, relevance_score_fn=relevance_score_fn, - by_text=by_text, use_multi_tenancy=tenant is not None, ) diff --git a/tests/integration_tests/test_vectorstores.py b/tests/integration_tests/test_vectorstores.py index 471adaf..4f7ee50 100644 --- a/tests/integration_tests/test_vectorstores.py +++ b/tests/integration_tests/test_vectorstores.py @@ -165,7 +165,9 @@ def test_similarity_search_by_text( """Test end to end construction and search by text.""" docsearch = WeaviateVectorStore.from_texts( - texts, embedding_openai, client=weaviate_client, by_text=True + texts, + embedding_openai, + client=weaviate_client, ) output = docsearch.similarity_search("foo", k=1) @@ -361,7 +363,7 @@ def test_similarity_search_with_score( # now create an instance with an embedding docsearch = WeaviateVectorStore.from_texts( - texts, embedding_openai, client=weaviate_client, by_text=False + texts, embedding_openai, client=weaviate_client ) results = docsearch.similarity_search_with_score("kitty", k=1) @@ -588,3 +590,35 @@ def test_search_with_multi_tenancy( ValueError, match="has multi-tenancy enabled, but request was without tenant" ): docsearch.similarity_search("foo", k=1) + + +def test_invalid_client_type(): + with pytest.raises(ValueError) as excinfo: + invalid_client = "invalid_client" + index_name = "test_index" + text_key = "text" + + WeaviateVectorStore( + client=invalid_client, + index_name=index_name, + text_key=text_key, + ) + + assert ( + str(excinfo.value) + == "client should be an instance of weaviate.WeaviateClient, got " + ) + + +def test_embedding_property(weaviate_client, embedding_openai): + index_name = "test_index" + text_key = "text" + + docsearch = WeaviateVectorStore( + client=weaviate_client, + index_name=index_name, + text_key=text_key, + embedding=embedding_openai, + ) + + assert type(docsearch.embeddings) == OpenAIEmbeddings