CohereDocumentImageEmbedder
Compute document embeddings based on images using Cohere's multimodal embedding API. Use this component in indexing pipelines to embed image documents before writing them to a document store.
Key Features
- Uses Cohere multimodal models (such as
embed-v4.0) to embed documents containing images or PDFs. - Stores the computed embedding in each document's
embeddingfield, enabling image-based semantic search and retrieval. - Reads image file paths from a configurable document metadata field (default:
file_path). - Supports JPEG and PNG images, as well as PDF pages converted to JPEG automatically.
- Configurable embedding type (
float,int8,uint8,binary,ubinary) and optional embedding dimension for v4 and newer models. - Supports both synchronous and asynchronous operation via
run()andrun_async().
Configuration
- Drag the
CohereDocumentImageEmbeddercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Select the embedding model. Make sure Haystack Platform is connected to your Cohere account. For details, see Use Cohere Models.
- Set the file_path_meta_field to the document metadata key that holds the image file path (default:
file_path).
- Go to the Advanced tab to configure
embedding_type,embedding_dimension,image_size,timeout, andprogress_bar.
Connections
CohereDocumentImageEmbedder receives a list of documents through its documents input. Each document must include an image file path in its metadata under the field specified by file_path_meta_field. It outputs the same documents with their embeddings added through its documents output.
Connect it after a converter that creates documents with image paths in their metadata. Connect its documents output to DocumentWriter to store embedded documents in a document store.
Source Code
To check this component's source code, open document_image_embedder.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
CohereDocumentImageEmbedder:
type: haystack_integrations.components.embedders.cohere.document_image_embedder.CohereDocumentImageEmbedder
init_parameters:
api_key:
type: env_var
env_vars:
- COHERE_API_KEY
- CO_API_KEY
strict: false
model: embed-v4.0
file_path_meta_field: file_path
api_base_url: https://api.cohere.com
timeout: 120.0
progress_bar: true
Using the Component in a Pipeline
This example shows an indexing pipeline that takes documents with image file paths in their metadata, embeds the images using Cohere's multimodal API, and writes them to a document store.
# haystack-pipeline
components:
CohereDocumentImageEmbedder:
type: haystack_integrations.components.embedders.cohere.document_image_embedder.CohereDocumentImageEmbedder
init_parameters:
api_key:
type: env_var
env_vars:
- COHERE_API_KEY
- CO_API_KEY
strict: false
model: embed-v4.0
file_path_meta_field: file_path
root_path:
image_size:
api_base_url: https://api.cohere.com
timeout: 120.0
embedding_dimension:
embedding_type: float
progress_bar: true
DocumentWriter:
type: haystack.components.writers.document_writer.DocumentWriter
init_parameters:
policy: OVERWRITE
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: Image-Index
max_chunk_bytes: 104857600
embedding_dim: 1536
return_embedding: false
method:
mappings:
settings:
create_index: true
http_auth:
use_ssl:
verify_certs:
timeout:
connections:
- sender: CohereDocumentImageEmbedder.documents
receiver: DocumentWriter.documents
max_runs_per_component: 100
metadata: {}
inputs:
documents:
- CohereDocumentImageEmbedder.documents
Parameters
Inputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | A list of Documents to embed. Each document must have an image file path in its metadata under the field specified by file_path_meta_field. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | Documents with their embedding field populated and an embedding_source entry added to their metadata. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | Secret | Secret.from_env_var(['COHERE_API_KEY', 'CO_API_KEY']) | The Cohere API key. |
model | str | embed-v4.0 | The Cohere multimodal embedding model to use. Supported models: embed-v4.0, embed-english-v3.0, embed-english-light-v3.0, embed-multilingual-v3.0, embed-multilingual-light-v3.0. See Cohere documentation for the full list. |
api_base_url | str | https://api.cohere.com | The Cohere API base URL. |
file_path_meta_field | str | file_path | The document metadata field that contains the file path to the image or PDF. |
root_path | Optional[str] | None | The root directory for resolving relative file paths. When None, file paths are treated as absolute. |
image_size | Optional[tuple[int, int]] | None | Target dimensions (width, height) to resize images while maintaining aspect ratio. Reduces file size, memory usage, and processing time. |
timeout | float | 120.0 | Request timeout in seconds. |
embedding_dimension | Optional[int] | None | The dimension of the embeddings to return. Only valid for v4 and newer models. |
embedding_type | EmbeddingTypes | float | The type of embeddings to return. Specifying a type other than float is only supported for Embed v3.0 and newer models. |
progress_bar | bool | True | Whether to show a progress bar. Disable in production to keep logs clean. |
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 | Description |
|---|---|---|
documents | List[Document] | A list of Documents to embed. |
Related Information
Was this page helpful?