liveBook · Manning

Haystack

As explained in Natural Language Processing in Action, Second Edition

Haystack is an open-source framework for building natural-language search, question-answering, and retrieval-augmented generation pipelines.

Haystack is an open-source Python framework for indexing and searching documents, then connecting semantic retrieval with language models. Its main practical role is building retrieval-augmented generation (RAG) and question-answering pipelines that ground responses in retrieved text. section 10.3.6 section 10.3.7

A Haystack RAG workflow typically combines:

  • A retriever that selects relevant documents for a query. section 10.3.11
  • A PromptNode that instructs a generative model how to synthesize an answer from the retrieved text. section 10.3.11
  • A Pipeline that connects the query, retriever, and prompt node while exposing settings such as top_k. section 10.3.11
  • A grounding instruction that returns “I don't know” when the supplied sources cannot answer the question. section 10.3.11

A grounded question-answering pipeline

A PromptNode using google/flan-t5-base can be connected to an existing retriever. Asking “How are LSTM neural networks different from RNNs?” produces an answer from retrieved material. Asking “Where is the Louvre Museum?” returns “I don't know” when the retrieved sources do not support the answer, while a broader question about artificial intelligence produces a qualified response. section 10.3.11

Listing 10.23 Creating a Haystack PromptNode for RAG
>>> from haystack.nodes import PromptNode, PromptTemplate, AnswerParser

rag_prompt = PromptTemplate(
     prompt="""Synthesize a comprehensive answer from the
               following text for the given question.
               Provide a clear response that summarizes the
               key points and information presented in the text.
               If you can't answer the question based on
               provided sources, say 'I don't know'.
               \n\n Related text: {join(documents)}
               \n\n Question: {query}
               \n\n Answer:""",
)
>>> prompt_node = PromptNode(model_name_or_path="google/flan-t5-base", default_prompt_template=rag_prompt)

Inspect the runnable PromptNode definition, including its synthesis instructions, document placeholder, question placeholder, and fallback response. section 10.3.11

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Demonstrates Python components, prompt design, pipeline wiring, retrieval parameters, and outputs, without detailing deployment internals.
Examples
Uses retrieved documents to answer LSTM-versus-RNN, Louvre, and artificial-intelligence questions.
What it assumes
Assumes an existing retriever and adds a generative node around it.
What you can do after
Build RAG QA pipelines that retrieve documents, prompt a model, reject unsupported answers, and inspect returned results.
How it connects
Connects semantic search, vector search, LLMs, retrieval-augmented generation, guardrails, and question answering.

Also explained in

Compare how 2 books explain Haystack →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.