Home / Class/ Embeddings Class — langchain Architecture

Embeddings Class — langchain Architecture

Architecture documentation for the Embeddings class in embeddings.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c58e6864_9429_b081_883b_39ba15df0485["Embeddings"]
  61da8d12_a1af_4a8a_c08d_ad6e636bafcc["embeddings.py"]
  c58e6864_9429_b081_883b_39ba15df0485 -->|defined in| 61da8d12_a1af_4a8a_c08d_ad6e636bafcc
  55869738_311b_1d8b_5e9b_222f31663f38["embed_documents()"]
  c58e6864_9429_b081_883b_39ba15df0485 -->|method| 55869738_311b_1d8b_5e9b_222f31663f38
  ef0cce0d_cf75_dcf2_e603_fea189df84be["embed_query()"]
  c58e6864_9429_b081_883b_39ba15df0485 -->|method| ef0cce0d_cf75_dcf2_e603_fea189df84be
  20b55ba4_cfe8_83ae_5419_4bb924f293a6["aembed_documents()"]
  c58e6864_9429_b081_883b_39ba15df0485 -->|method| 20b55ba4_cfe8_83ae_5419_4bb924f293a6
  420efba8_4357_1953_fe48_399c43f595ac["aembed_query()"]
  c58e6864_9429_b081_883b_39ba15df0485 -->|method| 420efba8_4357_1953_fe48_399c43f595ac

Relationship Graph

Source Code

libs/core/langchain_core/embeddings/embeddings.py lines 8–78

class Embeddings(ABC):
    """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.
    """

    @abstractmethod
    def embed_documents(self, texts: list[str]) -> list[list[float]]:
        """Embed search docs.

        Args:
            texts: List of text to embed.

        Returns:
            List of embeddings.
        """

    @abstractmethod
    def embed_query(self, text: str) -> list[float]:
        """Embed query text.

        Args:
            text: Text to embed.

        Returns:
            Embedding.
        """

    async def aembed_documents(self, texts: list[str]) -> list[list[float]]:
        """Asynchronous Embed search docs.

        Args:
            texts: List of text to embed.

        Returns:
            List of embeddings.
        """
        return await run_in_executor(None, self.embed_documents, texts)

    async def aembed_query(self, text: str) -> list[float]:
        """Asynchronous Embed query text.

        Args:
            text: Text to embed.

        Returns:
            Embedding.
        """
        return await run_in_executor(None, self.embed_query, text)

Frequently Asked Questions

What is the Embeddings class?
Embeddings is a class in the langchain codebase, defined in libs/core/langchain_core/embeddings/embeddings.py.
Where is Embeddings defined?
Embeddings is defined in libs/core/langchain_core/embeddings/embeddings.py at line 8.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free