[docs]classFakeEmbeddings(Embeddings,BaseModel):"""Fake embedding model."""size:int"""The size of the embedding vector."""def_get_embedding(self)->List[float]:returnlist(np.random.normal(size=self.size))
[docs]classDeterministicFakeEmbedding(Embeddings,BaseModel):""" Fake embedding model that always returns the same embedding vector for the same text. """size:int"""The size of the embedding vector."""def_get_embedding(self,seed:int)->List[float]:# set the seed for the random generatornp.random.seed(seed)returnlist(np.random.normal(size=self.size))def_get_seed(self,text:str)->int:""" Get a seed for the random generator, using the hash of the text. """returnint(hashlib.sha256(text.encode("utf-8")).hexdigest(),16)%10**8