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 toDocumentWriterto write into a document store.- Preprocessors: Receives documents from a preprocessor, such as
DocumentSplitter, for embedding.
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| documents | List[Document] | A list of documents to embed. |
Outputs
| Parameter | Type | Default | 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. |
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:
| 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?