Skip to content

Commit

Permalink
docs:Review and normalize docstrings - integrations.fastembed (#519)
Browse files Browse the repository at this point in the history
* Review and normalize docstrings

* Fix linting errors
  • Loading branch information
vblagoje authored Mar 1, 2024
1 parent 419f477 commit e2d2ee7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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__(
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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 = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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. "
Expand Down

0 comments on commit e2d2ee7

Please sign in to comment.