prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Change `SentenceTransformersTextEmbedder` to non-batch mode
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `haystack/preview/components/embedders/sentence_transformers_text_embedder.py`
  Content:
  ```
  1 from typing import List, Optional, Union, Dict, Any
  2 
  3 from haystack.preview import component, default_to_dict, default_from_dict
  4 from haystack.preview.embedding_backends.sentence_transformers_backend import (
  5     _SentenceTransformersEmbeddingBackendFactory,
  6 )
  7 
  8 
  9 @component
  10 class SentenceTransformersTextEmbedder:
  11     """
  12     A component for embedding strings using Sentence Transformers models.
  13     """
  14 
  15     def __init__(
  16         self,
  17         model_name_or_path: str = "sentence-transformers/all-mpnet-base-v2",
  18         device: Optional[str] = None,
  19         use_auth_token: Union[bool, str, None] = None,
  20         prefix: str = "",
  21         suffix: str = "",
  22         batch_size: int = 32,
  23         progress_bar: bool = True,
  24         normalize_embeddings: bool = False,
  25     ):
  26         """
  27         Create a SentenceTransformersTextEmbedder component.
  28 
  29         :param model_name_or_path: Local path or name of the model in Hugging Face's model hub, such as ``'sentence-transformers/all-mpnet-base-v2'``.
  30         :param device: Device (like 'cuda' / 'cpu') that should be used for computation. If None, checks if a GPU can be used.
  31         :param use_auth_token: The API token used to download private models from Hugging Face.
  32                         If this parameter is set to `True`, then the token generated when running
  33                         `transformers-cli login` (stored in ~/.huggingface) will be used.
  34         :param prefix: A string to add to the beginning of each text.
  35         :param suffix: A string to add to the end of each text.
  36         :param batch_size: Number of strings to encode at once.
  37         :param progress_bar: If true, displays progress bar during embedding.
  38         :param normalize_embeddings: If set to true, returned vectors will have length 1.
  39         """
  40 
  41         self.model_name_or_path = model_name_or_path
  42         # TODO: remove device parameter and use Haystack's device management once migrated
  43         self.device = device or "cpu"
  44         self.use_auth_token = use_auth_token
  45         self.prefix = prefix
  46         self.suffix = suffix
  47         self.batch_size = batch_size
  48         self.progress_bar = progress_bar
  49         self.normalize_embeddings = normalize_embeddings
  50 
  51     def to_dict(self) -> Dict[str, Any]:
  52         """
  53         Serialize this component to a dictionary.
  54         """
  55         return default_to_dict(
  56             self,
  57             model_name_or_path=self.model_name_or_path,
  58             device=self.device,
  59             use_auth_token=self.use_auth_token,
  60             prefix=self.prefix,
  61             suffix=self.suffix,
  62             batch_size=self.batch_size,
  63             progress_bar=self.progress_bar,
  64             normalize_embeddings=self.normalize_embeddings,
  65         )
  66 
  67     @classmethod
  68     def from_dict(cls, data: Dict[str, Any]) -> "SentenceTransformersTextEmbedder":
  69         """
  70         Deserialize this component from a dictionary.
  71         """
  72         return default_from_dict(cls, data)
  73 
  74     def warm_up(self):
  75         """
  76         Load the embedding backend.
  77         """
  78         if not hasattr(self, "embedding_backend"):
  79             self.embedding_backend = _SentenceTransformersEmbeddingBackendFactory.get_embedding_backend(
  80                 model_name_or_path=self.model_name_or_path, device=self.device, use_auth_token=self.use_auth_token
  81             )
  82 
  83     @component.output_types(embeddings=List[List[float]])
  84     def run(self, texts: List[str]):
  85         """Embed a list of strings."""
  86         if not isinstance(texts, list) or not isinstance(texts[0], str):
  87             raise TypeError(
  88                 "SentenceTransformersTextEmbedder expects a list of strings as input."
  89                 "In case you want to embed a list of Documents, please use the SentenceTransformersDocumentEmbedder."
  90             )
  91         if not hasattr(self, "embedding_backend"):
  92             raise RuntimeError("The embedding model has not been loaded. Please call warm_up() before running.")
  93 
  94         texts_to_embed = [self.prefix + text + self.suffix for text in texts]
  95         embeddings = self.embedding_backend.embed(
  96             texts_to_embed,
  97             batch_size=self.batch_size,
  98             show_progress_bar=self.progress_bar,
  99             normalize_embeddings=self.normalize_embeddings,
  100         )
  101         return {"embeddings": embeddings}
  102
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/haystack/preview/components/embedders/sentence_transformers_text_embedder.py b/haystack/preview/components/embedders/sentence_transformers_text_embedder.py
  --- a/haystack/preview/components/embedders/sentence_transformers_text_embedder.py
  +++ b/haystack/preview/components/embedders/sentence_transformers_text_embedder.py
  @@ -80,22 +80,22 @@
                   model_name_or_path=self.model_name_or_path, device=self.device, use_auth_token=self.use_auth_token
               )
   
  -    @component.output_types(embeddings=List[List[float]])
  -    def run(self, texts: List[str]):
  -        """Embed a list of strings."""
  -        if not isinstance(texts, list) or not isinstance(texts[0], str):
  +    @component.output_types(embedding=List[float])
  +    def run(self, text: str):
  +        """Embed a string."""
  +        if not isinstance(text, str):
               raise TypeError(
  -                "SentenceTransformersTextEmbedder expects a list of strings as input."
  +                "SentenceTransformersTextEmbedder expects a string as input."
                   "In case you want to embed a list of Documents, please use the SentenceTransformersDocumentEmbedder."
               )
           if not hasattr(self, "embedding_backend"):
               raise RuntimeError("The embedding model has not been loaded. Please call warm_up() before running.")
   
  -        texts_to_embed = [self.prefix + text + self.suffix for text in texts]
  -        embeddings = self.embedding_backend.embed(
  -            texts_to_embed,
  +        text_to_embed = self.prefix + text + self.suffix
  +        embedding = self.embedding_backend.embed(
  +            [text_to_embed],
               batch_size=self.batch_size,
               show_progress_bar=self.progress_bar,
               normalize_embeddings=self.normalize_embeddings,
  -        )
  -        return {"embeddings": embeddings}
  +        )[0]
  +        return {"embedding": embedding}
  
verification_info: {"golden_diff": "diff --git a/haystack/preview/components/embedders/sentence_transformers_text_embedder.py b/haystack/preview/components/embedders/sentence_transformers_text_embedder.py\n--- a/haystack/preview/components/embedders/sentence_transformers_text_embedder.py\n+++ b/haystack/preview/components/embedders/sentence_transformers_text_embedder.py\n@@ -80,22 +80,22 @@\n                 model_name_or_path=self.model_name_or_path, device=self.device, use_auth_token=self.use_auth_token\n             )\n \n-    @component.output_types(embeddings=List[List[float]])\n-    def run(self, texts: List[str]):\n-        \"\"\"Embed a list of strings.\"\"\"\n-        if not isinstance(texts, list) or not isinstance(texts[0], str):\n+    @component.output_types(embedding=List[float])\n+    def run(self, text: str):\n+        \"\"\"Embed a string.\"\"\"\n+        if not isinstance(text, str):\n             raise TypeError(\n-                \"SentenceTransformersTextEmbedder expects a list of strings as input.\"\n+                \"SentenceTransformersTextEmbedder expects a string as input.\"\n                 \"In case you want to embed a list of Documents, please use the SentenceTransformersDocumentEmbedder.\"\n             )\n         if not hasattr(self, \"embedding_backend\"):\n             raise RuntimeError(\"The embedding model has not been loaded. Please call warm_up() before running.\")\n \n-        texts_to_embed = [self.prefix + text + self.suffix for text in texts]\n-        embeddings = self.embedding_backend.embed(\n-            texts_to_embed,\n+        text_to_embed = self.prefix + text + self.suffix\n+        embedding = self.embedding_backend.embed(\n+            [text_to_embed],\n             batch_size=self.batch_size,\n             show_progress_bar=self.progress_bar,\n             normalize_embeddings=self.normalize_embeddings,\n-        )\n-        return {\"embeddings\": embeddings}\n+        )[0]\n+        return {\"embedding\": embedding}\n", "issue": "Change `SentenceTransformersTextEmbedder` to non-batch mode\n\n", "before_files": [{"content": "from typing import List, Optional, Union, Dict, Any\n\nfrom haystack.preview import component, default_to_dict, default_from_dict\nfrom haystack.preview.embedding_backends.sentence_transformers_backend import (\n    _SentenceTransformersEmbeddingBackendFactory,\n)\n\n\n@component\nclass SentenceTransformersTextEmbedder:\n    \"\"\"\n    A component for embedding strings using Sentence Transformers models.\n    \"\"\"\n\n    def __init__(\n        self,\n        model_name_or_path: str = \"sentence-transformers/all-mpnet-base-v2\",\n        device: Optional[str] = None,\n        use_auth_token: Union[bool, str, None] = None,\n        prefix: str = \"\",\n        suffix: str = \"\",\n        batch_size: int = 32,\n        progress_bar: bool = True,\n        normalize_embeddings: bool = False,\n    ):\n        \"\"\"\n        Create a SentenceTransformersTextEmbedder component.\n\n        :param model_name_or_path: Local path or name of the model in Hugging Face's model hub, such as ``'sentence-transformers/all-mpnet-base-v2'``.\n        :param device: Device (like 'cuda' / 'cpu') that should be used for computation. If None, checks if a GPU can be used.\n        :param use_auth_token: The API token used to download private models from Hugging Face.\n                        If this parameter is set to `True`, then the token generated when running\n                        `transformers-cli login` (stored in ~/.huggingface) will be used.\n        :param prefix: A string to add to the beginning of each text.\n        :param suffix: A string to add to the end of each text.\n        :param batch_size: Number of strings to encode at once.\n        :param progress_bar: If true, displays progress bar during embedding.\n        :param normalize_embeddings: If set to true, returned vectors will have length 1.\n        \"\"\"\n\n        self.model_name_or_path = model_name_or_path\n        # TODO: remove device parameter and use Haystack's device management once migrated\n        self.device = device or \"cpu\"\n        self.use_auth_token = use_auth_token\n        self.prefix = prefix\n        self.suffix = suffix\n        self.batch_size = batch_size\n        self.progress_bar = progress_bar\n        self.normalize_embeddings = normalize_embeddings\n\n    def to_dict(self) -> Dict[str, Any]:\n        \"\"\"\n        Serialize this component to a dictionary.\n        \"\"\"\n        return default_to_dict(\n            self,\n            model_name_or_path=self.model_name_or_path,\n            device=self.device,\n            use_auth_token=self.use_auth_token,\n            prefix=self.prefix,\n            suffix=self.suffix,\n            batch_size=self.batch_size,\n            progress_bar=self.progress_bar,\n            normalize_embeddings=self.normalize_embeddings,\n        )\n\n    @classmethod\n    def from_dict(cls, data: Dict[str, Any]) -> \"SentenceTransformersTextEmbedder\":\n        \"\"\"\n        Deserialize this component from a dictionary.\n        \"\"\"\n        return default_from_dict(cls, data)\n\n    def warm_up(self):\n        \"\"\"\n        Load the embedding backend.\n        \"\"\"\n        if not hasattr(self, \"embedding_backend\"):\n            self.embedding_backend = _SentenceTransformersEmbeddingBackendFactory.get_embedding_backend(\n                model_name_or_path=self.model_name_or_path, device=self.device, use_auth_token=self.use_auth_token\n            )\n\n    @component.output_types(embeddings=List[List[float]])\n    def run(self, texts: List[str]):\n        \"\"\"Embed a list of strings.\"\"\"\n        if not isinstance(texts, list) or not isinstance(texts[0], str):\n            raise TypeError(\n                \"SentenceTransformersTextEmbedder expects a list of strings as input.\"\n                \"In case you want to embed a list of Documents, please use the SentenceTransformersDocumentEmbedder.\"\n            )\n        if not hasattr(self, \"embedding_backend\"):\n            raise RuntimeError(\"The embedding model has not been loaded. Please call warm_up() before running.\")\n\n        texts_to_embed = [self.prefix + text + self.suffix for text in texts]\n        embeddings = self.embedding_backend.embed(\n            texts_to_embed,\n            batch_size=self.batch_size,\n            show_progress_bar=self.progress_bar,\n            normalize_embeddings=self.normalize_embeddings,\n        )\n        return {\"embeddings\": embeddings}\n", "path": "haystack/preview/components/embedders/sentence_transformers_text_embedder.py"}], "after_files": [{"content": "from typing import List, Optional, Union, Dict, Any\n\nfrom haystack.preview import component, default_to_dict, default_from_dict\nfrom haystack.preview.embedding_backends.sentence_transformers_backend import (\n    _SentenceTransformersEmbeddingBackendFactory,\n)\n\n\n@component\nclass SentenceTransformersTextEmbedder:\n    \"\"\"\n    A component for embedding strings using Sentence Transformers models.\n    \"\"\"\n\n    def __init__(\n        self,\n        model_name_or_path: str = \"sentence-transformers/all-mpnet-base-v2\",\n        device: Optional[str] = None,\n        use_auth_token: Union[bool, str, None] = None,\n        prefix: str = \"\",\n        suffix: str = \"\",\n        batch_size: int = 32,\n        progress_bar: bool = True,\n        normalize_embeddings: bool = False,\n    ):\n        \"\"\"\n        Create a SentenceTransformersTextEmbedder component.\n\n        :param model_name_or_path: Local path or name of the model in Hugging Face's model hub, such as ``'sentence-transformers/all-mpnet-base-v2'``.\n        :param device: Device (like 'cuda' / 'cpu') that should be used for computation. If None, checks if a GPU can be used.\n        :param use_auth_token: The API token used to download private models from Hugging Face.\n                        If this parameter is set to `True`, then the token generated when running\n                        `transformers-cli login` (stored in ~/.huggingface) will be used.\n        :param prefix: A string to add to the beginning of each text.\n        :param suffix: A string to add to the end of each text.\n        :param batch_size: Number of strings to encode at once.\n        :param progress_bar: If true, displays progress bar during embedding.\n        :param normalize_embeddings: If set to true, returned vectors will have length 1.\n        \"\"\"\n\n        self.model_name_or_path = model_name_or_path\n        # TODO: remove device parameter and use Haystack's device management once migrated\n        self.device = device or \"cpu\"\n        self.use_auth_token = use_auth_token\n        self.prefix = prefix\n        self.suffix = suffix\n        self.batch_size = batch_size\n        self.progress_bar = progress_bar\n        self.normalize_embeddings = normalize_embeddings\n\n    def to_dict(self) -> Dict[str, Any]:\n        \"\"\"\n        Serialize this component to a dictionary.\n        \"\"\"\n        return default_to_dict(\n            self,\n            model_name_or_path=self.model_name_or_path,\n            device=self.device,\n            use_auth_token=self.use_auth_token,\n            prefix=self.prefix,\n            suffix=self.suffix,\n            batch_size=self.batch_size,\n            progress_bar=self.progress_bar,\n            normalize_embeddings=self.normalize_embeddings,\n        )\n\n    @classmethod\n    def from_dict(cls, data: Dict[str, Any]) -> \"SentenceTransformersTextEmbedder\":\n        \"\"\"\n        Deserialize this component from a dictionary.\n        \"\"\"\n        return default_from_dict(cls, data)\n\n    def warm_up(self):\n        \"\"\"\n        Load the embedding backend.\n        \"\"\"\n        if not hasattr(self, \"embedding_backend\"):\n            self.embedding_backend = _SentenceTransformersEmbeddingBackendFactory.get_embedding_backend(\n                model_name_or_path=self.model_name_or_path, device=self.device, use_auth_token=self.use_auth_token\n            )\n\n    @component.output_types(embedding=List[float])\n    def run(self, text: str):\n        \"\"\"Embed a string.\"\"\"\n        if not isinstance(text, str):\n            raise TypeError(\n                \"SentenceTransformersTextEmbedder expects a string as input.\"\n                \"In case you want to embed a list of Documents, please use the SentenceTransformersDocumentEmbedder.\"\n            )\n        if not hasattr(self, \"embedding_backend\"):\n            raise RuntimeError(\"The embedding model has not been loaded. Please call warm_up() before running.\")\n\n        text_to_embed = self.prefix + text + self.suffix\n        embedding = self.embedding_backend.embed(\n            [text_to_embed],\n            batch_size=self.batch_size,\n            show_progress_bar=self.progress_bar,\n            normalize_embeddings=self.normalize_embeddings,\n        )[0]\n        return {\"embedding\": embedding}\n", "path": "haystack/preview/components/embedders/sentence_transformers_text_embedder.py"}]}