Skip to content

The agent engineering platform.

style: even more refs work (#33619)

Mason Daughertyd9e659ca4f02
diff --git a/libs/core/langchain_core/callbacks/base.py b/libs/core/langchain_core/callbacks/base.py
index f887736057..af455bd970 100644
--- a/libs/core/langchain_core/callbacks/base.py
+++ b/libs/core/langchain_core/callbacks/base.py
@@ -420,8 +420,6 @@ class RunManagerMixin:
(includes inherited tags).
metadata: The metadata associated with the custom event
(includes inherited metadata).
-
- !!! version-added "Added in version 0.2.15"
"""
@@ -882,8 +880,6 @@ class AsyncCallbackHandler(BaseCallbackHandler):
(includes inherited tags).
metadata: The metadata associated with the custom event
(includes inherited metadata).
-
- !!! version-added "Added in version 0.2.15"
"""
diff --git a/libs/core/langchain_core/callbacks/manager.py b/libs/core/langchain_core/callbacks/manager.py
index 79ca9a2a0a..bcea96d8ea 100644
--- a/libs/core/langchain_core/callbacks/manager.py
+++ b/libs/core/langchain_core/callbacks/manager.py
@@ -1566,9 +1566,6 @@ class CallbackManager(BaseCallbackManager):
Raises:
ValueError: If additional keyword arguments are passed.
-
- !!! version-added "Added in version 0.2.14"
-
"""
if not self.handlers:
return
@@ -2042,8 +2039,6 @@ class AsyncCallbackManager(BaseCallbackManager):
Raises:
ValueError: If additional keyword arguments are passed.
-
- !!! version-added "Added in version 0.2.14"
"""
if not self.handlers:
return
@@ -2555,9 +2550,6 @@ async def adispatch_custom_event(
This is due to a limitation in asyncio for python <= 3.10 that prevents
LangChain from automatically propagating the config object on the user's
behalf.
-
- !!! version-added "Added in version 0.2.15"
-
"""
# Import locally to prevent circular imports.
from langchain_core.runnables.config import ( # noqa: PLC0415
@@ -2630,9 +2622,6 @@ def dispatch_custom_event(
foo_ = RunnableLambda(foo)
foo_.invoke({"a": "1"}, {"callbacks": [CustomCallbackManager()]})
```
-
- !!! version-added "Added in version 0.2.15"
-
"""
# Import locally to prevent circular imports.
from langchain_core.runnables.config import ( # noqa: PLC0415
diff --git a/libs/core/langchain_core/document_loaders/langsmith.py b/libs/core/langchain_core/document_loaders/langsmith.py
index 724e743ca4..a826281a92 100644
--- a/libs/core/langchain_core/document_loaders/langsmith.py
+++ b/libs/core/langchain_core/document_loaders/langsmith.py
@@ -34,9 +34,6 @@ class LangSmithLoader(BaseLoader):
```python
# -> [Document("...", metadata={"inputs": {...}, "outputs": {...}, ...}), ...]
```
-
- !!! version-added "Added in version 0.2.34"
-
"""
def __init__(
diff --git a/libs/core/langchain_core/documents/base.py b/libs/core/langchain_core/documents/base.py
index 4776ec44d8..56870f2447 100644
--- a/libs/core/langchain_core/documents/base.py
+++ b/libs/core/langchain_core/documents/base.py
@@ -38,8 +38,6 @@ class BaseMedia(Serializable):
Ideally this should be unique across the document collection and formatted
as a UUID, but this will not be enforced.
-
- !!! version-added "Added in version 0.2.11"
"""
metadata: dict = Field(default_factory=dict)
diff --git a/libs/core/langchain_core/indexing/base.py b/libs/core/langchain_core/indexing/base.py
index 810858d7a8..a4a4310134 100644
--- a/libs/core/langchain_core/indexing/base.py
+++ b/libs/core/langchain_core/indexing/base.py
@@ -508,8 +508,6 @@ class DocumentIndex(BaseRetriever):
1. Storing document in the index.
2. Fetching document by ID.
3. Searching for document using a query.
-
- !!! version-added "Added in version 0.2.29"
"""
@abc.abstractmethod
diff --git a/libs/core/langchain_core/indexing/in_memory.py b/libs/core/langchain_core/indexing/in_memory.py
index 1ef40f9947..5fd6292a09 100644
--- a/libs/core/langchain_core/indexing/in_memory.py
+++ b/libs/core/langchain_core/indexing/in_memory.py
@@ -23,8 +23,6 @@ class InMemoryDocumentIndex(DocumentIndex):
It provides a simple search API that returns documents by the number of
counts the given query appears in the document.
-
- !!! version-added "Added in version 0.2.29"
"""
store: dict[str, Document] = Field(default_factory=dict)
diff --git a/libs/core/langchain_core/runnables/base.py b/libs/core/langchain_core/runnables/base.py
index a99845232c..af2438524e 100644
--- a/libs/core/langchain_core/runnables/base.py
+++ b/libs/core/langchain_core/runnables/base.py
@@ -2519,9 +2519,6 @@ class Runnable(ABC, Generic[Input, Output]):
as_tool = runnable.as_tool()
as_tool.invoke("b")
```
-
- !!! version-added "Added in version 0.2.14"
-
"""
# Avoid circular import
from langchain_core.tools import convert_runnable_to_tool # noqa: PLC0415
diff --git a/libs/core/langchain_core/runnables/schema.py b/libs/core/langchain_core/runnables/schema.py
index 4545650af8..05221c7f34 100644
--- a/libs/core/langchain_core/runnables/schema.py
+++ b/libs/core/langchain_core/runnables/schema.py
@@ -168,10 +168,7 @@ class StandardStreamEvent(BaseStreamEvent):
class CustomStreamEvent(BaseStreamEvent):
- """Custom stream event created by the user.
-
- !!! version-added "Added in version 0.2.15"
- """
+ """Custom stream event created by the user."""
# Overwrite the event field to be more specific.
event: Literal["on_custom_event"] # type: ignore[misc]
diff --git a/libs/core/langchain_core/stores.py b/libs/core/langchain_core/stores.py
index 8bd52c7622..77408d6096 100644
--- a/libs/core/langchain_core/stores.py
+++ b/libs/core/langchain_core/stores.py
@@ -86,7 +86,7 @@ class BaseStore(ABC, Generic[K, V]):
Returns:
A sequence of optional values associated with the keys.
- If a key is not found, the corresponding value will be None.
+ If a key is not found, the corresponding value will be `None`.
"""
async def amget(self, keys: Sequence[K]) -> list[V | None]:
@@ -97,7 +97,7 @@ class BaseStore(ABC, Generic[K, V]):
Returns:
A sequence of optional values associated with the keys.
- If a key is not found, the corresponding value will be None.
+ If a key is not found, the corresponding value will be `None`.
"""
return await run_in_executor(None, self.mget, keys)
@@ -243,8 +243,7 @@ class InMemoryStore(InMemoryBaseStore[Any]):
"""In-memory store for any type of data.
Attributes:
- store (dict[str, Any]): The underlying dictionary that stores
- the key-value pairs.
+ store: The underlying dictionary that stores the key-value pairs.
Examples:
```python
@@ -267,8 +266,7 @@ class InMemoryByteStore(InMemoryBaseStore[bytes]):
"""In-memory store for bytes.
Attributes:
- store (dict[str, bytes]): The underlying dictionary that stores
- the key-value pairs.
+ store: The underlying dictionary that stores the key-value pairs.
Examples:
```python
diff --git a/libs/core/langchain_core/tools/convert.py b/libs/core/langchain_core/tools/convert.py
index 97b3068d9e..cf16aef45a 100644
--- a/libs/core/langchain_core/tools/convert.py
+++ b/libs/core/langchain_core/tools/convert.py
@@ -151,8 +151,6 @@ def tool(
return "partial json of results", {"full": "object of results"}
```
- !!! version-added "Added in version 0.2.14"
-
Parse Google-style docstrings:
```python
diff --git a/libs/core/langchain_core/vectorstores/base.py b/libs/core/langchain_core/vectorstores/base.py
index a64f61cd6a..d4b90d1d14 100644
--- a/libs/core/langchain_core/vectorstores/base.py
+++ b/libs/core/langchain_core/vectorstores/base.py
@@ -139,8 +139,6 @@ class VectorStore(ABC):
Returns:
List of Documents.
-
- !!! version-added "Added in version 0.2.11"
"""
msg = f"{self.__class__.__name__} does not yet support get_by_ids."
raise NotImplementedError(msg)
@@ -167,8 +165,6 @@ class VectorStore(ABC):
Returns:
List of Documents.
-
- !!! version-added "Added in version 0.2.11"
"""
return await run_in_executor(None, self.get_by_ids, ids)
diff --git a/libs/langchain/langchain_classic/chat_models/base.py b/libs/langchain/langchain_classic/chat_models/base.py
index 04cbaa4e77..fcddcea93d 100644
--- a/libs/langchain/langchain_classic/chat_models/base.py
+++ b/libs/langchain/langchain_classic/chat_models/base.py
@@ -287,8 +287,6 @@ def init_chat_model(
)
```
- !!! version-added "Added in version 0.2.7"
-
!!! warning "Behavior changed in 0.2.8"
Support for `configurable_fields` and `config_prefix` added.
diff --git a/libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py b/libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py
index 01b9c6afd3..9a53c477d0 100644
--- a/libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py
+++ b/libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py
@@ -343,7 +343,7 @@ Performance may be significantly worse with other models.",
**kwargs: Additional keyword arguments.
Returns:
- A dictionary containing:
+ `dict` containing:
- reasoning: The reasoning for the preference.
- value: The preference value, which is either 'A', 'B', or None
for no preference.
@@ -389,7 +389,7 @@ Performance may be significantly worse with other models.",
**kwargs: Additional keyword arguments.
Returns:
- A dictionary containing:
+ `dict` containing:
- reasoning: The reasoning for the preference.
- value: The preference value, which is either 'A', 'B', or None
for no preference.
diff --git a/libs/langchain/langchain_classic/evaluation/embedding_distance/base.py b/libs/langchain/langchain_classic/evaluation/embedding_distance/base.py
index 46b13eb7ed..e2af7665ea 100644
--- a/libs/langchain/langchain_classic/evaluation/embedding_distance/base.py
+++ b/libs/langchain/langchain_classic/evaluation/embedding_distance/base.py
@@ -454,7 +454,7 @@ class EmbeddingDistanceEvalChain(_EmbeddingDistanceChainMixin, StringEvaluator):
**kwargs: Additional keyword arguments.
Returns:
- A dictionary containing:
+ `dict` containing:
- score: The embedding distance between the two predictions.
"""
result = self(
@@ -490,7 +490,7 @@ class EmbeddingDistanceEvalChain(_EmbeddingDistanceChainMixin, StringEvaluator):
**kwargs: Additional keyword arguments.
Returns:
- A dictionary containing:
+ `dict` containing:
- score: The embedding distance between the two predictions.
"""
result = await self.acall(
@@ -608,7 +608,7 @@ class PairwiseEmbeddingDistanceEvalChain(
**kwargs: Additional keyword arguments.
Returns:
- A dictionary containing:
+ `dict` containing:
- score: The embedding distance between the two predictions.
"""
result = self(
@@ -644,8 +644,8 @@ class PairwiseEmbeddingDistanceEvalChain(
**kwargs: Additional keyword arguments.
Returns:
- A dictionary containing:
- - score: The embedding distance between the two predictions.
+ `dict` containing:
+ - score: The embedding distance between the two predictions.
"""
result = await self.acall(
inputs={"prediction": prediction, "prediction_b": prediction_b},
diff --git a/libs/langchain/langchain_classic/evaluation/parsing/base.py b/libs/langchain/langchain_classic/evaluation/parsing/base.py
index ab23325383..bed2e6e378 100644
--- a/libs/langchain/langchain_classic/evaluation/parsing/base.py
+++ b/libs/langchain/langchain_classic/evaluation/parsing/base.py
@@ -71,11 +71,11 @@ class JsonValidityEvaluator(StringEvaluator):
**kwargs: Additional keyword arguments (not used).
Returns:
- A dictionary containing the evaluation score. The score is `1` if
- the prediction is valid JSON, and `0` otherwise.
+ `dict` containing the evaluation score. The score is `1` if
+ the prediction is valid JSON, and `0` otherwise.
- If the prediction is not valid JSON, the dictionary also contains
- a `reasoning` field with the error message.
+ If the prediction is not valid JSON, the dictionary also contains
+ a `reasoning` field with the error message.
"""
try:
@@ -169,7 +169,7 @@ class JsonEqualityEvaluator(StringEvaluator):
**kwargs: Additional keyword arguments (not used).
Returns:
- A dictionary containing the evaluation score.
+ `dict` containing the evaluation score.
"""
parsed = self._parse_json(prediction)
label = self._parse_json(cast("str", reference))
diff --git a/libs/langchain/langchain_classic/evaluation/schema.py b/libs/langchain/langchain_classic/evaluation/schema.py
index 3bb4d2e12d..d8e598846d 100644
--- a/libs/langchain/langchain_classic/evaluation/schema.py
+++ b/libs/langchain/langchain_classic/evaluation/schema.py
@@ -285,7 +285,7 @@ class PairwiseStringEvaluator(_EvalArgsMixin, ABC):
**kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
Returns:
- A dictionary containing the preference, scores, and/or other information.
+ `dict` containing the preference, scores, and/or other information.
""" # noqa: E501
async def _aevaluate_string_pairs(
@@ -307,7 +307,7 @@ class PairwiseStringEvaluator(_EvalArgsMixin, ABC):
**kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
Returns:
- A dictionary containing the preference, scores, and/or other information.
+ `dict` containing the preference, scores, and/or other information.
""" # noqa: E501
return await run_in_executor(
None,
@@ -338,7 +338,7 @@ class PairwiseStringEvaluator(_EvalArgsMixin, ABC):
**kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
Returns:
- A dictionary containing the preference, scores, and/or other information.
+ `dict` containing the preference, scores, and/or other information.
""" # noqa: E501
self._check_evaluation_args(reference=reference, input_=input)
return self._evaluate_string_pairs(
@@ -368,7 +368,7 @@ class PairwiseStringEvaluator(_EvalArgsMixin, ABC):
**kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
Returns:
- A dictionary containing the preference, scores, and/or other information.
+ `dict` containing the preference, scores, and/or other information.
""" # noqa: E501
self._check_evaluation_args(reference=reference, input_=input)
return await self._aevaluate_string_pairs(
diff --git a/libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py b/libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py
index fefa204193..b46d83ae48 100644
--- a/libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py
+++ b/libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py
@@ -354,7 +354,7 @@ Performance may be significantly worse with other models.",
**kwargs: Additional keyword arguments.
Returns:
- A dictionary containing:
+ `dict` containing:
- reasoning: The reasoning for the preference.
- score: A score between 1 and 10.
@@ -395,7 +395,7 @@ Performance may be significantly worse with other models.",
**kwargs: Additional keyword arguments.
Returns:
- A dictionary containing:
+ `dict` containing:
- reasoning: The reasoning for the preference.
- score: A score between 1 and 10.
diff --git a/libs/langchain/langchain_classic/hub.py b/libs/langchain/langchain_classic/hub.py
index 7abc310ab4..f23887a454 100644
--- a/libs/langchain/langchain_classic/hub.py
+++ b/libs/langchain/langchain_classic/hub.py
@@ -15,6 +15,21 @@ def _get_client(
api_key: str | None = None,
api_url: str | None = None,
) -> Any:
+ """Get a client for interacting with the LangChain Hub.
+
+ Attempts to use LangSmith client if available, otherwise falls back to
+ the legacy `langchainhub` client.
+
+ Args:
+ api_key: API key to authenticate with the LangChain Hub API.
+ api_url: URL of the LangChain Hub API.
+
+ Returns:
+ Client instance for interacting with the hub.
+
+ Raises:
+ ImportError: If neither `langsmith` nor `langchainhub` can be imported.
+ """
try:
from langsmith import Client as LangSmithClient
@@ -51,18 +66,22 @@ def push(
) -> str:
"""Push an object to the hub and returns the URL it can be viewed at in a browser.
- :param repo_full_name: The full name of the prompt to push to in the format of
- `owner/prompt_name` or `prompt_name`.
- :param object: The LangChain to serialize and push to the hub.
- :param api_url: The URL of the LangChain Hub API. Defaults to the hosted API service
- if you have an api key set, or a localhost instance if not.
- :param api_key: The API key to use to authenticate with the LangChain Hub API.
- :param parent_commit_hash: The commit hash of the parent commit to push to. Defaults
- to the latest commit automatically.
- :param new_repo_is_public: Whether the prompt should be public. Defaults to
- False (Private by default).
- :param new_repo_description: The description of the prompt. Defaults to an empty
- string.
+ Args:
+ repo_full_name: The full name of the prompt to push to in the format of
+ `owner/prompt_name` or `prompt_name`.
+ object: The LangChain object to serialize and push to the hub.
+ api_url: The URL of the LangChain Hub API. Defaults to the hosted API service
+ if you have an API key set, or a localhost instance if not.
+ api_key: The API key to use to authenticate with the LangChain Hub API.
+ parent_commit_hash: The commit hash of the parent commit to push to. Defaults
+ to the latest commit automatically.
+ new_repo_is_public: Whether the prompt should be public.
+ new_repo_description: The description of the prompt.
+ readme: README content for the repository.
+ tags: Tags to associate with the prompt.
+
+ Returns:
+ URL where the pushed object can be viewed in a browser.
"""
client = _get_client(api_key=api_key, api_url=api_url)
@@ -98,12 +117,17 @@ def pull(
) -> Any:
"""Pull an object from the hub and returns it as a LangChain object.
- :param owner_repo_commit: The full name of the prompt to pull from in the format of
- `owner/prompt_name:commit_hash` or `owner/prompt_name`
- or just `prompt_name` if it's your own prompt.
- :param api_url: The URL of the LangChain Hub API. Defaults to the hosted API service
- if you have an api key set, or a localhost instance if not.
- :param api_key: The API key to use to authenticate with the LangChain Hub API.
+ Args:
+ owner_repo_commit: The full name of the prompt to pull from in the format of
+ `owner/prompt_name:commit_hash` or `owner/prompt_name`
+ or just `prompt_name` if it's your own prompt.
+ include_model: Whether to include the model configuration in the pulled prompt.
+ api_url: The URL of the LangChain Hub API. Defaults to the hosted API service
+ if you have an API key set, or a localhost instance if not.
+ api_key: The API key to use to authenticate with the LangChain Hub API.
+
+ Returns:
+ The pulled LangChain object.
"""
client = _get_client(api_key=api_key, api_url=api_url)
diff --git a/libs/langchain/langchain_classic/indexes/vectorstore.py b/libs/langchain/langchain_classic/indexes/vectorstore.py
index 0680241739..040e895529 100644
--- a/libs/langchain/langchain_classic/indexes/vectorstore.py
+++ b/libs/langchain/langchain_classic/indexes/vectorstore.py
@@ -117,7 +117,7 @@ class VectorStoreIndexWrapper(BaseModel):
**kwargs: Additional keyword arguments forwarded to the chain.
Returns:
- A dictionary containing the answer and source documents.
+ `dict` containing the answer and source documents.
"""
if llm is None:
msg = (
@@ -152,7 +152,7 @@ class VectorStoreIndexWrapper(BaseModel):
**kwargs: Additional keyword arguments forwarded to the chain.
Returns:
- A dictionary containing the answer and source documents.
+ `dict` containing the answer and source documents.
"""
if llm is None:
msg = (
diff --git a/libs/langchain/langchain_classic/runnables/hub.py b/libs/langchain/langchain_classic/runnables/hub.py
index 9d0bdbf56c..4c6a358fce 100644
--- a/libs/langchain/langchain_classic/runnables/hub.py
+++ b/libs/langchain/langchain_classic/runnables/hub.py
@@ -17,7 +17,7 @@ class HubRunnable(RunnableBindingBase[Input, Output]): # type: ignore[no-redef]
api_key: str | None = None,
**kwargs: Any,
) -> None:
- """Initialize the HubRunnable.
+ """Initialize the `HubRunnable`.
Args:
owner_repo_commit: The full name of the prompt to pull from in the format of
diff --git a/libs/langchain/langchain_classic/runnables/openai_functions.py b/libs/langchain/langchain_classic/runnables/openai_functions.py
index 38434559a9..29f2194c85 100644
--- a/libs/langchain/langchain_classic/runnables/openai_functions.py
+++ b/libs/langchain/langchain_classic/runnables/openai_functions.py
@@ -10,7 +10,7 @@ from typing_extensions import TypedDict
class OpenAIFunction(TypedDict):
- """A function description for ChatOpenAI."""
+ """A function description for `ChatOpenAI`."""
name: str
"""The name of the function."""
@@ -33,7 +33,7 @@ class OpenAIFunctionsRouter(RunnableBindingBase[BaseMessage, Any]): # type: ign
],
functions: list[OpenAIFunction] | None = None,
):
- """Initialize the OpenAIFunctionsRouter.
+ """Initialize the `OpenAIFunctionsRouter`.
Args:
runnables: A mapping of function names to runnables.
diff --git a/libs/langchain/langchain_classic/smith/__init__.py b/libs/langchain/langchain_classic/smith/__init__.py
index 24a75f48da..a744151182 100644
--- a/libs/langchain/langchain_classic/smith/__init__.py
+++ b/libs/langchain/langchain_classic/smith/__init__.py
@@ -1,9 +1,7 @@
"""**LangSmith** utilities.
This module provides utilities for connecting to
-[LangSmith](https://smith.langchain.com/).
-For more information on LangSmith,
-see the [LangSmith documentation](https://docs.smith.langchain.com/).
+[LangSmith](https://docs.langchain.com/langsmith/home).
**Evaluation**
diff --git a/libs/langchain/langchain_classic/smith/evaluation/config.py b/libs/langchain/langchain_classic/smith/evaluation/config.py
index 6f3063ce6f..6d1df6232b 100644
--- a/libs/langchain/langchain_classic/smith/evaluation/config.py
+++ b/libs/langchain/langchain_classic/smith/evaluation/config.py
@@ -34,28 +34,17 @@ BATCH_EVALUATOR_LIKE = Callable[
class EvalConfig(BaseModel):
"""Configuration for a given run evaluator.
- Parameters
- ----------
- evaluator_type : EvaluatorType
- The type of evaluator to use.
-
- Methods:
- -------
- get_kwargs()
- Get the keyword arguments for the evaluator configuration.
-
+ Attributes:
+ evaluator_type: The type of evaluator to use.
"""
evaluator_type: EvaluatorType
def get_kwargs(self) -> dict[str, Any]:
- """Get the keyword arguments for the load_evaluator call.
+ """Get the keyword arguments for the `load_evaluator` call.
Returns:
- -------
- Dict[str, Any]
- The keyword arguments for the load_evaluator call.
-
+ The keyword arguments for the `load_evaluator` call.
"""
kwargs = {}
for field, val in self:
@@ -110,7 +99,7 @@ class RunEvalConfig(BaseModel):
batch_evaluators: list[BATCH_EVALUATOR_LIKE] | None = None
"""Evaluators that run on an aggregate/batch level.
- These generate 1 or more metrics that are assigned to the full test run.
+ These generate one or more metrics that are assigned to the full test run.
As a result, they are not associated with individual traces.
"""
@@ -134,13 +123,9 @@ class RunEvalConfig(BaseModel):
class Criteria(SingleKeyEvalConfig):
"""Configuration for a reference-free criteria evaluator.
- Parameters
- ----------
- criteria : CRITERIA_TYPE | None
- The criteria to evaluate.
- llm : BaseLanguageModel | None
- The language model to use for the evaluation chain.
-
+ Attributes:
+ criteria: The criteria to evaluate.
+ llm: The language model to use for the evaluation chain.
"""
criteria: CRITERIA_TYPE | None = None
@@ -150,12 +135,9 @@ class RunEvalConfig(BaseModel):
class LabeledCriteria(SingleKeyEvalConfig):
"""Configuration for a labeled (with references) criteria evaluator.
- Parameters
- ----------
- criteria : CRITERIA_TYPE | None
- The criteria to evaluate.
- llm : BaseLanguageModel | None
- The language model to use for the evaluation chain.
+ Attributes:
+ criteria: The criteria to evaluate.
+ llm: The language model to use for the evaluation chain.
"""
criteria: CRITERIA_TYPE | None = None
@@ -165,14 +147,9 @@ class RunEvalConfig(BaseModel):
class EmbeddingDistance(SingleKeyEvalConfig):
"""Configuration for an embedding distance evaluator.
- Parameters
- ----------
- embeddings : Optional[Embeddings]
- The embeddings to use for computing the distance.
-
- distance_metric : Optional[EmbeddingDistanceEnum]
- The distance metric to use for computing the distance.
-
+ Attributes:
+ embeddings: The embeddings to use for computing the distance.
+ distance_metric: The distance metric to use for computing the distance.
"""
evaluator_type: EvaluatorType = EvaluatorType.EMBEDDING_DISTANCE
@@ -186,34 +163,23 @@ class RunEvalConfig(BaseModel):
class StringDistance(SingleKeyEvalConfig):
"""Configuration for a string distance evaluator.
- Parameters
- ----------
- distance : Optional[StringDistanceEnum]
- The string distance metric to use.
-
+ Attributes:
+ distance: The string distance metric to use (`damerau_levenshtein`,
+ `levenshtein`, `jaro`, or `jaro_winkler`).
+ normalize_score: Whether to normalize the distance to between 0 and 1.
+ Applies only to the Levenshtein and Damerau-Levenshtein distances.
"""
evaluator_type: EvaluatorType = EvaluatorType.STRING_DISTANCE
distance: StringDistanceEnum | None = None
- """The string distance metric to use.
- damerau_levenshtein: The Damerau-Levenshtein distance.
- levenshtein: The Levenshtein distance.
- jaro: The Jaro distance.
- jaro_winkler: The Jaro-Winkler distance.
- """
normalize_score: bool = True
- """Whether to normalize the distance to between 0 and 1.
- Applies only to the Levenshtein and Damerau-Levenshtein distances."""
class QA(SingleKeyEvalConfig):
"""Configuration for a QA evaluator.
- Parameters
- ----------
- prompt : Optional[BasePromptTemplate]
- The prompt template to use for generating the question.
- llm : BaseLanguageModel | None
- The language model to use for the evaluation chain.
+ Attributes:
+ prompt: The prompt template to use for generating the question.
+ llm: The language model to use for the evaluation chain.
"""
evaluator_type: EvaluatorType = EvaluatorType.QA
@@ -223,13 +189,9 @@ class RunEvalConfig(BaseModel):
class ContextQA(SingleKeyEvalConfig):
"""Configuration for a context-based QA evaluator.
- Parameters
- ----------
- prompt : Optional[BasePromptTemplate]
- The prompt template to use for generating the question.
- llm : BaseLanguageModel | None
- The language model to use for the evaluation chain.
-
+ Attributes:
+ prompt: The prompt template to use for generating the question.
+ llm: The language model to use for the evaluation chain.
"""
evaluator_type: EvaluatorType = EvaluatorType.CONTEXT_QA
@@ -239,13 +201,9 @@ class RunEvalConfig(BaseModel):
class CoTQA(SingleKeyEvalConfig):
"""Configuration for a context-based QA evaluator.
- Parameters
- ----------
- prompt : Optional[BasePromptTemplate]
- The prompt template to use for generating the question.
- llm : BaseLanguageModel | None
- The language model to use for the evaluation chain.
-
+ Attributes:
+ prompt: The prompt template to use for generating the question.
+ llm: The language model to use for the evaluation chain.
"""
evaluator_type: EvaluatorType = EvaluatorType.CONTEXT_QA
@@ -253,34 +211,22 @@ class RunEvalConfig(BaseModel):
prompt: BasePromptTemplate | None = None
class JsonValidity(SingleKeyEvalConfig):
- """Configuration for a json validity evaluator.
-
- Parameters
- ----------
- """
+ """Configuration for a json validity evaluator."""
evaluator_type: EvaluatorType = EvaluatorType.JSON_VALIDITY
class JsonEqualityEvaluator(EvalConfig):
- """Configuration for a json equality evaluator.
-
- Parameters
- ----------
- """
+ """Configuration for a json equality evaluator."""
evaluator_type: EvaluatorType = EvaluatorType.JSON_EQUALITY
class ExactMatch(SingleKeyEvalConfig):
"""Configuration for an exact match string evaluator.
- Parameters
- ----------
- ignore_case : bool
- Whether to ignore case when comparing strings.
- ignore_punctuation : bool
- Whether to ignore punctuation when comparing strings.
- ignore_numbers : bool
- Whether to ignore numbers when comparing strings.
+ Attributes:
+ ignore_case: Whether to ignore case when comparing strings.
+ ignore_punctuation: Whether to ignore punctuation when comparing strings.
+ ignore_numbers: Whether to ignore numbers when comparing strings.
"""
evaluator_type: EvaluatorType = EvaluatorType.EXACT_MATCH
@@ -291,10 +237,8 @@ class RunEvalConfig(BaseModel):
class RegexMatch(SingleKeyEvalConfig):
"""Configuration for a regex match string evaluator.
- Parameters
- ----------
- flags : int
- The flags to pass to the regex. Example: re.IGNORECASE.
+ Attributes:
+ flags: The flags to pass to the regex. Example: `re.IGNORECASE`.
"""
evaluator_type: EvaluatorType = EvaluatorType.REGEX_MATCH
@@ -309,17 +253,12 @@ class RunEvalConfig(BaseModel):
It is recommended to normalize these scores
by setting `normalize_by` to 10.
- Parameters
- ----------
- criteria : CRITERIA_TYPE | None
- The criteria to evaluate.
- llm : BaseLanguageModel | None
- The language model to use for the evaluation chain.
- normalize_by: int | None = None
- If you want to normalize the score, the denominator to use.
- If not provided, the score will be between 1 and 10 (by default).
- prompt : Optional[BasePromptTemplate]
-
+ Attributes:
+ criteria: The criteria to evaluate.
+ llm: The language model to use for the evaluation chain.
+ normalize_by: If you want to normalize the score, the denominator to use.
+ If not provided, the score will be between 1 and 10.
+ prompt: The prompt template to use for evaluation.
"""
evaluator_type: EvaluatorType = EvaluatorType.SCORE_STRING
diff --git a/libs/langchain/langchain_classic/smith/evaluation/progress.py b/libs/langchain/langchain_classic/smith/evaluation/progress.py
index 42862e3d1a..d0d2e750aa 100644
--- a/libs/langchain/langchain_classic/smith/evaluation/progress.py
+++ b/libs/langchain/langchain_classic/smith/evaluation/progress.py
@@ -23,10 +23,10 @@ class ProgressBarCallback(base_callbacks.BaseCallbackHandler):
"""Initialize the progress bar.
Args:
- total: int, the total number of items to be processed.
- ncols: int, the character width of the progress bar.
- end_with: str, last string to print after progress bar reaches end.
- **kwargs: additional keyword arguments.
+ total: The total number of items to be processed.
+ ncols: The character width of the progress bar.
+ end_with: Last string to print after progress bar reaches end.
+ **kwargs: Additional keyword arguments.
"""
self.total = total
self.ncols = ncols
diff --git a/libs/langchain/langchain_classic/smith/evaluation/runner_utils.py b/libs/langchain/langchain_classic/smith/evaluation/runner_utils.py
index 7637ef266b..e8f25cb2be 100644
--- a/libs/langchain/langchain_classic/smith/evaluation/runner_utils.py
+++ b/libs/langchain/langchain_classic/smith/evaluation/runner_utils.py
@@ -153,7 +153,7 @@ class EvalError(dict):
"""Your architecture raised an error."""
def __init__(self, Error: BaseException, **kwargs: Any) -> None: # noqa: N803
- """Initialize the EvalError with an error and additional attributes.
+ """Initialize the `EvalError` with an error and additional attributes.
Args:
Error: The error that occurred.
@@ -162,7 +162,7 @@ class EvalError(dict):
super().__init__(Error=Error, **kwargs)
def __getattr__(self, name: str) -> Any:
- """Get an attribute from the EvalError.
+ """Get an attribute from the `EvalError`.
Args:
name: The name of the attribute to get.
@@ -1383,7 +1383,7 @@ async def arun_on_dataset(
**kwargs: Should not be used, but is provided for backwards compatibility.
Returns:
- A dictionary containing the run's project name and the resulting model outputs.
+ `dict` containing the run's project name and the resulting model outputs.
Examples:
```python
@@ -1423,9 +1423,8 @@ async def arun_on_dataset(
evaluation=evaluation_config,
)
```
- You can also create custom evaluators by subclassing the
- `StringEvaluator <langchain.evaluation.schema.StringEvaluator>`
- or LangSmith's `RunEvaluator` classes.
+ You can also create custom evaluators by subclassing the `StringEvaluator or
+ LangSmith's `RunEvaluator` classes.
```python
from typing import Optional
@@ -1558,7 +1557,7 @@ def run_on_dataset(
**kwargs: Should not be used, but is provided for backwards compatibility.
Returns:
- A dictionary containing the run's project name and the resulting model outputs.
+ `dict` containing the run's project name and the resulting model outputs.
Examples:
```python
@@ -1599,9 +1598,8 @@ def run_on_dataset(
)
```
- You can also create custom evaluators by subclassing the
- `StringEvaluator <langchain.evaluation.schema.StringEvaluator>`
- or LangSmith's `RunEvaluator` classes.
+ You can also create custom evaluators by subclassing the `StringEvaluator` or
+ LangSmith's `RunEvaluator` classes.
```python
from typing import Optional
diff --git a/libs/langchain/langchain_classic/storage/_lc_store.py b/libs/langchain/langchain_classic/storage/_lc_store.py
index f4f64939ea..00a50b15e4 100644
--- a/libs/langchain/langchain_classic/storage/_lc_store.py
+++ b/libs/langchain/langchain_classic/storage/_lc_store.py
@@ -11,12 +11,12 @@ from langchain_classic.storage.encoder_backed import EncoderBackedStore
def _dump_as_bytes(obj: Serializable) -> bytes:
- """Return a bytes representation of a document."""
+ """Return a bytes representation of a `Document`."""
return dumps(obj).encode("utf-8")
def _dump_document_as_bytes(obj: Any) -> bytes:
- """Return a bytes representation of a document."""
+ """Return a bytes representation of a `Document`."""
if not isinstance(obj, Document):
msg = "Expected a Document instance"
raise TypeError(msg)
@@ -50,14 +50,14 @@ def create_lc_store(
*,
key_encoder: Callable[[str], str] | None = None,
) -> BaseStore[str, Serializable]:
- """Create a store for langchain serializable objects from a bytes store.
+ """Create a store for LangChain serializable objects from a bytes store.
Args:
store: A bytes store to use as the underlying store.
- key_encoder: A function to encode keys; if None uses identity function.
+ key_encoder: A function to encode keys; if `None` uses identity function.
Returns:
- A key-value store for documents.
+ A key-value store for `Document` objects.
"""
return EncoderBackedStore(
store,
@@ -72,17 +72,17 @@ def create_kv_docstore(
*,
key_encoder: Callable[[str], str] | None = None,
) -> BaseStore[str, Document]:
- """Create a store for langchain Document objects from a bytes store.
+ """Create a store for langchain `Document` objects from a bytes store.
This store does run time type checking to ensure that the values are
- Document objects.
+ `Document` objects.
Args:
store: A bytes store to use as the underlying store.
- key_encoder: A function to encode keys; if None uses identity function.
+ key_encoder: A function to encode keys; if `None`, uses identity function.
Returns:
- A key-value store for documents.
+ A key-value store for `Document` objects.
"""
return EncoderBackedStore(
store,
diff --git a/libs/langchain/langchain_classic/storage/encoder_backed.py b/libs/langchain/langchain_classic/storage/encoder_backed.py
index c3a02acadf..0e5cefb7a8 100644
--- a/libs/langchain/langchain_classic/storage/encoder_backed.py
+++ b/libs/langchain/langchain_classic/storage/encoder_backed.py
@@ -56,14 +56,29 @@ class EncoderBackedStore(BaseStore[K, V]):
value_serializer: Callable[[V], bytes],
value_deserializer: Callable[[Any], V],
) -> None:
- """Initialize an EncodedStore."""
+ """Initialize an `EncodedStore`.
+
+ Args:
+ store: The underlying byte store to wrap.
+ key_encoder: Function to encode keys from type `K` to strings.
+ value_serializer: Function to serialize values from type `V` to bytes.
+ value_deserializer: Function to deserialize bytes back to type V.
+ """
self.store = store
self.key_encoder = key_encoder
self.value_serializer = value_serializer
self.value_deserializer = value_deserializer
def mget(self, keys: Sequence[K]) -> list[V | None]:
- """Get the values associated with the given keys."""
+ """Get the values associated with the given keys.
+
+ Args:
+ keys: A sequence of keys.
+
+ Returns:
+ A sequence of optional values associated with the keys.
+ If a key is not found, the corresponding value will be `None`.
+ """
encoded_keys: list[str] = [self.key_encoder(key) for key in keys]
values = self.store.mget(encoded_keys)
return [
@@ -72,7 +87,15 @@ class EncoderBackedStore(BaseStore[K, V]):
]
async def amget(self, keys: Sequence[K]) -> list[V | None]:
- """Get the values associated with the given keys."""
+ """Async get the values associated with the given keys.
+
+ Args:
+ keys: A sequence of keys.
+
+ Returns:
+ A sequence of optional values associated with the keys.
+ If a key is not found, the corresponding value will be `None`.
+ """
encoded_keys: list[str] = [self.key_encoder(key) for key in keys]
values = await self.store.amget(encoded_keys)
return [
@@ -81,7 +104,11 @@ class EncoderBackedStore(BaseStore[K, V]):
]
def mset(self, key_value_pairs: Sequence[tuple[K, V]]) -> None:
- """Set the values for the given keys."""
+ """Set the values for the given keys.
+
+ Args:
+ key_value_pairs: A sequence of key-value pairs.
+ """
encoded_pairs = [
(self.key_encoder(key), self.value_serializer(value))
for key, value in key_value_pairs
@@ -89,7 +116,11 @@ class EncoderBackedStore(BaseStore[K, V]):
self.store.mset(encoded_pairs)
async def amset(self, key_value_pairs: Sequence[tuple[K, V]]) -> None:
- """Set the values for the given keys."""
+ """Async set the values for the given keys.
+
+ Args:
+ key_value_pairs: A sequence of key-value pairs.
+ """
encoded_pairs = [
(self.key_encoder(key), self.value_serializer(value))
for key, value in key_value_pairs
@@ -97,12 +128,20 @@ class EncoderBackedStore(BaseStore[K, V]):
await self.store.amset(encoded_pairs)
def mdelete(self, keys: Sequence[K]) -> None:
- """Delete the given keys and their associated values."""
+ """Delete the given keys and their associated values.
+
+ Args:
+ keys: A sequence of keys to delete.
+ """
encoded_keys = [self.key_encoder(key) for key in keys]
self.store.mdelete(encoded_keys)
async def amdelete(self, keys: Sequence[K]) -> None:
- """Delete the given keys and their associated values."""
+ """Async delete the given keys and their associated values.
+
+ Args:
+ keys: A sequence of keys to delete.
+ """
encoded_keys = [self.key_encoder(key) for key in keys]
await self.store.amdelete(encoded_keys)
@@ -111,7 +150,14 @@ class EncoderBackedStore(BaseStore[K, V]):
*,
prefix: str | None = None,
) -> Iterator[K] | Iterator[str]:
- """Get an iterator over keys that match the given prefix."""
+ """Get an iterator over keys that match the given prefix.
+
+ Args:
+ prefix: The prefix to match.
+
+ Yields:
+ Keys that match the given prefix.
+ """
# For the time being this does not return K, but str
# it's for debugging purposes. Should fix this.
yield from self.store.yield_keys(prefix=prefix)
@@ -121,7 +167,14 @@ class EncoderBackedStore(BaseStore[K, V]):
*,
prefix: str | None = None,
) -> AsyncIterator[K] | AsyncIterator[str]:
- """Get an iterator over keys that match the given prefix."""
+ """Async get an iterator over keys that match the given prefix.
+
+ Args:
+ prefix: The prefix to match.
+
+ Yields:
+ Keys that match the given prefix.
+ """
# For the time being this does not return K, but str
# it's for debugging purposes. Should fix this.
async for key in self.store.ayield_keys(prefix=prefix):
diff --git a/libs/langchain/langchain_classic/storage/file_system.py b/libs/langchain/langchain_classic/storage/file_system.py
index 403312b8e3..67a0a76f5a 100644
--- a/libs/langchain/langchain_classic/storage/file_system.py
+++ b/libs/langchain/langchain_classic/storage/file_system.py
@@ -10,10 +10,10 @@ from langchain_classic.storage.exceptions import InvalidKeyException
class LocalFileStore(ByteStore):
- """BaseStore interface that works on the local file system.
+ """`BaseStore` interface that works on the local file system.
Examples:
- Create a LocalFileStore instance and perform operations on it:
+ Create a `LocalFileStore` instance and perform operations on it:
```python
from langchain_classic.storage import LocalFileStore
@@ -44,20 +44,18 @@ class LocalFileStore(ByteStore):
chmod_dir: int | None = None,
update_atime: bool = False,
) -> None:
- """Implement the BaseStore interface for the local file system.
+ """Implement the `BaseStore` interface for the local file system.
Args:
root_path: The root path of the file store. All keys are interpreted as
paths relative to this root.
- chmod_file: If specified, sets permissions for newly created files,
- overriding the current `umask` if needed.
- chmod_dir: If specified, sets permissions for newly created dirs,
- overriding the current `umask` if needed.
- update_atime: If `True`, updates the filesystem access time
- (but not the modified time) when a file is read.
-
- This allows MRU/LRU cache policies to be implemented for filesystems
- where access time updates are disabled.
+ chmod_file: Sets permissions for newly created files, overriding the
+ current `umask` if needed.
+ chmod_dir: Sets permissions for newly created dirs, overriding the
+ current `umask` if needed.
+ update_atime: Updates the filesystem access time (but not the modified
+ time) when a file is read. This allows MRU/LRU cache policies to be
+ implemented for filesystems where access time updates are disabled.
"""
self.root_path = Path(root_path).absolute()
self.chmod_file = chmod_file
@@ -95,10 +93,7 @@ class LocalFileStore(ByteStore):
whereas the explicit `os.chmod()` used here is not.
Args:
- dir_path: (Path) The store directory to make
-
- Returns:
- None
+ dir_path: The store directory to make.
"""
if not dir_path.exists():
self._mkdir_for_store(dir_path.parent)
@@ -114,7 +109,7 @@ class LocalFileStore(ByteStore):
Returns:
A sequence of optional values associated with the keys.
- If a key is not found, the corresponding value will be None.
+ If a key is not found, the corresponding value will be `None`.
"""
values: list[bytes | None] = []
for key in keys:
@@ -134,9 +129,6 @@ class LocalFileStore(ByteStore):
Args:
key_value_pairs: A sequence of key-value pairs.
-
- Returns:
- None
"""
for key, value in key_value_pairs:
full_path = self._get_full_path(key)
@@ -150,7 +142,6 @@ class LocalFileStore(ByteStore):
Args:
keys: A sequence of keys to delete.
-
"""
for key in keys:
full_path = self._get_full_path(key)