Skip to main content

Haystack: Production-Ready RAG & NLP Pipeline Framework

Haystack is deepset's open-source framework for building production-grade NLP and RAG pipelines. Its component-based architecture lets you compose modular, swappable pipeline stages — document loaders, retrievers, embedders, readers, and LLM generators — into explicit, testable pipelines. The enterprise-grade choice for document Q&A, semantic search, and RAG at scale.

✓ Component-based pipelines ✓ 10+ DocumentStore integrations ✓ Hybrid retrieval (BM25 + vector) ✓ Streaming & async support ✓ Deepset Cloud managed option
Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →

Building a RAG Pipeline with Haystack 2.x

Define a pipeline by connecting components explicitly — indexing and querying are separate pipelines in Haystack.

pip install haystack-ai

from haystack import Document, Pipeline
from haystack.components.embedders import OpenAIDocumentEmbedder, OpenAITextEmbedder
from haystack.components.writers import DocumentWriter
from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
from haystack.components.builders import PromptBuilder
from haystack.components.generators import OpenAIGenerator
from haystack.document_stores.in_memory import InMemoryDocumentStore

# --- INDEXING PIPELINE ---
document_store = InMemoryDocumentStore()

docs = [
    Document(content="Haystack uses a component-based pipeline architecture.", meta={"source": "docs"}),
    Document(content="RAG combines retrieval with LLM generation for grounded answers.", meta={"source": "blog"}),
    Document(content="Hybrid search merges BM25 sparse and dense vector retrieval.", meta={"source": "docs"}),
]

indexing_pipeline = Pipeline()
indexing_pipeline.add_component("embedder",    OpenAIDocumentEmbedder(model="text-embedding-3-small"))
indexing_pipeline.add_component("writer",      DocumentWriter(document_store=document_store))

# Connect component outputs to inputs
indexing_pipeline.connect("embedder.documents", "writer.documents")

# Run indexing
indexing_pipeline.run({"embedder": {"documents": docs}})
print(f"Indexed {document_store.count_documents()} documents")

RAG Query Pipeline: Retrieve + Generate

The query pipeline embeds the user question, retrieves relevant documents, and passes them to an LLM for generation.

rag_template = """
Answer the question based on the provided documents.
If the answer is not in the documents, say "I don't know."

Documents:
{% for doc in documents %}
  - {{ doc.content }}
{% endfor %}

Question: {{ question }}
Answer:
"""

# --- QUERY PIPELINE ---
query_pipeline = Pipeline()
query_pipeline.add_component("text_embedder", OpenAITextEmbedder(model="text-embedding-3-small"))
query_pipeline.add_component("retriever",     InMemoryEmbeddingRetriever(document_store=document_store, top_k=3))
query_pipeline.add_component("prompt_builder",PromptBuilder(template=rag_template))
query_pipeline.add_component("llm",           OpenAIGenerator(model="gpt-4o-mini"))

# Wire components together
query_pipeline.connect("text_embedder.embedding",  "retriever.query_embedding")
query_pipeline.connect("retriever.documents",       "prompt_builder.documents")
query_pipeline.connect("prompt_builder.prompt",     "llm.prompt")

# Run query
result = query_pipeline.run({
    "text_embedder": {"text": "How does Haystack handle retrieval?"},
    "prompt_builder": {"question": "How does Haystack handle retrieval?"}
})
print(result["llm"]["replies"][0])

Hybrid Retrieval: BM25 + Embedding + DocumentJoiner

Run sparse and dense retrieval in parallel, then merge results with Reciprocal Rank Fusion.

from haystack.components.retrievers.in_memory import (
    InMemoryBM25Retriever,
    InMemoryEmbeddingRetriever
)
from haystack.components.joiners import DocumentJoiner
from haystack.components.rankers import MetaFieldRanker

hybrid_pipeline = Pipeline()

# Add both retriever types
hybrid_pipeline.add_component("text_embedder",    OpenAITextEmbedder(model="text-embedding-3-small"))
hybrid_pipeline.add_component("bm25_retriever",   InMemoryBM25Retriever(document_store=document_store, top_k=10))
hybrid_pipeline.add_component("embed_retriever",  InMemoryEmbeddingRetriever(document_store=document_store, top_k=10))
hybrid_pipeline.add_component("joiner",           DocumentJoiner(
    join_mode="reciprocal_rank_fusion",   # merge with RRF
    top_k=5
))
hybrid_pipeline.add_component("prompt_builder",   PromptBuilder(template=rag_template))
hybrid_pipeline.add_component("llm",              OpenAIGenerator(model="gpt-4o-mini"))

# Connect: two parallel retrieval branches → joiner → LLM
hybrid_pipeline.connect("text_embedder.embedding",  "embed_retriever.query_embedding")
hybrid_pipeline.connect("bm25_retriever.documents", "joiner.documents")
hybrid_pipeline.connect("embed_retriever.documents","joiner.documents")
hybrid_pipeline.connect("joiner.documents",          "prompt_builder.documents")
hybrid_pipeline.connect("prompt_builder.prompt",     "llm.prompt")

result = hybrid_pipeline.run({
    "text_embedder":  {"text": "hybrid retrieval BM25 vector"},
    "bm25_retriever": {"query": "hybrid retrieval BM25 vector"},
    "prompt_builder": {"question": "What is hybrid retrieval?"}
})

Haystack vs LangChain vs LlamaIndex

Dimension Haystack LangChain LlamaIndex
Pipeline modelExplicit component graphLCEL pipe chainsIndex + query engines
Hybrid retrievalNative (DocumentJoiner)Manual assemblyGood
TestabilityExcellent (unit test components)GoodGood
Agent supportBasicExcellentGood
LLM integrations30+100+50+
Enterprise featuresDeepset Cloud, eval, fine-tuneLangSmithLlamaCloud
Best forEnterprise NLP, production RAGAgents, rapid prototypingComplex document RAG

Frequently Asked Questions

What is Haystack and what is it used for?▼

Haystack is an open-source NLP framework by deepset for building production-ready RAG and NLP pipelines. It uses a component-based architecture where you compose pipelines from modular, reusable Components (DocumentStore, Retriever, Reader, Embedder, LLM). Haystack is particularly strong for enterprise search, question answering systems, and RAG pipelines that need robust document preprocessing, multiple retrieval strategies, and production deployment.

What changed in Haystack 2.x?▼

Haystack 2.x (released 2024) was a major rewrite with a fundamentally new design. The old YAML-based pipeline definition and Node/Graph architecture was replaced with a Python-first, decorator-based Component system. Pipelines are now defined by connecting component inputs to outputs explicitly. The new design is more flexible, easier to debug, supports async execution, and works better with modern LLMs and RAG patterns.

What DocumentStore integrations does Haystack support?▼

Haystack integrates with most major document and vector stores: InMemoryDocumentStore (development/testing), Elasticsearch/OpenSearch (keyword + BM25), OpenSearch, FAISS (local vector search), Pinecone, Weaviate, Qdrant, Chroma, and MongoDB Atlas Vector Search. Each DocumentStore can be swapped without changing the pipeline logic — a key advantage for testing vs. production configurations.

How does Haystack handle hybrid retrieval?▼

Haystack supports hybrid retrieval by running both a BM25 (sparse) retriever and an embedding (dense) retriever in the same pipeline, then merging results with a DocumentJoiner component using reciprocal rank fusion or score normalization. This is a native first-class pattern in Haystack — you declare two parallel retrieval branches and connect both to the joiner before the LLM step.

What is Deepset Cloud?▼

Deepset Cloud (now deepset AI Platform) is the managed enterprise platform built on top of Haystack. It provides a visual pipeline editor, hosted document stores, REST API deployment, fine-tuning, evaluation workflows, and access controls. It targets enterprise teams who want Haystack capabilities without self-managing infrastructure. A free tier is available for experimentation.

Haystack vs LangChain vs LlamaIndex: which to choose?▼

Haystack is the strongest choice for enterprise NLP pipelines with strict production requirements — robust preprocessing, multiple retrieval strategies, and structured evaluation. LangChain is best for agent-heavy applications and rapid prototyping with diverse LLM integrations. LlamaIndex excels at sophisticated RAG patterns over complex document collections. Haystack's component model is the most explicit and testable of the three, which matters in enterprise settings.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

AI Hallucination Detector AI Safety Checklist Generator CrewAI Agent Config Generator AI Model Comparator Test Coverage Calculator AI Agent Memory Planner AI Model Comparison Tool Jotai Atom Explorer Embedding Storage Calculator RAG Chunk Size Optimizer LLM Cost Calculator CSS Container Query Builder LLM Context Window Calculator AI Prompt Cost Calculator LLM JSON Schema Builder AI Agent Run Cost Tracker AI Pipeline DAG Builder LLM Benchmark Calculator Prompt Injection Tester LangChain PromptTemplate Builder AI Token Cost Calculator MySQL Query Explainer PostgreSQL EXPLAIN Analyzer GraphQL Fragment Generator Jest Coverage Config Generator AI Model Benchmark Comparator Cron Expression Explainer Font Pairing Preview LLM Prompt Cost Calculator AI Model Context Window Visualizer RAG Chunking Calculator OpenAI Prompt Tester AI Rate Limit Calculator LLM System Prompt Analyzer Vibe Coding Prompt Optimizer AI IDE Comparator RAG Chunking Calculator Token Counter & Cost Estimator AI Model Comparison Table LLM Prompt Template Builder AI Commit Message Generator AI Doc Generator — Pro Tool AI Regex Explainer — Pro Tool AI System Guardian Vitest Configuration Generator Mermaid Diagram Generator Elasticsearch Query Tester mTLS Certificate Chain Builder Prompt Token Estimator JS Prototype Chain Visualizer OpenAI Token Counter System Prompt Builder Token Context Calculator LLM Prompt Caching Calculator Multi-Agent Orchestration Planner AI Prompt Token Estimator OpenAI Function Calling Generator AI Context Window Visualizer AI API Rate Limit Calculator HTTP Headers Analyzer AI Code Review — Pro Tool AI Error Explainer — Pro Tool AI SQL Builder — Pro Tool AI Unit Test Generator — Pro Tool Color Palette Generator Docker Compose Generator JWT Decoder Prompt Template Builder Regex Tester RSA Key Pair Generator SMTP Server Tester Biome Config Generator Terraform Variable Validator Haproxy Config Validator SBOM Generator AI Variable Namer AI PR Description Generator AI JSDoc Generator K8s Resource Limits Calculator Regex Flags Explainer LLM Token Counter OAuth2 Flow Visualizer Vector Embedding Visualizer Jest Testing Framework Guide Vitest Guide — Vite-native Testing Playwright E2E Testing Guide Core Web Vitals Calculator Solana Program ID Generator Multi-Chain Wallet Address Validator AI Embeddings Dimension Explorer Bezier Curve Editor Embedding Similarity Calculator TypeScript Discriminated Union Builder Core Web Vitals Budget Calculator JWT Decoder & Validator Blockchain Transaction Fee Calculator Database Query Cost Analyzer

Related Articles

Mar 27, 2026 · 13 min read

LangChain vs LlamaIndex vs Haystack: RAG Framework Comparison 2026

A practical comparison of LangChain vs LlamaIndex vs Haystack for building RAG applications in 2026. Covers retrieval-augmented generation architecture, indexing strategies, query pipelines, LLM support, and a decision framework.

Apr 2, 2026 · 13 min read

Prompt Engineering Techniques 2026: Chain-of-Thought, RAG, and Advanced Patterns

Advanced prompt engineering guide for 2026: Chain-of-Thought, Tree-of-Thought, RAG integration, few-shot learning, prompt chaining, and evaluation techniques.

Apr 1, 2026 · 13 min read

Prompt Engineering Techniques 2026: Chain-of-Thought, Few-Shot, and RAG Patterns

Master practical prompt engineering in 2026. Learn chain-of-thought prompting, few-shot examples, RAG integration patterns, and advanced techniques like tree-of-thought and self-consistency with real code examples.

Apr 1, 2026 · 12 min read

Vector Database Comparison 2026: Pinecone vs Weaviate vs Qdrant vs Chroma

In-depth comparison of the top vector databases in 2026. Evaluate Pinecone, Weaviate, Qdrant, and Chroma on performance, scalability, filtering, pricing, and self-hosting for production AI applications.

Apr 1, 2026 · 15 min read

LLM Fine-tuning Complete Guide: When to Fine-tune vs RAG vs Prompting (2026)

A practical guide to LLM fine-tuning in 2026: when fine-tuning actually makes sense, step-by-step PEFT/LoRA and QLoRA walkthrough, OpenAI fine-tuning API, cost estimates, and how to evaluate if it worked.

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →