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

MistralDocumentEmbedder

Embeds documents using Mistral AI embedding models and stores results in each document's embedding field.

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.

Key Features

  • Embeds documents using Mistral AI embedding models.
  • Stores computed embeddings in each document's embedding field for semantic search.
  • Configurable batch size for efficient processing of large document collections.
  • Optionally embeds metadata fields alongside document text.
  • Works in indexing pipelines alongside DocumentSplitter and DocumentWriter.

Configuration

Authentication

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.

  1. Drag the MistralDocumentEmbedder component onto the canvas from the Component Library.
  2. Click the component to open the configuration panel.
  3. On the General tab:
    1. Enter the name of the Mistral embedding model to use, such as mistral-embed.
  4. Go to the Advanced tab to configure the API key, API base URL, prefix and suffix text, batch size, metadata fields to embed, and embedding separator.

Connections

MistralDocumentEmbedder receives a list of documents as input and outputs those documents with embeddings stored in their embedding field, along with a meta dictionary with model name and usage statistics.

Connect DocumentSplitter or another preprocessor to its documents input. Connect its documents output to DocumentWriter to store the embedded documents.

Use the same embedding model in MistralTextEmbedder in your query pipeline to ensure consistent results.

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

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.

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.