AnswerJoiner
AnswerJoiner
서로 다른 Generator들의 여러 답변을 하나의 목록으로 병합하는 컴포넌트예요.
파이프라인에서 가장 흔한 위치: 쿼리 파이프라인에서 Generators 뒤, 그리고 AnswerBuilder처럼 답변 목록을 반환하는 컴포넌트 뒤
필수 run 변수: answers — Generator에서 받아 병합할 답변의 중첩 목록. 이 입력은 variadic이라 가변 개수의 컴포넌트를 연결할 수 있어요.
출력 변수: answers — 병합된 답변 목록
API reference: Joiners
GitHub link: https://github.com/deepset-ai/haystack/blob/main/haystack/components/joiners/answer_joiner.py
Package name: haystack-ai
출처: 문서
본문
Overview
AnswerJoiner는 여러 연결에서 입력으로 받은 Answer 객체 목록을 합쳐 하나의 목록으로 반환해요.
선택적으로 top_k 파라미터를 설정할 수 있는데, 이는 반환할 최대 답변 수를 지정합니다. 이 파라미터를 설정하지 않으면 컴포넌트는 받은 모든 답변을 반환해요.
Usage
이 간단한 예시 파이프라인에서 AnswerJoiner는 두 Generator 인스턴스의 답변을 병합합니다:
from haystack.components.builders import AnswerBuilder
from haystack.components.joiners import AnswerJoiner
from haystack.core.pipeline import Pipeline
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
query = "What's Natural Language Processing?"
messages = [
ChatMessage.from_system(
"You are a helpful, respectful and honest assistant. Be super concise.",
),
ChatMessage.from_user(query),
]
pipe = Pipeline()
pipe.add_component("gpt-4o", OpenAIChatGenerator(model="gpt-4o"))
pipe.add_component("llama", OpenAIChatGenerator())
pipe.add_component("aba", AnswerBuilder())
pipe.add_component("abb", AnswerBuilder())
pipe.add_component("joiner", AnswerJoiner())
pipe.connect("gpt-4o.replies", "aba")
pipe.connect("llama.replies", "abb")
pipe.connect("aba.answers", "joiner")
pipe.connect("abb.answers", "joiner")
results = pipe.run(
data={
"gpt-4o": {"messages": messages},
"llama": {"messages": messages},
"aba": {"query": query},
"abb": {"query": query},
},
)
더 알아보기 (Learn more)
- Joiners — Joiner 컴포넌트
- AnswerBuilder — 답변 빌더
- Answer — 데이터 클래스