@@ -121,6 +121,7 @@ def __init__(
121121 self .__loop = loop
122122
123123 self ._headers = {"content-type" : "application/json" }
124+ self .__add_weaviate_embedding_service_header (connection_params .http .host )
124125 if additional_headers is not None :
125126 _validate_input (_ValidateArgument ([dict ], "additional_headers" , additional_headers ))
126127 self .__additional_headers = additional_headers
@@ -141,6 +142,12 @@ def __init__(
141142
142143 self ._prepare_grpc_headers ()
143144
145+ def __add_weaviate_embedding_service_header (self , wcd_host : str ) -> None :
146+ if not is_weaviate_domain (wcd_host ) or not isinstance (self ._auth , AuthApiKey ):
147+ return
148+ self ._headers ["X-Weaviate-Api-Key" ] = self ._auth .api_key
149+ self ._headers ["X-Weaviate-Cluster-URL" ] = "https://" + wcd_host
150+
144151 async def connect (self , skip_init_checks : bool ) -> None :
145152 self .__connected = True
146153
@@ -655,7 +662,17 @@ def _prepare_grpc_headers(self) -> None:
655662
656663 if self ._auth is not None :
657664 if isinstance (self ._auth , AuthApiKey ):
658- self .__metadata_list .append (("authorization" , self ._auth .api_key ))
665+ if (
666+ "X-Weaviate-Cluster-URL" in self ._headers
667+ and "X-Weaviate-Api-Key" in self ._headers
668+ ):
669+ self .__metadata_list .append (
670+ ("x-weaviate-cluster-url" , self ._headers ["X-Weaviate-Cluster-URL" ])
671+ )
672+ self .__metadata_list .append (
673+ ("x-weaviate-api-key" , self ._headers ["X-Weaviate-Api-Key" ])
674+ )
675+ self .__metadata_list .append (("authorization" , "Bearer " + self ._auth .api_key ))
659676 else :
660677 self .__metadata_list .append (
661678 ("authorization" , "dummy_will_be_refreshed_for_each_call" )
@@ -667,7 +684,7 @@ def _prepare_grpc_headers(self) -> None:
667684 self .__grpc_headers = None
668685
669686 def grpc_headers (self ) -> Optional [Tuple [Tuple [str , str ], ...]]:
670- if self ._auth is None or not isinstance (self ._auth , AuthApiKey ):
687+ if self ._auth is None or isinstance (self ._auth , AuthApiKey ):
671688 return self .__grpc_headers
672689
673690 assert self .__grpc_headers is not None
@@ -676,34 +693,6 @@ def grpc_headers(self) -> Optional[Tuple[Tuple[str, str], ...]]:
676693 self .__metadata_list [len (self .__metadata_list ) - 1 ] = ("authorization" , access_token )
677694 return tuple (self .__metadata_list )
678695
679- # async def _ping_grpc(self) -> None:
680- # """Performs a grpc health check and raises WeaviateGRPCUnavailableError if not."""
681- # if not self.is_connected():
682- # raise WeaviateClosedClientError()
683- # assert self._grpc_channel is not None
684- # try:
685- # request = self._grpc_channel.request(
686- # "/grpc.health.v1.Health/Check",
687- # Cardinality.UNARY_UNARY,
688- # health_pb2.HealthCheckRequest,
689- # health_pb2.HealthCheckResponse,
690- # timeout=self.timeout_config.init,
691- # )
692- # async with request as stream:
693- # await stream.send_message(health_pb2.HealthCheckRequest())
694- # res = await stream.recv_message()
695- # await stream.end()
696- # if res is None or res.status != health_pb2.HealthCheckResponse.SERVING:
697- # self.__connected = False
698- # raise WeaviateGRPCUnavailableError(
699- # f"v{self.server_version}", self._connection_params._grpc_address
700- # )
701- # except Exception as e:
702- # self.__connected = False
703- # raise WeaviateGRPCUnavailableError(
704- # f"v{self.server_version}", self._connection_params._grpc_address
705- # ) from e
706-
707696 async def _ping_grpc (self ) -> None :
708697 """Performs a grpc health check and raises WeaviateGRPCUnavailableError if not."""
709698 if not self .is_connected ():
0 commit comments