|
| 1 | +--- |
| 2 | +layout: integration |
| 3 | +name: OPEA |
| 4 | +description: Use the OPEA framework for hardware abstraction and orchestration |
| 5 | +authors: |
| 6 | + - name: OPEA-Project |
| 7 | + socials: |
| 8 | + github: opea-project |
| 9 | +pypi: https://pypi.org/project/haystack-opea/ |
| 10 | +repo: https://github.com/opea-project/Haystack-OPEA |
| 11 | +type: Distributed Computing |
| 12 | +report_issue: https://github.com/opea-project/Haystack-OPEA/issues |
| 13 | +logo: /logos/opea.png |
| 14 | +version: Haystack 2.0 |
| 15 | +toc: true |
| 16 | +--- |
| 17 | + |
| 18 | +### Table of Contents |
| 19 | + |
| 20 | +- [Overview](#overview) |
| 21 | +- [Installation](#installation) |
| 22 | +- [Usage](#usage) |
| 23 | + - [Embeddings](#embeddings) |
| 24 | + - [LLM Generation](#llm-generation) |
| 25 | + |
| 26 | +## Overview |
| 27 | + |
| 28 | +The `haystack-opea` integration connects Haystack to [OPEA](https://opea.dev/)—a collection of containerized microservices for LLMs, embedding, retrieval and reranking. By delegating heavy compute to OPEA services, you can build flexible Retrieval-Augmented Generation (RAG) pipelines that scale across cloud, on-prem and edge deployments. |
| 29 | + |
| 30 | +Key features: |
| 31 | +- Hardware-agnostic LLM & embedding services. |
| 32 | +- Easy orchestration of LLM, embedder, retriever, ranker, among others. |
| 33 | +- Support for local development via Docker Compose or production clusters. |
| 34 | + |
| 35 | +## Installation |
| 36 | + |
| 37 | +Install from source: |
| 38 | + |
| 39 | +```bash |
| 40 | +git clone https://github.com/opea-project/Haystack-OPEA.git |
| 41 | +cd Haystack-OPEA |
| 42 | +pip install poetry |
| 43 | +poetry install --with test |
| 44 | +``` |
| 45 | + |
| 46 | +## Usage |
| 47 | + |
| 48 | +Below are quickstart examples for embeddings and LLM generation. Make sure your OPEA backend is running: e.g. via the provided [Docker Compose](https://github.com/opea-project/Haystack-OPEA/blob/main/samples/compose.yaml) file. OPEA services can be configured to use a variety of model serving backends like TGI, vLLM, ollama, OVMS... and offer validated runtime settings for good performance on various hardware's including Intel Gaudi, see the [LLM](https://github.com/opea-project/GenAIComps/tree/main/comps/llms/src/text-generation) section in the OPEA components library. |
| 49 | + |
| 50 | +### Embeddings |
| 51 | + |
| 52 | +```python |
| 53 | +from haystack import Document |
| 54 | +from haystack_opea import OPEATextEmbedder, OPEADocumentEmbedder |
| 55 | + |
| 56 | +# Text embedding example |
| 57 | +text_embedder = OPEATextEmbedder(api_url="http://localhost:6006") |
| 58 | +text_embedder.warm_up() |
| 59 | +result = text_embedder.run("I love pizza!") |
| 60 | +print("Text embedding:", result["vectors"][0]) |
| 61 | + |
| 62 | +# Document embedding example |
| 63 | +doc = Document(content="I love pizza!") |
| 64 | +doc_embedder = OPEADocumentEmbedder(api_url="http://localhost:6006") |
| 65 | +doc_embedder.warm_up() |
| 66 | +out = doc_embedder.run([doc]) |
| 67 | +print("Document embedding:", out["documents"][0].embedding) |
| 68 | +``` |
| 69 | + |
| 70 | +### LLM Generation |
| 71 | + |
| 72 | +```python |
| 73 | +from haystack_opea import OPEAGenerator |
| 74 | + |
| 75 | +# Initialize the OPEA LLM service |
| 76 | +generator = OPEAGenerator( |
| 77 | + api_url="http://localhost:9009", |
| 78 | + model_arguments={ |
| 79 | + "temperature": 0.2, |
| 80 | + "top_p": 0.7, |
| 81 | + "max_tokens": 512, |
| 82 | + }, |
| 83 | +) |
| 84 | +generator.warm_up() |
| 85 | + |
| 86 | +# Run a simple prompt |
| 87 | +response = generator.run(prompt="What is the capital of France?") |
| 88 | +print("LLM reply:", response["replies"][0]) |
| 89 | +``` |
| 90 | + |
| 91 | +For more examples, see the `samples/` folder and the [official OPEA documentation](https://opea.dev/), as well as the [Components Library](https://github.com/opea-project/GenAIComps). |
0 commit comments