Files
T
wehub-resource-sync c56bef871b
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:22:28 +08:00

9.3 KiB
Raw Blame History

title, id, description, slug
title id description slug
Lara integrations-lara Lara integration for Haystack /integrations-lara

haystack_integrations.components.translators.lara.document_translator

LaraDocumentTranslator

Translates the text content of Haystack Documents using translated's Lara translation API.

Lara is an adaptive translation AI that combines the fluency and context handling of LLMs with low hallucination and latency. It adapts to domains at inference time using optional context, instructions, translation memories, and glossaries. You can find more detailed information in the Lara documentation.

Usage example

from haystack import Document
from haystack.utils import Secret
from haystack_integrations.components.lara import LaraDocumentTranslator

translator = LaraDocumentTranslator(
    access_key_id=Secret.from_env_var("LARA_ACCESS_KEY_ID"),
    access_key_secret=Secret.from_env_var("LARA_ACCESS_KEY_SECRET"),
    source_lang="en-US",
    target_lang="de-DE",
)

doc = Document(content="Hello, world!")
result = translator.run(documents=[doc])
print(result["documents"][0].content)

init

__init__(
    access_key_id: Secret = Secret.from_env_var("LARA_ACCESS_KEY_ID"),
    access_key_secret: Secret = Secret.from_env_var("LARA_ACCESS_KEY_SECRET"),
    source_lang: str | None = None,
    target_lang: str | None = None,
    context: str | None = None,
    instructions: str | None = None,
    style: Literal["faithful", "fluid", "creative"] = "faithful",
    adapt_to: list[str] | None = None,
    glossaries: list[str] | None = None,
    reasoning: bool = False,
)

Creats an instance of the LaraDocumentTranslator component.

Parameters:

  • access_key_id (Secret) Lara API access key ID. Defaults to the LARA_ACCESS_KEY_ID environment variable.
  • access_key_secret (Secret) Lara API access key secret. Defaults to the LARA_ACCESS_KEY_SECRET environment variable.
  • source_lang (str | None) Language code of the source text. If None, Lara auto-detects the source language. Use locale codes from the supported languages list.
  • target_lang (str | None) Language code of the target text. Use locale codes from the supported languages list.
  • context (str | None) Optional external context: text that is not translated but is sent to Lara to improve translation quality (e.g. surrounding sentences, prior messages). You can find more detailed information in the Lara documentation.
  • instructions (str | None) Optional natural-language instructions to guide translation and specify domain-specific terminology (e.g. "Be formal", "Use a professional tone"). You can find more detailed information in the Lara documentation.
  • style (Literal['faithful', 'fluid', 'creative']) One of "faithful", "fluid", or "creative". Default is "faithful". Style description:
  • "faithful": For accuracy and precision. Keeps original structure and meaning. Ideal for manuals, legal documents.
  • "fluid": For readability and natural flow. Smooth, conversational. Good for general content.
  • "creative": For artistic and creative expression. Best for literature, marketing, or content where impact and tone matter more than literal wording. You can find more detailed information in the Lara documentation.
  • adapt_to (list[str] | None) Optional list of translation memory IDs. Lara adapts to the style and terminology of these memories at inference time. Domain adaptation is available depending on your plan. You can find more detailed information in the Lara documentation.
  • glossaries (list[str] | None) Optional list of glossary IDs. Lara applies these glossaries at inference time to enforce consistent terminology (e.g. brand names, product terms, legal or technical phrases) across translations. Glossary management and availability depends on your plan. You can find more detailed information in the Lara documentation.
  • reasoning (bool) If True, uses the Lara Think model for higher-quality translation (multi-step linguistic analysis). Increases latency and cost. Availability depends on your plan. You can find more detailed information in the Lara documentation.

warm_up

warm_up() -> None

Warm up the Lara translator by initializing the client.

run

run(
    documents: list[Document],
    source_lang: str | list[str | None] | None = None,
    target_lang: str | list[str] | None = None,
    context: str | list[str] | None = None,
    instructions: str | list[str] | None = None,
    style: str | list[str] | None = None,
    adapt_to: list[str] | list[list[str]] | None = None,
    glossaries: list[str] | list[list[str]] | None = None,
    reasoning: bool | list[bool] | None = None,
) -> dict[str, list[Document]]

Translate the text content of each input Document using the Lara API.

Any of the translation parameters (source_lang, target_lang, context, instructions, style, adapt_to, glossaries, reasoning) can be passed here to override the defaults set when creating the component. They can be a single value (applied to all documents) or a list of values with the same length as documents for per-document settings.

Parameters:

  • documents (list[Document]) List of Haystack Documents whose content is to be translated.
  • source_lang (str | list[str | None] | None) Source language code(s). Use locale codes from the supported languages list. If None, Lara auto-detects the source language. Single value or list (one per document).
  • target_lang (str | list[str] | None) Target language code(s). Use locale codes from the supported languages list. Single value or list (one per document).
  • context (str | list[str] | None) Optional external context: text that is not translated but is sent to Lara to improve translation quality (e.g. surrounding sentences, prior messages). You can find more detailed information in the Lara documentation.
  • instructions (str | list[str] | None) Optional natural-language instructions to guide translation and specify domain-specific terminology (e.g. "Be formal", "Use a professional tone"). You can find more detailed information in the Lara documentation.
  • style (str | list[str] | None) One of "faithful", "fluid", or "creative". Style description:
  • "faithful": For accuracy and precision. Keeps original structure and meaning. Ideal for manuals, legal documents.
  • "fluid": For readability and natural flow. Smooth, conversational. Good for general content.
  • "creative": For artistic and creative expression. Best for literature, marketing, or content where impact and tone matter more than literal wording. You can find more detailed information in the Lara documentation.
  • adapt_to (list[str] | list[list[str]] | None) Optional list of translation memory IDs. Lara adapts to the style and terminology of these memories at inference time. Domain adaptation is available depending on your plan. You can find more detailed information in the Lara documentation.
  • glossaries (list[str] | list[list[str]] | None) Optional list of glossary IDs. Lara applies these glossaries at inference time to enforce consistent terminology (e.g. brand names, product terms, legal or technical phrases) across translations. Glossary management and availability depends on your plan. You can find more detailed information in the Lara documentation.
  • reasoning (bool | list[bool] | None) If True, uses the Lara Think model for higher-quality translation (multi-step linguistic analysis). Increases latency and cost. Availability depends on your plan. You can find more detailed information in the Lara documentation.

Returns:

  • dict[str, list[Document]] A dictionary with the following keys:
  • documents: A list of translated documents.

Raises:

  • ValueError If any list-valued parameter has length != len(documents).