MistralDocumentEmbedder
Embed documents using Mistral embedding models.
Key Features
- Embeds documents using Mistral AI embedding models.
- Stores the embedding in each document's
embeddingfield, 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
MistralTextEmbedderin 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
- Drag the
MistralDocumentEmbeddercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Create a secret with your Mistral API key. Use
MISTRAL_API_KEYas the secret key. For instructions, see Create Secrets. Get your API key from Mistral AI. - Select the embedding model.
- Create a secret with your Mistral API key. Use
- Go to the Advanced tab to configure
batch_size,prefix,suffix,meta_fields_to_embed,embedding_separator,timeout,max_retries, andhttp_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
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | A list of documents to embed. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | A list of documents with embeddings stored in the embedding field of each document. |
meta | Dict[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:
| Parameter | Type | Default | Description |
|---|---|---|---|
| api_key | Secret | Secret.from_env_var('MISTRAL_API_KEY') | The Mistral API key. |
| model | str | mistral-embed | The name of the model to use. |
| api_base_url | Optional[str] | https://api.mistral.ai/v1 | The Mistral API Base url. For more details, see Mistral docs. |
| prefix | str | A string to add to the beginning of each text. | |
| suffix | str | A string to add to the end of each text. | |
| batch_size | int | 32 | Number of Documents to encode at once. |
| progress_bar | bool | True | Whether to show a progress bar or not. Can be helpful to disable in production deployments to keep the logs clean. |
| meta_fields_to_embed | Optional[List[str]] | None | List of meta fields that should be embedded along with the Document text. |
| embedding_separator | str | \n | Separator used to concatenate the meta fields to the Document text. |
| timeout | Optional[float] | None | Timeout for Mistral client calls. If not set, it defaults to either the OPENAI_TIMEOUT environment variable, or 30 seconds. |
| max_retries | Optional[int] | None | Maximum 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_kwargs | Optional[Dict[str, Any]] | None | A 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
| documents | List[Document] | A list of documents to embed. |
Was this page helpful?