Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

MistralDocumentEmbedder

Embed documents using Mistral embedding models.

Key Features

  • Embeds documents using Mistral AI embedding models.
  • Stores the embedding in each document's embedding field, ready for semantic search.
  • Use in indexing pipelines to embed documents before storing them in a document store.
  • Use the same embedding model as in MistralTextEmbedder in your query pipeline.
  • Configurable batch size and timeout for production use.

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.

Configuration

  1. Drag the MistralDocumentEmbedder component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    1. Create a secret with your Mistral API key. Use MISTRAL_API_KEY as the secret key. For instructions, see Create Secrets. Get your API key from Mistral AI.
    2. Select the embedding model.
  4. Go to the Advanced tab to configure batch_size, prefix, suffix, meta_fields_to_embed, embedding_separator, timeout, max_retries, and http_client_kwargs.

Connections

MistralDocumentEmbedder receives a list of documents through its documents input. It outputs the same documents with embeddings added through its documents output, plus usage metadata through its meta output.

Connect a preprocessor (such as DocumentSplitter) output to MistralDocumentEmbedder's documents input. Then connect its documents output to DocumentWriter.

Source Code

To check this component's source code, open document_embedder.py in the Haystack Core Integrations repository.

Usage Examples

Basic Configuration

  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

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

Inputs

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

Outputs

ParameterTypeDescription
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.

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.