Home / File/ embeddings.py — langchain Source File

embeddings.py — langchain Source File

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

Entity Profile

Dependency Diagram

graph LR
  58d61588_fecc_6705_a73e_295de683aa58["embeddings.py"]
  a327e534_84f6_5308_58ca_5727d5eda0cf["asyncio"]
  58d61588_fecc_6705_a73e_295de683aa58 --> a327e534_84f6_5308_58ca_5727d5eda0cf
  2a7f66a7_8738_3d47_375b_70fcaa6ac169["logging"]
  58d61588_fecc_6705_a73e_295de683aa58 --> 2a7f66a7_8738_3d47_375b_70fcaa6ac169
  0c635125_6987_b8b3_7ff7_d60249aecde7["warnings"]
  58d61588_fecc_6705_a73e_295de683aa58 --> 0c635125_6987_b8b3_7ff7_d60249aecde7
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  58d61588_fecc_6705_a73e_295de683aa58 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  1803c8c1_a347_1256_1454_9f04c3553d93["httpx"]
  58d61588_fecc_6705_a73e_295de683aa58 --> 1803c8c1_a347_1256_1454_9f04c3553d93
  bc46b61d_cfdf_3f6b_a9dd_ac2a328d84b3["langchain_core.embeddings"]
  58d61588_fecc_6705_a73e_295de683aa58 --> bc46b61d_cfdf_3f6b_a9dd_ac2a328d84b3
  f4d905c6_a2b2_eb8f_be9b_7808b72f6a16["langchain_core.utils"]
  58d61588_fecc_6705_a73e_295de683aa58 --> f4d905c6_a2b2_eb8f_be9b_7808b72f6a16
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  58d61588_fecc_6705_a73e_295de683aa58 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  30db3e5b_4549_fdf8_eed3_1cfd8cacbe56["tenacity"]
  58d61588_fecc_6705_a73e_295de683aa58 --> 30db3e5b_4549_fdf8_eed3_1cfd8cacbe56
  a6275907_1b74_782e_c22f_ec5376e7bc64["tokenizers"]
  58d61588_fecc_6705_a73e_295de683aa58 --> a6275907_1b74_782e_c22f_ec5376e7bc64
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  58d61588_fecc_6705_a73e_295de683aa58 --> 91721f45_4909_e489_8c1f_084f8bd87145
  style 58d61588_fecc_6705_a73e_295de683aa58 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import asyncio
import logging
import warnings
from collections.abc import Callable, Iterable

import httpx
from httpx import Response
from langchain_core.embeddings import Embeddings
from langchain_core.utils import (
    secret_from_env,
)
from pydantic import (
    BaseModel,
    ConfigDict,
    Field,
    SecretStr,
    model_validator,
)
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_fixed
from tokenizers import Tokenizer  # type: ignore[import]
from typing_extensions import Self

logger = logging.getLogger(__name__)

MAX_TOKENS = 16_000
"""A batching parameter for the Mistral API. This is NOT the maximum number of tokens
accepted by the embedding model for each document/chunk, but rather the maximum number
of tokens that can be sent in a single request to the Mistral API (across multiple
documents/chunks)"""


class DummyTokenizer:
    """Dummy tokenizer for when tokenizer cannot be accessed (e.g., via Huggingface)."""

    @staticmethod
    def encode_batch(texts: list[str]) -> list[list[str]]:
        return [list(text) for text in texts]


class MistralAIEmbeddings(BaseModel, Embeddings):
    """MistralAI embedding model integration.

    Setup:
        Install `langchain_mistralai` and set environment variable
        `MISTRAL_API_KEY`.

        ```bash
        pip install -U langchain_mistralai
        export MISTRAL_API_KEY="your-api-key"
        ```

    Key init args — completion params:
        model:
            Name of `MistralAI` model to use.

    Key init args — client params:
        api_key:
            The API key for the MistralAI API. If not provided, it will be read from the
            environment variable `MISTRAL_API_KEY`.
        max_concurrent_requests: int
// ... (270 more lines)

Subdomains

Dependencies

  • asyncio
  • collections.abc
  • httpx
  • langchain_core.embeddings
  • langchain_core.utils
  • logging
  • pydantic
  • tenacity
  • tokenizers
  • typing_extensions
  • warnings

Frequently Asked Questions

What does embeddings.py do?
embeddings.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What does embeddings.py depend on?
embeddings.py imports 11 module(s): asyncio, collections.abc, httpx, langchain_core.embeddings, langchain_core.utils, logging, pydantic, tenacity, and 3 more.
Where is embeddings.py in the architecture?
embeddings.py is located at libs/partners/mistralai/langchain_mistralai/embeddings.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/partners/mistralai/langchain_mistralai).

Analyze Your Own Codebase

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

Try Supermodel Free