diff --git a/haystack/dataclasses/byte_stream.py b/haystack/dataclasses/byte_stream.py index ee736c001d..9c228d5f2c 100644 --- a/haystack/dataclasses/byte_stream.py +++ b/haystack/dataclasses/byte_stream.py @@ -55,7 +55,7 @@ def to_string(self, encoding: str = "utf-8") -> str: Convert the ByteStream to a string, metadata will not be included. :param encoding: The encoding used to convert the bytes to a string. Defaults to "utf-8". - :return: The string representation of the ByteStream. - :raises UnicodeDecodeError: If the ByteStream data cannot be decoded with the specified encoding. + :returns: The string representation of the ByteStream. + :raises: UnicodeDecodeError: If the ByteStream data cannot be decoded with the specified encoding. """ return self.data.decode(encoding) diff --git a/haystack/dataclasses/chat_message.py b/haystack/dataclasses/chat_message.py index b85c137475..550214efae 100644 --- a/haystack/dataclasses/chat_message.py +++ b/haystack/dataclasses/chat_message.py @@ -33,7 +33,7 @@ def is_from(self, role: ChatRole) -> bool: Check if the message is from a specific role. :param role: The role to check against. - :return: True if the message is from the specified role, False otherwise. + :returns: True if the message is from the specified role, False otherwise. """ return self.role == role @@ -44,7 +44,7 @@ def from_assistant(cls, content: str, meta: Optional[Dict[str, Any]] = None) -> :param content: The text content of the message. :param meta: Additional metadata associated with the message. - :return: A new ChatMessage instance. + :returns: A new ChatMessage instance. """ return cls(content, ChatRole.ASSISTANT, None, meta or {}) @@ -54,7 +54,7 @@ def from_user(cls, content: str) -> "ChatMessage": Create a message from the user. :param content: The text content of the message. - :return: A new ChatMessage instance. + :returns: A new ChatMessage instance. """ return cls(content, ChatRole.USER, None) @@ -64,7 +64,7 @@ def from_system(cls, content: str) -> "ChatMessage": Create a message from the system. :param content: The text content of the message. - :return: A new ChatMessage instance. + :returns: A new ChatMessage instance. """ return cls(content, ChatRole.SYSTEM, None) @@ -75,6 +75,6 @@ def from_function(cls, content: str, name: str) -> "ChatMessage": :param content: The text content of the message. :param name: The name of the function being called. - :return: A new ChatMessage instance. + :returns: A new ChatMessage instance. """ return cls(content, ChatRole.FUNCTION, name) diff --git a/haystack/dataclasses/document.py b/haystack/dataclasses/document.py index 0f26ba96c1..e1f35ac03e 100644 --- a/haystack/dataclasses/document.py +++ b/haystack/dataclasses/document.py @@ -47,8 +47,9 @@ def __call__(cls, *args, **kwargs): class Document(metaclass=_BackwardCompatible): """ Base data class containing some data to be queried. - Can contain text snippets, tables, and file paths to images or audios. - Documents can be sorted by score and saved to/from dictionary and JSON. + + Can contain text snippets, tables, and file paths to images or audios. Documents can be sorted by score and saved + to/from dictionary and JSON. :param id: Unique identifier for the document. When not set, it's generated based on the Document fields' values. :param content: Text of the document, if the document contains text. @@ -89,6 +90,7 @@ def __repr__(self): def __eq__(self, other): """ Compares Documents for equality. + Two Documents are considered equals if their dictionary representation is identical. """ if type(self) != type(other): @@ -118,9 +120,11 @@ def _create_id(self): def to_dict(self, flatten=True) -> Dict[str, Any]: """ Converts Document into a dictionary. + `dataframe` and `blob` fields are converted to JSON-serializable types. - :param flatten: Whether to flatten `meta` field or not. Defaults to `True` to be backward-compatible with Haystack 1.x. + :param flatten: + Whether to flatten `meta` field or not. Defaults to `True` to be backward-compatible with Haystack 1.x. """ data = asdict(self) if (dataframe := data.get("dataframe")) is not None: @@ -138,7 +142,8 @@ def to_dict(self, flatten=True) -> Dict[str, Any]: def from_dict(cls, data: Dict[str, Any]) -> "Document": """ Creates a new Document object from a dictionary. - `dataframe` and `blob` fields are converted to their original types. + + NOTE: `dataframe` and `blob` fields are converted to their original types. """ if (dataframe := data.get("dataframe")) is not None: data["dataframe"] = read_json(io.StringIO(dataframe)) @@ -172,9 +177,11 @@ def from_dict(cls, data: Dict[str, Any]) -> "Document": def content_type(self): """ Returns the type of the content for the document. + This is necessary to keep backward compatibility with 1.x. - A ValueError will be raised if both `text` and `dataframe` fields are set - or both are missing. + + :raises ValueError: + If both `text` and `dataframe` fields are set or both are missing. """ if self.content is not None and self.dataframe is not None: raise ValueError("Both text and dataframe are set.") diff --git a/haystack/dataclasses/streaming_chunk.py b/haystack/dataclasses/streaming_chunk.py index f2f2b990f8..b88a0b57f5 100644 --- a/haystack/dataclasses/streaming_chunk.py +++ b/haystack/dataclasses/streaming_chunk.py @@ -5,9 +5,9 @@ @dataclass class StreamingChunk: """ - The StreamingChunk class encapsulates a segment of streamed content along with - associated metadata. This structure facilitates the handling and processing of - streamed data in a systematic manner. + The StreamingChunk class encapsulates a segment of streamed content along with associated metadata. + + This structure facilitates the handling and processing of streamed data in a systematic manner. :param content: The content of the message chunk as a string. :param meta: A dictionary containing metadata related to the message chunk.