Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Langchain ai Langgraph Store Embedding Support

From Leeroopedia
Knowledge Sources
Domains Store, Embeddings, Semantic_Search
Last Updated 2026-02-11 15:00 GMT

Overview

Store Embedding Support is the principle of normalizing diverse embedding sources into a unified interface and providing path-based text extraction, enabling semantic vector search within the LangGraph store layer.

Description

LangGraph stores can optionally augment their key-value storage with vector embeddings for semantic similarity search. Store Embedding Support provides the foundational utilities that make this possible: a normalization layer for embedding functions and a text extraction system for structured data.

The embedding normalization layer, centered on `ensure_embeddings()`, accepts multiple input types -- an existing LangChain `Embeddings` instance, a synchronous callable, an asynchronous callable, or a provider string (e.g., `"openai:text-embedding-3-small"`) -- and returns a conformant `Embeddings` object. The `EmbeddingsLambda` wrapper class bridges plain Python functions to the LangChain `Embeddings` protocol, supporting both sync and async variants.

The text extraction layer, provided by `get_text_at_path()` and `tokenize_path()`, extracts text values from nested JSON-like data structures using path expressions. These support dot-separated field access, array indexing (`[0]`, `[*]`, `[-1]`), wildcards (`*`), and multi-field selection (`{field1,field2}`). This enables stores to embed only specific fields from stored documents rather than the entire structure, saving embedding tokens and improving search relevance.

Usage

Use Store Embedding Support when configuring vector search in a LangGraph store:

  • Wrap custom embedding functions using `ensure_embeddings()` to make them compatible with the store's index configuration.
  • Use provider strings for quick initialization of standard embedding models.
  • Specify field paths in the store's `fields` configuration to control which parts of stored documents are embedded.
  • Extract text from nested structures using path expressions for fine-grained control over embedding content.

Theoretical Basis

Store Embedding Support is grounded in the following principles:

1. Adapter pattern for embeddings: Different embedding sources (API services, local models, custom functions) have incompatible interfaces. The `ensure_embeddings()` function implements the adapter pattern, wrapping each source in a common `Embeddings` interface. This decouples the store layer from any specific embedding provider and allows seamless swapping of embedding backends.

2. Selective field embedding: Real-world stored documents often contain a mix of fields: some are semantically meaningful (descriptions, content) while others are structural (IDs, timestamps). By embedding only the fields specified via path expressions, the system avoids polluting the vector space with irrelevant tokens. This follows the information retrieval principle that precision improves when the indexed text is relevant to the expected queries.

3. Sync/async duality: The `EmbeddingsLambda` wrapper preserves the execution model of the underlying function. A synchronous function supports sync embedding operations, while an async function supports async operations. This ensures that the embedding layer does not inadvertently block the event loop in async applications or require unnecessary async overhead in sync contexts.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment