JinaTextEmbedder
Embed strings, such as a user query, using Jina AI models.
Key Features
- Embeds a single text string (typically a query) using Jina AI models.
- Use in query pipelines to convert user queries into embeddings for semantic search.
- Supports multiple task types for optimized embeddings.
- Configurable dimensions and late chunking for
jina-embeddings-v3. - For embedding documents in indexes, use
JinaDocumentEmbedderwith the same model.
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
JinaTextEmbeddercomponent 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. Use the same model as in
JinaDocumentEmbedderin your indexing pipeline. - Set the
taskparameter. Useretrieval.queryfor search queries.
- Create a secret with your Jina API key. Use
- Go to the Advanced tab to configure
prefix,suffix,dimensions, andlate_chunking.
Connections
JinaTextEmbedder accepts a string through its text input. It outputs the embedding as a list of floats through its embedding output, plus usage metadata through its meta output.
Connect the Input component's query output to JinaTextEmbedder's text input. Then connect JinaTextEmbedder's embedding output to an embedding retriever's query_embedding input.
Source Code
To check this component's source code, open text_embedder.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
JinaTextEmbedder:
type: haystack_integrations.components.embedders.jina.text_embedder.JinaTextEmbedder
init_parameters:
api_key:
type: env_var
env_vars:
- JINA_API_KEY
strict: false
model: jina-embeddings-v3
task: retrieval.query
This example shows a query pipeline that embeds a user query using Jina and retrieves relevant documents.
components:
JinaTextEmbedder:
type: haystack_integrations.components.embedders.jina.text_embedder.JinaTextEmbedder
init_parameters:
api_key:
type: env_var
env_vars:
- JINA_API_KEY
strict: false
model: jina-embeddings-v3
task: retrieval.query
InMemoryEmbeddingRetriever:
type: haystack.components.retrievers.in_memory.embedding_retriever.InMemoryEmbeddingRetriever
init_parameters:
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:
top_k: 5
connections:
- sender: JinaTextEmbedder.embedding
receiver: InMemoryEmbeddingRetriever.query_embedding
max_runs_per_component: 100
metadata: {}
inputs:
query:
- JinaTextEmbedder.text
- InMemoryEmbeddingRetriever.query
outputs:
documents: InMemoryEmbeddingRetriever.documents
Parameters
Inputs
| Parameter | Type | Description |
|---|---|---|
text | str | The string to embed. |
Outputs
| Parameter | Type | Description |
|---|---|---|
embedding | List[float] | The embedding of the input string. |
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. It can be explicitly provided or automatically read from the environment variable JINA_API_KEY (recommended). |
| 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. | |
| 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 |
|---|---|---|---|
| text | str | The string to embed. |
Was this page helpful?