JSON string with a "inputs" key:        input_str = json.dumps({"inputs": inputs, **model_kwargs})          return input_str.encode("utf-8")    def transform_output(self, output: bytes) -> List[List[float]]:        """        Transforms the bytes output from the endpoint into a list of embeddings.        Args:            output: The bytes output from SageMaker endpoint.        Returns:            The transformed output - list of embeddings        Note:            The length of the outer list is the number of input strings.            The length of the inner lists is the embedding dimension.        """        # Example: inference.py returns a JSON string with the list of        # embeddings in a "vectors" key:        response_json = json.loads(output.read().decode("utf-8"))        return response_json["vectors"]content_handler = ContentHandler()embeddings = SagemakerEndpointEmbeddings(    # credentials_profile_name="credentials-profile-name",    endpoint_name="huggingface-pytorch-inference-2023-03-21-16-14-03-834",    region_name="us-east-1",    content_handler=content_handler,)query_result = embeddings.embed_query("foo")doc_results = embeddings.embed_documents(["foo"])doc_resultsPreviousOpenAINextSelf HostedCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.
Let's load the SageMaker Endpoints Embeddings class. The class can be used if you host, e.g. your own Hugging Face model on SageMaker.
Let's load the SageMaker Endpoints Embeddings class. The class can be used if you host, e.g. your own Hugging Face model on SageMaker. ->: JSON string with a "inputs" key:        input_str = json.dumps({"inputs": inputs, **model_kwargs})          return input_str.encode("utf-8")    def transform_output(self, output: bytes) -> List[List[float]]:        """        Transforms the bytes output from the endpoint into a list of embeddings.        Args:            output: The bytes output from SageMaker endpoint.        Returns:            The transformed output - list of embeddings        Note:            The length of the outer list is the number of input strings.            The length of the inner lists is the embedding dimension.        """        # Example: inference.py returns a JSON string with the list of        # embeddings in a "vectors" key:        response_json = json.loads(output.read().decode("utf-8"))        return response_json["vectors"]content_handler = ContentHandler()embeddings = SagemakerEndpointEmbeddings(    # credentials_profile_name="credentials-profile-name",    endpoint_name="huggingface-pytorch-inference-2023-03-21-16-14-03-834",    region_name="us-east-1",    content_handler=content_handler,)query_result = embeddings.embed_query("foo")doc_results = embeddings.embed_documents(["foo"])doc_resultsPreviousOpenAINextSelf HostedCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.