Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove by_text param #85

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions langchain_weaviate/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,21 @@ 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}"
self._embedding = embedding
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)

Expand Down Expand Up @@ -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,
Expand All @@ -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).
Expand Down Expand Up @@ -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,
)

Expand Down
38 changes: 36 additions & 2 deletions tests/integration_tests/test_vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 <class 'str'>"
)


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
Loading