DeterministicFakeEmbedding#

class langchain_core.embeddings.fake.DeterministicFakeEmbedding[source]#

Bases: Embeddings, BaseModel

Deterministic fake embedding model for unit testing purposes.

This embedding model creates embeddings by sampling from a normal distribution with a seed based on the hash of the text.

Do not use this outside of testing, as it is not a real embedding model.

Example

from langchain_core.embeddings import DeterministicFakeEmbedding

fake_embeddings = DeterministicFakeEmbedding(size=100)
fake_embeddings.embed_documents(["hello world", "foo bar"])

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param size: int [Required]#

The size of the embedding vector.

async aembed_documents(texts: List[str]) List[List[float]]#

Asynchronous Embed search docs.

Parameters:

texts (List[str]) – List of text to embed.

Returns:

List of embeddings.

Return type:

List[List[float]]

async aembed_query(text: str) List[float]#

Asynchronous Embed query text.

Parameters:

text (str) – Text to embed.

Returns:

Embedding.

Return type:

List[float]

embed_documents(texts: List[str]) List[List[float]][source]#

Embed search docs.

Parameters:

texts (List[str]) – List of text to embed.

Returns:

List of embeddings.

Return type:

List[List[float]]

embed_query(text: str) List[float][source]#

Embed query text.

Parameters:

text (str) – Text to embed.

Returns:

Embedding.

Return type:

List[float]

Examples using DeterministicFakeEmbedding#