Home / File/ base.py — langchain Source File

base.py — langchain Source File

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

File python CoreAbstractions Serialization 9 imports 1 functions 6 classes

Entity Profile

Dependency Diagram

graph LR
  44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8["base.py"]
  cccbe73e_4644_7211_4d55_e8fb133a8014["abc"]
  44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8 --> cccbe73e_4644_7211_4d55_e8fb133a8014
  0c1d9a1b_c553_0388_dbc1_58af49567aa2["time"]
  44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8 --> 0c1d9a1b_c553_0388_dbc1_58af49567aa2
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8 --> 91721f45_4909_e489_8c1f_084f8bd87145
  b19a8b7e_fbee_95b1_65b8_509a1ed3cad7["langchain_core._api"]
  44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8 --> b19a8b7e_fbee_95b1_65b8_509a1ed3cad7
  38bc5323_3713_7377_32f8_091293bea54b["langchain_core.retrievers"]
  44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8 --> 38bc5323_3713_7377_32f8_091293bea54b
  2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"]
  44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8 --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"]
  44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8 --> c554676d_b731_47b2_a98f_c1c2d537c0aa
  style 44ffc3da_66a5_f9ca_57ac_f9a80e82f0c8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Base classes for indexing."""

from __future__ import annotations

import abc
import time
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Any, TypedDict

from typing_extensions import override

from langchain_core._api import beta
from langchain_core.retrievers import BaseRetriever
from langchain_core.runnables import run_in_executor

if TYPE_CHECKING:
    from collections.abc import Sequence

    from langchain_core.documents import Document


class RecordManager(ABC):
    """Abstract base class representing the interface for a record manager.

    The record manager abstraction is used by the langchain indexing API.

    The record manager keeps track of which documents have been
    written into a `VectorStore` and when they were written.

    The indexing API computes hashes for each document and stores the hash
    together with the write time and the source id in the record manager.

    On subsequent indexing runs, the indexing API can check the record manager
    to determine which documents have already been indexed and which have not.

    This allows the indexing API to avoid re-indexing documents that have
    already been indexed, and to only index new documents.

    The main benefit of this abstraction is that it works across many vectorstores.
    To be supported, a `VectorStore` needs to only support the ability to add and
    delete documents by ID. Using the record manager, the indexing API will
    be able to delete outdated documents and avoid redundant indexing of documents
    that have already been indexed.

    The main constraints of this abstraction are:

    1. It relies on the time-stamps to determine which documents have been
        indexed and which have not. This means that the time-stamps must be
        monotonically increasing. The timestamp should be the timestamp
        as measured by the server to minimize issues.
    2. The record manager is currently implemented separately from the
        vectorstore, which means that the overall system becomes distributed
        and may create issues with consistency. For example, writing to
        record manager succeeds, but corresponding writing to `VectorStore` fails.
    """

    def __init__(
        self,
        namespace: str,
    ) -> None:
// ... (602 more lines)

Subdomains

Functions

Dependencies

  • abc
  • collections.abc
  • langchain_core._api
  • langchain_core.documents
  • langchain_core.retrievers
  • langchain_core.runnables
  • time
  • typing
  • typing_extensions

Frequently Asked Questions

What does base.py do?
base.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in base.py?
base.py defines 1 function(s): collections.
What does base.py depend on?
base.py imports 9 module(s): abc, collections.abc, langchain_core._api, langchain_core.documents, langchain_core.retrievers, langchain_core.runnables, time, typing, and 1 more.
Where is base.py in the architecture?
base.py is located at libs/core/langchain_core/indexing/base.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/langchain_core/indexing).

Analyze Your Own Codebase

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

Try Supermodel Free