Embeddings#

class langchain_core.embeddings.embeddings.Embeddings[source]#

Interface for embedding models.

This is an interface meant for implementing text embedding models.

Text embedding models are used to map text to a vector (a point in n-dimensional space).

Texts that are similar will usually be mapped to points that are close to each other in this space. The exact details of what’s considered β€œsimilar” and how β€œdistance” is measured in this space are dependent on the specific embedding model.

This abstraction contains a method for embedding a list of documents and a method for embedding a query text. The embedding of a query text is expected to be a single vector, while the embedding of a list of documents is expected to be a list of vectors.

Usually the query embedding is identical to the document embedding, but the abstraction allows treating them independently.

In addition to the synchronous methods, this interface also provides asynchronous versions of the methods.

By default, the asynchronous methods are implemented using the synchronous methods; however, implementations may choose to override the asynchronous methods with an async native implementation for performance reasons.

Methods

__init__()

aembed_documents(texts)

Asynchronous Embed search docs.

aembed_query(text)

Asynchronous Embed query text.

embed_documents(texts)

Embed search docs.

embed_query(text)

Embed query text.

__init__()#
async aembed_documents(texts: list[str]) β†’ list[list[float]][source]#

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][source]#

Asynchronous Embed query text.

Parameters:

text (str) – Text to embed.

Returns:

Embedding.

Return type:

list[float]

abstract 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]]

abstract embed_query(text: str) β†’ list[float][source]#

Embed query text.

Parameters:

text (str) – Text to embed.

Returns:

Embedding.

Return type:

list[float]

Examples using Embeddings