LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    LangGraph Checkpoint
    LangGraph Store
    Checkpoint Postgres
    Store Postgres
    Checkpoint SQLite
    LangGraph Prebuilt
    LangGraph CLI
    LangGraph SDK
    LangGraph Supervisor
    LangGraph Swarm
    Language
    Theme
    Pythonlanggraph.storebaseembedEmbeddingsLambda
    Classā—Since v2.0

    EmbeddingsLambda

    Copy
    EmbeddingsLambda(
        self,
        func: EmbeddingsFunc | AEmbeddingsFunc,
    )

    Bases

    Embeddings

    Constructors

    Attributes

    Methods

    View source on GitHub

    Parameters

    NameTypeDescription
    func*EmbeddingsFunc | AEmbeddingsFunc

    Function that converts text to embeddings. Can be sync or async. If async, it will be used for async operations, but sync operations will raise an error. If sync, it will be used for both sync and async operations.

    constructor
    __init__
    NameType
    funcEmbeddingsFunc | AEmbeddingsFunc
    attribute
    afunc: func
    attribute
    func: func
    method
    embed_documents

    Embed a list of texts into vectors.

    method
    embed_query

    Embed a single piece of text.

    method
    aembed_documents

    Asynchronously embed a list of texts into vectors.

    method
    aembed_query

    Asynchronously embed a single piece of text.

    Wrapper to convert embedding functions into LangChain's Embeddings interface.

    This class allows arbitrary embedding functions to be used with LangChain-compatible tools. It supports both synchronous and asynchronous operations, and can handle:

    1. A synchronous function for sync operations (async operations will use sync function)
    2. An async function for both sync/async operations (sync operations will raise an error)

    The embedding functions should convert text into fixed-dimensional vectors that capture the semantic meaning of the text.

    With a sync function:

    def my_embed_fn(texts):
        # Return 2D embeddings for each text
        return [[0.1, 0.2] for _ in texts]
    
    embeddings = EmbeddingsLambda(my_embed_fn)
    result = embeddings.embed_query("hello")  # Returns [0.1, 0.2]
    await embeddings.aembed_query("hello")  # Also returns [0.1, 0.2]

    With an async function:

    async def my_async_fn(texts):
        return [[0.1, 0.2] for _ in texts]
    
    embeddings = EmbeddingsLambda(my_async_fn)
    await embeddings.aembed_query("hello")  # Returns [0.1, 0.2]
    # Note: embed_query() would raise an error