class_docstr: Chain that wraps a retriever for use with MLflow.
  
  The MLflow ``langchain`` flavor provides the functionality to log a retriever object and
  evaluate it individually. This is useful if you want to evaluate the quality of the
  relevant documents returned by a retriever object without directing these documents
  through a large language model (LLM) to yield a summarized response.
  
  In order to log the retriever object in the ``langchain`` flavor, the retriever object
  needs to be wrapped within a ``_RetrieverChain``.
  
  See :ref:`log-retriever-chain` for how to log the ``_RetrieverChain``.
  
  :param retriever: The retriever to wrap.
class_docstr_tok: ["Chain","that","wraps","a","retriever","for","use","with","MLflow",".","The","MLflow","``","langchain","``","flavor","provides","the","functionality","to","log","a","retriever","object","and","evaluate","it","individually",".","This","is","useful","if","you","want","to","evaluate","the","quality","of","the","relevant","documents","returned","by","a","retriever","object","without","directing","these","documents","through","a","large","language","model","(","LLM",")","to","yield","a","summarized","response",".","In","order","to","log","the","retriever","object","in","the","``","langchain","``","flavor",",","the","retriever","object","needs","to","be","wrapped","within","a","``","_RetrieverChain","``",".","See",":","ref",":","`","log-retriever-chain","`","for","how","to","log","the","``","_RetrieverChain","``",".",":","param","retriever",":","The","retriever","to","wrap","."]
docstr: Load a _RetrieverChain from a file.
docstr_tok: ["Load","a","_RetrieverChain","from","a","file","."]
code: def load(
      cls, file: Union[str, Path], **kwargs: Any
  ) -> _RetrieverChain:
      """Load a _RetrieverChain from a file."""
      # Convert file to Path object.
      file_path = Path(file) if isinstance(file, str) else file
      # Load from either json or yaml.
      if file_path.suffix == ".json":
          with open(file_path) as f:
              config = json.load(f)
      elif file_path.suffix in (".yaml", ".yml"):
          with open(file_path) as f:
              # This is to ignore certain tags that are not supported
              # with pydantic >= 2.0
              yaml.add_multi_constructor(
                  "tag:yaml.org,2002:python/object",
                  lambda loader, suffix, node: None,
                  Loader=yaml.SafeLoader,
              )
              config = yaml.load(f, yaml.SafeLoader)
      else:
          raise ValueError("File type must be json or yaml")
  
      # Override default 'verbose' and 'memory' for the chain
      if verbose := kwargs.pop("verbose", None):
          config["verbose"] = verbose
      if memory := kwargs.pop("memory", None):
          config["memory"] = memory
  
      if "_type" not in config:
          raise ValueError("Must specify a chain Type in config")
      config_type = config.pop("_type")
  
      if config_type != "retriever_chain":
          raise ValueError(f"Loading {config_type} chain not supported")
  
      retriever = kwargs.pop("retriever", None)
      if retriever is None:
          raise ValueError("`retriever` must be present.")
  
      config.pop("retriever", None)
  
      return cls(
          retriever=retriever,
          **config,
      )
  
file_path: mlflow/mlflow/langchain/retriever_chain.py
imports: from __future__ import annotations
  import json
  from pathlib import Path
  from typing import Any, Dict, List, Optional, Union
  import yaml
  from langchain.callbacks.manager import AsyncCallbackManagerForChainRun, CallbackManagerForChainRun
  from langchain.chains.base import Chain
  from langchain.schema import BaseRetriever, Document
  from pydantic import Extra, Field
  from mlflow.utils.annotations import experimental
label_desc: Use image node_id 6 for calling the _RetrieverChain obj's underlying member method code with example usage: obj.load(cls, file) and returns: cls