From ecd3b6111bc8ed28f8e4c3af54f59ffb0fa9feb2 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Tue, 26 Mar 2024 21:55:00 +0100 Subject: [PATCH] Fix connection to Weaviate Cloud Service --- .../weaviate/document_store.py | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py index 5bacac010..d45bf5f5f 100644 --- a/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py +++ b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py @@ -172,22 +172,32 @@ def client(self): if self._client: return self._client - # proxies, timeout_config, trust_env are part of additional_config now - # startup_period has been removed - self._client = weaviate.WeaviateClient( - connection_params=( - weaviate.connect.base.ConnectionParams.from_url( - url=self._url, grpc_port=self._grpc_port, grpc_secure=self._grpc_secure - ) - if self._url - else None - ), - auth_client_secret=self._auth_client_secret.resolve_value() if self._auth_client_secret else None, - additional_config=self._additional_config, - additional_headers=self._additional_headers, - embedded_options=self._embedded_options, - skip_init_checks=False, - ) + # This is a quick ugly fix to make sure that users can use the DocumentStore + # with Weaviate Cloud Services with no issues + if self._url and self._url.startswith("http") and self._url.endswith(".weaviate.network"): + self._client = weaviate.connect_to_wcs( + self._url, + auth_credentials=self._auth_client_secret.resolve_value(), + headers=self._additional_headers, + additional_config=self._additional_config, + ) + else: + # proxies, timeout_config, trust_env are part of additional_config now + # startup_period has been removed + self._client = weaviate.WeaviateClient( + connection_params=( + weaviate.connect.base.ConnectionParams.from_url( + url=self._url, grpc_port=self._grpc_port, grpc_secure=self._grpc_secure + ) + if self._url + else None + ), + auth_client_secret=self._auth_client_secret.resolve_value() if self._auth_client_secret else None, + additional_config=self._additional_config, + additional_headers=self._additional_headers, + embedded_options=self._embedded_options, + skip_init_checks=False, + ) self._client.connect()