Home / File/ encoder_backed.py — langchain Source File

encoder_backed.py — langchain Source File

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

File python LangChainCore Runnables 3 imports 1 classes

Entity Profile

Dependency Diagram

graph LR
  6396544b_6282_c633_57d8_1b40e0ca4ec6["encoder_backed.py"]
  2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"]
  6396544b_6282_c633_57d8_1b40e0ca4ec6 --> 2bf6d401_816d_d011_3b05_a6114f55ff58
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  6396544b_6282_c633_57d8_1b40e0ca4ec6 --> feec1ec4_6917_867b_d228_b134d0ff8099
  18bf18ce_a804_12d4_efe2_700bc6c22630["langchain_core.stores"]
  6396544b_6282_c633_57d8_1b40e0ca4ec6 --> 18bf18ce_a804_12d4_efe2_700bc6c22630
  style 6396544b_6282_c633_57d8_1b40e0ca4ec6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from collections.abc import AsyncIterator, Callable, Iterator, Sequence
from typing import (
    Any,
    TypeVar,
)

from langchain_core.stores import BaseStore

K = TypeVar("K")
V = TypeVar("V")


class EncoderBackedStore(BaseStore[K, V]):
    """Wraps a store with key and value encoders/decoders.

    Examples that uses JSON for encoding/decoding:

    ```python
    import json


    def key_encoder(key: int) -> str:
        return json.dumps(key)


    def value_serializer(value: float) -> str:
        return json.dumps(value)


    def value_deserializer(serialized_value: str) -> float:
        return json.loads(serialized_value)


    # Create an instance of the abstract store
    abstract_store = MyCustomStore()

    # Create an instance of the encoder-backed store
    store = EncoderBackedStore(
        store=abstract_store,
        key_encoder=key_encoder,
        value_serializer=value_serializer,
        value_deserializer=value_deserializer,
    )

    # Use the encoder-backed store methods
    store.mset([(1, 3.14), (2, 2.718)])
    values = store.mget([1, 2])  # Retrieves [3.14, 2.718]
    store.mdelete([1, 2])  # Deletes the keys 1 and 2
    ```
    """

    def __init__(
        self,
        store: BaseStore[str, Any],
        key_encoder: Callable[[K], str],
        value_serializer: Callable[[V], bytes],
        value_deserializer: Callable[[Any], V],
    ) -> None:
        """Initialize an `EncodedStore`.

// ... (122 more lines)

Domain

Subdomains

Dependencies

  • collections.abc
  • langchain_core.stores
  • typing

Frequently Asked Questions

What does encoder_backed.py do?
encoder_backed.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, Runnables subdomain.
What does encoder_backed.py depend on?
encoder_backed.py imports 3 module(s): collections.abc, langchain_core.stores, typing.
Where is encoder_backed.py in the architecture?
encoder_backed.py is located at libs/langchain/langchain_classic/storage/encoder_backed.py (domain: LangChainCore, subdomain: Runnables, directory: libs/langchain/langchain_classic/storage).

Analyze Your Own Codebase

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

Try Supermodel Free