Home / File/ __init__.py — langchain Source File

__init__.py — langchain Source File

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

File python CoreAbstractions Serialization 4 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  6dd80fdb_9b4c_5518_54fe_8dc9cc75afa9["__init__.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  6dd80fdb_9b4c_5518_54fe_8dc9cc75afa9 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  923d222e_e249_1c30_4cfe_3c907f050b78["langchain_core._import_utils"]
  6dd80fdb_9b4c_5518_54fe_8dc9cc75afa9 --> 923d222e_e249_1c30_4cfe_3c907f050b78
  ba11ce6e_2d0d_a28d_4b37_a0d5f8ef8da8["langchain_core.vectorstores.base"]
  6dd80fdb_9b4c_5518_54fe_8dc9cc75afa9 --> ba11ce6e_2d0d_a28d_4b37_a0d5f8ef8da8
  1c9ec44f_fcfa_1774_ddf2_cdd2f6b0e944["langchain_core.vectorstores.in_memory"]
  6dd80fdb_9b4c_5518_54fe_8dc9cc75afa9 --> 1c9ec44f_fcfa_1774_ddf2_cdd2f6b0e944
  style 6dd80fdb_9b4c_5518_54fe_8dc9cc75afa9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Vector stores."""

from typing import TYPE_CHECKING

from langchain_core._import_utils import import_attr

if TYPE_CHECKING:
    from langchain_core.vectorstores.base import VST, VectorStore, VectorStoreRetriever
    from langchain_core.vectorstores.in_memory import InMemoryVectorStore

__all__ = (
    "VST",
    "InMemoryVectorStore",
    "VectorStore",
    "VectorStoreRetriever",
)

_dynamic_imports = {
    "VectorStore": "base",
    "VST": "base",
    "VectorStoreRetriever": "base",
    "InMemoryVectorStore": "in_memory",
}


def __getattr__(attr_name: str) -> object:
    """Dynamically import and return an attribute from a submodule.

    This function enables lazy loading of vectorstore classes from submodules, reducing
    initial import time and circular dependency issues.

    Args:
        attr_name: Name of the attribute to import.

    Returns:
        The imported attribute object.

    Raises:
        AttributeError: If the attribute is not found in `_dynamic_imports`.
    """
    module_name = _dynamic_imports.get(attr_name)
    result = import_attr(attr_name, module_name, __spec__.parent)
    globals()[attr_name] = result
    return result


def __dir__() -> list[str]:
    """Return a list of available attributes for this module.

    Returns:
        List of attribute names that can be imported from this module.
    """
    return list(__all__)

Subdomains

Dependencies

  • langchain_core._import_utils
  • langchain_core.vectorstores.base
  • langchain_core.vectorstores.in_memory
  • typing

Frequently Asked Questions

What does __init__.py do?
__init__.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 __init__.py?
__init__.py defines 3 function(s): __dir__, __getattr__, langchain_core.
What does __init__.py depend on?
__init__.py imports 4 module(s): langchain_core._import_utils, langchain_core.vectorstores.base, langchain_core.vectorstores.in_memory, typing.
Where is __init__.py in the architecture?
__init__.py is located at libs/core/langchain_core/vectorstores/__init__.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/langchain_core/vectorstores).

Analyze Your Own Codebase

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

Try Supermodel Free