diff --git a/integrations/fastembed/src/haystack_integrations/components/embedders/fastembed/fastembed_document_embedder.py b/integrations/fastembed/src/haystack_integrations/components/embedders/fastembed/fastembed_document_embedder.py index 1aa2b9539..f08ff1adc 100644 --- a/integrations/fastembed/src/haystack_integrations/components/embedders/fastembed/fastembed_document_embedder.py +++ b/integrations/fastembed/src/haystack_integrations/components/embedders/fastembed/fastembed_document_embedder.py @@ -8,7 +8,7 @@ @component class FastembedDocumentEmbedder: """ - A component for computing Document embeddings using Fastembed embedding models. + FastembedDocumentEmbedder computes Document embeddings using Fastembed embedding models. The embedding of each Document is stored in the `embedding` field of the Document. Usage example: @@ -48,6 +48,7 @@ class FastembedDocumentEmbedder: print(f"Document Text: {result['documents'][0].content}") print(f"Document Embedding: {result['documents'][0].embedding}") print(f"Embedding Dimension: {len(result['documents'][0].embedding)}") + ``` """ # noqa: E501 def __init__( @@ -97,7 +98,9 @@ def __init__( def to_dict(self) -> Dict[str, Any]: """ - Serialize this component to a dictionary. + Serializes the component to a dictionary. + :returns: + Dictionary with serialized data. """ return default_to_dict( self, @@ -115,7 +118,7 @@ def to_dict(self) -> Dict[str, Any]: def warm_up(self): """ - Load the embedding backend. + Initializes the component. """ if not hasattr(self, "embedding_backend"): self.embedding_backend = _FastembedEmbeddingBackendFactory.get_embedding_backend( @@ -138,8 +141,11 @@ def _prepare_texts_to_embed(self, documents: List[Document]) -> List[str]: @component.output_types(documents=List[Document]) def run(self, documents: List[Document]): """ - Embed a list of Documents. - The embedding of each Document is stored in the `embedding` field of the Document. + Embeds a list of Documents. + + :param documents: List of Documents to embed. + :return: A dictionary with the following keys: + - `documents`: List of Documents with each Document's `embedding` field set to the computed embeddings. """ if not isinstance(documents, list) or documents and not isinstance(documents[0], Document): msg = ( diff --git a/integrations/fastembed/src/haystack_integrations/components/embedders/fastembed/fastembed_text_embedder.py b/integrations/fastembed/src/haystack_integrations/components/embedders/fastembed/fastembed_text_embedder.py index c075875b7..ffba6a902 100644 --- a/integrations/fastembed/src/haystack_integrations/components/embedders/fastembed/fastembed_text_embedder.py +++ b/integrations/fastembed/src/haystack_integrations/components/embedders/fastembed/fastembed_text_embedder.py @@ -8,7 +8,7 @@ @component class FastembedTextEmbedder: """ - A component for embedding strings using fastembed embedding models. + FastembedTextEmbedder computes string embedding using fastembed embedding models. Usage example: ```python @@ -69,7 +69,10 @@ def __init__( def to_dict(self) -> Dict[str, Any]: """ - Serialize this component to a dictionary. + Serializes the component to a dictionary. + + :returns: + Dictionary with serialized data. """ return default_to_dict( self, @@ -85,7 +88,7 @@ def to_dict(self) -> Dict[str, Any]: def warm_up(self): """ - Load the embedding backend. + Initializes the component. """ if not hasattr(self, "embedding_backend"): self.embedding_backend = _FastembedEmbeddingBackendFactory.get_embedding_backend( @@ -94,7 +97,15 @@ def warm_up(self): @component.output_types(embedding=List[float]) def run(self, text: str): - """Embed a string.""" + """ + Embeds text using the Fastembed model. + + :param text: A string to embed. + :return: A dictionary with the following keys: + - `embedding`: A list of floats representing the embedding of the input text. + :raises TypeError: If the input is not a string. + :raises RuntimeError: If the embedding model has not been loaded. + """ if not isinstance(text, str): msg = ( "FastembedTextEmbedder expects a string as input. "