Haystack (Deepset)
Explicit, modular pipelines for RAG and Agents.
1. Philosophy
Haystack (v2) uses a directed graph of components. You explicitly connect `output` of one to `input` of another.
2. Components
Components are the building blocks. Each has `run()` and distinct inputs/outputs.
Generators: Interact with LLMs (OpenAI,
HuggingFace).
Retrievers: Fetch documents from Vector DBs.
Builders: Construct prompts dynamically.
from haystack.components.generators import OpenAIGenerator
# Init component
llm = OpenAIGenerator(model="gpt-4")
3. Example RAG Pipeline
from haystack import Pipeline
from haystack.components.builders import PromptBuilder
template = "Answer: {{ query }} based on {{ documents }}"
builder = PromptBuilder(template=template)
pipe = Pipeline()
pipe.add_component("builder", builder)
pipe.add_component("llm", llm)
pipe.connect("builder", "llm")
pipe.run({"builder": {"query": "Hello"}})