Skip to content

Commit c33bedc

Browse files
aminamostaprosoft
andauthored
feat: add options for Mistral AI (#707) #none
* add Mistral AI emb AI embedding vendor, types * add mistral env setting to example * add mistral LLM option * chore: fix default embedding back to normal * fix: comfort CI --------- Co-authored-by: Tadashi <[email protected]>
1 parent 9b05693 commit c33bedc

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT=text-embedding-ada-002
1616
# settings for Cohere
1717
COHERE_API_KEY=<COHERE_API_KEY>
1818

19+
# settings for Mistral
20+
# MISTRAL_API_KEY=placeholder
21+
1922
# settings for local models
2023
LOCAL_MODEL=qwen2.5:7b
2124
LOCAL_MODEL_EMBEDDINGS=nomic-embed-text

flowsettings.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@
243243
},
244244
"default": False,
245245
}
246+
KH_LLMS["mistral"] = {
247+
"spec": {
248+
"__type__": "kotaemon.llms.ChatOpenAI",
249+
"base_url": "https://api.mistral.ai/v1",
250+
"model": "ministral-8b-latest",
251+
"api_key": config("MISTRAL_API_KEY", default="your-key"),
252+
},
253+
"default": False,
254+
}
246255

247256
# additional embeddings configurations
248257
KH_EMBEDDINGS["cohere"] = {
@@ -262,6 +271,14 @@
262271
},
263272
"default": not IS_OPENAI_DEFAULT,
264273
}
274+
KH_EMBEDDINGS["mistral"] = {
275+
"spec": {
276+
"__type__": "kotaemon.embeddings.LCMistralEmbeddings",
277+
"model": "mistral-embed",
278+
"api_key": config("MISTRAL_API_KEY", default="your-key"),
279+
},
280+
"default": False,
281+
}
265282
# KH_EMBEDDINGS["huggingface"] = {
266283
# "spec": {
267284
# "__type__": "kotaemon.embeddings.LCHuggingFaceEmbeddings",

libs/kotaemon/kotaemon/embeddings/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
LCCohereEmbeddings,
77
LCGoogleEmbeddings,
88
LCHuggingFaceEmbeddings,
9+
LCMistralEmbeddings,
910
LCOpenAIEmbeddings,
1011
)
1112
from .openai import AzureOpenAIEmbeddings, OpenAIEmbeddings
@@ -20,6 +21,7 @@
2021
"LCCohereEmbeddings",
2122
"LCHuggingFaceEmbeddings",
2223
"LCGoogleEmbeddings",
24+
"LCMistralEmbeddings",
2325
"OpenAIEmbeddings",
2426
"AzureOpenAIEmbeddings",
2527
"FastEmbedEmbeddings",

libs/kotaemon/kotaemon/embeddings/langchain_based.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,40 @@ def _get_lc_class(self):
254254
raise ImportError("Please install langchain-google-genai")
255255

256256
return GoogleGenerativeAIEmbeddings
257+
258+
259+
class LCMistralEmbeddings(LCEmbeddingMixin, BaseEmbeddings):
260+
"""Wrapper around LangChain's MistralAI embedding, focusing on key parameters"""
261+
262+
api_key: str = Param(
263+
help="API key (https://console.mistral.ai/api-keys)",
264+
default=None,
265+
required=True,
266+
)
267+
model: str = Param(
268+
help="Model name to use ('mistral-embed')",
269+
default="mistral-embed",
270+
required=True,
271+
)
272+
273+
def __init__(
274+
self,
275+
model: str = "mistral-embed",
276+
api_key: Optional[str] = None,
277+
**params,
278+
):
279+
super().__init__(
280+
model=model,
281+
api_key=api_key,
282+
**params,
283+
)
284+
285+
def _get_lc_class(self):
286+
try:
287+
from langchain_mistralai import MistralAIEmbeddings
288+
except ImportError:
289+
raise ImportError(
290+
"Please install langchain_mistralai: "
291+
"`pip install -U langchain_mistralai`"
292+
)
293+
return MistralAIEmbeddings

libs/kotaemon/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dependencies = [
3636
"langchain-google-genai>=1.0.3,<2.0.0",
3737
"langchain-anthropic",
3838
"langchain-ollama",
39+
"langchain-mistralai",
3940
"langchain-cohere>=0.2.4,<0.3.0",
4041
"llama-hub>=0.0.79,<0.1.0",
4142
"llama-index>=0.10.40,<0.11.0",

libs/ktem/ktem/embeddings/manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def load_vendors(self):
5959
LCCohereEmbeddings,
6060
LCGoogleEmbeddings,
6161
LCHuggingFaceEmbeddings,
62+
LCMistralEmbeddings,
6263
OpenAIEmbeddings,
6364
TeiEndpointEmbeddings,
6465
)
@@ -70,6 +71,7 @@ def load_vendors(self):
7071
LCCohereEmbeddings,
7172
LCHuggingFaceEmbeddings,
7273
LCGoogleEmbeddings,
74+
LCMistralEmbeddings,
7375
TeiEndpointEmbeddings,
7476
]
7577

0 commit comments

Comments
 (0)