Home / File/ embeddings.py — langchain Source File

embeddings.py — langchain Source File

Architecture documentation for embeddings.py, a python file in the langchain codebase. 2 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  61da8d12_a1af_4a8a_c08d_ad6e636bafcc["embeddings.py"]
  cccbe73e_4644_7211_4d55_e8fb133a8014["abc"]
  61da8d12_a1af_4a8a_c08d_ad6e636bafcc --> cccbe73e_4644_7211_4d55_e8fb133a8014
  2971f9da_6393_a3e3_610e_ace3d35ee978["langchain_core.runnables.config"]
  61da8d12_a1af_4a8a_c08d_ad6e636bafcc --> 2971f9da_6393_a3e3_610e_ace3d35ee978
  style 61da8d12_a1af_4a8a_c08d_ad6e636bafcc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""**Embeddings** interface."""

from abc import ABC, abstractmethod

from langchain_core.runnables.config import run_in_executor


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)

Subdomains

Classes

Dependencies

  • abc
  • langchain_core.runnables.config

Frequently Asked Questions

What does embeddings.py do?
embeddings.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What does embeddings.py depend on?
embeddings.py imports 2 module(s): abc, langchain_core.runnables.config.
Where is embeddings.py in the architecture?
embeddings.py is located at libs/core/langchain_core/embeddings/embeddings.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/langchain_core/embeddings).

Analyze Your Own Codebase

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

Try Supermodel Free