📘 **TELUS Agriculture & Consumer Goods** 如何通过 **Haystack Agents** 转变促销交易
由 deepset 维护

集成:Optimum

使用 Hugging Face Optimum 实现高性能推理

作者
deepset

目录

概述

Hugging Face OptimumTransformers 库的扩展,提供了一套性能优化工具,可在目标硬件上以最高效率训练和运行模型。使用 Optimum,您可以利用 ONNX Runtime 自动从 Hugging Face Model Hub 导出模型,并将其部署到管道中,以显著提高性能。

安装

pip install optimum-haystack

使用

组件

此集成引入了两个组件:OptimumTextEmbedderOptimumDocumentEmbedder

要为文档创建语义嵌入,请在索引管道中使用 OptimumDocumentEmbedder。要生成查询嵌入,请使用 OptimumTextEmbedder

以下是使用 InMemoryDocumentStoreOptimumDocumentEmbedderDocumentWriter 的示例索引管道

from haystack import Document, Pipeline
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.writers import DocumentWriter
from haystack_integrations.components.embedders.optimum import (
    OptimumDocumentEmbedder,
    OptimumEmbedderPooling,
)


document_store = InMemoryDocumentStore(embedding_similarity_function="cosine")

documents = [Document(content="I enjoy programming in Python"),
             Document(content="My city does not get snow in winter"),
             Document(content="Japanese diet is well known for being good for your health"),
             Document(content="Thomas is injured and can't play sports")]

indexing_pipeline = Pipeline()
indexing_pipeline.add_component("embedder", OptimumDocumentEmbedder(
    model="intfloat/e5-base-v2",
    normalize_embeddings=True,
    pooling_mode=OptimumEmbedderPooling.MEAN,
))
indexing_pipeline.add_component("writer", DocumentWriter(document_store=document_store))
indexing_pipeline.connect("embedder", "writer")

indexing_pipeline.run({"embedder": {"documents": documents}})

许可证

optimum-haystack 是在 Apache-2.0 许可条款下分发的。