mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-12-14 00:25:07 +00:00
* fixing all D205 issues * Update haystack/components/embedders/hugging_face_api_document_embedder.py Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com> * Update haystack/components/embedders/hugging_face_api_text_embedder.py Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com> * Update haystack/components/generators/chat/hugging_face_api.py Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com> * Update haystack/components/generators/chat/hugging_face_local.py Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com> * Update haystack/components/generators/hugging_face_api.py Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com> * fixing 205 issues and attending PR comments * fixing 205 issues and attending PR comments * Update haystack/components/converters/azure.py Co-authored-by: Daria Fokina <daria.fokina@deepset.ai> * Update haystack/components/converters/azure.py Co-authored-by: Daria Fokina <daria.fokina@deepset.ai> * Update haystack/components/extractors/named_entity_extractor.py Co-authored-by: Daria Fokina <daria.fokina@deepset.ai> * Update haystack/components/extractors/named_entity_extractor.py Co-authored-by: Daria Fokina <daria.fokina@deepset.ai> * Update haystack/core/component/component.py Co-authored-by: Daria Fokina <daria.fokina@deepset.ai> * Update haystack/components/evaluators/answer_exact_match.py Co-authored-by: Daria Fokina <daria.fokina@deepset.ai> * Update haystack/core/pipeline/template.py Co-authored-by: Daria Fokina <daria.fokina@deepset.ai> * Update haystack/core/serialization.py Co-authored-by: Daria Fokina <daria.fokina@deepset.ai> * Update haystack/core/serialization.py Co-authored-by: Daria Fokina <daria.fokina@deepset.ai> * Update haystack/core/pipeline/draw.py Co-authored-by: Daria Fokina <daria.fokina@deepset.ai> * Update haystack/components/generators/azure.py Co-authored-by: Daria Fokina <daria.fokina@deepset.ai> * Apply suggestions from code review Co-authored-by: Daria Fokina <daria.fokina@deepset.ai> --------- Co-authored-by: Stefano Fiorucci <stefanofiorucci@gmail.com> Co-authored-by: Daria Fokina <daria.fokina@deepset.ai>
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
from typing import List
|
|
|
|
|
|
class SparseEmbedding:
|
|
"""
|
|
Class representing a sparse embedding.
|
|
"""
|
|
|
|
def __init__(self, indices: List[int], values: List[float]):
|
|
"""
|
|
Initialize a SparseEmbedding object.
|
|
|
|
:param indices: List of indices of non-zero elements in the embedding.
|
|
:param values: List of values of non-zero elements in the embedding.
|
|
|
|
:raises ValueError: If the indices and values lists are not of the same length.
|
|
"""
|
|
if len(indices) != len(values):
|
|
raise ValueError("Length of indices and values must be the same.")
|
|
self.indices = indices
|
|
self.values = values
|
|
|
|
def to_dict(self):
|
|
"""
|
|
Convert the SparseEmbedding object to a dictionary.
|
|
|
|
:returns:
|
|
Serialized sparse embedding.
|
|
"""
|
|
return {"indices": self.indices, "values": self.values}
|
|
|
|
@classmethod
|
|
def from_dict(cls, sparse_embedding_dict):
|
|
"""
|
|
Deserializes the sparse embedding from a dictionary.
|
|
|
|
:param sparse_embedding_dict:
|
|
Dictionary to deserialize from.
|
|
:returns:
|
|
Deserialized sparse embedding.
|
|
"""
|
|
return cls(indices=sparse_embedding_dict["indices"], values=sparse_embedding_dict["values"])
|