validate_environment() — langchain Function Reference
Architecture documentation for the validate_environment() function in cohere_rerank.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6011faf4_4634_1dee_7212_ffb2dbbc0a19["validate_environment()"] dddf6c97_e67e_69d4_e813_fd10af808b8f["CohereRerank"] 6011faf4_4634_1dee_7212_ffb2dbbc0a19 -->|defined in| dddf6c97_e67e_69d4_e813_fd10af808b8f style 6011faf4_4634_1dee_7212_ffb2dbbc0a19 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/retrievers/document_compressors/cohere_rerank.py lines 42–60
def validate_environment(cls, values: dict) -> Any:
"""Validate that api key and python package exists in environment."""
if not values.get("client"):
try:
import cohere
except ImportError as e:
msg = (
"Could not import cohere python package. "
"Please install it with `pip install cohere`."
)
raise ImportError(msg) from e
cohere_api_key = get_from_dict_or_env(
values,
"cohere_api_key",
"COHERE_API_KEY",
)
client_name = values.get("user_agent", "langchain")
values["client"] = cohere.Client(cohere_api_key, client_name=client_name)
return values
Domain
Subdomains
Source
Frequently Asked Questions
What does validate_environment() do?
validate_environment() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/retrievers/document_compressors/cohere_rerank.py.
Where is validate_environment() defined?
validate_environment() is defined in libs/langchain/langchain_classic/retrievers/document_compressors/cohere_rerank.py at line 42.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free