# MistralAIEmbeddings

> **Class** in `langchain_mistralai`

📖 [View in docs](https://reference.langchain.com/python/langchain-mistralai/embeddings/MistralAIEmbeddings)

MistralAI embedding model integration.

## Signature

```python
MistralAIEmbeddings()
```

## Description

**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

- `BaseModel`
- `Embeddings`

## Properties

- `client`
- `async_client`
- `mistral_api_key`
- `endpoint`
- `max_retries`
- `timeout`
- `wait_time`
- `max_concurrent_requests`
- `tokenizer`
- `model`
- `model_config`

## Methods

- [`validate_environment()`](https://reference.langchain.com/python/langchain-mistralai/embeddings/MistralAIEmbeddings/validate_environment)
- [`embed_documents()`](https://reference.langchain.com/python/langchain-mistralai/embeddings/MistralAIEmbeddings/embed_documents)
- [`aembed_documents()`](https://reference.langchain.com/python/langchain-mistralai/embeddings/MistralAIEmbeddings/aembed_documents)
- [`embed_query()`](https://reference.langchain.com/python/langchain-mistralai/embeddings/MistralAIEmbeddings/embed_query)
- [`aembed_query()`](https://reference.langchain.com/python/langchain-mistralai/embeddings/MistralAIEmbeddings/aembed_query)

---

[View source on GitHub](https://github.com/langchain-ai/langchain/blob/6fb37dba71da807af60aa7b909f71f0625a666bf/libs/partners/mistralai/langchain_mistralai/embeddings.py#L59)