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

SentenceTransformersDocumentImageEmbedder

Compute document embeddings from image files using Sentence Transformers multimodal models. Use this component in indexing pipelines when document content references image or PDF files stored in metadata.

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 images referenced by a metadata field such as file_path.
  • Supports image files and PDF pages through the configured metadata field.
  • Works with multimodal models that embed images and text into the same vector space.
  • Stores embeddings in each document's embedding field.
  • Supports multiple embedding precisions and backends (PyTorch, ONNX, OpenVINO).

Configuration

  1. Drag the SentenceTransformersDocumentImageEmbedder component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    1. Set the model to a multimodal Sentence Transformers model (for example, sentence-transformers/clip-ViT-B-32).
    2. Set file_path_meta_field to the metadata key that contains the image or PDF file path.
  4. Go to the Advanced tab to configure root_path, batch_size, normalize_embeddings, precision, and backend.
note

Compatible models include CLIP variants and Jina CLIP models. The model must support image embedding.

Connections

SentenceTransformersDocumentImageEmbedder receives a list of documents whose metadata contains file paths to images or PDFs. It outputs the same documents with embeddings added to their embedding field, ready to be sent to a DocumentWriter.

Source Code

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

Usage Examples

Basic Configuration

  SentenceTransformersDocumentImageEmbedder:
type: haystack_integrations.components.embedders.sentence_transformers.SentenceTransformersDocumentImageEmbedder
init_parameters:
model: sentence-transformers/clip-ViT-B-32
file_path_meta_field: file_path
normalize_embeddings: true

Using the Component in a Pipeline

# haystack-pipeline
components:
SentenceTransformersDocumentImageEmbedder:
type: haystack_integrations.components.embedders.sentence_transformers.SentenceTransformersDocumentImageEmbedder
init_parameters:
model: sentence-transformers/clip-ViT-B-32
file_path_meta_field: file_path
token:
type: env_var
env_vars:
- HF_API_TOKEN
- HF_TOKEN
strict: false

document_writer:
type: haystack.components.writers.document_writer.DocumentWriter
init_parameters:
document_store:
type: haystack.document_stores.in_memory.document_store.InMemoryDocumentStore
init_parameters: {}

connections:
- sender: SentenceTransformersDocumentImageEmbedder.documents
receiver: document_writer.documents

max_runs_per_component: 100

metadata: {}

Parameters

Inputs

ParameterTypeDescription
documentsList[Document]Documents whose metadata contains paths to image or PDF files.

Outputs

ParameterTypeDescription
documentsList[Document]Documents with embedding populated and an embedding_source entry added to metadata.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
file_path_meta_fieldstrfile_pathThe metadata field that contains the file path to the image or PDF.
root_pathOptional[str]NoneRoot directory for resolving relative file paths in document metadata.
modelstrsentence-transformers/clip-ViT-B-32The Sentence Transformers model to use. Must support image embedding.
deviceOptional[ComponentDevice]NoneThe device to load the model on.
tokenOptional[Secret]Secret.from_env_var(["HF_API_TOKEN", "HF_TOKEN"], strict=False)The API token to download private models from Hugging Face.
batch_sizeint32Number of documents to embed at once.
progress_barboolTrueWhether to show a progress bar while embedding.
normalize_embeddingsboolFalseWhether to normalize embedding vectors to unit length.
trust_remote_codeboolFalseWhether to allow custom models and scripts from Hugging Face.
local_files_onlyboolFalseWhether to use only local files without downloading from Hugging Face.
model_kwargsOptional[Dict[str, Any]]NoneAdditional keyword arguments for the model constructor.
tokenizer_kwargsOptional[Dict[str, Any]]NoneAdditional keyword arguments for the tokenizer.
config_kwargsOptional[Dict[str, Any]]NoneAdditional keyword arguments for the model configuration.
precisionLiteral["float32", "int8", "uint8", "binary", "ubinary"]float32The precision of the output embeddings.
encode_kwargsOptional[Dict[str, Any]]NoneAdditional keyword arguments for SentenceTransformer.encode.
backendLiteral["torch", "onnx", "openvino"]torchThe backend to use for the Sentence Transformers model.

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]Documents to embed from image or PDF file paths in metadata.