Home / Class/ MistralAIEmbeddings Class — langchain Architecture

MistralAIEmbeddings Class — langchain Architecture

Architecture documentation for the MistralAIEmbeddings class in embeddings.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  8ffbd15a_923a_c258_fc8b_25df9b4cba69["MistralAIEmbeddings"]
  b1e4f760_c634_d3bf_ca9a_db7ab899cc4a["Embeddings"]
  8ffbd15a_923a_c258_fc8b_25df9b4cba69 -->|extends| b1e4f760_c634_d3bf_ca9a_db7ab899cc4a
  7ec4ef8d_dfc4_e4b4_f7b6_daac27f34072["embeddings.py"]
  8ffbd15a_923a_c258_fc8b_25df9b4cba69 -->|defined in| 7ec4ef8d_dfc4_e4b4_f7b6_daac27f34072
  78589fff_3de9_bddd_b676_7f7cd0fbcb35["validate_environment()"]
  8ffbd15a_923a_c258_fc8b_25df9b4cba69 -->|method| 78589fff_3de9_bddd_b676_7f7cd0fbcb35
  1ebd0b7d_e260_a53f_7605_d0c94c73ee54["_get_batches()"]
  8ffbd15a_923a_c258_fc8b_25df9b4cba69 -->|method| 1ebd0b7d_e260_a53f_7605_d0c94c73ee54
  b63650a7_8bd1_901e_6719_77952ae677e4["_retry()"]
  8ffbd15a_923a_c258_fc8b_25df9b4cba69 -->|method| b63650a7_8bd1_901e_6719_77952ae677e4
  899cf409_68f4_e6ef_1223_d9393754b32d["embed_documents()"]
  8ffbd15a_923a_c258_fc8b_25df9b4cba69 -->|method| 899cf409_68f4_e6ef_1223_d9393754b32d
  0451d400_70ed_ded5_006c_e334458a80ae["aembed_documents()"]
  8ffbd15a_923a_c258_fc8b_25df9b4cba69 -->|method| 0451d400_70ed_ded5_006c_e334458a80ae
  0d87a6aa_6a08_89f5_f97a_08ce13e94bc8["embed_query()"]
  8ffbd15a_923a_c258_fc8b_25df9b4cba69 -->|method| 0d87a6aa_6a08_89f5_f97a_08ce13e94bc8
  b4b1a205_f414_00ed_dbb1_d40d4e5baef9["aembed_query()"]
  8ffbd15a_923a_c258_fc8b_25df9b4cba69 -->|method| b4b1a205_f414_00ed_dbb1_d40d4e5baef9

Relationship Graph

Source Code

libs/partners/mistralai/langchain_mistralai/embeddings.py lines 40–329

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
        max_retries:
            The number of times to retry a request if it fails.
        timeout:
            The number of seconds to wait for a response before timing out.
        wait_time:
            The number of seconds to wait before retrying a request in case of 429
            error.
        max_concurrent_requests:
            The maximum number of concurrent requests to make to the Mistral API.

    See full list of supported init args and their descriptions in the params section.

    Instantiate:

        ```python
        from __module_name__ import MistralAIEmbeddings

        embed = MistralAIEmbeddings(
            model="mistral-embed",
            # api_key="...",
            # other params...
        )
        ```

    Embed single text:

        ```python
        input_text = "The meaning of life is 42"
        vector = embed.embed_query(input_text)
        print(vector[:3])
        ```
        ```python
        [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
        ```

    Embed multiple text:

        ```python
        input_texts = ["Document 1...", "Document 2..."]
        vectors = embed.embed_documents(input_texts)
        print(len(vectors))
        # The first 3 coordinates for the first vector
        print(vectors[0][:3])
        ```
        ```python
        2
        [-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
        ```

    Async:

        ```python
        vector = await embed.aembed_query(input_text)
        print(vector[:3])

        # multiple:
        # await embed.aembed_documents(input_texts)
        ```
        ```python
        [-0.009100092574954033, 0.005071679595857859, -0.0029193938244134188]

Extends

Frequently Asked Questions

What is the MistralAIEmbeddings class?
MistralAIEmbeddings is a class in the langchain codebase, defined in libs/partners/mistralai/langchain_mistralai/embeddings.py.
Where is MistralAIEmbeddings defined?
MistralAIEmbeddings is defined in libs/partners/mistralai/langchain_mistralai/embeddings.py at line 40.
What does MistralAIEmbeddings extend?
MistralAIEmbeddings extends Embeddings.

Analyze Your Own Codebase

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

Try Supermodel Free