@@ -54,21 +54,23 @@ class MistralAIEmbeddings(BaseModel, Embeddings):
54
54
Name of MistralAI model to use.
55
55
56
56
Key init args — client params:
57
- api_key: Optional[SecretStr]
58
- The API key for the MistralAI API. If not provided, it will be read from the
59
- environment variable `MISTRAL_API_KEY`.
60
- max_retries: int
61
- The number of times to retry a request if it fails.
62
- timeout: int
63
- The number of seconds to wait for a response before timing out.
64
- wait_time: int
65
- The number of seconds to wait before retrying a request in case of 429 error.
66
- max_concurrent_requests: int
67
- The maximum number of concurrent requests to make to the Mistral API.
57
+ api_key: Optional[SecretStr]
58
+ The API key for the MistralAI API. If not provided, it will be read from the
59
+ environment variable ``MISTRAL_API_KEY``.
60
+ max_retries: int
61
+ The number of times to retry a request if it fails.
62
+ timeout: int
63
+ The number of seconds to wait for a response before timing out.
64
+ wait_time: int
65
+ The number of seconds to wait before retrying a request in case of 429
66
+ error.
67
+ max_concurrent_requests: int
68
+ The maximum number of concurrent requests to make to the Mistral API.
68
69
69
70
See full list of supported init args and their descriptions in the params section.
70
71
71
72
Instantiate:
73
+
72
74
.. code-block:: python
73
75
74
76
from __module_name__ import MistralAIEmbeddings
@@ -80,6 +82,7 @@ class MistralAIEmbeddings(BaseModel, Embeddings):
80
82
)
81
83
82
84
Embed single text:
85
+
83
86
.. code-block:: python
84
87
85
88
input_text = "The meaning of life is 42"
@@ -91,9 +94,10 @@ class MistralAIEmbeddings(BaseModel, Embeddings):
91
94
[-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
92
95
93
96
Embed multiple text:
97
+
94
98
.. code-block:: python
95
99
96
- input_texts = ["Document 1...", "Document 2..."]
100
+ input_texts = ["Document 1...", "Document 2..."]
97
101
vectors = embed.embed_documents(input_texts)
98
102
print(len(vectors))
99
103
# The first 3 coordinates for the first vector
@@ -105,10 +109,11 @@ class MistralAIEmbeddings(BaseModel, Embeddings):
105
109
[-0.024603435769677162, -0.007543657906353474, 0.0039630369283258915]
106
110
107
111
Async:
112
+
108
113
.. code-block:: python
109
114
110
115
vector = await embed.aembed_query(input_text)
111
- print(vector[:3])
116
+ print(vector[:3])
112
117
113
118
# multiple:
114
119
# await embed.aembed_documents(input_texts)
@@ -188,8 +193,8 @@ def validate_environment(self) -> Self:
188
193
return self
189
194
190
195
def _get_batches (self , texts : list [str ]) -> Iterable [list [str ]]:
191
- """Split a list of texts into batches of less than 16k tokens
192
- for Mistral API."""
196
+ """Split a list of texts into batches of less than 16k tokens for Mistral
197
+ API."""
193
198
batch : list [str ] = []
194
199
batch_tokens = 0
195
200
0 commit comments