파이프라인 디버깅
파이프라인 디버깅 (Debugging Pipelines)
Haystack 파이프라인을 디버깅하고 문제를 해결하는 방법을 알아봐요.
파이프라인을 디버깅하는 옵션은 여러 가지가 있어요.
- 컴포넌트의 출력 살펴보기
- 로깅 조정하기
- 추적(tracing) 설정하기
- 모니터링 도구 통합 중 하나 사용해 보기
출처: 공식문서
컴포넌트 출력 살펴보기
특정 파이프라인 컴포넌트의 출력을 보려면 파이프라인 실행 시 include_outputs_from 파라미터를 추가하면 됩니다. 입력 딕셔너리 뒤에 위치시키고, 결과에 포함하고 싶은 출력을 가진 컴포넌트의 이름을 지정해요.
예를 들어 이 파이프라인에서 PromptBuilder의 출력을 출력하려면 이렇게 합니다.
from haystack import Pipeline, Document
from haystack.utils import Secret
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder
from haystack.dataclasses import ChatMessage
# Documents
documents = [
Document(content="Joe lives in Berlin"),
Document(content="Joe is a software engineer"),
]
# Define prompt template
prompt_template = [
ChatMessage.from_system("You are a helpful assistant."),
ChatMessage.from_user(
"Given these documents, answer the question.\nDocuments:\n"
"{% for doc in documents %}{{ doc.content }}{% endfor %}\n"
"Question: {{query}}\nAnswer:",
),
]
# Define pipeline
p = Pipeline()
p.add_component(
instance=ChatPromptBuilder(
template=prompt_template,
required_variables={"query", "documents"},
),
name="prompt_builder",
)
p.add_component(
instance=OpenAIChatGenerator(
api_key=Secret.from_env_var("OPENAI_API_KEY"),
),
name="llm",
)
p.connect("prompt_builder", "llm.messages")
# Define question
question = "Where does Joe live?"
# Execute pipeline
result = p.run(
{"prompt_builder": {"documents": documents, "query": question}},
include_outputs_from="prompt_builder",
)
# Print result
print(result)
로깅 조정하기
디버깅 필요에 맞게 로깅 형식을 조정할 수 있어요. 자세한 내용은 Logging 문서를 참고하세요.
파이프라인을 타고 흐르는 데이터를 실시간으로 검사하려면 Haystack의 LoggingTracer 로그를 쓰면 돼요.
이 기능은 실험·프로토타이핑 단계에서 특히 유용합니다. 미리 추적 백엔드를 설정할 필요가 없거든요.
이 트레이서를 활성화하는 방법을 볼게요. 이 예시에서는 컴포넌트 이름과 입력을 강조하기 위해 색상 태그를 추가했어요(이건 선택 사항입니다).
import logging
from haystack import tracing
from haystack.tracing.logging_tracer import LoggingTracer
logging.basicConfig(
format="%(levelname)s - %(name)s - %(message)s",
level=logging.WARNING,
)
logging.getLogger("haystack").setLevel(logging.DEBUG)
tracing.tracer.is_content_tracing_enabled = (
True # to enable tracing/logging content (inputs/outputs)
)
tracing.enable_tracing(
LoggingTracer(
tags_color_strings={
"haystack.component.input": "\x1b[1;31m",
"haystack.component.name": "\x1b[1;34m",
},
),
)
파이프라인을 실행하면 결과 로그가 다음과 같은 모습이 됩니다.
더 넓은 시야로 보기
파이프라인의 성능을 더 큰 그림으로 보고 싶다면 Langfuse로 추적해 보세요. Haystack의 다른 추적 솔루션에 대한 내용은 Tracing 페이지에 더 자세히 나와 있어요.
Haystack 파이프라인을 위한 Arize AI나 Arize Phoenix 같은 추적·모니터링 통합도 살펴보세요.
더 알아보기 (Learn more)
- 파이프라인 디버깅 (Debugging Pipelines) — 원문 문서.