Home / Class/ InMemoryRecordManager Class — langchain Architecture

InMemoryRecordManager Class — langchain Architecture

Architecture documentation for the InMemoryRecordManager class in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  d78e108a_0500_230a_3cfd_ffeb42e0f193["InMemoryRecordManager"]
  d5396e7d_8f96_f74d_2e53_741efbe757bc["RecordManager"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|extends| d5396e7d_8f96_f74d_2e53_741efbe757bc
  44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8["base.py"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|defined in| 44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8
  24e0335b_742f_73a0_f69e_f344d1b913f0["__init__()"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|method| 24e0335b_742f_73a0_f69e_f344d1b913f0
  e5ae9fbb_9995_5a4e_bb9f_08714673d6c5["create_schema()"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|method| e5ae9fbb_9995_5a4e_bb9f_08714673d6c5
  c6663dbb_639d_de46_1f8d_e98f180c9947["acreate_schema()"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|method| c6663dbb_639d_de46_1f8d_e98f180c9947
  08cd0c30_250b_1928_aa91_19902a822678["get_time()"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|method| 08cd0c30_250b_1928_aa91_19902a822678
  e3fda019_8889_4190_7cee_6db08576454f["aget_time()"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|method| e3fda019_8889_4190_7cee_6db08576454f
  c11eb10f_e927_0273_007c_35ef9ce96ab8["update()"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|method| c11eb10f_e927_0273_007c_35ef9ce96ab8
  f52e88b9_e3f3_4295_a5d0_295cdbe5cc0a["aupdate()"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|method| f52e88b9_e3f3_4295_a5d0_295cdbe5cc0a
  b871e8bf_2da5_0058_e1d5_293dfc49a53a["exists()"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|method| b871e8bf_2da5_0058_e1d5_293dfc49a53a
  785dc327_2063_fbd1_6e58_14199fa1dd40["aexists()"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|method| 785dc327_2063_fbd1_6e58_14199fa1dd40
  3b23350f_9171_c11d_4319_07912ca2d5d6["list_keys()"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|method| 3b23350f_9171_c11d_4319_07912ca2d5d6
  3f28b341_addb_1358_1dbb_22a5a8cea3cd["alist_keys()"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|method| 3f28b341_addb_1358_1dbb_22a5a8cea3cd
  a300c141_eb7a_b561_e790_2cfd90f36d6f["delete_keys()"]
  d78e108a_0500_230a_3cfd_ffeb42e0f193 -->|method| a300c141_eb7a_b561_e790_2cfd90f36d6f

Relationship Graph

Source Code

libs/core/langchain_core/indexing/base.py lines 240–431

class InMemoryRecordManager(RecordManager):
    """An in-memory record manager for testing purposes."""

    def __init__(self, namespace: str) -> None:
        """Initialize the in-memory record manager.

        Args:
            namespace: The namespace for the record manager.
        """
        super().__init__(namespace)
        # Each key points to a dictionary
        # of {'group_id': group_id, 'updated_at': timestamp}
        self.records: dict[str, _Record] = {}
        self.namespace = namespace

    def create_schema(self) -> None:
        """In-memory schema creation is simply ensuring the structure is initialized."""

    async def acreate_schema(self) -> None:
        """In-memory schema creation is simply ensuring the structure is initialized."""

    @override
    def get_time(self) -> float:
        return time.time()

    @override
    async def aget_time(self) -> float:
        return self.get_time()

    def update(
        self,
        keys: Sequence[str],
        *,
        group_ids: Sequence[str | None] | None = None,
        time_at_least: float | None = None,
    ) -> None:
        """Upsert records into the database.

        Args:
            keys: A list of record keys to upsert.
            group_ids: A list of group IDs corresponding to the keys.

            time_at_least: Optional timestamp. Implementation can use this
                to optionally verify that the timestamp IS at least this time
                in the system that stores.
                E.g., use to validate that the time in the postgres database
                is equal to or larger than the given timestamp, if not
                raise an error.
                This is meant to help prevent time-drift issues since
                time may not be monotonically increasing!

        Raises:
            ValueError: If the length of keys doesn't match the length of group
                ids.
            ValueError: If time_at_least is in the future.
        """
        if group_ids and len(keys) != len(group_ids):
            msg = "Length of keys must match length of group_ids"
            raise ValueError(msg)
        for index, key in enumerate(keys):
            group_id = group_ids[index] if group_ids else None
            if time_at_least and time_at_least > self.get_time():
                msg = "time_at_least must be in the past"
                raise ValueError(msg)
            self.records[key] = {"group_id": group_id, "updated_at": self.get_time()}

    async def aupdate(
        self,
        keys: Sequence[str],
        *,
        group_ids: Sequence[str | None] | None = None,
        time_at_least: float | None = None,
    ) -> None:
        """Async upsert records into the database.

        Args:
            keys: A list of record keys to upsert.
            group_ids: A list of group IDs corresponding to the keys.

            time_at_least: Optional timestamp. Implementation can use this
                to optionally verify that the timestamp IS at least this time

Extends

Frequently Asked Questions

What is the InMemoryRecordManager class?
InMemoryRecordManager is a class in the langchain codebase, defined in libs/core/langchain_core/indexing/base.py.
Where is InMemoryRecordManager defined?
InMemoryRecordManager is defined in libs/core/langchain_core/indexing/base.py at line 240.
What does InMemoryRecordManager extend?
InMemoryRecordManager extends RecordManager.

Analyze Your Own Codebase

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

Try Supermodel Free