Home / Class/ AddableDict Class — langchain Architecture

AddableDict Class — langchain Architecture

Architecture documentation for the AddableDict class in utils.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  3b0dc9f2_fc0d_e56f_51c2_b1c423b52259["AddableDict"]
  ca66092c_447c_d201_0d3c_cfa6ca2cc9d3["utils.py"]
  3b0dc9f2_fc0d_e56f_51c2_b1c423b52259 -->|defined in| ca66092c_447c_d201_0d3c_cfa6ca2cc9d3
  14980c77_5b69_67cc_a319_b755caceb264["__add__()"]
  3b0dc9f2_fc0d_e56f_51c2_b1c423b52259 -->|method| 14980c77_5b69_67cc_a319_b755caceb264
  b85e7b28_7ce6_0ab7_d110_01c0591b9f52["__radd__()"]
  3b0dc9f2_fc0d_e56f_51c2_b1c423b52259 -->|method| b85e7b28_7ce6_0ab7_d110_01c0591b9f52

Relationship Graph

Source Code

libs/core/langchain_core/runnables/utils.py lines 466–509

class AddableDict(dict[str, Any]):
    """Dictionary that can be added to another dictionary."""

    def __add__(self, other: AddableDict) -> AddableDict:
        """Add a dictionary to this dictionary.

        Args:
            other: The other dictionary to add.

        Returns:
            A dictionary that is the result of adding the two dictionaries.
        """
        chunk = AddableDict(self)
        for key in other:
            if key not in chunk or chunk[key] is None:
                chunk[key] = other[key]
            elif other[key] is not None:
                try:
                    added = chunk[key] + other[key]
                except TypeError:
                    added = other[key]
                chunk[key] = added
        return chunk

    def __radd__(self, other: AddableDict) -> AddableDict:
        """Add this dictionary to another dictionary.

        Args:
            other: The other dictionary to be added to.

        Returns:
            A dictionary that is the result of adding the two dictionaries.
        """
        chunk = AddableDict(other)
        for key in self:
            if key not in chunk or chunk[key] is None:
                chunk[key] = self[key]
            elif self[key] is not None:
                try:
                    added = chunk[key] + self[key]
                except TypeError:
                    added = self[key]
                chunk[key] = added
        return chunk

Frequently Asked Questions

What is the AddableDict class?
AddableDict is a class in the langchain codebase, defined in libs/core/langchain_core/runnables/utils.py.
Where is AddableDict defined?
AddableDict is defined in libs/core/langchain_core/runnables/utils.py at line 466.

Analyze Your Own Codebase

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

Try Supermodel Free