Skip to main content

MistralDocumentEmbedder

Embed documents using Mistral embedding models.

Basic Information

  • Type: haystack_integrations.components.embedders.mistral.document_embedder.MistralDocumentEmbedder
  • Components it can connect with:
    • DocumentWriter: Sends embedded documents to DocumentWriter to write into a document store.
    • Preprocessors: Receives documents from a preprocessor, such as DocumentSplitter, for embedding.

Inputs

ParameterTypeDefaultDescription
documentsList[Document]A list of documents to embed.

Outputs

ParameterTypeDefaultDescription
documentsList[Document]A list of documents with embeddings stored in the embedding field of each document.
metaDict[str, Any]Information about the usage of the model, including model name and token usage.

Overview

MistralDocumentEmbedder embeds documents using Mistral AI embedding models. The embedding of each document is stored in the embedding field of the document.

Use this component in indexes to embed documents before storing them in a document store. Make sure to use the same embedding model as the one used to embed queries in your query pipeline.

Embedding Models in Query Pipelines and Indexes

The embedding model you use to embed documents in your indexing pipeline must be the same as the embedding model you use to embed the query in your query pipeline.

This means the embedders for your indexing and query pipelines must match. For example, if you use CohereDocumentEmbedder to embed your documents, you should use CohereTextEmbedder with the same model to embed your queries.

Authorization

Create a secret with your Mistral API key. Type MISTRAL_API_KEY as the secret key. For detailed instructions on creating secrets, see Create Secrets.

Get your API key from Mistral AI.

Usage Example

This example shows an indexing pipeline that embeds documents using Mistral before storing them in a document store.

components:
DocumentSplitter:
type: haystack.components.preprocessors.document_splitter.DocumentSplitter
init_parameters:
split_by: word
split_length: 250
split_overlap: 30
respect_sentence_boundary: true
language: en
MistralDocumentEmbedder:
type: haystack_integrations.components.embedders.mistral.document_embedder.MistralDocumentEmbedder
init_parameters:
api_key:
type: env_var
env_vars:
- MISTRAL_API_KEY
strict: false
model: mistral-embed
batch_size: 32
DocumentWriter:
type: haystack.components.writers.document_writer.DocumentWriter
init_parameters:
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: 'mistral-embeddings'
max_chunk_bytes: 104857600
embedding_dim: 1024
return_embedding: false
method:
mappings:
settings:
create_index: true
http_auth:
use_ssl:
verify_certs:
timeout:
policy: OVERWRITE

MultiFileConverter:
type: haystack.components.converters.multi_file_converter.MultiFileConverter
init_parameters:
encoding: utf-8
json_content_key: content

connections:
- sender: DocumentSplitter.documents
receiver: MistralDocumentEmbedder.documents
- sender: MistralDocumentEmbedder.documents
receiver: DocumentWriter.documents

- sender: MultiFileConverter.documents
receiver: DocumentSplitter.documents

max_runs_per_component: 100

metadata: {}

inputs:
files:
- MultiFileConverter.sources


Parameters

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
api_keySecretSecret.from_env_var('MISTRAL_API_KEY')The Mistral API key.
modelstrmistral-embedThe name of the model to use.
api_base_urlOptional[str]https://api.mistral.ai/v1The Mistral API Base url. For more details, see Mistral docs.
prefixstrA string to add to the beginning of each text.
suffixstrA string to add to the end of each text.
batch_sizeint32Number of Documents to encode at once.
progress_barboolTrueWhether to show a progress bar or not. Can be helpful to disable in production deployments to keep the logs clean.
meta_fields_to_embedOptional[List[str]]NoneList of meta fields that should be embedded along with the Document text.
embedding_separatorstr\nSeparator used to concatenate the meta fields to the Document text.
timeoutOptional[float]NoneTimeout for Mistral client calls. If not set, it defaults to either the OPENAI_TIMEOUT environment variable, or 30 seconds.
max_retriesOptional[int]NoneMaximum number of retries to contact Mistral after an internal error. If not set, it defaults to either the OPENAI_MAX_RETRIES environment variable, or set to 5.
http_client_kwargsOptional[Dict[str, Any]]NoneA dictionary of keyword arguments to configure a custom httpx.Clientor httpx.AsyncClient. For more information, see the HTTPX documentation.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
documentsList[Document]A list of documents to embed.