JinaDocumentEmbedder
Compute document embeddings using Jina AI models.
Key Features
- Computes embeddings for documents using Jina AI models.
- Stores the embedding in each document's
embeddingfield, making documents ready for semantic search and retrieval. - Supports multiple task types optimized for different use cases:
retrieval.passage,retrieval.query,text-matching,classification, andseparation. - Configurable batch size and progress bar for production deployments.
- Supports late chunking for contextual chunk embeddings with
jina-embeddings-v3.
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
JinaDocumentEmbeddercomponent 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 Jina API key. Use
JINA_API_KEYas the secret key. For instructions, see Create Secrets. Get your API key from Jina AI. - Select the embedding model. Check available models on the Jina documentation.
- Set the
taskparameter to match your use case (for example,retrieval.passagefor document passages).
- Create a secret with your Jina API key. Use
- Go to the Advanced tab to configure additional settings such as
batch_size,prefix,suffix,meta_fields_to_embed,dimensions,late_chunking, andembedding_separator.
Connections
JinaDocumentEmbedder receives a list of documents through its documents input. It outputs the same documents with their embeddings added through its documents output, plus usage metadata through its meta output.
Connect it after converters (such as TextFileToDocument, HTMLToDocument, or MarkdownToDocument) or after DocumentSplitter to embed chunks. 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_embedder.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
JinaDocumentEmbedder:
type: haystack_integrations.components.embedders.jina.document_embedder.JinaDocumentEmbedder
init_parameters:
api_key:
type: env_var
env_vars:
- JINA_API_KEY
strict: false
model: jina-embeddings-v3
batch_size: 32
progress_bar: true
task: retrieval.passage
This example shows an indexing pipeline that reads text files, splits them into chunks, embeds them using Jina, and writes them to an in-memory document store.
components:
TextFileToDocument:
type: haystack.components.converters.txt.TextFileToDocument
init_parameters:
encoding: utf-8
store_full_path: false
DocumentSplitter:
type: haystack.components.preprocessors.document_splitter.DocumentSplitter
init_parameters:
split_by: sentence
split_length: 100
split_overlap: 0
split_threshold: 0
splitting_function:
JinaDocumentEmbedder:
type: haystack_integrations.components.embedders.jina.document_embedder.JinaDocumentEmbedder
init_parameters:
api_key:
type: env_var
env_vars:
- JINA_API_KEY
strict: false
model: jina-embeddings-v3
batch_size: 32
progress_bar: true
task: retrieval.passage
DocumentWriter:
type: haystack.components.writers.document_writer.DocumentWriter
init_parameters:
policy: OVERWRITE
document_store:
type: haystack.document_stores.in_memory.document_store.InMemoryDocumentStore
init_parameters:
bm25_tokenization_regex: (?u)\b\w\w+\b
bm25_algorithm: BM25L
bm25_parameters:
embedding_similarity_function: dot_product
index: 'default'
async_executor:
connections:
- sender: TextFileToDocument.documents
receiver: DocumentSplitter.documents
- sender: DocumentSplitter.documents
receiver: JinaDocumentEmbedder.documents
- sender: JinaDocumentEmbedder.documents
receiver: DocumentWriter.documents
max_runs_per_component: 100
metadata: {}
inputs:
files:
- TextFileToDocument.sources
Parameters
Inputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | A list of Documents to embed. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | List of Documents, each with an embedding field containing the computed embedding. |
meta | Dict[str, Any] | A dictionary with metadata including the model name and usage statistics. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| api_key | Secret | Secret.from_env_var('JINA_API_KEY') | The Jina API key. |
| model | str | jina-embeddings-v3 | The name of the Jina model to use. Check the list of available models on Jina documentation. |
| 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. |
| task | Optional[str] | None | The downstream task for which the embeddings will be used. The model will return the optimized embeddings for that task. Check the list of available tasks on Jina documentation. |
| dimensions | Optional[int] | None | Number of desired dimension. Smaller dimensions are easier to store and retrieve, with minimal performance impact thanks to MRL. |
| late_chunking | Optional[bool] | None | A boolean to enable or disable late chunking. Apply the late chunking technique to leverage the model's long-context capabilities for generating contextual chunk embeddings. The support of task and late_chunking parameters is only available for jina-embeddings-v3. |
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?