[docs]defto_dict(self)->dict:"""Serialize Embeddings. :return: serializes this Embeddings so that it can be reconstructed by ``from_dict`` class method. :rtype: dict """return{"__class__":self.__class__.__name__,"__module__":self.__module__}
[docs]@classmethoddeffrom_dict(cls,data:dict)->BaseEmbeddings|None:"""Deserialize ``BaseEmbeddings`` into a concrete one using arguments. :return: concrete Embeddings or None if data is incorrect :rtype: BaseEmbeddings | None """data=copy.deepcopy(data)ifisinstance(data,dict):class_type=data.pop("__class__",None)module_name=data.pop("__module__",None)ifmodule_name:module=importlib.import_module(module_name)ifclass_type:try:cls=getattr(module,class_type)exceptAttributeError:raiseAttributeError(f"Module: {module} has no attribute {class_type}")ifcls:withwarnings.catch_warnings(record=True):warnings.simplefilter("ignore",category=DeprecationWarning)returncls(**data)returnNone