Mistral Embedder

The MistralEmbedder class is used to embed text data into vectors using the Mistral API. Get your key from here.

Usage

1from kern.knowledge.knowledge import Knowledge
2from kern.vectordb.pgvector import PgVector
3from kern.knowledge.embedder.mistral import MistralEmbedder
4
5# Embed sentence in database
6embeddings = MistralEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.")
7
8# Print the embeddings and their dimensions
9print(f"Embeddings: {embeddings[:5]}")
10print(f"Dimensions: {len(embeddings)}")
11
12# Use an embedder in a knowledge base
13knowledge = Knowledge(
14 vector_db=PgVector(
15 db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
16 table_name="mistral_embeddings",
17 embedder=MistralEmbedder(),
18 ),
19 max_results=2,
20)

Params

ParameterTypeDefaultDescription
modelstr"mistral-embed"The name of the model used for generating embeddings.
dimensionsint1024The dimensionality of the embeddings generated by the model.
request_paramsOptional[Dict[str, Any]]-Additional parameters to include in the API request. Optional.
api_keystr-The API key used for authenticating requests.
endpointstr-The endpoint URL for the API requests.
max_retriesOptional[int]-The maximum number of retries for API requests. Optional.
timeoutOptional[int]-The timeout duration for API requests. Optional.
client_paramsOptional[Dict[str, Any]]-Additional parameters for configuring the API client. Optional.
mistral_clientOptional[MistralClient]-An instance of the MistralClient to use for making API requests. Optional.
enable_batchboolFalseEnable batch processing to reduce API calls and avoid rate limits
batch_sizeint100Number of texts to process in each API call for batch operations.

Developer Resources