集成:Arize Phoenix
使用 Arize Phoenix 追踪您的 Haystack 管道
目录
概述
Arize Phoenix 是 Arize 的开源平台,为开发人员提供了一种最快捷的方式来对 LLM 应用程序进行故障排除、评估和实验。
有关详细的集成指南,请参阅 Phoenix + Haystack 的文档
安装
pip install openinference-instrumentation-haystack haystack-ai arize-phoenix
使用
要追踪任何 Haystack 管道与 Phoenix,只需初始化 OpenTelemetry 和 HaystackInstrumentor。在同一环境中运行的 Haystack 管道会将追踪发送到 Phoenix。
首先,启动一个 Phoenix 实例以发送追踪信息。
phoenix serve
现在,让我们使用 OpenTelemetry 将我们的 Haystack 管道连接到 Phoenix。
from openinference.instrumentation.haystack import HaystackInstrumentor
from phoenix.otel import register
tracer_provider = register(endpoint="https://:4317")
HaystackInstrumentor().instrument(tracer_provider=tracer_provider)
现在,您可以在同一环境中运行 Haystack 管道,这将产生以下追踪结果:
要运行下面的示例,请将您的 OpenAI Key 导出到
OPENAI_API_KEY环境变量。
from haystack import Document, Pipeline
from haystack.components.builders.prompt_builder import PromptBuilder
from haystack.components.generators import OpenAIGenerator
from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
from haystack.document_stores.in_memory import InMemoryDocumentStore
document_store = InMemoryDocumentStore()
document_store.write_documents([
Document(content="My name is Jean and I live in Paris."),
Document(content="My name is Mark and I live in Berlin."),
Document(content="My name is Giorgio and I live in Rome.")
])
prompt_template = """
Given these documents, answer the question.
Documents:
{% for doc in documents %}
{{ doc.content }}
{% endfor %}
Question: {{question}}
Answer:
"""
retriever = InMemoryBM25Retriever(document_store=document_store)
prompt_builder = PromptBuilder(template=prompt_template)
llm = OpenAIGenerator()
rag_pipeline = Pipeline()
rag_pipeline.add_component("retriever", retriever)
rag_pipeline.add_component("prompt_builder", prompt_builder)
rag_pipeline.add_component("llm", llm)
rag_pipeline.connect("retriever", "prompt_builder.documents")
rag_pipeline.connect("prompt_builder", "llm")
question = "Who lives in Paris?"
results = rag_pipeline.run(
{
"retriever": {"query": question},
"prompt_builder": {"question": question},
}
)
资源
- 查看 Phoenix 的 GitHub 仓库
- 有关如何托管自己的 Phoenix 实例的深入指南,请参阅 Phoenix 文档
- 在 phoenix.arize.com 尝试免费托管的 Phoenix 实例
- 查看 Phoenix 文档
