Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ListJoiner #8758

Closed
wants to merge 2 commits into from
Closed

Conversation

Haystack-Agent
Copy link

Related Issues

Proposed Changes:

This PR adds a new ListJoiner component that allows merging multiple lists into a single flat list while preserving the order of inputs. This is particularly useful for scenarios where multiple List[ChatMessage] need to be consolidated into one unified list.

Changes
Add ListJoiner component in haystack/components/joiners/list_joiner.py
Add comprehensive test suite in test/components/joiners/test_list_joiner.py
Key Features
Generic implementation that works with any list type (e.g., List[ChatMessage], List[int], etc.)
Preserves input order (earlier inputs appear first in the output)
Simple interface that works with Haystack's Pipeline
Type-safe implementation using Python's generics
Example usage with ChatMessages:
from haystack import Pipeline
from haystack.dataclasses import ChatMessage
from haystack.components.joiners import ListJoiner

messages1 = [ChatMessage.from_user("Hello"), ChatMessage.from_assistant("Hi there")]
messages2 = [ChatMessage.from_user("How are you?")]

p = Pipeline()
p.add_component("joiner", ListJoiner())
result = p.run(data={"lists": [messages1, messages2]})

result.messages will be [messages1[0], messages1[1], messages2[0]]

How did you test it?

The test suite checks:

Empty list handling
Single list input
Multiple list inputs
ChatMessage list handling
Pipeline integration

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes
  • I added unit tests and updated the docstrings
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I documented my code
  • I ran pre-commit hooks and fixed any issue

@Haystack-Agent Haystack-Agent requested a review from a team as a code owner January 21, 2025 16:15
@Haystack-Agent Haystack-Agent requested review from Amnah199 and removed request for a team January 21, 2025 16:15
@CLAassistant
Copy link

CLAassistant commented Jan 21, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added topic:tests type:documentation Improvements on the docs labels Jan 21, 2025
@mathislucka
Copy link
Member

Ignore for now, only testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:tests type:documentation Improvements on the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a ListJoiner Component to Merge Multiple Lists into a Single List
3 participants