LaraDocumentTranslator
Translate Haystack Documents using Lara, an adaptive translation API that combines LLM fluency with low hallucination and latency.
Key Features
- Translates Document text content using the Lara translation API.
- Auto-detects source language when no source language is specified.
- Supports translation memories and glossaries for consistent domain-specific terminology.
- Offers three translation styles:
faithful(accuracy),fluid(readability), andcreative(expressive). - Accepts per-document translation settings via list parameters for batches with mixed language or style requirements.
- Preserves original Document metadata and adds
original_document_idto translated Documents.
Configuration
- Sign up at laratranslate.com and get an access key pair.
- Set the
LARA_ACCESS_KEY_IDandLARA_ACCESS_KEY_SECRETenvironment variables. For instructions, see Create Secrets. - Configure
LaraDocumentTranslatorin your pipeline YAML with the source and target language codes.
Connections
LaraDocumentTranslator takes a list of Document objects as documents input and outputs a list of translated Document objects as documents.
Connect a document converter's or retriever's documents output to the documents input. Connect the documents output to downstream processing components such as a document writer or embedder.
Source Code
To check this component's source code, open document_translator.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
lara_translator:
type: haystack_integrations.components.translators.lara.document_translator.LaraDocumentTranslator
init_parameters:
access_key_id:
type: env_var
env_vars:
- LARA_ACCESS_KEY_ID
strict: false
access_key_secret:
type: env_var
env_vars:
- LARA_ACCESS_KEY_SECRET
strict: false
source_lang: en-US
target_lang: de-DE
style: faithful
Using the Component in a Pipeline
# haystack-pipeline
components:
pdf_converter:
type: haystack.components.converters.pypdf.PyPDFToDocument
init_parameters: {}
lara_translator:
type: haystack_integrations.components.translators.lara.document_translator.LaraDocumentTranslator
init_parameters:
access_key_id:
type: env_var
env_vars:
- LARA_ACCESS_KEY_ID
strict: false
access_key_secret:
type: env_var
env_vars:
- LARA_ACCESS_KEY_SECRET
strict: false
source_lang: en-US
target_lang: de-DE
writer:
type: haystack.components.writers.document_writer.DocumentWriter
init_parameters:
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
- ${OPENSEARCH_HOST}
index: translated-docs
embedding_dim: 768
create_index: true
connections:
- sender: pdf_converter.documents
receiver: lara_translator.documents
- sender: lara_translator.documents
receiver: writer.documents
inputs:
files:
- pdf_converter.sources
max_runs_per_component: 100
metadata: {}
Parameters
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
access_key_id | Secret | Secret.from_env_var("LARA_ACCESS_KEY_ID") | Lara API access key ID. |
access_key_secret | Secret | Secret.from_env_var("LARA_ACCESS_KEY_SECRET") | Lara API access key secret. |
source_lang | str | None | None | Source language locale code (for example, en-US). If None, Lara auto-detects the language. See the supported languages list. |
target_lang | str | None | None | Target language locale code (for example, de-DE). See the supported languages list. |
context | str | None | None | Optional context text sent to Lara to improve translation quality. This text is not translated. |
instructions | str | None | None | Optional natural-language instructions to guide translation style or terminology (for example, "Be formal"). |
style | str | faithful | Translation style. One of faithful (accuracy and precision), fluid (natural readability), or creative (artistic expression). |
adapt_to | list[str] | None | None | Optional list of translation memory IDs for domain adaptation at inference time. |
glossaries | list[str] | None | None | Optional list of glossary IDs for consistent terminology enforcement across translations. |
reasoning | bool | False | If True, uses the Lara Think model for multi-step linguistic analysis. Increases latency and cost. |
Related Information
Was this page helpful?