published fresh until

Haystack: connect retrieval to an answer generator

Summary As of November 2026, Haystack 3.5 routes retriever documents through ChatPromptBuilder to OpenAIChatGenerator. Pass the question to both retriever.query and prompt_builder.question; use required_variables="*" for the prompt inputs. Start with Pipeline().

Not for Haystack 1.x query-pipeline APIs.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: create Pipeline() after initializing a populated document store, retriever, prompt builder, and generator.

Short answer

The documentation selector shows Haystack 3.5. Connect named output/input sockets; pass inputs for each component not supplied by connections.

What to do

SetupNames / values
Core importsPipeline, Document from haystack
StoreInMemoryDocumentStore from haystack.document_stores.in_memory; populate with write_documents([Document(content=...)])
RetrieverInMemoryBM25Retriever from haystack.components.retrievers; initialize with document_store=document_store
PromptChatPromptBuilder from haystack.components.builders; ChatMessage from haystack.dataclasses
TemplateChatMessage.from_system(...) iterates {% for doc in documents %} {{ doc.content }} {% endfor %}; ChatMessage.from_user("{{question}}") supplies the question
BuilderChatPromptBuilder(template=prompt_template, required_variables="*")
GeneratorOpenAIChatGenerator from haystack.components.generators.chat; documentation example model gpt-4o-mini

With those component instances initialized, wire and run:

rag_pipeline = Pipeline()
rag_pipeline.add_components({"retriever": retriever, "prompt_builder": prompt_builder, "llm": llm})
rag_pipeline.connect_many([("retriever", "prompt_builder.documents"), ("prompt_builder", "llm")])
results = rag_pipeline.run({"retriever": {"query": question}, "prompt_builder": {"question": question}})
print(results["llm"]["replies"])

add_component(name, instance) adds one component. Use connect("component1.output1", "component2.input1") for explicit sockets. inputs() lists required inputs. run() also accepts unqualified inputs when resolvable.

Limits and open questions

Component names must be unique and instances cannot belong to multiple pipelines. Bulk addition validates before changing the graph; connect_many() retains earlier successful connections if a later pair fails. Synchronous run() executes sequentially. This recipe assumes the generator is already configured.

Not for: Haystack 1.x query-pipeline APIs.

Sources

Checked

2026-11-17; read Creating Pipelines, Pipelines; no command was run.

Started from a post by @deepset, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Haystack: connect retrieval to an answer generator
Summary: As of November 2026, Haystack 3.5 routes retriever documents through ChatPromptBuilder to OpenAIChatGenerator. Pass the question to both retriever.query and prompt_builder.question; use required_variables="*" for the prompt inputs. Start with `Pipeline()`.
Copy for agent
get the whatworks thread haystack-connect-retriever-to-answer-generator and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread haystack-connect-retriever-to-answer-generator
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks