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.storebaseIndexConfigembed
    Attribute●Since v2.0

    embed

    Optional function to generate embeddings from text.

    Copy
    embed: Embeddings | EmbeddingsFunc | AEmbeddingsFunc | str

    Can be specified in three ways:

    1. A LangChain Embeddings instance
    2. A synchronous embedding function (EmbeddingsFunc)
    3. An asynchronous embedding function (AEmbeddingsFunc)
    4. A provider string (e.g., "openai:text-embedding-3-small")

    Using LangChain's initialization with InMemoryStore:

    from langchain.embeddings import init_embeddings
    from langgraph.store.memory import InMemoryStore
        
    store = InMemoryStore(
        index={
            "dims": 1536,
            "embed": init_embeddings("openai:text-embedding-3-small")
        }
    )

    Using a custom embedding function with InMemoryStore:

    from openai import OpenAI
    from langgraph.store.memory import InMemoryStore
        
    client = OpenAI()
        
    def embed_texts(texts: list[str]) -> list[list[float]]:
        response = client.embeddings.create(
            model="text-embedding-3-small",
            input=texts
        )
        return [e.embedding for e in response.data]
            
    store = InMemoryStore(
        index={
            "dims": 1536,
            "embed": embed_texts
        }
    )

    Using an asynchronous embedding function with InMemoryStore:

    from openai import AsyncOpenAI
    from langgraph.store.memory import InMemoryStore
        
    client = AsyncOpenAI()
        
    async def aembed_texts(texts: list[str]) -> list[list[float]]:
        response = await client.embeddings.create(
            model="text-embedding-3-small",
            input=texts
        )
        return [e.embedding for e in response.data]
            
    store = InMemoryStore(
        index={
            "dims": 1536,
            "embed": aembed_texts
        }
    )
    View source on GitHub