Home / File/ retrievers.py — langchain Source File

retrievers.py — langchain Source File

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

File python CoreAbstractions Serialization 9 imports 1 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  b0b3cb2f_fcef_0784_b2ba_ee476260390d["retrievers.py"]
  cccbe73e_4644_7211_4d55_e8fb133a8014["abc"]
  b0b3cb2f_fcef_0784_b2ba_ee476260390d --> cccbe73e_4644_7211_4d55_e8fb133a8014
  614e7b9f_ed51_0780_749c_ff40b74963fc["inspect"]
  b0b3cb2f_fcef_0784_b2ba_ee476260390d --> 614e7b9f_ed51_0780_749c_ff40b74963fc
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  b0b3cb2f_fcef_0784_b2ba_ee476260390d --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  b0b3cb2f_fcef_0784_b2ba_ee476260390d --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  b0b3cb2f_fcef_0784_b2ba_ee476260390d --> 91721f45_4909_e489_8c1f_084f8bd87145
  e8ec017e_6c91_4b34_675f_2a96c5aa9be6["langchain_core.callbacks.manager"]
  b0b3cb2f_fcef_0784_b2ba_ee476260390d --> e8ec017e_6c91_4b34_675f_2a96c5aa9be6
  c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"]
  b0b3cb2f_fcef_0784_b2ba_ee476260390d --> c554676d_b731_47b2_a98f_c1c2d537c0aa
  2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"]
  b0b3cb2f_fcef_0784_b2ba_ee476260390d --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c
  2971f9da_6393_a3e3_610e_ace3d35ee978["langchain_core.runnables.config"]
  b0b3cb2f_fcef_0784_b2ba_ee476260390d --> 2971f9da_6393_a3e3_610e_ace3d35ee978
  style b0b3cb2f_fcef_0784_b2ba_ee476260390d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""**Retriever** class returns `Document` objects given a text **query**.

It is more general than a vector store. A retriever does not need to be able to
store documents, only to return (or retrieve) it. Vector stores can be used as
the backbone of a retriever, but there are other types of retrievers as well.
"""

from __future__ import annotations

from abc import ABC, abstractmethod
from inspect import signature
from typing import TYPE_CHECKING, Any

from pydantic import ConfigDict
from typing_extensions import Self, TypedDict, override

from langchain_core.callbacks.manager import AsyncCallbackManager, CallbackManager
from langchain_core.documents import Document
from langchain_core.runnables import (
    Runnable,
    RunnableConfig,
    RunnableSerializable,
    ensure_config,
)
from langchain_core.runnables.config import run_in_executor

if TYPE_CHECKING:
    from langchain_core.callbacks.manager import (
        AsyncCallbackManagerForRetrieverRun,
        CallbackManagerForRetrieverRun,
    )

RetrieverInput = str
RetrieverOutput = list[Document]
RetrieverLike = Runnable[RetrieverInput, RetrieverOutput]
RetrieverOutputLike = Runnable[Any, RetrieverOutput]


class LangSmithRetrieverParams(TypedDict, total=False):
    """LangSmith parameters for tracing."""

    ls_retriever_name: str
    """Retriever name."""

    ls_vector_store_provider: str | None
    """Vector store provider."""

    ls_embedding_provider: str | None
    """Embedding provider."""

    ls_embedding_model: str | None
    """Embedding model."""


class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
    """Abstract base class for a document retrieval system.

    A retrieval system is defined as something that can take string queries and return
    the most 'relevant' documents from some source.

// ... (269 more lines)

Subdomains

Functions

Dependencies

  • abc
  • inspect
  • langchain_core.callbacks.manager
  • langchain_core.documents
  • langchain_core.runnables
  • langchain_core.runnables.config
  • pydantic
  • typing
  • typing_extensions

Frequently Asked Questions

What does retrievers.py do?
retrievers.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 retrievers.py?
retrievers.py defines 1 function(s): langchain_core.
What does retrievers.py depend on?
retrievers.py imports 9 module(s): abc, inspect, langchain_core.callbacks.manager, langchain_core.documents, langchain_core.runnables, langchain_core.runnables.config, pydantic, typing, and 1 more.
Where is retrievers.py in the architecture?
retrievers.py is located at libs/core/langchain_core/retrievers.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/langchain_core).

Analyze Your Own Codebase

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

Try Supermodel Free