|
| 1 | +--- |
| 2 | +layout: integration |
| 3 | +name: Lara |
| 4 | +description: Translate Haystack documents using translated's Lara adaptive translation API |
| 5 | +authors: |
| 6 | + - name: deepset |
| 7 | + socials: |
| 8 | + github: deepset-ai |
| 9 | + twitter: deepset_ai |
| 10 | + linkedin: https://www.linkedin.com/company/deepset-ai/ |
| 11 | +pypi: https://pypi.org/project/lara-haystack/ |
| 12 | +repo: https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/lara |
| 13 | +type: Custom Component |
| 14 | +report_issue: https://github.com/deepset-ai/haystack-core-integrations/issues |
| 15 | +logo: /logos/lara.png |
| 16 | +version: Haystack 2.0 |
| 17 | +toc: true |
| 18 | +--- |
| 19 | + |
| 20 | +### **Table of Contents** |
| 21 | + |
| 22 | +- [Overview](#overview) |
| 23 | +- [Installation](#installation) |
| 24 | +- [Usage](#usage) |
| 25 | + - [Components](#components) |
| 26 | + - [API Keys](#api-keys) |
| 27 | +- [Examples](#examples) |
| 28 | + - [Standalone](#standalone) |
| 29 | + - [Pipeline](#pipeline) |
| 30 | +- [License](#license) |
| 31 | + |
| 32 | +## Overview |
| 33 | + |
| 34 | +[Lara](https://laratranslate.com/) is an adaptive translation API by [translated](https://translated.com/) 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. |
| 35 | + |
| 36 | +Key features: |
| 37 | + |
| 38 | +- **Translation styles**: Choose between `faithful`, `fluid`, or `creative` styles to control the balance between accuracy and natural flow. |
| 39 | +- **Context-aware translation**: Provide surrounding text as context to improve translation quality without translating it. |
| 40 | +- **Instruction-guided translation**: Use natural-language instructions to guide translations (e.g. "Be formal", "Use a professional tone"). |
| 41 | +- **Translation memories**: Adapt translations to the style and terminology of existing translation memories. |
| 42 | +- **Glossaries**: Enforce consistent terminology (e.g. brand names, product terms) across translations. |
| 43 | +- **Reasoning (Lara Think)**: Enable multi-step linguistic analysis for higher-quality translations. |
| 44 | + |
| 45 | +For more details, see the [Lara SDK documentation](https://developers.laratranslate.com/docs/introduction) and the [Lara support documentation](https://support.laratranslate.com/en). |
| 46 | + |
| 47 | +## Installation |
| 48 | + |
| 49 | +```bash |
| 50 | +pip install lara-haystack |
| 51 | +``` |
| 52 | + |
| 53 | +## Usage |
| 54 | + |
| 55 | +### Components |
| 56 | + |
| 57 | +This integration provides one component: |
| 58 | + |
| 59 | +- The [`LaraDocumentTranslator`](https://docs.haystack.deepset.ai/docs/laradocumenttranslator): translates the text content of Haystack `Document` objects using the Lara API. |
| 60 | + |
| 61 | +### API Keys |
| 62 | + |
| 63 | +To use the Lara integration, you need a Lara API access key ID and secret. You can obtain them from [Lara](https://laratranslate.com/). |
| 64 | + |
| 65 | +Once obtained, export them as environment variables: |
| 66 | + |
| 67 | +```bash |
| 68 | +export LARA_ACCESS_KEY_ID="your-access-key-id" |
| 69 | +export LARA_ACCESS_KEY_SECRET="your-access-key-secret" |
| 70 | +``` |
| 71 | + |
| 72 | +By default, `LaraDocumentTranslator` reads the API credentials from these environment variables. You can also pass them explicitly using the Haystack [Secret](https://docs.haystack.deepset.ai/reference/utils-api#secret) utility. |
| 73 | + |
| 74 | +## Examples |
| 75 | + |
| 76 | +### Standalone |
| 77 | + |
| 78 | +The following example translates a list of Documents from English to German: |
| 79 | + |
| 80 | +```python |
| 81 | +from haystack import Document |
| 82 | +from haystack_integrations.components.translators.lara import LaraDocumentTranslator |
| 83 | + |
| 84 | +translator = LaraDocumentTranslator( |
| 85 | + source_lang="en-US", |
| 86 | + target_lang="de-DE", |
| 87 | +) |
| 88 | + |
| 89 | +documents = [ |
| 90 | + Document(content="Hello, world!"), |
| 91 | + Document(content="Goodbye, world!"), |
| 92 | +] |
| 93 | + |
| 94 | +result = translator.run(documents=documents) |
| 95 | +for doc in result["documents"]: |
| 96 | + print(doc.content) |
| 97 | +``` |
| 98 | + |
| 99 | +### Pipeline |
| 100 | + |
| 101 | +You can use `LaraDocumentTranslator` in a Haystack pipeline. The following example converts text files to Documents, translates them, and writes them to an `InMemoryDocumentStore`: |
| 102 | + |
| 103 | +```python |
| 104 | +from haystack import Pipeline |
| 105 | +from haystack.components.converters import TextFileToDocument |
| 106 | +from haystack.components.writers import DocumentWriter |
| 107 | +from haystack.document_stores.in_memory import InMemoryDocumentStore |
| 108 | + |
| 109 | +from haystack_integrations.components.translators.lara import LaraDocumentTranslator |
| 110 | + |
| 111 | +document_store = InMemoryDocumentStore() |
| 112 | + |
| 113 | +pipeline = Pipeline() |
| 114 | +pipeline.add_component("converter", TextFileToDocument()) |
| 115 | +pipeline.add_component( |
| 116 | + "translator", |
| 117 | + LaraDocumentTranslator(source_lang="en-US", target_lang="es-ES"), |
| 118 | +) |
| 119 | +pipeline.add_component("writer", DocumentWriter(document_store=document_store)) |
| 120 | + |
| 121 | +pipeline.connect("converter", "translator") |
| 122 | +pipeline.connect("translator", "writer") |
| 123 | + |
| 124 | +pipeline.run({"converter": {"sources": ["filename.txt"]}}) |
| 125 | +print(document_store.filter_documents()) |
| 126 | +``` |
| 127 | + |
| 128 | +### License |
| 129 | + |
| 130 | +`lara-haystack` is distributed under the terms of the |
| 131 | +[Apache-2.0](https://opensource.org/license/apache-2-0) license. |
0 commit comments