> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Haystack

> WeaveConnector 인테그레이션을 사용하여 W&B Weave로 Deepset Haystack 파이프라인을 트레이스하세요.

[Haystack](https://haystack.deepset.ai/)은 검색 및 LLM 애플리케이션을 구축하기 위한 오픈 소스 프레임워크입니다. Deepset에서 관리하는 WeaveConnector 컴포넌트는 Haystack 파이프라인 트레이스를 W\&B Weave로 전달합니다. 이를 통해 Weights & Biases UI에서 컴포넌트 run, 프롬프트, 출력을 살펴볼 수 있습니다.

이 가이드는 파이프라인에 관측성을 추가하려는 Haystack 개발자를 대상으로 합니다.

전체 API 세부 정보와 추가 예시는 다음 Deepset 리소스를 참조하세요.

* Haystack의 [WeaveConnector](https://docs.haystack.deepset.ai/docs/weaveconnector)
* Haystack의 [Weave 인테그레이션 API 레퍼런스](https://docs.haystack.deepset.ai/reference/integrations-weave)
* RAG 파이프라인을 활용한 Haystack의 [W\&B Weave로 트레이스하기](https://docs.cloud.deepset.ai/docs/use-weights-and-biases) 예시

<h2 id="prerequisites">
  사전 요구 사항
</h2>

시작하기 전에 다음 작업을 완료해야 합니다.

* Forge [API 키](https://forge.coreweave.com/settings)를 사용하여 환경에 `WANDB_API_KEY`를 설정하세요. 이 키로 커넥터가 W\&B Weave에 인증됩니다.
* 파이프라인을 실행하기 전에 `HAYSTACK_CONTENT_TRACING_ENABLED`를 `true`로 설정하세요. 그래야 Haystack이 트레이싱 데이터를 내보내고, 커넥터가 이 데이터를 전달할 수 있습니다.

<h2 id="install">
  설치
</h2>

`pip`를 사용하여 필요한 의존성을 설치하세요.

```bash lines theme={"system"}
pip install weave-haystack
```

이 패키지는 서로 호환되는 버전의 `haystack-ai`와 `weave`를 의존성으로 선언합니다.

<h2 id="trace-a-haystack-pipeline-with-weave">
  Weave로 Haystack 파이프라인 트레이스하기
</h2>

다음 예시에서는 Haystack의 `WeaveConnector`를 Haystack [`Pipeline`](https://docs.haystack.deepset.ai/docs/pipelines)에 추가하고 W\&B Weave와 통합하여 파이프라인 컴포넌트를 트레이스하고 모니터링합니다. 전달한 `pipeline_name`은 해당 파이프라인에서 생성되는 트레이스의 Weave 프로젝트 이름으로 사용됩니다.

Haystack 파이프라인에서 `WeaveConnector`를 다른 컴포넌트와 연결하지 마세요.

```python lines theme={"system"}
import os

os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"

from haystack import Pipeline
from haystack.components.builders import ChatPromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.connectors.weave import WeaveConnector

pipe = Pipeline()
pipe.add_component("prompt_builder", ChatPromptBuilder())
pipe.add_component("llm", OpenAIChatGenerator(model="gpt-3.5-turbo"))
pipe.connect("prompt_builder.prompt", "llm.messages")

# pipeline_name이 W&B 프로젝트 이름으로 사용됩니다.
connector = WeaveConnector(pipeline_name="haystack_demo")
# 커넥터를 파이프라인에 추가하되, 다른 컴포넌트와 연결하지는 마세요.
pipe.add_component("weave", connector)

messages = [
    ChatMessage.from_system(
        "Always respond in German even if some input data is in other languages.",
    ),
    ChatMessage.from_user("Tell me about {{location}}"),
]

response = pipe.run(
    data={
        "prompt_builder": {
            "template_variables": {"location": "Berlin"},
            "template": messages,
        },
    },
)

print(response["llm"]["replies"][0])
```

파이프라인 실행이 끝나면 Weights & Biases 워크스페이스를 열고 `pipeline_name`에 지정한 이름의 프로젝트를 선택한 다음, **Traces**로 이동하여 완료된 트레이스를 확인하세요.
