base.py — langchain Source File
Architecture documentation for base.py, a python file in the langchain codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 5edec524_25e6_28b9_8133_408bbec653d2["base.py"] f46e1812_79f8_1bd0_7815_2ba4471dc470["functools"] 5edec524_25e6_28b9_8133_408bbec653d2 --> f46e1812_79f8_1bd0_7815_2ba4471dc470 3b5ab66f_4fcb_ca7c_bc35_2244b5f521fc["importlib"] 5edec524_25e6_28b9_8133_408bbec653d2 --> 3b5ab66f_4fcb_ca7c_bc35_2244b5f521fc 2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"] 5edec524_25e6_28b9_8133_408bbec653d2 --> 2bf6d401_816d_d011_3b05_a6114f55ff58 feec1ec4_6917_867b_d228_b134d0ff8099["typing"] 5edec524_25e6_28b9_8133_408bbec653d2 --> feec1ec4_6917_867b_d228_b134d0ff8099 918b8514_ba55_6df2_7254_4598ec160e33["langchain_core.embeddings"] 5edec524_25e6_28b9_8133_408bbec653d2 --> 918b8514_ba55_6df2_7254_4598ec160e33 style 5edec524_25e6_28b9_8133_408bbec653d2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Factory functions for embeddings."""
import functools
import importlib
from collections.abc import Callable
from typing import Any
from langchain_core.embeddings import Embeddings
def _call(cls: type[Embeddings], **kwargs: Any) -> Embeddings:
return cls(**kwargs)
_BUILTIN_PROVIDERS: dict[str, tuple[str, str, Callable[..., Embeddings]]] = {
"azure_openai": ("langchain_openai", "AzureOpenAIEmbeddings", _call),
"bedrock": (
"langchain_aws",
"BedrockEmbeddings",
lambda cls, model, **kwargs: cls(model_id=model, **kwargs),
),
"cohere": ("langchain_cohere", "CohereEmbeddings", _call),
"google_genai": ("langchain_google_genai", "GoogleGenerativeAIEmbeddings", _call),
"google_vertexai": ("langchain_google_vertexai", "VertexAIEmbeddings", _call),
"huggingface": (
"langchain_huggingface",
"HuggingFaceEmbeddings",
lambda cls, model, **kwargs: cls(model_name=model, **kwargs),
),
"mistralai": ("langchain_mistralai", "MistralAIEmbeddings", _call),
"ollama": ("langchain_ollama", "OllamaEmbeddings", _call),
"openai": ("langchain_openai", "OpenAIEmbeddings", _call),
}
"""Registry mapping provider names to their import configuration.
Each entry maps a provider key to a tuple of:
- `module_path`: The Python module path containing the embeddings class.
- `class_name`: The name of the embeddings class to import.
- `creator_func`: A callable that instantiates the class with provided kwargs.
!!! note
This dict is not exhaustive of all providers supported by LangChain, but is
meant to cover the most popular ones and serve as a template for adding more
providers in the future. If a provider is not in this dict, it can still be
used with `init_chat_model` as long as its integration package is installed,
but the provider key will not be inferred from the model name and must be
specified explicitly via the `model_provider` parameter.
Refer to the LangChain [integration documentation](https://docs.langchain.com/oss/python/integrations/providers/overview)
for a full list of supported providers and their corresponding packages.
"""
@functools.lru_cache(maxsize=len(_BUILTIN_PROVIDERS))
def _get_embeddings_class_creator(provider: str) -> Callable[..., Embeddings]:
"""Return a factory function that creates an embeddings model for the given provider.
This function is cached to avoid repeated module imports.
// ... (214 more lines)
Domain
Subdomains
Functions
Dependencies
- collections.abc
- functools
- importlib
- langchain_core.embeddings
- typing
Source
Frequently Asked Questions
What does base.py do?
base.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, LanguageModelBase subdomain.
What functions are defined in base.py?
base.py defines 6 function(s): _call, _get_embeddings_class_creator, _get_provider_list, _infer_model_and_provider, _parse_model_string, init_embeddings.
What does base.py depend on?
base.py imports 5 module(s): collections.abc, functools, importlib, langchain_core.embeddings, typing.
Where is base.py in the architecture?
base.py is located at libs/langchain_v1/langchain/embeddings/base.py (domain: LangChainCore, subdomain: LanguageModelBase, directory: libs/langchain_v1/langchain/embeddings).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free